diff options
Diffstat (limited to 'helper/test')
-rw-r--r-- | helper/test/.gitignore | 4 | ||||
-rw-r--r-- | helper/test/Makefile.am | 10 | ||||
-rw-r--r-- | helper/test/cli.c | 15 | ||||
-rw-r--r-- | helper/test/cuckootable.c | 577 | ||||
-rw-r--r-- | helper/test/iplookuptable.c | 170 | ||||
-rw-r--r-- | helper/test/odpthreads.c | 39 | ||||
-rw-r--r-- | helper/test/stress.c | 118 | ||||
-rw-r--r-- | helper/test/table.c | 130 |
8 files changed, 165 insertions, 898 deletions
diff --git a/helper/test/.gitignore b/helper/test/.gitignore index 3db451f68..6fb54ea3b 100644 --- a/helper/test/.gitignore +++ b/helper/test/.gitignore @@ -2,13 +2,11 @@ *.log chksum cli -cuckootable -iplookuptable macros odpthreads parse process -table +stress thread pthread version diff --git a/helper/test/Makefile.am b/helper/test/Makefile.am index 9cf48d7d9..07986761c 100644 --- a/helper/test/Makefile.am +++ b/helper/test/Makefile.am @@ -3,11 +3,9 @@ include $(top_srcdir)/test/Makefile.inc EXECUTABLES = version \ debug \ chksum \ - cuckootable \ macros \ - parse\ - table \ - iplookuptable + parse \ + stress #These are platform specific extensions that are not portable #They are a convenience to app writers who have chosen to @@ -39,12 +37,10 @@ test_PROGRAMS = $(EXECUTABLES) $(COMPILE_ONLY) dist_check_SCRIPTS = odpthreads_as_processes odpthreads_as_pthreads chksum_SOURCES = chksum.c -cuckootable_SOURCES = cuckootable.c macros_SOURCES = macros.c odpthreads_SOURCES = odpthreads.c parse_SOURCES = parse.c -table_SOURCES = table.c -iplookuptable_SOURCES = iplookuptable.c +stress_SOURCES = stress.c version_SOURCES = version.c debug_SOURCES = debug.c diff --git a/helper/test/cli.c b/helper/test/cli.c index 08e750153..f7f072fef 100644 --- a/helper/test/cli.c +++ b/helper/test/cli.c @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2021 Nokia + * Copyright (c) 2021-2024 Nokia */ #include <odp_api.h> @@ -9,7 +9,7 @@ static int cli_server(void *arg ODP_UNUSED) { if (odph_cli_run()) { ODPH_ERR("odph_cli_run() failed.\n"); - exit(EXIT_FAILURE); + return -1; } return 0; @@ -55,6 +55,7 @@ int main(int argc, char *argv[]) odph_thread_common_param_t thr_common; odph_thread_param_t thr_param; odph_thread_t thr_server; + odph_thread_join_result_t res; if (odp_cpumask_default_control(&cpumask, 1) != 1) { ODPH_ERR("Failed to get default CPU mask.\n"); @@ -86,8 +87,14 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } - if (odph_thread_join(&thr_server, 1) != 1) { - ODPH_ERR("Failed to join server thread.\n"); + if (odph_thread_join_result(&thr_server, &res, 1) != 1) { + ODPH_ERR("Error: failed to join server thread.\n"); + exit(EXIT_FAILURE); + } + + if (res.is_sig || res.ret != 0) { + ODPH_ERR("Error: worker thread failure%s: %d.\n", res.is_sig ? " (signaled)" : "", + res.ret); exit(EXIT_FAILURE); } diff --git a/helper/test/cuckootable.c b/helper/test/cuckootable.c deleted file mode 100644 index d17f79562..000000000 --- a/helper/test/cuckootable.c +++ /dev/null @@ -1,577 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2016-2018 Linaro Limited - */ - -/*- - * BSD LICENSE - * - * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * * Neither the name of Intel Corporation nor the names of its - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include <stdio.h> -#include <stdint.h> -#include <string.h> -#include <stdlib.h> -#include <stdarg.h> -#include <errno.h> -#include <sys/queue.h> -#include <sys/time.h> -#include <time.h> - -#include <odp_api.h> -#include <odp/helper/odph_api.h> - -/******************************************************************************* - * Hash function performance test configuration section. - * - * The five arrays below control what tests are performed. Every combination - * from the array entries is tested. - */ -/******************************************************************************/ - -/* 5-tuple key type */ -struct flow_key { - uint32_t ip_src; - uint32_t ip_dst; - uint16_t port_src; - uint16_t port_dst; - uint8_t proto; -} __packed; - -/* - * Print out result of unit test hash operation. - */ -static void print_key_info( - const char *msg, const struct flow_key *key) -{ - const uint8_t *p = (const uint8_t *)key; - unsigned i; - - printf("%s key:0x", msg); - for (i = 0; i < sizeof(struct flow_key); i++) - printf("%02X", p[i]); - printf("\n"); -} - -static double get_time_diff(struct timeval *start, struct timeval *end) -{ - int sec = end->tv_sec - start->tv_sec; - int usec = end->tv_usec - start->tv_usec; - - if (usec < 0) { - sec--; - usec += 1000000; - } - double diff = sec + (double)usec / 1000000; - - return diff; -} - -/** Create IPv4 address */ -#define IPv4(a, b, c, d) ((uint32_t)(((a) & 0xff) << 24) | \ - (((b) & 0xff) << 16) | \ - (((c) & 0xff) << 8) | \ - ((d) & 0xff)) - -/* Keys used by unit test functions */ -static struct flow_key keys[5] = { { - .ip_src = IPv4(0x03, 0x02, 0x01, 0x00), - .ip_dst = IPv4(0x07, 0x06, 0x05, 0x04), - .port_src = 0x0908, - .port_dst = 0x0b0a, - .proto = 0x0c, -}, { - .ip_src = IPv4(0x13, 0x12, 0x11, 0x10), - .ip_dst = IPv4(0x17, 0x16, 0x15, 0x14), - .port_src = 0x1918, - .port_dst = 0x1b1a, - .proto = 0x1c, -}, { - .ip_src = IPv4(0x23, 0x22, 0x21, 0x20), - .ip_dst = IPv4(0x27, 0x26, 0x25, 0x24), - .port_src = 0x2928, - .port_dst = 0x2b2a, - .proto = 0x2c, -}, { - .ip_src = IPv4(0x33, 0x32, 0x31, 0x30), - .ip_dst = IPv4(0x37, 0x36, 0x35, 0x34), - .port_src = 0x3938, - .port_dst = 0x3b3a, - .proto = 0x3c, -}, { - .ip_src = IPv4(0x43, 0x42, 0x41, 0x40), - .ip_dst = IPv4(0x47, 0x46, 0x45, 0x44), - .port_src = 0x4948, - .port_dst = 0x4b4a, - .proto = 0x4c, -} }; - -/* - * Basic sequence of operations for a single key: - * - put - * - get (hit) - * - remove - * - get (miss) - */ -static int test_put_remove(void) -{ - odph_table_t table; - odph_table_ops_t *ops; - - ops = &odph_cuckoo_table_ops; - - /* test with standard put/get/remove functions */ - int ret; - - table = ops->f_create("put_remove", 10, sizeof(struct flow_key), 0); - if (table == NULL) { - printf("cuckoo hash table creation failed\n"); - return -1; - } - - ret = odph_cuckoo_table_put_value(table, &keys[0], NULL); - print_key_info("Add", &keys[0]); - if (ret < 0) { - printf("failed to add key\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - ret = odph_cuckoo_table_get_value(table, &keys[0], NULL, 0); - print_key_info("Lkp", &keys[0]); - if (ret < 0) { - printf("failed to find key\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - ret = odph_cuckoo_table_remove_value(table, &keys[0]); - print_key_info("Del", &keys[0]); - if (ret < 0) { - printf("failed to delete key\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - ret = odph_cuckoo_table_get_value(table, &keys[0], NULL, 0); - print_key_info("Lkp", &keys[0]); - if (ret >= 0) { - printf("error: found key after deleting!\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - odph_cuckoo_table_destroy(table); - return 0; -} - -/* - * Sequence of operations for a single key: - * key type : struct flow_key - * value type: uint8_t - * - remove: miss - * - put - * - get: hit - * - put: update - * - get: hit (updated data) - * - remove: hit - * - remove: miss - */ -static int test_put_update_remove(void) -{ - odph_table_t table; - int ret; - uint8_t val1 = 1, val2 = 2, val = 0; - - table = odph_cuckoo_table_create( - "put_update_remove", - 10, sizeof(struct flow_key), sizeof(uint8_t)); - if (table == NULL) { - printf("failed to create table\n"); - return -1; - } - - ret = odph_cuckoo_table_remove_value(table, &keys[0]); - print_key_info("Del", &keys[0]); - if (ret >= 0) { - printf("error: found non-existent key\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - ret = odph_cuckoo_table_put_value(table, &keys[0], &val1); - print_key_info("Add", &keys[0]); - if (ret < 0) { - printf("failed to add key\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - ret = odph_cuckoo_table_get_value( - table, &keys[0], &val, sizeof(uint8_t)); - print_key_info("Lkp", &keys[0]); - if (ret < 0) { - printf("failed to find key\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - ret = odph_cuckoo_table_put_value(table, &keys[0], &val2); - if (ret < 0) { - printf("failed to re-add key\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - ret = odph_cuckoo_table_get_value( - table, &keys[0], &val, sizeof(uint8_t)); - print_key_info("Lkp", &keys[0]); - if (ret < 0) { - printf("failed to find key\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - ret = odph_cuckoo_table_remove_value(table, &keys[0]); - print_key_info("Del", &keys[0]); - if (ret < 0) { - printf("failed to delete key\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - ret = odph_cuckoo_table_remove_value(table, &keys[0]); - print_key_info("Del", &keys[0]); - if (ret >= 0) { - printf("error: deleted already deleted key\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - odph_cuckoo_table_destroy(table); - return 0; -} - -/* - * Sequence of operations for find existing hash table - * - * - create table - * - find existing table: hit - * - find non-existing table: miss - * - */ -static int test_table_lookup(void) -{ - odph_table_t table, result; - - /* Create cuckoo hash table. */ - table = odph_cuckoo_table_create("table_lookup", 10, 4, 0); - if (table == NULL) { - printf("failed to create table\n"); - return -1; - } - - /* Try to find existing hash table */ - result = odph_cuckoo_table_lookup("table_lookup"); - if (result != table) { - printf("error: could not find existing table\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - /* Try to find non-existing hash table */ - result = odph_cuckoo_table_lookup("non_existing"); - if (result != NULL) { - printf("error: found table that shouldn't exist.\n"); - odph_cuckoo_table_destroy(table); - return -1; - } - - /* Cleanup. */ - odph_cuckoo_table_destroy(table); - return 0; -} - -/* - * Sequence of operations for 5 keys - * - put keys - * - get keys: hit - * - remove keys : hit - * - get keys: miss - */ -static int test_five_keys(void) -{ - odph_table_t table; - unsigned i; - int ret; - - table = odph_cuckoo_table_create( - "five_keys", 10, sizeof(struct flow_key), 0); - if (table == NULL) { - printf("failed to create table\n"); - return -1; - } - - /* put */ - for (i = 0; i < 5; i++) { - ret = odph_cuckoo_table_put_value(table, &keys[i], NULL); - print_key_info("Add", &keys[i]); - if (ret < 0) { - printf("failed to add key %d\n", i); - odph_cuckoo_table_destroy(table); - return -1; - } - } - - /* get */ - for (i = 0; i < 5; i++) { - ret = odph_cuckoo_table_get_value(table, &keys[i], NULL, 0); - print_key_info("Lkp", &keys[i]); - if (ret < 0) { - printf("failed to find key %d\n", i); - odph_cuckoo_table_destroy(table); - return -1; - } - } - - /* remove */ - for (i = 0; i < 5; i++) { - ret = odph_cuckoo_table_remove_value(table, &keys[i]); - print_key_info("Del", &keys[i]); - if (ret < 0) { - printf("failed to delete key %d\n", i); - odph_cuckoo_table_destroy(table); - return -1; - } - } - - /* get */ - for (i = 0; i < 5; i++) { - ret = odph_cuckoo_table_get_value(table, &keys[i], NULL, 0); - print_key_info("Lkp", &keys[i]); - if (ret >= 0) { - printf("found non-existing key %d\n", i); - odph_cuckoo_table_destroy(table); - return -1; - } - } - - odph_cuckoo_table_destroy(table); - return 0; -} - -#define BUCKET_ENTRIES 4 -#define HASH_ENTRIES_MAX 1048576 -/* - * Do tests for cuchoo table creation with bad parameters. - */ -static int test_creation_with_bad_parameters(void) -{ - odph_table_t table; - - table = odph_cuckoo_table_create( - "bad_param_0", HASH_ENTRIES_MAX + 1, 4, 0); - if (table != NULL) { - odph_cuckoo_table_destroy(table); - printf("Impossible creating table successfully with entries in parameter exceeded\n"); - return -1; - } - - table = odph_cuckoo_table_create( - "bad_param_1", BUCKET_ENTRIES - 1, 4, 0); - if (table != NULL) { - odph_cuckoo_table_destroy(table); - printf("Impossible creating hash successfully if entries less than bucket_entries in parameter\n"); - return -1; - } - - table = odph_cuckoo_table_create("bad_param_2", 10, 0, 0); - if (table != NULL) { - odph_cuckoo_table_destroy(table); - printf("Impossible creating hash successfully if key_len in parameter is zero\n"); - return -1; - } - - printf("# Test successful. No more errors expected\n"); - - return 0; -} - -#define PERFORMANCE_CAPACITY 4000 - -/* - * Test the performance of cuckoo hash table. - * table capacity : 1,000,000 - * key size : 4 bytes - * value size : 0 - * Insert at most number random keys into the table. If one - * insertion is failed, the rest insertions will be cancelled. - * The table utilization of the report will show actual number - * of items inserted. - * Then search all inserted items. - */ -static int test_performance(int number) -{ - odph_table_t table; - - /* generate random keys */ - uint8_t *key_space = NULL; - const void **key_ptr = NULL; - unsigned key_len = 4, j; - unsigned elem_num = (number > PERFORMANCE_CAPACITY) ? - PERFORMANCE_CAPACITY : number; - unsigned key_num = key_len * elem_num; - - key_space = (uint8_t *)malloc(key_num); - if (key_space == NULL) - return -ENOENT; - - key_ptr = (const void **)malloc(sizeof(void *) * elem_num); - if (key_ptr == NULL) { - free(key_space); - return -ENOENT; - } - - for (j = 0; j < key_num; j++) { - key_space[j] = rand() % 255; - if (j % key_len == 0) - key_ptr[j / key_len] = &key_space[j]; - } - - unsigned num; - int ret = 0; - struct timeval start, end; - double add_time = 0; - - fflush(stdout); - table = odph_cuckoo_table_create( - "performance_test", PERFORMANCE_CAPACITY, key_len, 0); - if (table == NULL) { - printf("cuckoo table creation failed\n"); - free(key_ptr); - free(key_space); - return -ENOENT; - } - - /* insert (put) */ - gettimeofday(&start, 0); - for (j = 0; j < elem_num; j++) { - ret = odph_cuckoo_table_put_value( - table, &key_space[j * key_len], NULL); - if (ret < 0) - break; - } - gettimeofday(&end, 0); - num = j; - add_time = get_time_diff(&start, &end); - printf( - "add %u/%u (%.2f) items, time = %.9lfs\n", - num, PERFORMANCE_CAPACITY, - (double)num / PERFORMANCE_CAPACITY, add_time); - - /* search (get) */ - gettimeofday(&start, 0); - for (j = 0; j < num; j++) { - ret = odph_cuckoo_table_get_value( - table, &key_space[j * key_len], NULL, 0); - - if (ret < 0) - printf("lookup error\n"); - } - gettimeofday(&end, 0); - printf( - "lookup %u items, time = %.9lfs\n", - num, get_time_diff(&start, &end)); - - odph_cuckoo_table_destroy(table); - free(key_ptr); - free(key_space); - return ret; -} - -/* - * Do all unit and performance tests. - */ -static int -test_cuckoo_hash_table(void) -{ - if (test_put_remove() < 0) - return -1; - if (test_table_lookup() < 0) - return -1; - if (test_put_update_remove() < 0) - return -1; - if (test_five_keys() < 0) - return -1; - if (test_creation_with_bad_parameters() < 0) - return -1; - if (test_performance(950000) < 0) - return -1; - - return 0; -} - -int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED) -{ - odp_instance_t instance; - int ret = 0; - - ret = odp_init_global(&instance, NULL, NULL); - if (ret != 0) { - fprintf(stderr, "Error: ODP global init failed.\n"); - exit(EXIT_FAILURE); - } - - ret = odp_init_local(instance, ODP_THREAD_WORKER); - if (ret != 0) { - fprintf(stderr, "Error: ODP local init failed.\n"); - exit(EXIT_FAILURE); - } - - srand(time(0)); - ret = test_cuckoo_hash_table(); - - if (ret < 0) - printf("cuckoo hash table test fail!!\n"); - else - printf("All Tests pass!!\n"); - - if (odp_term_local()) { - fprintf(stderr, "Error: ODP local term failed.\n"); - exit(EXIT_FAILURE); - } - - if (odp_term_global(instance)) { - fprintf(stderr, "Error: ODP global term failed.\n"); - exit(EXIT_FAILURE); - } - - return ret; -} diff --git a/helper/test/iplookuptable.c b/helper/test/iplookuptable.c deleted file mode 100644 index 669d334dd..000000000 --- a/helper/test/iplookuptable.c +++ /dev/null @@ -1,170 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2016-2018 Linaro Limited - */ - -#include <stdio.h> -#include <stdint.h> -#include <string.h> -#include <stdlib.h> -#include <errno.h> - -#include <odp_api.h> -#include <odp/helper/odph_api.h> - -static void print_prefix_info( - const char *msg, uint32_t ip, uint8_t cidr) -{ - int i = 0; - uint8_t *ptr = (uint8_t *)(&ip); - - printf("%s IP prefix: ", msg); - for (i = 3; i >= 0; i--) { - if (i != 3) - printf("."); - printf("%d", ptr[i]); - } - printf("/%d\n", cidr); -} - -/* - * Basic sequence of operations for a single key: - * - put short prefix - * - put long prefix - * - get (hit long prefix) - * - remove long prefix - * - get (hit short prefix) - */ -static int test_ip_lookup_table(void) -{ - odph_iplookup_prefix_t prefix1, prefix2; - odph_table_t table; - int ret; - uint64_t value1 = 1, value2 = 2, result = 0; - uint32_t lkp_ip = 0; - - table = odph_iplookup_table_create( - "prefix_test", 0, 0, sizeof(uint32_t)); - if (table == NULL) { - printf("IP prefix lookup table creation failed\n"); - return -1; - } - - ret = odph_ipv4_addr_parse(&prefix1.ip, "192.168.0.0"); - if (ret < 0) { - printf("Failed to get IP addr from str\n"); - odph_iplookup_table_destroy(table); - return -1; - } - prefix1.cidr = 11; - - ret = odph_ipv4_addr_parse(&prefix2.ip, "192.168.0.0"); - if (ret < 0) { - printf("Failed to get IP addr from str\n"); - odph_iplookup_table_destroy(table); - return -1; - } - prefix2.cidr = 24; - - ret = odph_ipv4_addr_parse(&lkp_ip, "192.168.0.1"); - if (ret < 0) { - printf("Failed to get IP addr from str\n"); - odph_iplookup_table_destroy(table); - return -1; - } - - /* test with standard put/get/remove functions */ - ret = odph_iplookup_table_put_value(table, &prefix1, &value1); - print_prefix_info("Add", prefix1.ip, prefix1.cidr); - if (ret < 0) { - printf("Failed to add ip prefix\n"); - odph_iplookup_table_destroy(table); - return -1; - } - - ret = odph_iplookup_table_get_value(table, &lkp_ip, &result, 0); - print_prefix_info("Lkp", lkp_ip, 32); - if (ret < 0 || result != 1) { - printf("Failed to find longest prefix\n"); - odph_iplookup_table_destroy(table); - return -1; - } - - /* add a longer prefix */ - ret = odph_iplookup_table_put_value(table, &prefix2, &value2); - print_prefix_info("Add", prefix2.ip, prefix2.cidr); - if (ret < 0) { - printf("Failed to add ip prefix\n"); - odph_iplookup_table_destroy(table); - return -1; - } - - ret = odph_iplookup_table_get_value(table, &lkp_ip, &result, 0); - print_prefix_info("Lkp", lkp_ip, 32); - if (ret < 0 || result != 2) { - printf("Failed to find longest prefix\n"); - odph_iplookup_table_destroy(table); - return -1; - } - - ret = odph_iplookup_table_remove_value(table, &prefix2); - print_prefix_info("Del", prefix2.ip, prefix2.cidr); - if (ret < 0) { - printf("Failed to delete ip prefix\n"); - odph_iplookup_table_destroy(table); - return -1; - } - - ret = odph_iplookup_table_get_value(table, &lkp_ip, &result, 0); - print_prefix_info("Lkp", lkp_ip, 32); - if (ret < 0 || result != 1) { - printf("Error: found result ater deleting\n"); - odph_iplookup_table_destroy(table); - return -1; - } - - ret = odph_iplookup_table_remove_value(table, &prefix1); - print_prefix_info("Del", prefix1.ip, prefix1.cidr); - if (ret < 0) { - printf("Failed to delete prefix\n"); - odph_iplookup_table_destroy(table); - return -1; - } - - odph_iplookup_table_destroy(table); - return 0; -} - -int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED) -{ - odp_instance_t instance; - int ret = 0; - - ret = odp_init_global(&instance, NULL, NULL); - if (ret != 0) { - fprintf(stderr, "Error: ODP global init failed.\n"); - exit(EXIT_FAILURE); - } - - ret = odp_init_local(instance, ODP_THREAD_WORKER); - if (ret != 0) { - fprintf(stderr, "Error: ODP local init failed.\n"); - exit(EXIT_FAILURE); - } - - if (test_ip_lookup_table() < 0) - printf("Test failed\n"); - else - printf("All tests passed\n"); - - if (odp_term_local()) { - fprintf(stderr, "Error: ODP local term failed.\n"); - exit(EXIT_FAILURE); - } - - if (odp_term_global(instance)) { - fprintf(stderr, "Error: ODP global term failed.\n"); - exit(EXIT_FAILURE); - } - - return ret; -} diff --git a/helper/test/odpthreads.c b/helper/test/odpthreads.c index bf623569b..158b1d3c3 100644 --- a/helper/test/odpthreads.c +++ b/helper/test/odpthreads.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: BSD-3-Clause * Copyright (c) 2016-2018 Linaro Limited - * Copyright (c) 2021 Nokia + * Copyright (c) 2021-2024 Nokia */ /* @@ -73,7 +73,6 @@ int main(int argc, char *argv[]) odp_init_t init_param; int num_workers; int cpu, affinity; - int ret; char cpumaskstr[ODP_CPUMASK_STR_SIZE]; struct rlimit rlimit; pthread_attr_t attr; @@ -161,11 +160,25 @@ int main(int argc, char *argv[]) thr_param.arg = NULL; thr_param.thr_type = ODP_THREAD_WORKER; - odph_thread_create(thread_tbl, &thr_common, &thr_param, num_workers); + if (odph_thread_create(thread_tbl, &thr_common, &thr_param, num_workers) != num_workers) { + ODPH_ERR("Error: failed to create worker threads.\n"); + exit(EXIT_FAILURE); + } + + odph_thread_join_result_t res[num_workers]; - ret = odph_thread_join(thread_tbl, num_workers); - if (ret < 0) + if (odph_thread_join_result(thread_tbl, res, num_workers) != num_workers) { + ODPH_ERR("Error: failed to join worker threads.\n"); exit(EXIT_FAILURE); + } + + for (int i = 0; i < num_workers; i++) { + if (res[i].is_sig || res[i].ret != 0) { + ODPH_ERR("Error: worker thread failure%s: %d.\n", res[i].is_sig ? + " (signaled)" : "", res[i].ret); + exit(EXIT_FAILURE); + } + } /* Test threads with non-default stack size and sync timeout. */ @@ -195,11 +208,23 @@ int main(int argc, char *argv[]) printf("use sync timeout: %" PRIu64 "\n", thr_common.sync_timeout); printf("\n"); - if (odph_thread_create(thread_tbl, &thr_common, &thr_param, num_workers) != num_workers) + if (odph_thread_create(thread_tbl, &thr_common, &thr_param, num_workers) != num_workers) { + ODPH_ERR("Error: failed to create worker threads.\n"); exit(EXIT_FAILURE); + } - if (odph_thread_join(thread_tbl, num_workers) != num_workers) + if (odph_thread_join_result(thread_tbl, res, num_workers) != num_workers) { + ODPH_ERR("Error: failed to join worker threads.\n"); exit(EXIT_FAILURE); + } + + for (int i = 0; i < num_workers; i++) { + if (res[i].is_sig || res[i].ret != 0) { + ODPH_ERR("Error: worker thread failure%s: %d.\n", res[i].is_sig ? + " (signaled)" : "", res[i].ret); + exit(EXIT_FAILURE); + } + } return 0; } diff --git a/helper/test/stress.c b/helper/test/stress.c new file mode 100644 index 000000000..e66a0447d --- /dev/null +++ b/helper/test/stress.c @@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(C) 2024 Nokia + */ + +#include <odp_api.h> +#include <odp/helper/odph_api.h> + +#include <stdio.h> +#include <stdlib.h> + +static int test_pow2(void) +{ + uint32_t in[] = {0, 1, 2, 3, 4, 0xff, 0x100, 0xfffe, 0xffff, 0x10000}; + uint32_t out[] = {0, 1, 4, 9, 16, 0xfe01, 0x10000, 0xfffc0004, 0xfffe0001, 0xffffffff}; + uint32_t num = ODPH_ARRAY_SIZE(out); + int ret = 0; + + printf(" odph_stress_pow2_u32() ... "); + + for (uint32_t i = 0; i < num; i++) + if (odph_stress_pow2_u32(in[i]) != out[i]) + ret++; + + if (ret) + printf("%i tests failed\n", ret); + else + printf("passed\n"); + + return ret; +} + +static int test_log2(void) +{ + uint32_t in[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 15, 16, 255, 256, 257, 512, 513, 1023, 1024}; + uint32_t out[] = {0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 4, 7, 8, 8, 9, 9, 9, 10}; + uint32_t num = ODPH_ARRAY_SIZE(out); + int ret = 0; + + printf(" odph_stress_log2_u32() ... "); + + for (uint32_t i = 0; i < num; i++) + if (odph_stress_log2_u32(in[i]) != out[i]) + ret++; + + if (ret) + printf("%i tests failed\n", ret); + else + printf("passed\n"); + + return ret; +} + +static int test_sqrt_u32(void) +{ + uint32_t in[] = {0, 1, 2, 3, 4, 7, 8, 9, 100, 1500, 2900, 4096, 6213, 8191, 16384, 100000, + 1000000, 4036587, 0x42c1d80, 0x8000000, 0x1fffffff, 0x2faf0800, + 0xffffffff}; + uint32_t out[] = {0, 1, 1, 1, 2, 2, 2, 3, 10, 38, 53, 64, 78, 90, 128, 316, 1000, 2009, + 8366, 11585, 23170, 28284, 65535}; + uint32_t num = ODPH_ARRAY_SIZE(out); + int ret = 0; + + printf(" odph_stress_sqrt_u32() ... "); + + for (uint32_t i = 0; i < num; i++) + if (odph_stress_sqrt_u32(in[i]) != out[i]) + ret++; + + if (ret) + printf("%i tests failed\n", ret); + else + printf("passed\n"); + + return ret; +} + +/* + * 32-bit floating point can represent integers between 0 and 16777216 exactly, and integers + * between 16777216 and 33554432 in multiples of 2, etc. + */ +static int test_sqrt_f32(void) +{ + float in[] = {0, 1, 2, 3, 4, 7, 8, 9, 100, 1500, 2900, 4096, 6213, 8191, 16384, 100000, + 1000000, 4036587, 16777216, 33554432, 134217728, 3000000000, 4294967296}; + float out[] = {0, 1, 1, 1, 2, 2, 2, 3, 10, 38, 53, 64, 78, 90, 128, 316, 1000, 2009, 4096, + 5792, 11585, 54772, 65536}; + uint32_t num = ODPH_ARRAY_SIZE(out); + int ret = 0; + + printf(" odph_stress_sqrt_f32() ... "); + + for (uint32_t i = 0; i < num; i++) + if (odph_stress_sqrt_f32(in[i]) != out[i]) + ret++; + + if (ret) + printf("%i tests failed\n", ret); + else + printf("passed\n"); + + return ret; +} + +int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED) +{ + int ret = 0; + + printf("Running helper algorithm tests:\n"); + + ret += test_pow2(); + ret += test_log2(); + ret += test_sqrt_u32(); + ret += test_sqrt_f32(); + + printf("\n"); + + return ret ? EXIT_FAILURE : EXIT_SUCCESS; +} diff --git a/helper/test/table.c b/helper/test/table.c deleted file mode 100644 index fb17e8a37..000000000 --- a/helper/test/table.c +++ /dev/null @@ -1,130 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * Copyright (c) 2015-2018 Linaro Limited - */ - -#include <odp_api.h> -#include <odp/helper/odph_api.h> - -/** - * Address Resolution Protocol (ARP) - * Description: Once a route has been identified for an IP packet (so the - * output interface and the IP address of the next hop station are known), - * the MAC address of the next hop station is needed in order to send this - * packet onto the next leg of the journey towards its destination - * (as identified by its destination IP address). The MAC address of the next - * hop station becomes the destination MAC address of the outgoing - * Ethernet frame. - * Hash table name: ARP table - * Number of keys: Thousands - * Key format: The pair of (Output interface, Next Hop IP address), - * which is typically 5 bytes for IPv4 and 17 bytes for IPv6. - * value (data): MAC address of the next hop station (6 bytes). - */ - -int main(int argc ODP_UNUSED, char *argv[] ODP_UNUSED) -{ - odp_instance_t instance; - int ret = 0; - odph_table_t table; - odph_table_t tmp_tbl; - odph_table_ops_t *test_ops; - char tmp[32]; - char ip_addr1[] = "12345678"; - char ip_addr2[] = "11223344"; - char ip_addr3[] = "55667788"; - char mac_addr1[] = "0A1122334401"; - char mac_addr2[] = "0A1122334402"; - char mac_addr3[] = "0B4433221101"; - char mac_addr4[] = "0B4433221102"; - - ret = odp_init_global(&instance, NULL, NULL); - if (ret != 0) { - ODPH_ERR("odp_shm_init_global fail\n"); - exit(EXIT_FAILURE); - } - ret = odp_init_local(instance, ODP_THREAD_WORKER); - if (ret != 0) { - ODPH_ERR("odp_shm_init_local fail\n"); - exit(EXIT_FAILURE); - } - - printf("test hash table:\n"); - test_ops = &odph_hash_table_ops; - - table = test_ops->f_create("test", 2, 4, 16); - if (table == NULL) { - printf("table create fail\n"); - return -1; - } - ret += test_ops->f_put(table, &ip_addr1, mac_addr1); - - ret += test_ops->f_put(table, &ip_addr2, mac_addr2); - - ret += test_ops->f_put(table, &ip_addr3, mac_addr3); - - if (ret != 0) { - printf("put value fail\n"); - return -1; - } - - ret = test_ops->f_get(table, &ip_addr1, &tmp, 32); - if (ret != 0) { - printf("get value fail\n"); - return -1; - } - printf("\t1 get '123' tmp = %s,\n", tmp); - - ret = test_ops->f_put(table, &ip_addr1, mac_addr4); - if (ret != 0) { - printf("repeat put value fail\n"); - return -1; - } - - ret = test_ops->f_get(table, &ip_addr1, &tmp, 32); - if (ret != 0 || strcmp(tmp, mac_addr4) != 0) { - printf("get value fail\n"); - return -1; - } - - printf("\t2 repeat get '123' value = %s\n", tmp); - - ret = test_ops->f_remove(table, &ip_addr1); - if (ret != 0) { - printf("remove value fail\n"); - return -1; - } - ret = test_ops->f_get(table, &ip_addr1, tmp, 32); - if (ret == 0) { - printf("remove value fail actually\n"); - return -1; - } - printf("\t3 remove success!\n"); - - tmp_tbl = test_ops->f_lookup("test"); - if (tmp_tbl != table) { - printf("lookup table fail!!!\n"); - return -1; - } - printf("\t4 lookup table success!\n"); - - ret = test_ops->f_des(table); - if (ret != 0) { - printf("destroy table fail!!!\n"); - exit(EXIT_FAILURE); - } - printf("\t5 destroy table success!\n"); - - printf("all test finished success!!\n"); - - if (odp_term_local()) { - ODPH_ERR("Error: ODP local term failed.\n"); - exit(EXIT_FAILURE); - } - - if (odp_term_global(instance)) { - ODPH_ERR("Error: ODP global term failed.\n"); - exit(EXIT_FAILURE); - } - - return 0; -} |