aboutsummaryrefslogtreecommitdiffstats
path: root/src/vppinfra/test/test.h
diff options
context:
space:
mode:
authorDamjan Marion <damarion@cisco.com>2023-03-15 11:42:06 +0000
committerFlorin Coras <florin.coras@gmail.com>2023-03-15 17:07:01 +0000
commitc3542e17b5dfea27f46f0656e8f1f8092545b796 (patch)
tree623b16012e5b19484781245e1532024b1669fa2b /src/vppinfra/test/test.h
parentadeaf16960f8895eb246b388553a49d2ade80dc4 (diff)
vppinfra: widen the scope of test_vector_funcs
Location changed and binary renamed to test_infra Also it is built by default. Type: improvement Change-Id: I27cd97f274501ceb7a01213e2bc9676cea00f39c Signed-off-by: Damjan Marion <damarion@cisco.com>
Diffstat (limited to 'src/vppinfra/test/test.h')
-rw-r--r--src/vppinfra/test/test.h107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/vppinfra/test/test.h b/src/vppinfra/test/test.h
new file mode 100644
index 00000000000..7d54d80c6ec
--- /dev/null
+++ b/src/vppinfra/test/test.h
@@ -0,0 +1,107 @@
+/* SPDX-License-Identifier: Apache-2.0
+ * Copyright(c) 2021 Cisco Systems, Inc.
+ */
+
+#ifndef included_test_test_h
+#define included_test_test_h
+
+#include <vppinfra/cpu.h>
+#include <vppinfra/perfmon/perfmon.h>
+#ifdef __linux__
+#include <sys/ioctl.h>
+#include <linux/perf_event.h>
+#endif
+
+typedef clib_error_t *(test_fn_t) (clib_error_t *);
+
+struct test_perf_;
+typedef void (test_perf_fn_t) (struct test_perf_ *tp);
+
+typedef struct test_perf_
+{
+ int fd;
+ u64 n_ops;
+ union
+ {
+ u64 arg0;
+ void *ptr0;
+ };
+ union
+ {
+ u64 arg1;
+ void *ptr1;
+ };
+ union
+ {
+ u64 arg2;
+ void *ptr2;
+ };
+ char *name;
+ test_perf_fn_t *fn;
+} test_perf_t;
+
+typedef struct test_registration_
+{
+ char *name;
+ u8 multiarch : 1;
+ test_fn_t *fn;
+ test_perf_t *perf_tests;
+ u32 n_perf_tests;
+ struct test_registration_ *next;
+} test_registration_t;
+
+typedef struct
+{
+ test_registration_t *registrations[CLIB_MARCH_TYPE_N_VARIANTS];
+ u32 repeat;
+ u8 *filter;
+ u8 *bundle;
+ f64 ref_clock;
+} test_main_t;
+extern test_main_t test_main;
+
+#define __test_funct_fn \
+ static __clib_noinline __clib_noclone __clib_section (".test_func")
+#define __test_perf_fn \
+ static __clib_noinline __clib_noclone __clib_section (".test_perf")
+
+#define REGISTER_TEST(x) \
+ test_registration_t CLIB_MARCH_SFX (__test_##x); \
+ static void __clib_constructor CLIB_MARCH_SFX (__test_registration_##x) ( \
+ void) \
+ { \
+ test_registration_t *r = &CLIB_MARCH_SFX (__test_##x); \
+ r->next = \
+ test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)]; \
+ test_main.registrations[CLIB_MARCH_SFX (CLIB_MARCH_VARIANT_TYPE)] = r; \
+ } \
+ test_registration_t CLIB_MARCH_SFX (__test_##x)
+
+#define PERF_TESTS(...) \
+ (test_perf_t[]) \
+ { \
+ __VA_ARGS__, {} \
+ }
+
+static_always_inline void
+test_perf_event_reset (test_perf_t *t)
+{
+ clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_RESET);
+}
+static_always_inline void
+test_perf_event_enable (test_perf_t *t)
+{
+ clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_ENABLE);
+}
+static_always_inline void
+test_perf_event_disable (test_perf_t *t)
+{
+ clib_perfmon_ioctl (t->fd, PERF_EVENT_IOC_DISABLE);
+}
+
+void *test_mem_alloc (uword size);
+void *test_mem_alloc_and_fill_inc_u8 (uword size, u8 start, u8 mask);
+void *test_mem_alloc_and_splat (uword elt_size, uword n_elts, void *elt);
+void test_mem_free (void *p);
+
+#endif