blob: 7d54d80c6ec24b84460fe846040614ae117a6ebb [file] [log] [blame]
Damjan Marione3e35552021-05-06 17:34:49 +02001/* SPDX-License-Identifier: Apache-2.0
2 * Copyright(c) 2021 Cisco Systems, Inc.
3 */
4
5#ifndef included_test_test_h
6#define included_test_test_h
7
8#include <vppinfra/cpu.h>
Damjan Mariond5045e62022-04-06 21:16:37 +02009#include <vppinfra/perfmon/perfmon.h>
Damjan Marion3323e202021-12-02 11:28:57 +010010#ifdef __linux__
11#include <sys/ioctl.h>
12#include <linux/perf_event.h>
13#endif
Damjan Marione3e35552021-05-06 17:34:49 +020014
15typedef clib_error_t *(test_fn_t) (clib_error_t *);
16
Damjan Marion3323e202021-12-02 11:28:57 +010017struct test_perf_;
Damjan Mariond5045e62022-04-06 21:16:37 +020018typedef void (test_perf_fn_t) (struct test_perf_ *tp);
Damjan Marion3323e202021-12-02 11:28:57 +010019
20typedef struct test_perf_
21{
Damjan Mariond5045e62022-04-06 21:16:37 +020022 int fd;
Damjan Marion3323e202021-12-02 11:28:57 +010023 u64 n_ops;
Damjan Marionde3735f2021-12-06 12:48:46 +010024 union
25 {
26 u64 arg0;
27 void *ptr0;
28 };
29 union
30 {
31 u64 arg1;
32 void *ptr1;
33 };
34 union
35 {
36 u64 arg2;
37 void *ptr2;
38 };
Damjan Marion3323e202021-12-02 11:28:57 +010039 char *name;
40 test_perf_fn_t *fn;
41} test_perf_t;
42
Damjan Marione3e35552021-05-06 17:34:49 +020043typedef struct test_registration_
44{
45 char *name;
46 u8 multiarch : 1;
47 test_fn_t *fn;
Damjan Marion3323e202021-12-02 11:28:57 +010048 test_perf_t *perf_tests;
49 u32 n_perf_tests;
Damjan Marione3e35552021-05-06 17:34:49 +020050 struct test_registration_ *next;
51} test_registration_t;
52
Damjan Marion3323e202021-12-02 11:28:57 +010053typedef struct
54{
55 test_registration_t *registrations[CLIB_MARCH_TYPE_N_VARIANTS];
56 u32 repeat;
Damjan Marion68843d12021-12-06 13:21:33 +010057 u8 *filter;
Damjan Marionb97bec02021-12-12 21:43:56 +000058 u8 *bundle;
Damjan Marionf622bf42021-12-14 10:40:48 +010059 f64 ref_clock;
Damjan Marion3323e202021-12-02 11:28:57 +010060} test_main_t;
61extern test_main_t test_main;
Damjan Marione3e35552021-05-06 17:34:49 +020062
Damjan Marion88019c42021-12-15 10:17:04 +000063#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")
Damjan Marione3e35552021-05-06 17:34:49 +020067
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) ( \
71 void) \
72 { \
73 test_registration_t *r = &CLIB_MARCH_SFX (__test_##x); \
Damjan Marion3323e202021-12-02 11:28:57 +010074 r->next = \
75 test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)]; \
76 test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)] = r; \
Damjan Marione3e35552021-05-06 17:34:49 +020077 } \
78 test_registration_t CLIB_MARCH_SFX (__test_##x)
79
Damjan Marion3323e202021-12-02 11:28:57 +010080#define PERF_TESTS(...) \
81 (test_perf_t[]) \
82 { \
83 __VA_ARGS__, {} \
84 }
85
86static_always_inline void
Damjan Mariond5045e62022-04-06 21:16:37 +020087test_perf_event_reset (test_perf_t *t)
Damjan Marion3323e202021-12-02 11:28:57 +010088{
Damjan Mariond5045e62022-04-06 21:16:37 +020089 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_RESET);
Damjan Marion3323e202021-12-02 11:28:57 +010090}
91static_always_inline void
Damjan Mariond5045e62022-04-06 21:16:37 +020092test_perf_event_enable (test_perf_t *t)
Damjan Marion3323e202021-12-02 11:28:57 +010093{
Damjan Mariond5045e62022-04-06 21:16:37 +020094 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_ENABLE);
Damjan Marion3323e202021-12-02 11:28:57 +010095}
96static_always_inline void
Damjan Mariond5045e62022-04-06 21:16:37 +020097test_perf_event_disable (test_perf_t *t)
Damjan Marion3323e202021-12-02 11:28:57 +010098{
Damjan Mariond5045e62022-04-06 21:16:37 +020099 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_DISABLE);
Damjan Marion3323e202021-12-02 11:28:57 +0100100}
101
102void *test_mem_alloc (uword size);
103void *test_mem_alloc_and_fill_inc_u8 (uword size, u8 start, u8 mask);
104void *test_mem_alloc_and_splat (uword elt_size, uword n_elts, void *elt);
105void test_mem_free (void *p);
106
Damjan Marione3e35552021-05-06 17:34:49 +0200107#endif