FFmpeg
tests.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2025, Niklas Haas
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
19  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 #ifndef CHECKASM_TESTS_H
28 #define CHECKASM_TESTS_H
29 
30 #include <stddef.h>
31 #include <stdint.h>
32 #include <string.h>
33 
34 #include "src/checkasm_config.h"
35 
36 #include <checkasm/test.h>
37 #include <checkasm/utils.h>
38 
39 enum {
40  SELFTEST_CPU_FLAG_BAD_C = 1 << 0, // dummy flag for "bad" C implementations
41 #if ARCH_X86
42  SELFTEST_CPU_FLAG_X86 = 1 << 1,
43  SELFTEST_CPU_FLAG_MMX = 1 << 2,
44  SELFTEST_CPU_FLAG_SSE2 = 1 << 3,
45  SELFTEST_CPU_FLAG_AVX2 = 1 << 4,
46  SELFTEST_CPU_FLAG_AVX512 = 1 << 5,
47 #elif ARCH_RISCV
48  SELFTEST_CPU_FLAG_RVI = 1 << 1,
49  SELFTEST_CPU_FLAG_RVF = 1 << 2,
50  SELFTEST_CPU_FLAG_RVV = 1 << 3,
51 #elif ARCH_AARCH64
52  SELFTEST_CPU_FLAG_AARCH64 = 1 << 1,
53 #elif ARCH_ARM
54  SELFTEST_CPU_FLAG_ARM = 1 << 1,
55  SELFTEST_CPU_FLAG_VFP = 1 << 2,
56  SELFTEST_CPU_FLAG_VFPD32 = 1 << 3,
57 #endif
58 };
59 
60 #define DEF_GETTER(FLAG, NAME, func_type, fallback) \
61  static func_type *get_##NAME(void) \
62  { \
63  return (checkasm_get_cpu_flags() & FLAG) ? selftest_##NAME : fallback; \
64  }
65 
66 /* Should return the arch-specific flags */
67 uint64_t selftest_get_cpu_flags_x86(void);
68 uint64_t selftest_get_cpu_flags_riscv(void);
69 uint64_t selftest_get_cpu_flags_aarch64(void);
70 uint64_t selftest_get_cpu_flags_arm(void);
71 
72 /**
73  * Copy `size` (power-of-two) bytes from aligned buffers `src` to `dst`.
74  */
75 typedef void(copy_func)(uint8_t *dst, const uint8_t *src, size_t size);
76 void selftest_test_copy(copy_func *func, const char *name, int min_width);
77 
78 #define DEF_COPY_FUNC(NAME) \
79  void selftest_##NAME(uint8_t *dst, const uint8_t *src, size_t size)
80 
81 #define DEF_COPY_GETTER(FLAG, NAME) DEF_GETTER(FLAG, NAME, copy_func, selftest_copy_c)
82 
83 /* Reference function for copy routines */
84 static inline DEF_COPY_FUNC(copy_c)
85 {
86  memcpy(dst, src, size);
87 }
88 
89 /**
90  * Do nothing. Used to test side effects, stack corruption etc.
91  * The singular int parameter is just to have at least one parameter,
92  * which is required by `declare_func`.
93  */
94 typedef void(noop_func)(int unused);
95 void selftest_test_noop(noop_func *func, const char *name);
96 
97 #define DEF_NOOP_FUNC(NAME) void selftest_##NAME(int unused)
98 #define DEF_NOOP_GETTER(FLAG, NAME) DEF_GETTER(FLAG, NAME, noop_func, NULL)
99 
100 /* Used for testing floating point operations */
101 typedef float(float_func)(float input);
102 typedef double(double_func)(double input);
103 void selftest_test_float(float_func *func, const char *name, float input);
104 
105 #define DEF_FLOAT_FUNC(NAME) float selftest_##NAME(float input)
106 
107 /* Platform-specific tests */
108 void selftest_check_generic(void);
109 void selftest_check_x86(void);
110 void selftest_check_riscv(void);
111 void selftest_check_aarch64(void);
112 void selftest_check_arm(void);
113 
114 #endif /* CHECKASM_TESTS_H */
selftest_check_riscv
void selftest_check_riscv(void)
func
int(* func)(AVBPrint *dst, const char *in, const char *arg)
Definition: jacosubdec.c:66
DEF_COPY_FUNC
#define DEF_COPY_FUNC(NAME)
Definition: tests.h:78
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
checkasm_config.h
selftest_test_float
void selftest_test_float(float_func *func, const char *name, float input)
copy_c
static av_always_inline void copy_c(uint8_t *restrict dst, ptrdiff_t dst_stride, const uint8_t *restrict src, ptrdiff_t src_stride, int w, int h)
Definition: vp9dsp_template.c:1971
selftest_check_aarch64
void selftest_check_aarch64(void)
selftest_check_arm
void selftest_check_arm(void)
selftest_get_cpu_flags_arm
uint64_t selftest_get_cpu_flags_arm(void)
selftest_check_x86
void selftest_check_x86(void)
selftest_test_noop
void selftest_test_noop(noop_func *func, const char *name)
float
float
Definition: af_crystalizer.c:122
SELFTEST_CPU_FLAG_BAD_C
@ SELFTEST_CPU_FLAG_BAD_C
Definition: tests.h:40
selftest_get_cpu_flags_aarch64
uint64_t selftest_get_cpu_flags_aarch64(void)
double
double
Definition: af_crystalizer.c:132
noop_func
void() noop_func(int unused)
Do nothing.
Definition: tests.h:94
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
test.h
Test writing API for checkasm.
size
int size
Definition: twinvq_data.h:10344
selftest_test_copy
void selftest_test_copy(copy_func *func, const char *name, int min_width)
input
and forward the test the status of outputs and forward it to the corresponding return FFERROR_NOT_READY If the filters stores internally one or a few frame for some input
Definition: filter_design.txt:172
utils.h
Utility functions for checkasm tests.
double_func
double() double_func(double input)
Definition: tests.h:102
float_func
float() float_func(float input)
Definition: tests.h:101
selftest_get_cpu_flags_x86
uint64_t selftest_get_cpu_flags_x86(void)
selftest_check_generic
void selftest_check_generic(void)
Definition: generic.c:300
copy_func
void() copy_func(uint8_t *dst, const uint8_t *src, size_t size)
Copy size (power-of-two) bytes from aligned buffers src to dst.
Definition: tests.h:75
src
#define src
Definition: vp8dsp.c:248
selftest_get_cpu_flags_riscv
uint64_t selftest_get_cpu_flags_riscv(void)