FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/flacdsp.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 114 119 95.8%
Functions: 6 6 100.0%
Branches: 57 98 58.2%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2015 James Almer
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 #include "checkasm.h"
23 #include "libavcodec/flacdsp.h"
24 #include "libavcodec/mathops.h"
25 #include "libavutil/common.h"
26 #include "libavutil/internal.h"
27 #include "libavutil/intreadwrite.h"
28 #include "libavutil/mem_internal.h"
29
30 #define BUF_SIZE 256
31 #define MAX_CHANNELS 8
32
33 #define randomize_buffers() \
34 do { \
35 int i, j; \
36 for (i = 0; i < BUF_SIZE; i += 4) { \
37 for (j = 0; j < channels; j++) { \
38 uint32_t r = rnd() & (1 << (bits - 2)) - 1; \
39 AV_WN32A(ref_src[j] + i, r); \
40 AV_WN32A(new_src[j] + i, r); \
41 } \
42 } \
43 } while (0)
44
45 32 static void check_decorrelate(uint8_t **ref_dst, uint8_t **ref_src, uint8_t **new_dst, uint8_t **new_src,
46 int channels, int bits) {
47 32 declare_func(void, uint8_t **out, int32_t **in, int channels, int len, int shift);
48
49
4/4
✓ Branch 1 taken 8320 times.
✓ Branch 2 taken 2048 times.
✓ Branch 3 taken 2048 times.
✓ Branch 4 taken 32 times.
10400 randomize_buffers();
50 32 call_ref(ref_dst, (int32_t **)ref_src, channels, BUF_SIZE / sizeof(int32_t), 8);
51 32 call_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8);
52
3/4
✓ Branch 0 taken 15 times.
✓ Branch 1 taken 17 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
32 if (memcmp(*ref_dst, *new_dst, bits == 16 ? BUF_SIZE * (channels/2) : BUF_SIZE * channels) ||
53
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32 times.
32 memcmp(*ref_src, *new_src, BUF_SIZE * channels))
54 fail();
55
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 32 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.
32 bench_new(new_dst, (int32_t **)new_src, channels, BUF_SIZE / sizeof(int32_t), 8);
56 32 }
57
58 16 static void check_lpc(int pred_order, int bps)
59 {
60 16 int qlevel = rnd() % 16;
61 16 int coeff_prec = (rnd() % 15) + 1;
62 16 LOCAL_ALIGNED_16(int32_t, coeffs, [32]);
63 16 LOCAL_ALIGNED_16(int32_t, dst, [BUF_SIZE]);
64 16 LOCAL_ALIGNED_16(int32_t, dst0, [BUF_SIZE]);
65 16 LOCAL_ALIGNED_16(int32_t, dst1, [BUF_SIZE]);
66
67 16 declare_func(void, int32_t *, const int[32], int, int, int);
68
69
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 if (bps <= 16)
70 8 coeff_prec = av_clip(coeff_prec, 0, 32 - bps - av_log2(pred_order));
71
72
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 16 times.
528 for (int i = 0; i < 32; i++)
73 512 coeffs[i] = sign_extend(rnd(), coeff_prec);
74
2/2
✓ Branch 0 taken 4096 times.
✓ Branch 1 taken 16 times.
4112 for (int i = 0; i < BUF_SIZE; i++)
75 4096 dst[i] = sign_extend(rnd(), bps);
76
77 16 memcpy(dst0, dst, BUF_SIZE * sizeof (int32_t));
78 16 memcpy(dst1, dst, BUF_SIZE * sizeof (int32_t));
79 16 call_ref(dst0, coeffs, pred_order, qlevel, BUF_SIZE);
80 16 call_new(dst1, coeffs, pred_order, qlevel, BUF_SIZE);
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int32_t)) != 0)
82 fail();
83
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 16 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.
16 bench_new(dst, coeffs, pred_order, qlevel, BUF_SIZE);
84 16 }
85
86 4 static void check_lpc33(int pred_order)
87 {
88 4 int qlevel = rnd() % 16;
89 4 int coeff_prec = (rnd() % 15) + 1;
90 4 LOCAL_ALIGNED_16(int64_t, dst, [BUF_SIZE]);
91 4 LOCAL_ALIGNED_16(int64_t, dst0, [BUF_SIZE]);
92 4 LOCAL_ALIGNED_16(int64_t, dst1, [BUF_SIZE]);
93 4 LOCAL_ALIGNED_16(int32_t, residuals, [BUF_SIZE]);
94 4 LOCAL_ALIGNED_16(int32_t, coeffs, [32]);
95
96 4 declare_func(void, int64_t *, const int32_t *, const int[32], int, int, int);
97
98
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 4 times.
132 for (int i = 0; i < 32; i++)
99 128 coeffs[i] = sign_extend(rnd(), coeff_prec);
100
101
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 4 times.
1028 for (int i = 0; i < BUF_SIZE; i++) {
102 1024 residuals[i] = sign_extend(rnd(), pred_order);
103 1024 dst[i] = sign_extend64(((int64_t)rnd() << 1) | (rnd() & 1), 33);
104 }
105
106 4 memcpy(dst0, dst, BUF_SIZE * sizeof (int64_t));
107 4 memcpy(dst1, dst, BUF_SIZE * sizeof (int64_t));
108 4 call_ref(dst0, residuals, coeffs, pred_order, qlevel, BUF_SIZE);
109 4 call_new(dst1, residuals, coeffs, pred_order, qlevel, BUF_SIZE);
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int64_t)) != 0)
111 fail();
112
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 4 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.
4 bench_new(dst, residuals, coeffs, pred_order, qlevel, BUF_SIZE);
113 4 }
114
115 2 static void check_wasted32(void)
116 {
117 2 int wasted = rnd() % 32;
118 2 LOCAL_ALIGNED_16(int32_t, dst, [BUF_SIZE]);
119 2 LOCAL_ALIGNED_16(int32_t, dst0, [BUF_SIZE]);
120 2 LOCAL_ALIGNED_16(int32_t, dst1, [BUF_SIZE]);
121
122 2 declare_func(void, int32_t *, int, int);
123
124
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 2 times.
514 for (int i = 0; i < BUF_SIZE; i++)
125 512 dst[i] = rnd();
126
127 2 memcpy(dst0, dst, BUF_SIZE * sizeof (int32_t));
128 2 memcpy(dst1, dst, BUF_SIZE * sizeof (int32_t));
129 2 call_ref(dst0, wasted, BUF_SIZE);
130 2 call_new(dst1, wasted, BUF_SIZE);
131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int32_t)) != 0)
132 fail();
133
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(dst, wasted, BUF_SIZE);
134 2 }
135
136 2 static void check_wasted33(void)
137 {
138 2 int wasted = rnd() % 33;
139 2 LOCAL_ALIGNED_16(int64_t, dst0, [BUF_SIZE]);
140 2 LOCAL_ALIGNED_16(int64_t, dst1, [BUF_SIZE]);
141 2 LOCAL_ALIGNED_16(int32_t, residuals, [BUF_SIZE]);
142
143 2 declare_func(void, int64_t *, const int32_t *, int, int);
144
145
2/2
✓ Branch 0 taken 512 times.
✓ Branch 1 taken 2 times.
514 for (int i = 0; i < BUF_SIZE; i++)
146 512 residuals[i] = rnd();
147
148 2 call_ref(dst0, residuals, wasted, BUF_SIZE);
149 2 call_new(dst1, residuals, wasted, BUF_SIZE);
150
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (memcmp(dst0, dst1, BUF_SIZE * sizeof (int64_t)) != 0)
151 fail();
152
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(dst0, residuals, wasted, BUF_SIZE);
153 2 }
154
155 13 void checkasm_check_flacdsp(void)
156 {
157 13 LOCAL_ALIGNED_16(uint8_t, ref_dst, [BUF_SIZE*MAX_CHANNELS]);
158 13 LOCAL_ALIGNED_16(uint8_t, ref_buf, [BUF_SIZE*MAX_CHANNELS]);
159 13 LOCAL_ALIGNED_16(uint8_t, new_dst, [BUF_SIZE*MAX_CHANNELS]);
160 13 LOCAL_ALIGNED_16(uint8_t, new_buf, [BUF_SIZE*MAX_CHANNELS]);
161 13 uint8_t *ref_src[] = { &ref_buf[BUF_SIZE*0], &ref_buf[BUF_SIZE*1], &ref_buf[BUF_SIZE*2], &ref_buf[BUF_SIZE*3],
162 13 &ref_buf[BUF_SIZE*4], &ref_buf[BUF_SIZE*5], &ref_buf[BUF_SIZE*6], &ref_buf[BUF_SIZE*7] };
163 13 uint8_t *new_src[] = { &new_buf[BUF_SIZE*0], &new_buf[BUF_SIZE*1], &new_buf[BUF_SIZE*2], &new_buf[BUF_SIZE*3],
164 13 &new_buf[BUF_SIZE*4], &new_buf[BUF_SIZE*5], &new_buf[BUF_SIZE*6], &new_buf[BUF_SIZE*7] };
165 static const char * const names[3] = { "ls", "rs", "ms" };
166 static const struct {
167 enum AVSampleFormat fmt;
168 int bits;
169 } fmts[] = {
170 { AV_SAMPLE_FMT_S16, 16 },
171 { AV_SAMPLE_FMT_S32, 32 },
172 };
173 static const signed char pred_orders[] = { 13, 16, 29, 32 };
174 FLACDSPContext h;
175 int i, j;
176
177
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 13 times.
39 for (i = 0; i < 2; i++) {
178 26 ff_flacdsp_init(&h, fmts[i].fmt, 2);
179
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 26 times.
104 for (j = 0; j < 3; j++)
180
2/2
✓ Branch 3 taken 12 times.
✓ Branch 4 taken 66 times.
78 if (check_func(h.decorrelate[j + 1], "flac_decorrelate_%s_%d", names[j], fmts[i].bits))
181 12 check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, 2, fmts[i].bits);
182
2/2
✓ Branch 0 taken 104 times.
✓ Branch 1 taken 26 times.
130 for (j = 2; j <= MAX_CHANNELS; j += 2) {
183 104 ff_flacdsp_init(&h, fmts[i].fmt, j);
184
2/2
✓ Branch 3 taken 20 times.
✓ Branch 4 taken 84 times.
104 if (check_func(h.decorrelate[0], "flac_decorrelate_indep%d_%d", j, fmts[i].bits))
185 20 check_decorrelate(&ref_dst, ref_src, &new_dst, new_src, j, fmts[i].bits);
186 }
187 }
188
189 13 report("decorrelate");
190
191
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 13 times.
65 for (i = 0; i < FF_ARRAY_ELEMS(pred_orders); i++)
192
2/2
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 44 times.
52 if (check_func(h.lpc16, "flac_lpc_16_%d", pred_orders[i]))
193 8 check_lpc(pred_orders[i], 16);
194
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 13 times.
65 for (i = 0; i < FF_ARRAY_ELEMS(pred_orders); i++)
195
2/2
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 44 times.
52 if (check_func(h.lpc32, "flac_lpc_32_%d", pred_orders[i]))
196 8 check_lpc(pred_orders[i], 32);
197
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 13 times.
65 for (i = 0; i < FF_ARRAY_ELEMS(pred_orders); i++)
198
2/2
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 48 times.
52 if (check_func(h.lpc33, "flac_lpc_33_%d", pred_orders[i]))
199 4 check_lpc33(pred_orders[i]);
200
201 13 report("lpc");
202
203
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(h.wasted32, "flac_wasted_32"))
204 2 check_wasted32();
205
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(h.wasted33, "flac_wasted_33"))
206 2 check_wasted33();
207
208 13 report("wasted");
209 13 }
210