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];
62 extern test_main_t test_main;
64 #define __test_funct_fn \
65 static __clib_noinline __clib_noclone __clib_section (".test_func")
66 #define __test_perf_fn \
67 static __clib_noinline __clib_noclone __clib_section (".test_perf")
69 #define REGISTER_TEST(x) \
70 test_registration_t CLIB_MARCH_SFX (__test_##x); \
71 static void __clib_constructor CLIB_MARCH_SFX (__test_registration_##x) ( \
74 test_registration_t *r = &CLIB_MARCH_SFX (__test_##x); \
76 test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)]; \
77 test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)] = r; \
79 test_registration_t CLIB_MARCH_SFX (__test_##x)
81 #define PERF_TESTS(...) \
87 static_always_inline void
88 test_perf_event_reset (test_perf_t *t)
90 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_RESET);
92 static_always_inline void
93 test_perf_event_enable (test_perf_t *t)
95 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_ENABLE);
97 static_always_inline void
98 test_perf_event_disable (test_perf_t *t)
100 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_DISABLE);
103 void *test_mem_alloc (uword size);
104 void *test_mem_alloc_and_fill_inc_u8 (uword size, u8 start, u8 mask);
105 void *test_mem_alloc_and_splat (uword elt_size, uword n_elts, void *elt);