../../../ffmpeg/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
36 / 37
97.3%
Branches:
27 / 46
58.7%
Functions:
2 / 2
100.0%

tests/checkasm/pixelutils.c
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
22 #include "checkasm.h"
23
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mem_internal.h"
26 #include "libavutil/pixelutils.h"
27
28 enum {
29 LOG2_MIN_DIMENSION = 1,
30 LOG2_MAX_DIMENSION = 5,
31 BUF_SIZE = 4096, ///< arbitrary
32 };
33
34 #define randomize_buffer(buf) \
35 do { \
36 for (size_t k = 0; k < sizeof(buf); k += 4) { \
37 uint32_t r = rnd(); \
38 AV_WN32A(buf + k, r); \
39 } \
40 } while (0)
41
42 14 static void checkasm_check_sad(void)
43 {
44 DECLARE_ALIGNED(32, uint8_t, buf1)[BUF_SIZE];
45 DECLARE_ALIGNED(32, uint8_t, buf2)[BUF_SIZE];
46 14 int inited = 0;
47
48 14 declare_func(int, const uint8_t *src1, ptrdiff_t stride1,
49 const uint8_t *src2, ptrdiff_t stride2);
50
51
2/2
✓ Branch 113 → 3 taken 70 times.
✓ Branch 113 → 114 taken 14 times.
84 for (int i = LOG2_MIN_DIMENSION; i <= LOG2_MAX_DIMENSION; ++i) {
52 70 const size_t width = 1 << i, height = 1 << i;
53
54
2/2
✓ Branch 111 → 4 taken 210 times.
✓ Branch 111 → 112 taken 70 times.
280 for (int aligned = 0; aligned <= 2; ++aligned) {
55 210 av_pixelutils_sad_fn fn = av_pixelutils_get_sad_fn(i, i, aligned, NULL);
56
2/2
✓ Branch 6 → 7 taken 27 times.
✓ Branch 6 → 110 taken 183 times.
210 if (check_func(fn, "sad_%zux%zu_%d", width, width, aligned)) {
57
2/2
✓ Branch 7 → 8 taken 9 times.
✓ Branch 7 → 10 taken 18 times.
27 const uint8_t *src1 = buf1 + ((aligned != 0) ? 0 : rnd() % width);
58
2/2
✓ Branch 11 → 12 taken 18 times.
✓ Branch 11 → 14 taken 9 times.
27 const uint8_t *src2 = buf2 + ((aligned == 2) ? 0 : rnd() % width);
59 // stride * (height - 1) needs to be so small that the alignment offset
60 // and the last line fit into the remaining buffer.
61 27 size_t max_stride = (BUF_SIZE - 2 * width) / (height - 1);
62 27 ptrdiff_t stride1 = 1 + rnd() % max_stride;
63 27 ptrdiff_t stride2 = 1 + rnd() % max_stride;
64
65
2/2
✓ Branch 17 → 18 taken 18 times.
✓ Branch 17 → 19 taken 9 times.
27 if (aligned != 0)
66 18 stride1 &= ~(width - 1);
67
2/2
✓ Branch 19 → 20 taken 9 times.
✓ Branch 19 → 21 taken 18 times.
27 if (aligned == 2)
68 9 stride2 &= ~(width - 1);
69
70
2/2
✓ Branch 22 → 23 taken 9 times.
✓ Branch 22 → 24 taken 18 times.
27 if (rnd() & 1) { // negate stride
71 9 src1 += (height - 1) * stride1;
72 9 stride1 = -stride1;
73 }
74
2/2
✓ Branch 25 → 26 taken 18 times.
✓ Branch 25 → 27 taken 9 times.
27 if (rnd() & 1) { // negate stride
75 18 src2 += (height - 1) * stride2;
76 18 stride2 = -stride2;
77 }
78
79
2/2
✓ Branch 27 → 28 taken 3 times.
✓ Branch 27 → 37 taken 24 times.
27 if (!inited) {
80
2/2
✓ Branch 31 → 29 taken 3072 times.
✓ Branch 31 → 32 taken 3 times.
3075 randomize_buffer(buf1);
81
2/2
✓ Branch 35 → 33 taken 3072 times.
✓ Branch 35 → 36 taken 3 times.
3075 randomize_buffer(buf2);
82 3 inited = 1;
83 }
84
1/2
✗ Branch 39 → 40 not taken.
✓ Branch 39 → 41 taken 27 times.
27 int res_ref = call_ref(src1, stride1, src2, stride2);
85 27 int ref_new = call_new(src1, stride1, src2, stride2);
86
1/2
✗ Branch 45 → 46 not taken.
✓ Branch 45 → 47 taken 27 times.
27 if (res_ref != ref_new)
87 ✗ fail();
88
89
1/18
✗ Branch 48 → 49 not taken.
✓ Branch 48 → 107 taken 27 times.
✗ Branch 51 → 52 not taken.
✗ Branch 51 → 94 not taken.
✗ Branch 87 → 88 not taken.
✗ Branch 87 → 91 not taken.
✗ Branch 88 → 89 not taken.
✗ Branch 88 → 90 not taken.
✗ Branch 89 → 90 not taken.
✗ Branch 89 → 91 not taken.
✗ Branch 92 → 53 not taken.
✗ Branch 92 → 93 not taken.
✗ Branch 98 → 96 not taken.
✗ Branch 98 → 99 not taken.
✗ Branch 100 → 101 not taken.
✗ Branch 100 → 102 not taken.
✗ Branch 104 → 50 not taken.
✗ Branch 104 → 105 not taken.
27 bench_new(src1, stride1, src2, stride2);
90 }
91 }
92 }
93 14 }
94
95 14 void checkasm_check_pixelutils(void)
96 {
97 14 checkasm_check_sad();
98 14 report("sad");
99 14 }
100