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>
10 #include <sys/ioctl.h>
11 #include <linux/perf_event.h>
14 typedef clib_error_t *(test_fn_t) (clib_error_t *);
17 typedef void (test_perf_fn_t) (int fd, struct test_perf_ *tp);
19 typedef struct test_perf_
42 typedef struct test_registration_
47 test_perf_t *perf_tests;
49 struct test_registration_ *next;
50 } test_registration_t;
54 test_registration_t *registrations[CLIB_MARCH_TYPE_N_VARIANTS];
60 extern test_main_t test_main;
62 #define __test_funct_fn static __clib_noinline __clib_section (".test_func")
63 #define __test_perf_fn static __clib_noinline __clib_section (".test_perf")
65 #define REGISTER_TEST(x) \
66 test_registration_t CLIB_MARCH_SFX (__test_##x); \
67 static void __clib_constructor CLIB_MARCH_SFX (__test_registration_##x) ( \
70 test_registration_t *r = &CLIB_MARCH_SFX (__test_##x); \
72 test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)]; \
73 test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)] = r; \
75 test_registration_t CLIB_MARCH_SFX (__test_##x)
77 #define PERF_TESTS(...) \
83 static_always_inline void
84 test_perf_event_ioctl (int fd, u32 req)
89 : "D"(fd), "S"(req), "a"(__NR_ioctl), "d"(PERF_IOC_FLAG_GROUP)
90 : "rcx", "r11" /* registers modified by kernel */);
92 ioctl (fd, req, PERF_IOC_FLAG_GROUP);
96 static_always_inline void
97 test_perf_event_reset (int fd)
99 test_perf_event_ioctl (fd, PERF_EVENT_IOC_RESET);
101 static_always_inline void
102 test_perf_event_enable (int fd)
104 test_perf_event_ioctl (fd, PERF_EVENT_IOC_ENABLE);
106 static_always_inline void
107 test_perf_event_disable (int fd)
109 test_perf_event_ioctl (fd, PERF_EVENT_IOC_DISABLE);
112 void *test_mem_alloc (uword size);
113 void *test_mem_alloc_and_fill_inc_u8 (uword size, u8 start, u8 mask);
114 void *test_mem_alloc_and_splat (uword elt_size, uword n_elts, void *elt);
115 void test_mem_free (void *p);