FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/audiodsp.c
Date: 2024-05-03 15:42:48
Exec Total Coverage
Lines: 54 57 94.7%
Functions: 1 1 100.0%
Branches: 28 54 51.9%

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 <math.h>
20 #include <string.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23
24 #include "libavcodec/audiodsp.h"
25
26 #include "libavutil/common.h"
27 #include "libavutil/intreadwrite.h"
28 #include "libavutil/mem_internal.h"
29
30 #include "checkasm.h"
31
32 #define MAX_SIZE (32 * 128)
33
34 #define randomize_float(buf, len) \
35 do { \
36 int i; \
37 for (i = 0; i < len; i++) { \
38 float f = (float)rnd() / (UINT_MAX >> 5) - 16.0f; \
39 buf[i] = f; \
40 } \
41 } while (0)
42
43 #define randomize_int(buf, len, size, bits) \
44 do { \
45 int i; \
46 for (i = 0; i < len; i++) { \
47 uint ## size ## _t r = rnd() & ((1LL << bits) - 1); \
48 AV_WN ## size ## A(buf + i, -(1LL << (bits - 1)) + r); \
49 } \
50 } while (0)
51
52 13 void checkasm_check_audiodsp(void)
53 {
54 AudioDSPContext adsp;
55
56 13 ff_audiodsp_init(&adsp);
57
58
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 10 times.
13 if (check_func(adsp.scalarproduct_int16, "audiodsp.scalarproduct_int16")) {
59 3 LOCAL_ALIGNED(32, int16_t, v1, [MAX_SIZE]);
60 3 LOCAL_ALIGNED(32, int16_t, v2, [MAX_SIZE]);
61 unsigned int len_bits_minus4, v1_bits, v2_bits, len;
62 int32_t res0, res1;
63
64 3 declare_func(int32_t, const int16_t *v1, const int16_t *v2, int len);
65
66 // generate random 5-12bit vector length
67 3 len_bits_minus4 = rnd() % 8;
68 3 len = rnd() & ((1 << len_bits_minus4) - 1);
69 3 len = 16 * FFMAX(len, 1);
70
71 // generate the bit counts for each of the vectors such that the result
72 // fits into int32
73 3 v1_bits = 1 + rnd() % 15;
74 3 v2_bits = FFMIN(32 - (len_bits_minus4 + 4) - v1_bits - 1, 15);
75
76
2/2
✓ Branch 1 taken 12288 times.
✓ Branch 2 taken 3 times.
12291 randomize_int(v1, MAX_SIZE, 16, v1_bits + 1);
77
2/2
✓ Branch 1 taken 12288 times.
✓ Branch 2 taken 3 times.
12291 randomize_int(v2, MAX_SIZE, 16, v2_bits + 1);
78
79 3 res0 = call_ref(v1, v2, len);
80 3 res1 = call_new(v1, v2, len);
81
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (res0 != res1)
82 fail();
83
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(v1, v2, MAX_SIZE);
84 }
85
86
2/2
✓ Branch 3 taken 3 times.
✓ Branch 4 taken 10 times.
13 if (check_func(adsp.vector_clip_int32, "audiodsp.vector_clip_int32")) {
87 3 LOCAL_ALIGNED(32, int32_t, src, [MAX_SIZE]);
88 3 LOCAL_ALIGNED(32, int32_t, dst0, [MAX_SIZE]);
89 3 LOCAL_ALIGNED(32, int32_t, dst1, [MAX_SIZE]);
90 int32_t val1, val2, min, max;
91 int len;
92
93 3 declare_func(void, int32_t *dst, const int32_t *src,
94 int32_t min, int32_t max, unsigned int len);
95
96 3 val1 = ((int32_t)rnd());
97
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 val1 = FFSIGN(val1) * (val1 & ((1 << 24) - 1));
98 3 val2 = ((int32_t)rnd());
99
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 val2 = FFSIGN(val2) * (val2 & ((1 << 24) - 1));
100
101 3 min = FFMIN(val1, val2);
102 3 max = FFMAX(val1, val2);
103
104
2/2
✓ Branch 1 taken 12288 times.
✓ Branch 2 taken 3 times.
12291 randomize_int(src, MAX_SIZE, 32, 32);
105
106 3 len = rnd() % 128;
107 3 len = 32 * FFMAX(len, 1);
108
109 3 call_ref(dst0, src, min, max, len);
110 3 call_new(dst1, src, min, max, len);
111
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (memcmp(dst0, dst1, len * sizeof(*dst0)))
112 fail();
113
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, src, min, max, MAX_SIZE);
114 }
115
116
2/2
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 11 times.
13 if (check_func(adsp.vector_clipf, "audiodsp.vector_clipf")) {
117 2 LOCAL_ALIGNED(32, float, src, [MAX_SIZE]);
118 2 LOCAL_ALIGNED(32, float, dst0, [MAX_SIZE]);
119 2 LOCAL_ALIGNED(32, float, dst1, [MAX_SIZE]);
120 float val1, val2, min, max;
121 int i, len;
122
123 2 declare_func(void, float *dst, const float *src,
124 int len, float min, float max);
125
126 2 val1 = (float)rnd() / (UINT_MAX >> 1) - 1.0f;
127 2 val2 = (float)rnd() / (UINT_MAX >> 1) - 1.0f;
128
129
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 min = FFMIN(val1, val2);
130
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 max = FFMAX(val1, val2);
131
132
2/2
✓ Branch 1 taken 8192 times.
✓ Branch 2 taken 2 times.
8194 randomize_float(src, MAX_SIZE);
133
134 2 len = rnd() % 128;
135 2 len = 16 * FFMAX(len, 1);
136
137 2 call_ref(dst0, src, len, min, max);
138 2 call_new(dst1, src, len, min, max);
139
2/2
✓ Branch 0 taken 3456 times.
✓ Branch 1 taken 2 times.
3458 for (i = 0; i < len; i++) {
140
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 3456 times.
3456 if (!float_near_ulp_array(dst0, dst1, 3, len))
141 fail();
142 }
143
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, src, MAX_SIZE, min, max);
144 }
145
146 13 report("audiodsp");
147 13 }
148