1 /* SPDX-License-Identifier: Apache-2.0
2 * Copyright(c) 2021 Cisco Systems, Inc.
5 #ifndef included_test_test_h
6 #define included_test_test_h
8 #include <vppinfra/cpu.h>
9 #include <vppinfra/perfmon/perfmon.h>
11 #include <sys/ioctl.h>
12 #include <linux/perf_event.h>
15 typedef clib_error_t *(test_fn_t) (clib_error_t *);
18 typedef void (test_perf_fn_t) (struct test_perf_ *tp);
20 typedef struct test_perf_
43 typedef struct test_registration_
48 test_perf_t *perf_tests;
50 struct test_registration_ *next;
51 } test_registration_t;
55 test_registration_t *registrations[CLIB_MARCH_TYPE_N_VARIANTS];
61 extern test_main_t test_main;
63 #define __test_funct_fn \
64 static __clib_noinline __clib_noclone __clib_section (".test_func")
65 #define __test_perf_fn \
66 static __clib_noinline __clib_noclone __clib_section (".test_perf")
68 #define REGISTER_TEST(x) \
69 test_registration_t CLIB_MARCH_SFX (__test_##x); \
70 static void __clib_constructor CLIB_MARCH_SFX (__test_registration_##x) ( \
73 test_registration_t *r = &CLIB_MARCH_SFX (__test_##x); \
75 test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)]; \
76 test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)] = r; \
78 test_registration_t CLIB_MARCH_SFX (__test_##x)
80 #define PERF_TESTS(...) \
86 static_always_inline void
87 test_perf_event_reset (test_perf_t *t)
89 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_RESET);
91 static_always_inline void
92 test_perf_event_enable (test_perf_t *t)
94 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_ENABLE);
96 static_always_inline void
97 test_perf_event_disable (test_perf_t *t)
99 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_DISABLE);
102 void *test_mem_alloc (uword size);
103 void *test_mem_alloc_and_fill_inc_u8 (uword size, u8 start, u8 mask);
104 void *test_mem_alloc_and_splat (uword elt_size, uword n_elts, void *elt);
105 void test_mem_free (void *p);