FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/av_tx.c
Date: 2026-08-15 14:54:27
Exec Total Coverage
Lines: 19 19 100.0%
Functions: 2 2 100.0%
Branches: 49 112 43.8%

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 "libavutil/mem.h"
20 #include "libavutil/mem_internal.h"
21 #include "libavutil/tx.h"
22 #include "libavutil/error.h"
23
24 #include "checkasm.h"
25
26 #include <stdlib.h>
27
28 #define EPS 0.0005
29
30 #define SCALE_NOOP(x) (x)
31 #define SCALE_INT20(x) (av_clip64(lrintf((x) * 2147483648.0), INT32_MIN, INT32_MAX) >> 12)
32
33 #define randomize_complex(BUF, LEN, TYPE, SCALE) \
34 do { \
35 TYPE *buf = (TYPE *)BUF; \
36 for (int i = 0; i < LEN; i++) { \
37 double fre = (double)rnd() / UINT_MAX; \
38 double fim = (double)rnd() / UINT_MAX; \
39 buf[i] = (TYPE){ SCALE(fre), SCALE(fim) }; \
40 } \
41 } while (0)
42
43 static const int check_lens[] = {
44 2, 4, 8, 16, 32, 64, 120, 960, 1024, 1920, 16384,
45 };
46
47 static AVTXContext *tx_refs[AV_TX_NB][2 /* Direction */][FF_ARRAY_ELEMS(check_lens)] = { 0 };
48
49 1 void checkasm_uninit_tx(void)
50 {
51
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 times.
19 for (int i = 0; i < FF_ARRAY_ELEMS(tx_refs); i++)
52
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 18 times.
54 for (int j = 0; j < FF_ARRAY_ELEMS(*tx_refs); j++)
53
2/2
✓ Branch 0 taken 396 times.
✓ Branch 1 taken 36 times.
432 for (int k = 0; k < FF_ARRAY_ELEMS(**tx_refs); k++)
54 396 av_tx_uninit(&tx_refs[i][j][k]);
55 1 }
56
57 #define CHECK_TEMPLATE(PREFIX, TYPE, DIR, DATA_TYPE, SCALE_TYPE, LENGTHS, CHECK_EXPRESSION) \
58 do { \
59 int err; \
60 AVTXContext *tx; \
61 av_tx_fn fn; \
62 int num_checks = 0; \
63 int last_check = 0; \
64 \
65 for (int i = 0; i < FF_ARRAY_ELEMS(LENGTHS); i++) { \
66 int len = LENGTHS[i]; \
67 const SCALE_TYPE scale = 1.0 / len; \
68 \
69 if ((err = av_tx_init(&tx, &fn, TYPE, DIR, len, &scale, 0x0)) < 0) { \
70 fprintf(stderr, "av_tx: %s\n", av_err2str(err)); \
71 return; \
72 } \
73 \
74 if (check_func(fn, PREFIX "_%i", len)) { \
75 AVTXContext *tx_ref = tx_refs[TYPE][DIR][i]; \
76 if (!tx_ref) \
77 tx_ref = tx; \
78 num_checks++; \
79 last_check = len; \
80 call_ref(tx_ref, out_ref, in, sizeof(DATA_TYPE)); \
81 call_new(tx, out_new, in, sizeof(DATA_TYPE)); \
82 if (CHECK_EXPRESSION) { \
83 fail(); \
84 av_tx_uninit(&tx); \
85 break; \
86 } \
87 bench_new(tx, out_new, in, sizeof(DATA_TYPE)); \
88 av_tx_uninit(&tx_refs[TYPE][DIR][i]); \
89 tx_refs[TYPE][DIR][i] = tx; \
90 } else { \
91 av_tx_uninit(&tx); \
92 } \
93 } \
94 \
95 if (num_checks == 1) \
96 report(PREFIX "_%i", last_check); \
97 else if (num_checks) \
98 report(PREFIX); \
99 } while (0)
100
101 14 void checkasm_check_av_tx(void)
102 {
103 14 declare_func(void, AVTXContext *tx, void *out, void *in, ptrdiff_t stride);
104
105 14 void *in = av_malloc(16384*2*8);
106 14 void *out_ref = av_malloc(16384*2*8);
107 14 void *out_new = av_malloc(16384*2*8);
108
109
2/2
✓ Branch 2 taken 229376 times.
✓ Branch 3 taken 14 times.
229390 randomize_complex(in, 16384, AVComplexFloat, SCALE_NOOP);
110
14/34
✗ Branch 1 not taken.
✓ Branch 2 taken 154 times.
✓ Branch 6 taken 28 times.
✓ Branch 7 taken 126 times.
✓ Branch 8 taken 11 times.
✓ Branch 9 taken 17 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 28 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 28 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 28 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✓ Branch 92 taken 154 times.
✓ Branch 93 taken 14 times.
✓ Branch 94 taken 1 times.
✓ Branch 95 taken 13 times.
✓ Branch 97 taken 5 times.
✓ Branch 98 taken 8 times.
168 CHECK_TEMPLATE("float_fft", AV_TX_FLOAT_FFT, 0, AVComplexFloat, float, check_lens,
111 !float_near_abs_eps_array(out_ref, out_new, EPS, len*2));
112
113
13/34
✗ Branch 1 not taken.
✓ Branch 2 taken 154 times.
✓ Branch 6 taken 19 times.
✓ Branch 7 taken 135 times.
✓ Branch 8 taken 11 times.
✓ Branch 9 taken 8 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 19 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 19 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 19 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✓ Branch 92 taken 154 times.
✓ Branch 93 taken 14 times.
✗ Branch 94 not taken.
✓ Branch 95 taken 14 times.
✓ Branch 97 taken 2 times.
✓ Branch 98 taken 12 times.
168 CHECK_TEMPLATE("float_imdct", AV_TX_FLOAT_MDCT, 1, float, float, check_lens,
114 !float_near_abs_eps_array(out_ref, out_new, EPS, len));
115
116
2/2
✓ Branch 2 taken 229376 times.
✓ Branch 3 taken 14 times.
229390 randomize_complex(in, 16384, AVComplexDouble, SCALE_NOOP);
117
12/34
✗ Branch 1 not taken.
✓ Branch 2 taken 154 times.
✓ Branch 6 taken 11 times.
✓ Branch 7 taken 143 times.
✓ Branch 8 taken 11 times.
✗ Branch 9 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 11 times.
✗ Branch 20 not taken.
✓ Branch 21 taken 11 times.
✗ Branch 25 not taken.
✓ Branch 26 taken 11 times.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 65 not taken.
✗ Branch 66 not taken.
✗ Branch 67 not taken.
✗ Branch 68 not taken.
✗ Branch 69 not taken.
✗ Branch 70 not taken.
✗ Branch 71 not taken.
✗ Branch 72 not taken.
✗ Branch 75 not taken.
✗ Branch 76 not taken.
✗ Branch 78 not taken.
✗ Branch 79 not taken.
✗ Branch 83 not taken.
✗ Branch 84 not taken.
✓ Branch 92 taken 154 times.
✓ Branch 93 taken 14 times.
✗ Branch 94 not taken.
✓ Branch 95 taken 14 times.
✓ Branch 97 taken 1 times.
✓ Branch 98 taken 13 times.
168 CHECK_TEMPLATE("double_fft", AV_TX_DOUBLE_FFT, 0, AVComplexDouble, double, check_lens,
118 !double_near_abs_eps_array(out_ref, out_new, EPS, len*2));
119
120 14 av_free(in);
121 14 av_free(out_ref);
122 14 av_free(out_new);
123 }
124