FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/llviddsp.c
Date: 2024-05-03 05:27:13
Exec Total Coverage
Lines: 115 123 93.5%
Functions: 6 6 100.0%
Branches: 55 118 46.6%

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