FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/llviddsp.c
Date: 2026-04-23 02:20:26
Exec Total Coverage
Lines: 116 124 93.5%
Functions: 6 6 100.0%
Branches: 59 122 48.4%

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.h"
26
27 #include "libavcodec/lossless_videodsp.h"
28
29 #include "checkasm.h"
30
31 #define randomize_buffers(buf, size) \
32 do { \
33 int j; \
34 uint8_t *tmp_buf = (uint8_t *)buf;\
35 for (j = 0; j < size; j++) \
36 tmp_buf[j] = rnd() & 0xFF; \
37 } while (0)
38
39 #define init_buffer(a0, a1, type, width)\
40 if (!a0 || !a1)\
41 fail();\
42 randomize_buffers(a0, width * sizeof(type));\
43 memcpy(a1, a0, width*sizeof(type));\
44
45 3 static void check_add_bytes(LLVidDSPContext *c, int width)
46 {
47 3 uint8_t *dst0 = av_mallocz(width);
48 3 uint8_t *dst1 = av_mallocz(width);
49 3 uint8_t *src0 = av_calloc(width, sizeof(*src0));
50 3 uint8_t *src1 = av_calloc(width, sizeof(*src1));
51 3 declare_func(void, uint8_t *dst, uint8_t *src, ptrdiff_t w);
52
53
4/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 7 taken 768 times.
✓ Branch 8 taken 3 times.
771 init_buffer(src0, src1, uint8_t, width);
54
55
2/4
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
3 if (!dst0 || !dst1)
56 fail();
57
58
59 3 call_ref(dst0, src0, width);
60 3 call_new(dst1, src1, width);
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (memcmp(dst0, dst1, width))
62 fail();
63
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, src1, width);
64
65 3 av_free(src0);
66 3 av_free(src1);
67 3 av_free(dst0);
68 3 av_free(dst1);
69 3 }
70
71 2 static void check_add_median_pred(LLVidDSPContext *c, int width) {
72 int a0, a1, b0, b1;
73 2 uint8_t *dst0 = av_mallocz(width);
74 2 uint8_t *dst1 = av_mallocz(width);
75 2 uint8_t *src0 = av_calloc(width, sizeof(*src0));
76 2 uint8_t *src1 = av_calloc(width, sizeof(*src1));
77 2 uint8_t *diff0 = av_calloc(width, sizeof(*diff0));
78 2 uint8_t *diff1 = av_calloc(width, sizeof(*diff1));
79 2 declare_func(void, uint8_t *dst, const uint8_t *src1,
80 const uint8_t *diff, ptrdiff_t w,
81 int *left, int *left_top);
82
83
4/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 7 taken 512 times.
✓ Branch 8 taken 2 times.
514 init_buffer(src0, src1, uint8_t, width);
84
4/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 7 taken 512 times.
✓ Branch 8 taken 2 times.
514 init_buffer(diff0, diff1, uint8_t, width);
85
86 2 a0 = rnd() & 0xFF;
87 2 b0 = rnd() & 0xFF;
88 2 a1 = a0;
89 2 b1 = b0;
90
91
92 2 call_ref(dst0, src0, diff0, width, &a0, &b0);
93 2 call_new(dst1, src1, diff1, width, &a1, &b1);
94
3/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
2 if (memcmp(dst0, dst1, width) || (a0 != a1) || (b0 != b1))
95 fail();
96
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, src1, diff1, width, &a1, &b1);
97
98 2 av_free(src0);
99 2 av_free(src1);
100 2 av_free(diff0);
101 2 av_free(diff1);
102 2 av_free(dst0);
103 2 av_free(dst1);
104 2 }
105
106 6 static void check_add_left_pred(LLVidDSPContext *c, int width, int acc)
107 {
108 int res0, res1;
109 6 uint8_t *dst0 = av_mallocz(width);
110 6 uint8_t *dst1 = av_mallocz(width);
111 6 uint8_t *src0 = av_calloc(width, sizeof(*src0));
112 6 uint8_t *src1 = av_calloc(width, sizeof(*src1));
113 6 declare_func(int, uint8_t *dst, const uint8_t *src, ptrdiff_t w, int acc);
114
115
4/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 7 taken 1536 times.
✓ Branch 8 taken 6 times.
1542 init_buffer(src0, src1, uint8_t, width);
116
117
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if (!dst0 || !dst1)
118 fail();
119
120 6 res0 = call_ref(dst0, src0, width, acc);
121 6 res1 = call_new(dst1, src1, width, acc);
122
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if ((res0 & 0xFF) != (res1 & 0xFF) || memcmp(dst0, dst1, width))
123 fail();
124
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 6 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.
6 bench_new(dst1, src1, width, acc);
125
126 6 av_free(src0);
127 6 av_free(src1);
128 6 av_free(dst0);
129 6 av_free(dst1);
130 6 }
131
132 2 static void check_add_left_pred_16(LLVidDSPContext *c, unsigned mask, int width, unsigned acc)
133 {
134 int res0, res1;
135 2 uint16_t *dst0 = av_calloc(width, sizeof(*dst0));
136 2 uint16_t *dst1 = av_calloc(width, sizeof(*dst1));
137 2 uint16_t *src0 = av_calloc(width, sizeof(*src0));
138 2 uint16_t *src1 = av_calloc(width, sizeof(*src1));
139 2 declare_func(int, uint16_t *dst, const uint16_t *src, unsigned mask, ptrdiff_t w, unsigned acc);
140
141
4/6
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✓ Branch 7 taken 1024 times.
✓ Branch 8 taken 2 times.
1026 init_buffer(src0, src1, uint16_t, width);
142
143
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if (!dst0 || !dst1)
144 fail();
145
146 2 res0 = call_ref(dst0, src0, mask, width, acc);
147 2 res1 = call_new(dst1, src1, mask, width, acc);
148
2/4
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
2 if ((res0 &0xFFFF) != (res1 &0xFFFF)|| memcmp(dst0, dst1, width))
149 fail();
150
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, src1, mask, width, acc);
151
152 2 av_free(src0);
153 2 av_free(src1);
154 2 av_free(dst0);
155 2 av_free(dst1);
156 2 }
157
158 3 static void check_add_gradient_pred(LLVidDSPContext *c, int w) {
159 int src_size, stride;
160 uint8_t *src0, *src1;
161 3 declare_func(void, uint8_t *src, const ptrdiff_t stride,
162 const ptrdiff_t width);
163
164 3 stride = w + 32;
165 3 src_size = (stride + 32) * 2; /* dsp need previous line, and ignore the start of the line */
166 3 src0 = av_mallocz(src_size);
167 3 src1 = av_mallocz(src_size);
168
169
4/6
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✓ Branch 7 taken 1920 times.
✓ Branch 8 taken 3 times.
1923 init_buffer(src0, src1, uint8_t, src_size);
170
171 3 call_ref(src0 + stride + 32, stride, w);
172 3 call_new(src1 + stride + 32, stride, w);
173
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (memcmp(src0, src1, stride)||/* previous line doesn't change */
174
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 memcmp(src0+stride, src1 + stride, w + 32)) {
175 fail();
176 }
177
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(src1 + stride + 32, stride, w);
178
179 3 av_free(src0);
180 3 av_free(src1);
181 3 }
182
183 14 void checkasm_check_llviddsp(void)
184 {
185 LLVidDSPContext c;
186 static int saved_width = 0;
187 14 int width = saved_width;
188 14 int accRnd = rnd() & 0xFF;
189
190
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 13 times.
14 if (!width)
191 1 saved_width = width = 16 * av_clip(rnd(), 16, 128);
192
193 14 ff_llviddsp_init(&c);
194
195
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 11 times.
14 if (check_func(c.add_bytes, "add_bytes"))
196 3 check_add_bytes(&c, width);
197 14 report("add_bytes");
198
199
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 12 times.
14 if (check_func(c.add_median_pred, "add_median_pred"))
200 2 check_add_median_pred(&c, width);
201 14 report("add_median_pred");
202
203
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 11 times.
14 if (check_func(c.add_left_pred, "add_left_pred_zero"))
204 3 check_add_left_pred(&c, width, 0);
205 14 report("add_left_pred_zero");
206
207
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 11 times.
14 if (check_func(c.add_left_pred, "add_left_pred_rnd_acc"))
208 3 check_add_left_pred(&c, width, accRnd);
209 14 report("add_left_pred_rnd_acc");
210
211
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 12 times.
14 if (check_func(c.add_left_pred_int16, "add_left_pred_int16"))
212 2 check_add_left_pred_16(&c, 255, width, accRnd);
213 14 report("add_left_pred_int16");
214
215
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 11 times.
14 if (check_func(c.add_gradient_pred, "add_gradient_pred"))
216 3 check_add_gradient_pred(&c, width);
217 14 report("add_gradient_pred");
218 14 }
219