blob: a0e5f6db669c02b362457777fa240eb56cf232f1 [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 Marionc7d3a5b2023-03-16 16:55:38 +000060 void **allocated_mem;
Damjan Marion3323e202021-12-02 11:28:57 +010061} test_main_t;
62extern test_main_t test_main;
Damjan Marione3e35552021-05-06 17:34:49 +020063
Damjan Marion88019c42021-12-15 10:17:04 +000064#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")
Damjan Marione3e35552021-05-06 17:34:49 +020068
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) ( \
72 void) \
73 { \
74 test_registration_t *r = &CLIB_MARCH_SFX (__test_##x); \
Damjan Marion3323e202021-12-02 11:28:57 +010075 r->next = \
76 test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)]; \
77 test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)] = r; \
Damjan Marione3e35552021-05-06 17:34:49 +020078 } \
79 test_registration_t CLIB_MARCH_SFX (__test_##x)
80
Damjan Marion3323e202021-12-02 11:28:57 +010081#define PERF_TESTS(...) \
82 (test_perf_t[]) \
83 { \
84 __VA_ARGS__, {} \
85 }
86
87static_always_inline void
Damjan Mariond5045e62022-04-06 21:16:37 +020088test_perf_event_reset (test_perf_t *t)
Damjan Marion3323e202021-12-02 11:28:57 +010089{
Damjan Mariond5045e62022-04-06 21:16:37 +020090 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_RESET);
Damjan Marion3323e202021-12-02 11:28:57 +010091}
92static_always_inline void
Damjan Mariond5045e62022-04-06 21:16:37 +020093test_perf_event_enable (test_perf_t *t)
Damjan Marion3323e202021-12-02 11:28:57 +010094{
Damjan Mariond5045e62022-04-06 21:16:37 +020095 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_ENABLE);
Damjan Marion3323e202021-12-02 11:28:57 +010096}
97static_always_inline void
Damjan Mariond5045e62022-04-06 21:16:37 +020098test_perf_event_disable (test_perf_t *t)
Damjan Marion3323e202021-12-02 11:28:57 +010099{
Damjan Mariond5045e62022-04-06 21:16:37 +0200100 clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_DISABLE);
Damjan Marion3323e202021-12-02 11:28:57 +0100101}
102
103void *test_mem_alloc (uword size);
104void *test_mem_alloc_and_fill_inc_u8 (uword size, u8 start, u8 mask);
105void *test_mem_alloc_and_splat (uword elt_size, uword n_elts, void *elt);
Damjan Marion3323e202021-12-02 11:28:57 +0100106
Damjan Marione3e35552021-05-06 17:34:49 +0200107#endif