FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/cavsdsp.c
Date: 2026-04-24 10:13:59
Exec Total Coverage
Lines: 31 32 96.9%
Functions: 2 2 100.0%
Branches: 19 28 67.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 <assert.h>
20 #include <stddef.h>
21
22 #include "checkasm.h"
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/macros.h"
25 #include "libavutil/mem_internal.h"
26 #include "libavcodec/cavsdsp.h"
27
28
29 enum {
30 // DECLARE_ALIGNED can't handle enum constants.
31 #define MAX_BLOCK_SIZE 16
32 MAX_STRIDE = 64,
33 /// BUF_SIZE is bigger than necessary in order to test strides > block width.
34 BUF_SIZE = ((MAX_BLOCK_SIZE - 1) * MAX_STRIDE + MAX_BLOCK_SIZE),
35 /**
36 * The qpel interpolation code accesses two lines above and three lines
37 * below the actual src block; it also accesses two pixels to the left
38 * and three to the right.
39 * The input is not subject to alignment requirements; making the input buffer
40 * bigger (by MAX_BLOCK_SIZE - 1) allows us to use a random misalignment.
41 */
42 INPUT_BUF_SIZE = (2 + (2 + MAX_BLOCK_SIZE - 1 + 3) * MAX_STRIDE + MAX_BLOCK_SIZE + 3 + (MAX_BLOCK_SIZE - 1))
43 };
44
45 #define randomize_buffers(buf0, buf1) \
46 do { \
47 static_assert(sizeof(buf0) == sizeof(buf1), "Incompatible buffers"); \
48 static_assert(!(sizeof(buf0) % 4), "Tail handling needed"); \
49 static_assert(sizeof(buf0[0]) == 1 && sizeof(buf1[0]) == 1, \
50 "Pointer arithmetic needs to be adapted"); \
51 for (size_t k = 0; k < sizeof(buf0); k += 4) { \
52 uint32_t r = rnd(); \
53 AV_WN32A(buf0 + k, r); \
54 AV_WN32A(buf1 + k, r); \
55 } \
56 } while (0)
57
58
59 14 static void check_cavs_qpeldsp(void)
60 {
61 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, srcbuf0)[INPUT_BUF_SIZE];
62 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, srcbuf1)[INPUT_BUF_SIZE];
63 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, dstbuf0)[BUF_SIZE];
64 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, dstbuf1)[BUF_SIZE];
65 CAVSDSPContext cavsdsp;
66 static const struct {
67 const char *name;
68 size_t offset;
69 } tests[] = {
70 #define TEST(NAME) { .name = #NAME, .offset = offsetof(CAVSDSPContext, NAME) }
71 TEST(put_cavs_qpel_pixels_tab),
72 TEST(avg_cavs_qpel_pixels_tab),
73 };
74
2/2
✓ Branch 1 taken 13 times.
✓ Branch 2 taken 1 times.
14 declare_func_emms(AV_CPU_FLAG_MMX | AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, const uint8_t *src, ptrdiff_t stride);
75
76 14 ff_cavsdsp_init(&cavsdsp);
77
78
2/2
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 14 times.
42 for (size_t i = 0; i < FF_ARRAY_ELEMS(tests); ++i) {
79 28 qpel_mc_func (*func_tab)[16] = (qpel_mc_func (*)[16])((char*)&cavsdsp + tests[i].offset);
80
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 28 times.
84 for (unsigned j = 0; j < 2; ++j) {
81 56 const unsigned blocksize = MAX_BLOCK_SIZE >> j;
82
83
2/2
✓ Branch 0 taken 896 times.
✓ Branch 1 taken 56 times.
952 for (unsigned dxy = 0; dxy < 16; ++dxy) {
84
2/2
✓ Branch 3 taken 84 times.
✓ Branch 4 taken 812 times.
896 if (check_func(func_tab[j][dxy], "%s[%u][%u]", tests[i].name, j, dxy)) {
85 // Don't always use output that is 16-aligned.
86 84 size_t dst_offset = (rnd() % (MAX_BLOCK_SIZE / blocksize)) * blocksize;
87 84 ptrdiff_t stride = (rnd() % (MAX_STRIDE / blocksize) + 1) * blocksize;
88 84 size_t src_offset = 2 + 2 * stride + rnd() % MAX_BLOCK_SIZE;
89 84 const uint8_t *src0 = srcbuf0 + src_offset, *src1 = srcbuf1 + src_offset;
90 84 uint8_t *dst0 = dstbuf0 + dst_offset, *dst1 = dstbuf1 + dst_offset;
91
92
2/2
✓ Branch 1 taken 51 times.
✓ Branch 2 taken 33 times.
84 if (rnd() & 1) {
93 // Flip stride.
94 51 dst1 += (blocksize - 1) * stride;
95 51 dst0 += (blocksize - 1) * stride;
96 // We need two lines above src and three lines below the block,
97 // hence blocksize * stride.
98 51 src0 += blocksize * stride;
99 51 src1 += blocksize * stride;
100 51 stride = -stride;
101 }
102
103
2/2
✓ Branch 1 taken 27636 times.
✓ Branch 2 taken 84 times.
27720 randomize_buffers(srcbuf0, srcbuf1);
104
2/2
✓ Branch 1 taken 20496 times.
✓ Branch 2 taken 84 times.
20580 randomize_buffers(dstbuf0, dstbuf1);
105 84 call_ref(dst0, src0, stride);
106 84 call_new(dst1, src1, stride);
107
2/4
✓ Branch 0 taken 84 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 84 times.
84 if (memcmp(srcbuf0, srcbuf1, sizeof(srcbuf0)) || memcmp(dstbuf0, dstbuf1, sizeof(dstbuf0)))
108 fail();
109
1/8
✗ Branch 1 not taken.
✓ Branch 2 taken 84 times.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
84 bench_new(dst0, src0, stride);
110 }
111 }
112 }
113 }
114 14 }
115
116 14 void checkasm_check_cavsdsp(void)
117 {
118 14 check_cavs_qpeldsp();
119 14 report("qpeldsp");
120 14 }
121