FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/llvidencdsp.c
Date: 2026-05-03 08:24:11
Exec Total Coverage
Lines: 62 65 95.4%
Functions: 4 4 100.0%
Branches: 35 64 54.7%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2016 Alexandra Hájková
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include <string.h>
22
23 #include "libavutil/common.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem_internal.h"
26
27 #include "libavcodec/lossless_videoencdsp.h"
28
29 #include "checkasm.h"
30
31 #define randomize_buffers(buf, size) \
32 do { \
33 for (size_t j = 0; j < (size & ~3); j += 4) \
34 AV_WN32(buf + j, rnd()); \
35 for (size_t j = size & ~3; j < size; ++j) \
36 buf[j] = rnd(); \
37 } while (0)
38
39 static const struct {uint8_t w, h, s;} planes[] = {
40 {16,16,16}, {21,23,25}, {32,17,48}, {15,128,16}, {128,127,128}
41 };
42
43 #define MAX_STRIDE 128
44 #define MAX_HEIGHT 127
45
46 14 static void check_diff_bytes(LLVidEncDSPContext *c)
47 {
48 int i;
49 14 LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE]);
50 14 LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE]);
51 14 LOCAL_ALIGNED_32(uint8_t, src0, [MAX_STRIDE]);
52 14 LOCAL_ALIGNED_32(uint8_t, src1, [MAX_STRIDE]);
53 14 LOCAL_ALIGNED_32(uint8_t, src2, [MAX_STRIDE]);
54 14 LOCAL_ALIGNED_32(uint8_t, src3, [MAX_STRIDE]);
55
56 14 declare_func(void, uint8_t *dst, const uint8_t *src1,
57 const uint8_t *src2, intptr_t w);
58
59 14 memset(dst0, 0, MAX_STRIDE);
60 14 memset(dst1, 0, MAX_STRIDE);
61
3/4
✓ Branch 1 taken 448 times.
✓ Branch 2 taken 14 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 14 times.
462 randomize_buffers(src0, MAX_STRIDE);
62 14 memcpy(src1, src0, MAX_STRIDE);
63
3/4
✓ Branch 1 taken 448 times.
✓ Branch 2 taken 14 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 14 times.
462 randomize_buffers(src2, MAX_STRIDE);
64 14 memcpy(src3, src2, MAX_STRIDE);
65
66
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 11 times.
14 if (check_func(c->diff_bytes, "diff_bytes")) {
67
2/2
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 3 times.
18 for (i = 0; i < 5; i ++) {
68 15 call_ref(dst0, src0, src2, planes[i].w);
69 15 call_new(dst1, src1, src3, planes[i].w);
70
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 15 times.
15 if (memcmp(dst0, dst1, planes[i].w))
71 fail();
72 }
73
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
3 bench_new(dst1, src0, src2, planes[4].w);
74 }
75 14 }
76
77 14 static void check_sub_median_pred(LLVidEncDSPContext *c)
78 {
79 enum {
80 BUF_SIZE = MAX_STRIDE + 15 /* to test misalignment */
81 };
82 uint8_t dst_ref[BUF_SIZE], dst_new[BUF_SIZE];
83 uint8_t src1[BUF_SIZE], src2[BUF_SIZE];
84
85 14 declare_func(void, uint8_t *dst, const uint8_t *src1,
86 const uint8_t *src2, intptr_t w,
87 int *left, int *left_top);
88
89
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 12 times.
14 if (check_func(c->sub_median_pred, "sub_median_pred")) {
90 2 size_t width = 1 + rnd() % MAX_STRIDE;
91 2 size_t offset = rnd() & 0xF;
92 2 int left_ref = rnd() & 0xFF, top_ref = rnd() & 0xFF;
93 2 int left_new = left_ref, top_new = top_ref;
94
95 2 memset(dst_ref, 0, sizeof(dst_ref));
96 2 memset(dst_new, 0, sizeof(dst_new));
97
98
4/4
✓ Branch 1 taken 70 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 2 times.
78 randomize_buffers(src1, sizeof(src1));
99
4/4
✓ Branch 1 taken 70 times.
✓ Branch 2 taken 2 times.
✓ Branch 4 taken 6 times.
✓ Branch 5 taken 2 times.
78 randomize_buffers(src2, sizeof(src2));
100
101 2 call_ref(dst_ref + offset, src1 + offset, src2 + offset, width, &left_ref, &top_ref);
102 2 call_new(dst_new + offset, src1 + offset, src2 + offset, width, &left_new, &top_new);
103
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 if (left_new != left_ref || top_ref != top_new ||
104
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 memcmp(dst_ref, dst_new, width + offset))
105 fail();
106
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
2 bench_new(dst_new, src1, src2, MAX_STRIDE, &left_new, &top_new);
107 }
108 14 }
109
110 14 static void check_sub_left_pred(LLVidEncDSPContext *c)
111 {
112 14 LOCAL_ALIGNED_32(uint8_t, dst0, [MAX_STRIDE * MAX_HEIGHT]);
113 14 LOCAL_ALIGNED_32(uint8_t, dst1, [MAX_STRIDE * MAX_HEIGHT]);
114 14 LOCAL_ALIGNED_32(uint8_t, src, [MAX_STRIDE * MAX_HEIGHT]);
115
116 14 declare_func(void, uint8_t *dst, const uint8_t *src,
117 ptrdiff_t stride, ptrdiff_t width, int height);
118
119
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 12 times.
14 if (check_func(c->sub_left_predict, "sub_left_predict")) {
120
3/4
✓ Branch 1 taken 8128 times.
✓ Branch 2 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
8130 randomize_buffers(src, MAX_STRIDE * MAX_HEIGHT);
121
122
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2 times.
12 for (size_t i = 0; i < FF_ARRAY_ELEMS(planes); i ++) {
123 10 memset(dst0, 0, MAX_STRIDE * MAX_HEIGHT);
124 10 memset(dst1, 0, MAX_STRIDE * MAX_HEIGHT);
125 10 call_ref(dst0, src, planes[i].s, planes[i].w, planes[i].h);
126 10 call_new(dst1, src, planes[i].s, planes[i].w, planes[i].h);
127
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if (memcmp(dst0, dst1, planes[i].w * planes[i].h))
128 fail();
129 }
130
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
2 bench_new(dst1, src, planes[4].s, planes[4].w, planes[4].h);
131 }
132 14 }
133
134 14 void checkasm_check_llvidencdsp(void)
135 {
136 LLVidEncDSPContext c;
137 14 ff_llvidencdsp_init(&c);
138
139 14 check_diff_bytes(&c);
140 14 report("diff_bytes");
141
142 14 check_sub_median_pred(&c);
143 14 report("sub_median_pred");
144
145 14 check_sub_left_pred(&c);
146 14 report("sub_left_predict");
147 14 }
148