diff options
author | Matias Elo <matias.elo@nokia.com> | 2024-01-17 09:57:07 +0200 |
---|---|---|
committer | Petri Savolainen <petri.savolainen@nokia.com> | 2024-01-23 11:08:29 +0200 |
commit | e1a65f2fe33354dad14bfb082a66772d2c01f56a (patch) | |
tree | dc18b7e4abc75013ce9faed97e666fb79f86c938 | |
parent | af4e94014b7a4130f0761ac070df7b1eae6ddf4e (diff) |
validation: hints: add tests
Add validation tests for hints module macros and attributes.
Signed-off-by: Matias Elo <matias.elo@nokia.com>
Reviewed-by: Tuomas Taipale <tuomas.taipale@nokia.com>
Reviewed-by: Petri Savolainen <petri.savolainen@nokia.com>
-rw-r--r-- | test/m4/configure.m4 | 1 | ||||
-rw-r--r-- | test/validation/api/Makefile.am | 2 | ||||
-rw-r--r-- | test/validation/api/hints/.gitignore | 1 | ||||
-rw-r--r-- | test/validation/api/hints/Makefile.am | 4 | ||||
-rw-r--r-- | test/validation/api/hints/hints.c | 92 |
5 files changed, 100 insertions, 0 deletions
diff --git a/test/m4/configure.m4 b/test/m4/configure.m4 index 84d2fd753..b979f400d 100644 --- a/test/m4/configure.m4 +++ b/test/m4/configure.m4 @@ -30,6 +30,7 @@ AC_CONFIG_FILES([test/common/Makefile test/validation/api/errno/Makefile test/validation/api/event/Makefile test/validation/api/hash/Makefile + test/validation/api/hints/Makefile test/validation/api/init/Makefile test/validation/api/ipsec/Makefile test/validation/api/lock/Makefile diff --git a/test/validation/api/Makefile.am b/test/validation/api/Makefile.am index 49cd0f4aa..558c2c8bb 100644 --- a/test/validation/api/Makefile.am +++ b/test/validation/api/Makefile.am @@ -11,6 +11,7 @@ ODP_MODULES = align \ errno \ event \ hash \ + hints \ init \ ipsec \ lock \ @@ -48,6 +49,7 @@ TESTS = \ errno/errno_main$(EXEEXT) \ event/event_main$(EXEEXT) \ hash/hash_main$(EXEEXT) \ + hints/hints_main$(EXEEXT) \ init/init_defaults.sh \ init/init_abort.sh \ init/init_log.sh \ diff --git a/test/validation/api/hints/.gitignore b/test/validation/api/hints/.gitignore new file mode 100644 index 000000000..586f429bc --- /dev/null +++ b/test/validation/api/hints/.gitignore @@ -0,0 +1 @@ +hints_main diff --git a/test/validation/api/hints/Makefile.am b/test/validation/api/hints/Makefile.am new file mode 100644 index 000000000..bcc77f606 --- /dev/null +++ b/test/validation/api/hints/Makefile.am @@ -0,0 +1,4 @@ +include ../Makefile.inc + +test_PROGRAMS = hints_main +hints_main_SOURCES = hints.c diff --git a/test/validation/api/hints/hints.c b/test/validation/api/hints/hints.c new file mode 100644 index 000000000..4c049f33b --- /dev/null +++ b/test/validation/api/hints/hints.c @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2024 Nokia + */ + +#include <odp_api.h> +#include <odp_cunit_common.h> + +#include <stdint.h> +#include <stdlib.h> + +ODP_NORETURN static void test_noreturn(void) +{ + abort(); +} + +int test_weak(void); + +ODP_WEAK_SYMBOL int test_weak(void) +{ + return 0; +} + +ODP_COLD_CODE static int test_cold(void) +{ + return -1; +} + +ODP_HOT_CODE static int test_hot(void) +{ + return 1; +} + +ODP_PRINTF_FORMAT(2, 3) +static int test_printf_format(int level ODP_UNUSED, const char *fmt ODP_UNUSED, ...) +{ + return 0; +} + +static void test_hints(void) +{ + volatile int val = 1; + + if (odp_unlikely(!val)) + test_noreturn(); + + test_weak(); + test_cold(); + + if (odp_likely(val)) + test_hot(); + + test_printf_format(0, "test"); +} + +static void test_prefetch(void) +{ + const int rounds = 10; + uint64_t data[rounds]; + + for (int i = 0; i < rounds; i++) + odp_prefetch(&data[i]); + + for (int i = 0; i < rounds; i++) + odp_prefetch_store(&data[i]); +} + +odp_testinfo_t hints_suite[] = { + ODP_TEST_INFO(test_hints), + ODP_TEST_INFO(test_prefetch), + ODP_TEST_INFO_NULL, +}; + +odp_suiteinfo_t align_suites[] = { + {"hints", NULL, NULL, hints_suite}, + ODP_SUITE_INFO_NULL +}; + +int main(int argc, char *argv[]) +{ + int ret; + + /* Parse common options */ + if (odp_cunit_parse_options(&argc, argv)) + return -1; + + ret = odp_cunit_register(align_suites); + + if (ret == 0) + ret = odp_cunit_run(); + + return ret; +} |