FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/tests/checkasm/qpeldsp.c
Date: 2026-08-26 10:34:04
Exec Total Coverage
Lines: 28 29 96.6%
Functions: 1 1 100.0%
Branches: 20 40 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 <assert.h>
20 #include <stddef.h>
21 #include <string.h>
22
23 #include "checkasm.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/macros.h"
26 #include "libavutil/mem_internal.h"
27 #include "libavcodec/qpeldsp.h"
28
29 #define MAX_BLOCK_SIZE 16
30 #define MAX_STRIDE 64
31 // BUF_SIZE is bigger than necessary in order to test strides > block width.
32 #define BUF_SIZE ((MAX_BLOCK_SIZE - 1) * MAX_STRIDE + MAX_BLOCK_SIZE)
33 // Due to qpel interpolation the input needs to have one more line than
34 // the output and the last line needs one more element.
35 // The input is not subject to alignment requirements; making the input buffer
36 // bigger (by MAX_BLOCK_SIZE - 1) allows us to use a random misalignment.
37 #define INPUT_BUF_SIZE (MAX_BLOCK_SIZE * MAX_STRIDE + MAX_BLOCK_SIZE + 1 + (MAX_BLOCK_SIZE - 1))
38
39 #define randomize_buffers(buf0, buf1) \
40 do { \
41 static_assert(sizeof(buf0) == sizeof(buf1), "Incompatible buffers"); \
42 static_assert(!(sizeof(buf0) % 4), "Tail handling needed"); \
43 static_assert(sizeof(buf0[0]) == 1 && sizeof(buf1[0]) == 1, \
44 "Pointer arithmetic needs to be adapted"); \
45 for (size_t k = 0; k < sizeof(buf0); k += 4) { \
46 uint32_t r = rnd(); \
47 AV_WN32A(buf0 + k, r); \
48 AV_WN32A(buf1 + k, r); \
49 } \
50 } while (0)
51
52
53 14 void checkasm_check_qpeldsp(void)
54 {
55 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, srcbuf0)[INPUT_BUF_SIZE];
56 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, srcbuf1)[INPUT_BUF_SIZE];
57 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, dstbuf0)[BUF_SIZE];
58 DECLARE_ALIGNED(MAX_BLOCK_SIZE, uint8_t, dstbuf1)[BUF_SIZE];
59 QpelDSPContext qdsp;
60 static const struct {
61 const char *name;
62 size_t offset;
63 } tests[] = {
64 #define TEST(NAME) { .name = #NAME, .offset = offsetof(QpelDSPContext, NAME) }
65 TEST(put_qpel_pixels_tab),
66 TEST(avg_qpel_pixels_tab),
67 TEST(put_no_rnd_qpel_pixels_tab),
68 };
69
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 2 times.
14 declare_func_emms(AV_CPU_FLAG_MMXEXT, void, uint8_t *dst, const uint8_t *src, ptrdiff_t stride);
70
71 14 ff_qpeldsp_init(&qdsp);
72
73
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 14 times.
56 for (size_t i = 0; i < FF_ARRAY_ELEMS(tests); ++i) {
74 42 qpel_mc_func (*func_tab)[16] = (qpel_mc_func (*)[16])((char*)&qdsp + tests[i].offset);
75
2/2
✓ Branch 0 taken 84 times.
✓ Branch 1 taken 42 times.
126 for (unsigned j = 0; j < 2; ++j) {
76 84 const unsigned blocksize = MAX_BLOCK_SIZE >> j;
77
78
2/2
✓ Branch 0 taken 1344 times.
✓ Branch 1 taken 84 times.
1428 for (unsigned dxy = 0; dxy < 16; ++dxy) {
79
2/2
✓ Branch 1 taken 192 times.
✓ Branch 2 taken 1152 times.
1344 if (check_func(func_tab[j][dxy], "%s[%u][%u]", tests[i].name, j, dxy)) {
80 // Don't always use output that is 16-aligned.
81 192 size_t dst_offset = (rnd() % (MAX_BLOCK_SIZE / blocksize)) * blocksize;
82 192 size_t src_offset = rnd() % MAX_BLOCK_SIZE;
83 192 ptrdiff_t stride = (rnd() % (MAX_STRIDE / blocksize) + 1) * blocksize;
84 192 const uint8_t *src0 = srcbuf0 + src_offset, *src1 = srcbuf1 + src_offset;
85 192 uint8_t *dst0 = dstbuf0 + dst_offset, *dst1 = dstbuf1 + dst_offset;
86
87
1/2
✓ Branch 1 taken 192 times.
✗ Branch 2 not taken.
192 if (rnd() & 1) {
88 // Flip stride.
89 192 dst1 += (blocksize - 1) * stride;
90 192 dst0 += (blocksize - 1) * stride;
91 // Due to interpolation potentially blocksize + 1 lines are read
92 // from src, hence blocksize * stride.
93 192 src0 += blocksize * stride;
94 192 src1 += blocksize * stride;
95 192 stride = -stride;
96 }
97
98
2/2
✓ Branch 1 taken 50688 times.
✓ Branch 2 taken 192 times.
50880 randomize_buffers(srcbuf0, srcbuf1);
99
2/2
✓ Branch 1 taken 46848 times.
✓ Branch 2 taken 192 times.
47040 randomize_buffers(dstbuf0, dstbuf1);
100
2/2
✓ Branch 2 taken 96 times.
✓ Branch 3 taken 96 times.
192 call_ref(dst0, src0, stride);
101 192 call_new(dst1, src1, stride);
102
2/4
✓ Branch 0 taken 192 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 192 times.
192 if (memcmp(srcbuf0, srcbuf1, sizeof(srcbuf0)) || memcmp(dstbuf0, dstbuf1, sizeof(dstbuf0)))
103 fail();
104
1/18
✗ Branch 1 not taken.
✓ Branch 2 taken 192 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.
192 bench_new(dst0, src0, stride);
105 }
106 }
107 }
108 }
109 14 report("mpeg4_qpeldsp");
110 14 }
111