FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/sbcdsp.c
Date: 2026-09-11 00:35:37
Exec Total Coverage
Lines: 42 44 95.5%
Functions: 3 3 100.0%
Branches: 42 84 50.0%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 #include <stddef.h>
20 #include <stdint.h>
21 #include <string.h>
22
23 #include "checkasm.h"
24 #include "libavcodec/sbcdsp.h"
25 #include "libavcodec/sbcdsp_data.h"
26 #include "libavutil/macros.h"
27 #include "libavutil/mem_internal.h"
28
29 enum {
30 SBC_MAX_SUBBANDS = 8,
31 };
32
33 #define randomize_buffer(buf) \
34 do { \
35 for (size_t k = 0; k < FF_ARRAY_ELEMS(buf); ++k) \
36 buf[k] = rnd(); \
37 } while (0)
38
39 14 static void check_sbc_analyze(SBCDSPContext *sbcdsp)
40 {
41 DECLARE_ALIGNED(SBC_ALIGN, int16_t, in)[10 * SBC_MAX_SUBBANDS];
42 DECLARE_ALIGNED(SBC_ALIGN, int32_t, out_ref)[SBC_MAX_SUBBANDS];
43 DECLARE_ALIGNED(SBC_ALIGN, int32_t, out_new)[SBC_MAX_SUBBANDS];
44
45 14 declare_func(void, const int16_t *in, int32_t *out, const int16_t *consts);
46
47
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14 times.
42 for (int i = 0; i < 2; ++i) {
48
6/6
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 14 times.
✓ Branch 2 taken 14 times.
✓ Branch 3 taken 14 times.
✓ Branch 5 taken 4 times.
✓ Branch 6 taken 24 times.
28 if (check_func(i ? sbcdsp->sbc_analyze_8 : sbcdsp->sbc_analyze_4, "sbc_analyze_%u", i ? 8 : 4)) {
49
2/2
✓ Branch 1 taken 320 times.
✓ Branch 2 taken 4 times.
324 randomize_buffer(in);
50
2/2
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 4 times.
36 randomize_buffer(out_ref);
51 4 memcpy(out_new, out_ref, sizeof(out_new));
52
53 // the input is always 16-byte aligned for sbc_analyze_8
54 // for sbc_analyze_4 it can be 0 or 8 mod 16.
55
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
4 const int16_t *const inp = i || rnd() & 1 ? in : in + 4;
56 // Use the proper const tables as random ones can cause overflow
57 #define A_CONST(SIZE, ODDEVEN) sbcdsp_analysis_consts_fixed ## SIZE ## _simd_ ## ODDEVEN
58
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 2 times.
6 const int16_t *const consts = rnd() & 1 ? (i ? A_CONST(8, odd) : A_CONST(4, odd))
59
3/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
6 : (i ? A_CONST(8, even) : A_CONST(4, even));
60
61
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
4 call_ref(inp, out_ref, consts);
62 4 call_new(inp, out_new, consts);
63
64
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if (memcmp(out_ref, out_new, sizeof(out_new)))
65 fail();
66
67
1/18
✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
4 bench_new(inp, out_new, consts);
68 }
69 }
70 14 report("sbc_analyze");
71 14 }
72
73 14 static void check_sbc_calc_scalefactors(const SBCDSPContext *const sbcdsp, int blocks)
74 {
75 DECLARE_ALIGNED(SBC_ALIGN, int32_t, sb_sample_f)[16][2][8];
76 DECLARE_ALIGNED(SBC_ALIGN, uint32_t, scale_factor_ref)[2][8];
77 DECLARE_ALIGNED(SBC_ALIGN, uint32_t, scale_factor_new)[2][8];
78
79 14 declare_func(void, const int32_t sb_sample_f[16][2][8],
80 uint32_t scale_factor[2][8],
81 int blocks, int channels, int subbands);
82
83 14 int inited = 0;
84
85
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 2 times.
18 for (int ch = 1; ch <= 2; ++ch) {
86
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 4 times.
24 for (int subbands = 4; subbands <= 8; subbands += 4) {
87
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 8 times.
20 if (!check_func(sbcdsp->sbc_calc_scalefactors, "calc_scalefactors_%dch_%dsubbands", ch, subbands))
88 12 return;
89
90
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!inited) {
91
2/2
✓ Branch 0 taken 128 times.
✓ Branch 1 taken 8 times.
136 for (size_t i = 0; i < FF_ARRAY_ELEMS(sb_sample_f); ++i)
92
2/2
✓ Branch 0 taken 256 times.
✓ Branch 1 taken 128 times.
384 for (size_t j = 0; j < FF_ARRAY_ELEMS(sb_sample_f[0]); ++j)
93
2/2
✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 256 times.
2304 for (size_t k = 0; k < FF_ARRAY_ELEMS(sb_sample_f[0][0]); ++k)
94 2048 sb_sample_f[i][j][k] = rnd();
95 }
96
97
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 call_ref(sb_sample_f, scale_factor_ref, blocks, ch, subbands);
98 8 call_new(sb_sample_f, scale_factor_new, blocks, ch, subbands);
99
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
20 for (int i = 0; i < ch; ++i)
100
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 12 times.
84 for (int j = 0; j < subbands; ++j)
101
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if (scale_factor_ref[i][j] != scale_factor_new[i][j])
102 fail();
103
104
1/18
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
✗ Branch 48 not taken.
✗ Branch 51 not taken.
✗ Branch 52 not taken.
✗ Branch 54 not taken.
✗ Branch 55 not taken.
✗ Branch 59 not taken.
✗ Branch 60 not taken.
8 bench_new(sb_sample_f, scale_factor_new, blocks, ch, subbands);
105 }
106 }
107 }
108
109 14 void checkasm_check_sbcdsp(void)
110 {
111 14 SBCDSPContext sbcdsp = { 0 };
112 14 int blocks = ((const int[]){4, 8, 12, 15, 16})[rnd() % 5];
113
114 14 ff_sbcdsp_init(&sbcdsp);
115
116 14 check_sbc_analyze(&sbcdsp);
117
118 14 check_sbc_calc_scalefactors(&sbcdsp, blocks);
119 14 report("calc_scalefactors");
120 14 }
121