diff options
Diffstat (limited to 'test')
22 files changed, 3210 insertions, 1199 deletions
diff --git a/test/performance/.gitignore b/test/performance/.gitignore index 7952530a3..6a891a146 100644 --- a/test/performance/.gitignore +++ b/test/performance/.gitignore @@ -6,6 +6,7 @@ odp_bench_packet odp_cpu_bench odp_crc odp_crypto +odp_dma_perf odp_ipsec odp_l2fwd odp_lock_perf diff --git a/test/performance/Makefile.am b/test/performance/Makefile.am index b6dbbd82e..2a87424f1 100644 --- a/test/performance/Makefile.am +++ b/test/performance/Makefile.am @@ -15,7 +15,8 @@ EXECUTABLES = odp_atomic_perf \ odp_queue_perf \ odp_random -COMPILE_ONLY = odp_l2fwd \ +COMPILE_ONLY = odp_dma_perf \ + odp_l2fwd \ odp_packet_gen \ odp_pktio_ordered \ odp_sched_latency \ @@ -24,7 +25,8 @@ COMPILE_ONLY = odp_l2fwd \ odp_scheduling \ odp_timer_perf -TESTSCRIPTS = odp_l2fwd_run.sh \ +TESTSCRIPTS = odp_dma_perf_run.sh \ + odp_l2fwd_run.sh \ odp_packet_gen_run.sh \ odp_sched_latency_run.sh \ odp_sched_perf_run.sh \ @@ -49,6 +51,7 @@ odp_bench_packet_SOURCES = odp_bench_packet.c odp_cpu_bench_SOURCES = odp_cpu_bench.c odp_crc_SOURCES = odp_crc.c odp_crypto_SOURCES = odp_crypto.c +odp_dma_perf_SOURCES = odp_dma_perf.c odp_ipsec_SOURCES = odp_ipsec.c odp_lock_perf_SOURCES = odp_lock_perf.c odp_mem_perf_SOURCES = odp_mem_perf.c diff --git a/test/performance/odp_crypto.c b/test/performance/odp_crypto.c index 341782630..d9acfb31e 100644 --- a/test/performance/odp_crypto.c +++ b/test/performance/odp_crypto.c @@ -219,10 +219,7 @@ static crypto_alg_config_t algs_config[] = { .data = test_key24, .length = sizeof(test_key24) }, - .cipher_iv = { - .data = test_iv, - .length = 8, - }, + .cipher_iv_len = 8, .auth_alg = ODP_AUTH_ALG_NULL }, }, @@ -234,10 +231,7 @@ static crypto_alg_config_t algs_config[] = { .data = test_key24, .length = sizeof(test_key24) }, - .cipher_iv = { - .data = test_iv, - .length = 8, - }, + .cipher_iv_len = 8, .auth_alg = ODP_AUTH_ALG_MD5_HMAC, .auth_key = { .data = test_key16, @@ -266,10 +260,7 @@ static crypto_alg_config_t algs_config[] = { .data = test_key16, .length = sizeof(test_key16) }, - .cipher_iv = { - .data = test_iv, - .length = 16, - }, + .cipher_iv_len = 16, .auth_alg = ODP_AUTH_ALG_NULL }, }, @@ -281,10 +272,7 @@ static crypto_alg_config_t algs_config[] = { .data = test_key16, .length = sizeof(test_key16) }, - .cipher_iv = { - .data = test_iv, - .length = 16, - }, + .cipher_iv_len = 16, .auth_alg = ODP_AUTH_ALG_SHA1_HMAC, .auth_key = { .data = test_key20, @@ -313,10 +301,7 @@ static crypto_alg_config_t algs_config[] = { .data = test_key16, .length = sizeof(test_key16) }, - .cipher_iv = { - .data = test_iv, - .length = 16, - }, + .cipher_iv_len = 16, .auth_alg = ODP_AUTH_ALG_NULL }, }, @@ -328,10 +313,7 @@ static crypto_alg_config_t algs_config[] = { .data = test_key16, .length = sizeof(test_key16) }, - .cipher_iv = { - .data = test_iv, - .length = 16, - }, + .cipher_iv_len = 16, .auth_alg = ODP_AUTH_ALG_SHA1_HMAC, .auth_key = { .data = test_key20, @@ -373,10 +355,7 @@ static crypto_alg_config_t algs_config[] = { .data = test_key16, .length = sizeof(test_key16) }, - .auth_iv = { - .data = test_iv, - .length = 12, - }, + .auth_iv_len = 12, .auth_digest_len = 16, }, }, @@ -388,10 +367,7 @@ static crypto_alg_config_t algs_config[] = { .data = test_key16, .length = sizeof(test_key16) }, - .cipher_iv = { - .data = test_iv, - .length = 12, - }, + .cipher_iv_len = 12, .auth_alg = ODP_AUTH_ALG_AES_GCM, .auth_digest_len = 16, }, @@ -404,10 +380,7 @@ static crypto_alg_config_t algs_config[] = { .data = test_key16, .length = sizeof(test_key16) }, - .cipher_iv = { - .data = test_iv, - .length = 11, - }, + .cipher_iv_len = 11, .auth_alg = ODP_AUTH_ALG_AES_CCM, .auth_digest_len = 16, }, @@ -420,10 +393,7 @@ static crypto_alg_config_t algs_config[] = { .data = test_key32, .length = sizeof(test_key32) }, - .cipher_iv = { - .data = test_iv, - .length = 12, - }, + .cipher_iv_len = 12, .auth_alg = ODP_AUTH_ALG_CHACHA20_POLY1305, .auth_digest_len = 16, }, @@ -725,6 +695,8 @@ run_measure_one(crypto_args_t *cargs, /* Initialize parameters block */ memset(¶ms, 0, sizeof(params)); params.session = *session; + params.cipher_iv_ptr = test_iv; + params.auth_iv_ptr = test_iv; params.cipher_range.offset = 0; params.cipher_range.length = payload_length; diff --git a/test/performance/odp_dma_perf.c b/test/performance/odp_dma_perf.c new file mode 100644 index 000000000..26397bf49 --- /dev/null +++ b/test/performance/odp_dma_perf.c @@ -0,0 +1,1106 @@ +/* Copyright (c) 2021-2022, Nokia + * + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <inttypes.h> + +#include <odp_api.h> +#include <odp/helper/odph_api.h> + +#define EXIT_NOT_SUP 2 + +#define DEFAULT_SEG_SIZE 1024U +#define ROUNDS 1000000 +#define COMPL_DELIMITER "," +/* For now, a static maximum amount of input segments */ +#define MAX_NUM_IN_SEGS 64 +#define SHM_SRC "odp_dma_perf_shm_src" +#define SHM_DST "odp_dma_perf_shm_dst" + +#define TRS_TYPE_SYNC 0 +#define TRS_TYPE_ASYNC 1 + +#define GRN_ALL 0 +#define GRN_IND 1 + +#define TYPE_PKT 0 +#define TYPE_MEM 1 + +#define COMPL_MODE_POLL 0 +#define COMPL_MODE_EVENT 1 + +#define GIGAS 1000000000 +#define MEGAS 1000000 +#define KILOS 1000 + +typedef struct test_config_t { + int trs_type; + int trs_grn; + int num_in_seg; + uint32_t seg_size; + int seg_type; + int num_rounds; + int dma_rounds; + + struct { + int num_modes; + uint32_t compl_mask; + int modes[MAX_NUM_IN_SEGS]; + } compl_modes; + + struct { + odp_pool_t pool; + odp_queue_t compl_q; + odp_dma_t handle; + odp_dma_seg_t dst_seg; + odp_dma_seg_t src_seg[MAX_NUM_IN_SEGS]; + } dma_config; + + union { + struct { + odp_shm_t shm_src; + odp_shm_t shm_dst; + void *src; + void *dst; + }; + + struct { + odp_pool_t pool; + odp_packet_t pkts[MAX_NUM_IN_SEGS + 1]; + }; + } seg_config; + + struct { + int (*setup_fn)(struct test_config_t *config); + void (*trs_base_fn)(struct test_config_t *config, + odp_dma_transfer_param_t *trs_params, uint32_t *trs_lengths); + void (*trs_dyn_fn)(struct test_config_t *config, uint32_t offset, uint32_t len); + int (*verify_fn)(const struct test_config_t *config); + void (*free_fn)(struct test_config_t *config); + int (*run_fn)(struct test_config_t *config); + } test_case_api; +} test_config_t; + +typedef struct compl_wait_entry_t { + int type; + odp_dma_transfer_id_t id; +} compl_wait_entry_t; + +static const int compl_mode_map[] = { ODP_DMA_COMPL_POLL, ODP_DMA_COMPL_EVENT }; + +static void set_option_defaults(test_config_t *config) +{ + memset(config, 0, sizeof(*config)); + config->num_in_seg = 1; + config->seg_size = DEFAULT_SEG_SIZE; + config->num_rounds = ROUNDS; + config->compl_modes.compl_mask = ODP_DMA_COMPL_SYNC; +} + +static void parse_completion_modes(test_config_t *config, const char *optarg) +{ + char *tmp_str = strdup(optarg); + char *tmp = strtok(tmp_str, COMPL_DELIMITER); + int mode; + uint32_t i = 0U; + + config->compl_modes.num_modes = 0; + + if (tmp == NULL) { + free(tmp_str); + return; + } + + while (tmp) { + mode = atoi(tmp); + config->compl_modes.modes[i] = mode; + config->compl_modes.compl_mask |= compl_mode_map[mode]; + ++i; + ++config->compl_modes.num_modes; + tmp = strtok(NULL, COMPL_DELIMITER); + } + + free(tmp_str); +} + +static void print_usage(void) +{ + printf("\n" + "DMA performance test. Transfers a set of source segments to a single destination\n" + "segment.\n" + "\n" + "Examples:\n" + " odp_dma_perf\n" + " odp_dma_perf -t 0 -g 1 -i 2\n" + " odp_dma_perf -t 1 -g 1 -i 4 -m 0,0,0,0\n" + " odp_dma_perf -t 1 -g 1 -i 7 -m 0,0,0,0,0,0,1 -T 1 -r 1000 -s 2048\n" + "\n" + "Usage: odp_dma_perf [options]\n" + "\n" + " -t, --trs_type Transfer type for test data. Synchronous by default.\n" + " Types:\n" + " 0: synchronous\n" + " 1: asynchronous\n" + " -g, --trs_grn Transfer granularity for source segments. All\n" + " segments are sent in one transfer by default.\n" + " Options:\n" + " 0: all segments in a single transfer\n" + " 1: individual transfers for segments\n" + " -i, --num_in_seg Number of input segments to transfer. 1 by\n" + " default. Maximum supported amount is %d.\n" + " -s, --in_seg_size Segment size for all input segments in bytes. 1024\n" + " bytes by default. Maximum allowed destination\n" + " segment size may limit this choice.\n" + " -T, --in_seg_type Input segment data type. Packet by default.\n" + " Types:\n" + " 0: packet\n" + " 1: memory\n" + " -m, --compl_modes Completion mode(s) for transfers delimited by a\n" + " comma. Only applicable in asynchronous mode.\n" + " Modes:\n" + " 0: poll\n" + " 1: event\n" + " -r, --num_rounds Number of times to run the test scenario. %d by\n" + " default.\n" + " -h, --help This help.\n" + "\n", + MAX_NUM_IN_SEGS, ROUNDS); +} + +static int check_completion_modes(test_config_t *config) +{ + if (config->trs_type == TRS_TYPE_SYNC) + return 0; + + if (config->compl_modes.num_modes > MAX_NUM_IN_SEGS) + return -1; + + if (config->trs_grn == GRN_IND && + config->num_in_seg != config->compl_modes.num_modes) + return -1; + + if (config->trs_grn == GRN_ALL && + config->compl_modes.num_modes != 1) + return -1; + + for (int i = 0; i < config->compl_modes.num_modes; ++i) { + if (config->compl_modes.modes[i] != COMPL_MODE_POLL && + config->compl_modes.modes[i] != COMPL_MODE_EVENT) + return -1; + + config->compl_modes.modes[i] = compl_mode_map[config->compl_modes.modes[i]]; + } + + return 0; +} + +static int check_options(test_config_t *config) +{ + if (config->trs_type != TRS_TYPE_SYNC && + config->trs_type != TRS_TYPE_ASYNC) { + ODPH_ERR("Invalid transfer type: %d.\n", config->trs_type); + return -1; + } + + if (config->trs_grn != GRN_ALL && config->trs_grn != GRN_IND) { + ODPH_ERR("Invalid granularity: %d.\n", config->trs_grn); + return -1; + } + + config->dma_rounds = config->trs_grn == GRN_IND ? config->num_in_seg : 1; + + if (config->num_in_seg < 1 || config->num_in_seg > MAX_NUM_IN_SEGS) { + ODPH_ERR("Invalid number of input segments: %d.\n", config->num_in_seg); + return -1; + } + + if (config->seg_type != TYPE_PKT && config->seg_type != TYPE_MEM) { + ODPH_ERR("Invalid input segment type: %d.\n", config->seg_type); + return -1; + } + + if (check_completion_modes(config)) { + ODPH_ERR("Invalid completion modes.\n"); + return -1; + } + + if (config->num_rounds < 1) { + ODPH_ERR("Invalid number of rounds: %d.\n", config->num_rounds); + return -1; + } + + return 0; +} + +static int parse_options(int argc, char **argv, test_config_t *config) +{ + int opt, long_index; + + static const struct option longopts[] = { + { "trs_type", required_argument, NULL, 't' }, + { "trs_grn", required_argument, NULL, 'g' }, + { "num_in_seg", required_argument, NULL, 'i' }, + { "in_seg_size", required_argument, NULL, 's' }, + { "in_seg_type", required_argument, NULL, 'T' }, + { "compl_modes", required_argument, NULL, 'm' }, + { "num_rounds", required_argument, NULL, 'r' }, + { "help", no_argument, NULL, 'h' }, + { NULL, 0, NULL, 0 } + }; + + static const char *shortopts = "t:g:i:s:T:m:r:h"; + + set_option_defaults(config); + + while (1) { + opt = getopt_long(argc, argv, shortopts, longopts, &long_index); + + if (opt == -1) + break; + + switch (opt) { + case 't': + config->trs_type = atoi(optarg); + break; + case 'g': + config->trs_grn = atoi(optarg); + break; + case 'i': + config->num_in_seg = atoi(optarg); + break; + case 's': + config->seg_size = atoi(optarg); + break; + case 'T': + config->seg_type = atoi(optarg); + break; + case 'm': + parse_completion_modes(config, optarg); + break; + case 'r': + config->num_rounds = atoi(optarg); + break; + case 'h': + default: + print_usage(); + return -1; + } + } + + if (check_options(config)) + return -1; + + return 0; +} + +static int check_shm_capabilities(const test_config_t *config) +{ + odp_shm_capability_t capa; + + if (odp_shm_capability(&capa)) { + ODPH_ERR("Error querying SHM capabilities.\n"); + return -1; + } + + if (capa.max_blocks < 2U) { + ODPH_ERR("Unsupported amount of SHM blocks.\n"); + return -1; + } + + if (capa.max_size != 0U && config->num_in_seg * config->seg_size > capa.max_size) { + ODPH_ERR("Unsupported total SHM block size.\n"); + return -1; + } + + if (capa.max_align != 0U && capa.max_align < ODP_CACHE_LINE_SIZE) { + ODPH_ERR("Unsupported SHM block alignment size.\n"); + return -1; + } + + return 0; +} + +static int check_dma_capabilities(const test_config_t *config) +{ + odp_dma_capability_t capa; + const int is_event = config->compl_modes.compl_mask & ODP_DMA_COMPL_EVENT; + uint32_t event_compl_count = 0U; + + if (odp_dma_capability(&capa)) { + ODPH_ERR("Error querying DMA capabilities.\n"); + return -1; + } + + if (capa.max_sessions == 0U) { + ODPH_ERR("DMA not supported.\n"); + return -1; + } + + if (config->trs_type == TRS_TYPE_ASYNC) { + if ((config->compl_modes.compl_mask & ODP_DMA_COMPL_POLL) && + (capa.compl_mode_mask & ODP_DMA_COMPL_POLL) == 0U) { + ODPH_ERR("Unsupported DMA completion mode, poll.\n"); + return -1; + } + + if (is_event && (capa.compl_mode_mask & ODP_DMA_COMPL_EVENT) == 0U) { + ODPH_ERR("Unsupported DMA completion mode, event.\n"); + return -1; + } + + if (is_event && capa.queue_type_sched == 0) { + ODPH_ERR("Unsupported DMA queueing type.\n"); + return -1; + } + + if (config->trs_grn == GRN_IND) { + if ((uint32_t)config->num_in_seg > capa.max_transfers) { + ODPH_ERR("Unsupported amount of in-flight DMA transfers.\n"); + return -1; + } + + for (int i = 0; i < config->compl_modes.num_modes; ++i) + if (config->compl_modes.modes[i] == ODP_DMA_COMPL_EVENT) + ++event_compl_count; + + if (event_compl_count > capa.pool.max_num) { + ODPH_ERR("Unsupported amount of completion events.\n"); + return -1; + } + } + } + + if (config->trs_grn == GRN_ALL) { + if ((uint32_t)config->num_in_seg > capa.max_src_segs) { + ODPH_ERR("Unsupported amount of DMA source segments.\n"); + return -1; + } + + if (config->num_in_seg + 1U > capa.max_segs) { + ODPH_ERR("Unsupported total amount of DMA segments.\n"); + return -1; + } + } + + if (config->trs_grn == GRN_IND && capa.max_segs < 2U) { + ODPH_ERR("Unsupported total amount of DMA segments.\n"); + return -1; + } + + if (config->num_in_seg * config->seg_size > capa.max_seg_len) { + ODPH_ERR("Unsupported total DMA segment size.\n"); + return -1; + } + + return 0; +} + +static int check_capabilities(const test_config_t *config) +{ + return check_shm_capabilities(config) || + check_dma_capabilities(config); +} + +static int configure_packets(test_config_t *config) +{ + odp_pool_param_t param; + + for (int i = 0; i < config->num_in_seg + 1; ++i) + config->seg_config.pkts[i] = ODP_PACKET_INVALID; + + odp_pool_param_init(¶m); + param.type = ODP_POOL_PACKET; + /* Configured amount of input segments and one output segment */ + param.pkt.num = config->num_in_seg + 1U; + param.pkt.len = config->num_in_seg * config->seg_size; + config->seg_config.pool = odp_pool_create("odp_dma_perf_packets", ¶m); + + if (config->seg_config.pool == ODP_POOL_INVALID) { + ODPH_ERR("Error creating packet pool.\n"); + return -1; + } + + return 0; +} + +static int allocate_packets(test_config_t *config) +{ + for (int i = 0; i < config->num_in_seg; ++i) { + config->seg_config.pkts[i] = odp_packet_alloc(config->seg_config.pool, + config->seg_size); + + if (config->seg_config.pkts[i] == ODP_PACKET_INVALID) { + ODPH_ERR("Error allocating input test packets.\n"); + return -1; + } + } + + config->seg_config.pkts[config->num_in_seg] = + odp_packet_alloc(config->seg_config.pool, config->num_in_seg * config->seg_size); + + if (config->seg_config.pkts[config->num_in_seg] == ODP_PACKET_INVALID) { + ODPH_ERR("Error allocating output test packet.\n"); + return -1; + } + + return 0; +} + +static int populate_packets(test_config_t *config) +{ + for (int i = 0; i < config->num_in_seg; ++i) { + uint8_t data[odp_packet_len(config->seg_config.pkts[i])]; + + memset(data, i + 1, sizeof(data)); + + if (odp_packet_copy_from_mem(config->seg_config.pkts[i], 0U, sizeof(data), data)) + return -1; + } + + return 0; +} + +static int setup_packet_segments(test_config_t *config) +{ + return configure_packets(config) || + allocate_packets(config) || + populate_packets(config); +} + +static void configure_packet_dma_transfer_base(test_config_t *config, + odp_dma_transfer_param_t trs_params[], + uint32_t trs_lengths[]) +{ + memset(trs_lengths, 0, sizeof(*trs_lengths) * config->dma_rounds); + + for (int i = 0; i < config->num_in_seg; ++i) { + config->dma_config.src_seg[i].packet = config->seg_config.pkts[i]; + config->dma_config.src_seg[i].offset = 0U; + config->dma_config.src_seg[i].len = odp_packet_len(config->seg_config.pkts[i]); + } + + config->dma_config.dst_seg.packet = config->seg_config.pkts[config->num_in_seg]; + + for (int i = 0; i < config->dma_rounds; ++i) { + odp_dma_transfer_param_init(&trs_params[i]); + trs_params[i].src_format = ODP_DMA_FORMAT_PACKET; + trs_params[i].dst_format = ODP_DMA_FORMAT_PACKET; + trs_params[i].num_src = config->trs_grn == GRN_IND ? 1 : config->num_in_seg; + trs_params[i].num_dst = 1U; + trs_params[i].src_seg = &config->dma_config.src_seg[i]; + trs_params[i].dst_seg = &config->dma_config.dst_seg; + trs_lengths[i] = config->trs_grn == GRN_IND ? + config->dma_config.src_seg[i].len : + config->num_in_seg * config->seg_size; + } +} + +static inline void configure_packet_dma_transfer_dynamic(test_config_t *config, uint32_t offset, + uint32_t len) +{ + config->dma_config.dst_seg.offset = offset; + config->dma_config.dst_seg.len = len; +} + +static int verify_packet_transfer(const test_config_t *config) +{ + uint32_t len, offset = 0U; + + for (int i = 0; i < config->num_in_seg; ++i) { + len = odp_packet_len(config->seg_config.pkts[i]); + uint8_t src_data[len]; + uint8_t dst_data[len]; + + if (odp_packet_copy_to_mem(config->seg_config.pkts[i], 0U, len, src_data) || + odp_packet_copy_to_mem(config->seg_config.pkts[config->num_in_seg], offset, + len, dst_data)) { + ODPH_ERR("Error verifying DMA transfer.\n"); + return -1; + } + + if (memcmp(src_data, dst_data, len)) { + ODPH_ERR("Error in DMA transfer, source and destination data do not match.\n"); + return -1; + } + + offset += len; + } + + return 0; +} + +static void free_packets(test_config_t *config) +{ + /* Configured amount of input segments and one output segment */ + for (int i = 0; i < config->num_in_seg + 1; ++i) + if (config->seg_config.pkts[i] != ODP_PACKET_INVALID) + odp_packet_free(config->seg_config.pkts[i]); + + if (config->seg_config.pool != ODP_POOL_INVALID) + (void)odp_pool_destroy(config->seg_config.pool); +} + +static int allocate_memory(test_config_t *config) +{ + const uint64_t size = config->num_in_seg * (uint64_t)config->seg_size; + + config->seg_config.shm_src = ODP_SHM_INVALID; + config->seg_config.shm_dst = ODP_SHM_INVALID; + config->seg_config.src = NULL; + config->seg_config.dst = NULL; + + config->seg_config.shm_src = odp_shm_reserve(SHM_SRC, size, ODP_CACHE_LINE_SIZE, 0); + config->seg_config.shm_dst = odp_shm_reserve(SHM_DST, size, ODP_CACHE_LINE_SIZE, 0); + + if (config->seg_config.shm_src == ODP_SHM_INVALID || + config->seg_config.shm_dst == ODP_SHM_INVALID) { + ODPH_ERR("Error allocating SHM block.\n"); + return -1; + } + + config->seg_config.src = odp_shm_addr(config->seg_config.shm_src); + config->seg_config.dst = odp_shm_addr(config->seg_config.shm_dst); + + if (config->seg_config.src == NULL || config->seg_config.dst == NULL) { + ODPH_ERR("Error resolving SHM block address.\n"); + return -1; + } + + return 0; +} + +static int populate_memory(test_config_t *config) +{ + uint8_t val; + uint8_t *addr; + + for (int i = 0; i < config->num_in_seg; ++i) { + val = 0U; + addr = (uint8_t *)config->seg_config.src + i * config->seg_size; + + for (uint32_t i = 0U; i < config->seg_size; ++i) + addr[i] = val++; + } + + return 0; +} + +static int setup_memory_segments(test_config_t *config) +{ + return allocate_memory(config) || + populate_memory(config); +} + +static void configure_address_dma_transfer_base(test_config_t *config, + odp_dma_transfer_param_t trs_params[], + uint32_t trs_lengths[]) +{ + memset(trs_lengths, 0, sizeof(*trs_lengths) * config->dma_rounds); + + for (int i = 0; i < config->num_in_seg; ++i) { + config->dma_config.src_seg[i].addr = + (uint8_t *)config->seg_config.src + i * config->seg_size; + config->dma_config.src_seg[i].len = config->seg_size; + } + + config->dma_config.dst_seg.addr = config->seg_config.dst; + + for (int i = 0; i < config->dma_rounds; ++i) { + odp_dma_transfer_param_init(&trs_params[i]); + trs_params[i].src_format = ODP_DMA_FORMAT_ADDR; + trs_params[i].dst_format = ODP_DMA_FORMAT_ADDR; + trs_params[i].num_src = config->trs_grn == GRN_IND ? 1 : config->num_in_seg; + trs_params[i].num_dst = 1U; + trs_params[i].src_seg = &config->dma_config.src_seg[i]; + trs_params[i].dst_seg = &config->dma_config.dst_seg; + trs_lengths[i] = config->trs_grn == GRN_IND ? + config->dma_config.src_seg[i].len : + config->num_in_seg * config->seg_size; + } +} + +static inline void configure_address_dma_transfer_dynamic(test_config_t *config, uint32_t offset, + uint32_t len) +{ + config->dma_config.dst_seg.addr = (uint8_t *)config->seg_config.dst + offset; + config->dma_config.dst_seg.len = len; +} + +static int verify_memory_transfer(const test_config_t *config) +{ + if (memcmp(config->seg_config.src, config->seg_config.dst, + config->num_in_seg * config->seg_size)) { + ODPH_ERR("Error in DMA transfer, source and destination data do not match.\n"); + return -1; + } + + return 0; +} + +static void free_memory(test_config_t *config) +{ + if (config->seg_config.shm_src != ODP_SHM_INVALID) + (void)odp_shm_free(config->seg_config.shm_src); + + if (config->seg_config.shm_dst != ODP_SHM_INVALID) + (void)odp_shm_free(config->seg_config.shm_dst); +} + +static void print_humanised_speed(uint64_t speed) +{ + if (speed > GIGAS) + printf("%.2f GB/s\n", (double)speed / GIGAS); + else if (speed > MEGAS) + printf("%.2f MB/s\n", (double)speed / MEGAS); + else if (speed > KILOS) + printf("%.2f KB/s\n", (double)speed / KILOS); + else + printf("%" PRIu64 " B/s\n", speed); +} + +static void print_results(const test_config_t *config, uint64_t time) +{ + const int is_sync = config->trs_type == TRS_TYPE_SYNC; + const uint64_t avg_time = time / config->num_rounds; + uint64_t avg_speed = 0U; + + printf("\n" + "=============================================\n\n" + "DMA transfer test done\n\n" + " mode: %s\n" + " granularity: %s\n" + " input segment count: %d\n" + " segment size: %u\n" + " segment type: %s\n", + is_sync ? "synchronous" : "asynchronous", + config->trs_grn == GRN_IND ? "individual" : "all", + config->num_in_seg, config->seg_size, + config->seg_type == TYPE_PKT ? "packet" : "memory"); + + if (!is_sync) { + printf(" completion modes in order: "); + + for (int i = 0; i < config->compl_modes.num_modes; ++i) + printf("%s", config->compl_modes.modes[i] == ODP_DMA_COMPL_POLL ? + "poll " : "event "); + + printf("\n"); + } + + if (avg_time > 0U) + avg_speed = config->num_in_seg * config->seg_size * ODP_TIME_SEC_IN_NS / avg_time; + + printf(" rounds run: %d\n" + " average time per transfer: %" PRIu64 " ns\n" + " average transfer speed: ", + config->num_rounds, avg_time); + print_humanised_speed(avg_speed); + printf("\n=============================================\n"); +} + +static int run_dma_sync(test_config_t *config) +{ + odp_dma_transfer_param_t trs_params[config->dma_rounds]; + uint32_t trs_lengths[config->dma_rounds]; + odp_time_t start, end; + uint32_t num_rounds = config->num_rounds, offset; + + config->test_case_api.trs_base_fn(config, trs_params, trs_lengths); + start = odp_time_local_strict(); + + while (num_rounds--) { + offset = 0U; + + for (int i = 0; i < config->dma_rounds; ++i) { + config->test_case_api.trs_dyn_fn(config, offset, trs_lengths[i]); + + if (odp_dma_transfer(config->dma_config.handle, &trs_params[i], NULL) + <= 0) { + ODPH_ERR("Error starting a sync DMA transfer.\n"); + return -1; + } + + offset += trs_lengths[i]; + } + } + + end = odp_time_local_strict(); + print_results(config, odp_time_diff_ns(end, start)); + return 0; +} + +static int configure_dma_event_completion(test_config_t *config) +{ + int ret; + odp_dma_pool_param_t pool_param; + odp_queue_param_t queue_param; + + config->dma_config.pool = ODP_POOL_INVALID; + config->dma_config.compl_q = ODP_QUEUE_INVALID; + + ret = odp_schedule_config(NULL); + + if (ret < 0) { + ODPH_ERR("Error configuring scheduler.\n"); + return -1; + } + + odp_dma_pool_param_init(&pool_param); + pool_param.num = config->num_in_seg; + config->dma_config.pool = odp_dma_pool_create("odp_dma_perf_events", &pool_param); + + if (config->dma_config.pool == ODP_POOL_INVALID) { + ODPH_ERR("Error creating DMA event completion pool.\n"); + return -1; + } + + odp_queue_param_init(&queue_param); + queue_param.type = ODP_QUEUE_TYPE_SCHED; + queue_param.sched.sync = ODP_SCHED_SYNC_PARALLEL; + queue_param.sched.prio = odp_schedule_default_prio(); + queue_param.sched.group = ODP_SCHED_GROUP_ALL; + config->dma_config.compl_q = odp_queue_create("odp_dma_perf_queue", &queue_param); + + if (config->dma_config.compl_q == ODP_QUEUE_INVALID) { + ODPH_ERR("Error creating DMA completion queue.\n"); + return -1; + } + + return 0; +} + +static int configure_dma_completion_params(test_config_t *config, + odp_dma_compl_param_t compl_params[]) +{ + odp_dma_compl_t compl_ev; + + for (int i = 0; i < config->dma_rounds; ++i) + odp_dma_compl_param_init(&compl_params[i]); + + for (int i = 0; i < config->dma_rounds; ++i) { + if (config->compl_modes.modes[i] == ODP_DMA_COMPL_EVENT) { + compl_params[i].compl_mode = ODP_DMA_COMPL_EVENT; + compl_ev = odp_dma_compl_alloc(config->dma_config.pool); + + if (compl_ev == ODP_DMA_COMPL_INVALID) { + ODPH_ERR("Error creating DMA completion event.\n"); + return -1; + } + + compl_params[i].event = odp_dma_compl_to_event(compl_ev); + compl_params[i].queue = config->dma_config.compl_q; + } else if (config->compl_modes.modes[i] == ODP_DMA_COMPL_POLL) { + compl_params[i].compl_mode = ODP_DMA_COMPL_POLL; + compl_params[i].transfer_id = + odp_dma_transfer_id_alloc(config->dma_config.handle); + + if (compl_params[i].transfer_id == ODP_DMA_TRANSFER_ID_INVALID) { + ODPH_ERR("Error creating DMA transfer ID.\n"); + return -1; + } + } + + compl_params[i].user_ptr = NULL; + } + + return 0; +} + +static void build_wait_list(const test_config_t *config, odp_dma_compl_param_t compl_params[], + compl_wait_entry_t list[]) +{ + int last_ev_idx, has_events = 0; + + memset(list, 0, sizeof(*list) * config->dma_rounds); + + for (int i = 0, j = 0, k = 0; i < config->dma_rounds; ++i) { + if (config->compl_modes.modes[i] == ODP_DMA_COMPL_EVENT) { + compl_wait_entry_t entry = { .type = ODP_DMA_COMPL_EVENT }; + + list[j] = entry; + ++j; + + for (; k < i; ++k) { + entry.type = ODP_DMA_COMPL_POLL; + entry.id = compl_params[k].transfer_id; + list[j++] = entry; + } + + ++k; + last_ev_idx = i; + has_events = 1; + } + } + + last_ev_idx = has_events ? last_ev_idx + 1 : 0; + + for (int i = last_ev_idx; i < config->dma_rounds; ++i) { + compl_wait_entry_t entry = { .type = ODP_DMA_COMPL_POLL, + .id = compl_params[i].transfer_id }; + list[i] = entry; + } +} + +static inline int wait_dma_transfers_ready(test_config_t *config, compl_wait_entry_t list[]) +{ + odp_event_t ev; + const uint64_t wait_time = odp_schedule_wait_time(ODP_TIME_SEC_IN_NS * 5U); + int done = 0; + + for (int i = 0; i < config->dma_rounds; ++i) { + if (list[i].type == ODP_DMA_COMPL_EVENT) { + ev = odp_schedule(NULL, wait_time); + + if (ev == ODP_EVENT_INVALID) { + ODPH_ERR("Error waiting event completion.\n"); + return -1; + } + } else { + while (1) { + done = odp_dma_transfer_done(config->dma_config.handle, list[i].id, + NULL); + + if (done > 0) + break; + + if (done == 0) + continue; + + ODPH_ERR("Error waiting poll completion.\n"); + return -1; + } + } + } + + return 0; +} + +static void free_dma_completion_events(test_config_t *config, odp_dma_compl_param_t compl_params[]) +{ + for (int i = 0; i < config->dma_rounds; ++i) + if (config->compl_modes.modes[i] == ODP_DMA_COMPL_EVENT && + compl_params[i].event != ODP_EVENT_INVALID) + odp_dma_compl_free(odp_dma_compl_from_event(compl_params[i].event)); +} + +static void free_dma_transfer_ids(test_config_t *config, odp_dma_compl_param_t compl_params[]) +{ + for (int i = 0; i < config->dma_rounds; ++i) + if (config->compl_modes.modes[i] == ODP_DMA_COMPL_POLL && + compl_params[i].transfer_id != ODP_DMA_TRANSFER_ID_INVALID) + odp_dma_transfer_id_free(config->dma_config.handle, + compl_params[i].transfer_id); +} + +static int run_dma_async_transfer(test_config_t *config) +{ + odp_dma_transfer_param_t trs_params[config->dma_rounds]; + uint32_t trs_lengths[config->dma_rounds]; + odp_dma_compl_param_t compl_params[config->dma_rounds]; + int ret = 0; + compl_wait_entry_t compl_wait_list[config->dma_rounds]; + odp_time_t start, end; + uint32_t num_rounds = config->num_rounds, offset; + + config->test_case_api.trs_base_fn(config, trs_params, trs_lengths); + + if (configure_dma_completion_params(config, compl_params)) { + ret = -1; + goto out_compl_evs; + } + + build_wait_list(config, compl_params, compl_wait_list); + start = odp_time_local_strict(); + + while (num_rounds--) { + offset = 0U; + + for (int i = 0; i < config->dma_rounds; ++i) { + config->test_case_api.trs_dyn_fn(config, offset, trs_lengths[i]); + + if (odp_dma_transfer_start(config->dma_config.handle, &trs_params[i], + &compl_params[i]) <= 0) { + ODPH_ERR("Error starting an async DMA transfer.\n"); + ret = -1; + goto out_trs_ids; + } + + offset += trs_lengths[i]; + } + + if (wait_dma_transfers_ready(config, compl_wait_list)) { + ODPH_ERR("Error finishing an async DMA transfer.\n"); + ret = -1; + goto out_trs_ids; + } + } + + end = odp_time_local_strict(); + print_results(config, odp_time_diff_ns(end, start)); + +out_compl_evs: + free_dma_completion_events(config, compl_params); + +out_trs_ids: + free_dma_transfer_ids(config, compl_params); + return ret; +} + +static void free_dma_event_completion(test_config_t *config) +{ + if (config->dma_config.compl_q != ODP_QUEUE_INVALID) + (void)odp_queue_destroy(config->dma_config.compl_q); + + if (config->dma_config.pool != ODP_POOL_INVALID) + (void)odp_pool_destroy(config->dma_config.pool); +} + +static int run_dma_async(test_config_t *config) +{ + const int is_event_compl = config->compl_modes.compl_mask & ODP_DMA_COMPL_EVENT; + int ret = 0; + + if (is_event_compl) + if (configure_dma_event_completion(config)) { + ret = -1; + goto out; + } + + if (run_dma_async_transfer(config)) + ret = -1; + +out: + if (is_event_compl) + free_dma_event_completion(config); + + return ret; +} + +static void setup_test_case_api(test_config_t *config) +{ + switch (config->seg_type) { + case TYPE_PKT: + config->test_case_api.setup_fn = setup_packet_segments; + config->test_case_api.trs_base_fn = configure_packet_dma_transfer_base; + config->test_case_api.trs_dyn_fn = configure_packet_dma_transfer_dynamic; + config->test_case_api.verify_fn = verify_packet_transfer; + config->test_case_api.free_fn = free_packets; + break; + case TYPE_MEM: + config->test_case_api.setup_fn = setup_memory_segments; + config->test_case_api.trs_base_fn = configure_address_dma_transfer_base; + config->test_case_api.trs_dyn_fn = configure_address_dma_transfer_dynamic; + config->test_case_api.verify_fn = verify_memory_transfer; + config->test_case_api.free_fn = free_memory; + break; + default: + break; + } + + config->test_case_api.run_fn = config->trs_type == TRS_TYPE_SYNC ? + run_dma_sync : + run_dma_async; +} + +static int configure_dma_session(test_config_t *config) +{ + const odp_dma_param_t params = { .direction = ODP_DMA_MAIN_TO_MAIN, + .type = ODP_DMA_TYPE_COPY, + .compl_mode_mask = config->compl_modes.compl_mask, + .mt_mode = ODP_DMA_MT_SERIAL, + .order = ODP_DMA_ORDER_NONE }; + + config->dma_config.handle = odp_dma_create("odp_dma_perf", ¶ms); + + if (config->dma_config.handle == ODP_DMA_INVALID) { + ODPH_ERR("Error creating DMA session.\n"); + return -1; + } + + return 0; +} + +static void free_dma_session(test_config_t *config) +{ + if (config->dma_config.handle != ODP_DMA_INVALID) + (void)odp_dma_destroy(config->dma_config.handle); +} + +int main(int argc, char **argv) +{ + odph_helper_options_t odph_opts; + test_config_t test_config; + odp_instance_t odp_instance; + int ret = EXIT_SUCCESS; + + argc = odph_parse_options(argc, argv); + + if (odph_options(&odph_opts)) { + ODPH_ERR("Error while reading ODP helper options, exiting.\n"); + exit(EXIT_FAILURE); + } + + if (parse_options(argc, argv, &test_config)) + exit(EXIT_FAILURE); + + if (odp_init_global(&odp_instance, NULL, NULL)) { + ODPH_ERR("ODP global init failed, exiting.\n"); + exit(EXIT_FAILURE); + } + + if (odp_init_local(odp_instance, ODP_THREAD_CONTROL)) { + ODPH_ERR("ODP local init failed, exiting.\n"); + exit(EXIT_FAILURE); + } + + if (check_capabilities(&test_config)) { + ODPH_ERR("Unsupported scenario attempted, exiting.\n"); + ret = EXIT_NOT_SUP; + goto out_odp; + } + + setup_test_case_api(&test_config); + + if (configure_dma_session(&test_config)) { + ret = EXIT_FAILURE; + goto out_dma; + } + + if (test_config.test_case_api.setup_fn(&test_config)) { + ret = EXIT_FAILURE; + goto out_test_case; + } + + if (test_config.test_case_api.run_fn(&test_config) || + test_config.test_case_api.verify_fn(&test_config)) + ret = EXIT_FAILURE; + +out_test_case: + test_config.test_case_api.free_fn(&test_config); + +out_dma: + free_dma_session(&test_config); + +out_odp: + if (odp_term_local()) { + ODPH_ERR("ODP local terminate failed, exiting.\n"); + exit(EXIT_FAILURE); + } + + if (odp_term_global(odp_instance)) { + ODPH_ERR("ODP global terminate failed, exiting.\n"); + exit(EXIT_FAILURE); + } + + return ret; +} diff --git a/test/performance/odp_dma_perf_run.sh b/test/performance/odp_dma_perf_run.sh new file mode 100755 index 000000000..dc314d400 --- /dev/null +++ b/test/performance/odp_dma_perf_run.sh @@ -0,0 +1,100 @@ +#!/bin/sh +# +# Copyright (c) 2022, Nokia +# All rights reserved. +# +# SPDX-License-Identifier: BSD-3-Clause + +TEST_DIR="${TEST_DIR:-$(dirname $0)}" +BIN_NAME=odp_dma_perf +SEG_SIZE=1024 +ROUNDS=1000 +TESTS_RUN=0 + +check_result() +{ + if [ $1 -eq 0 ]; then + TESTS_RUN=`expr $TESTS_RUN + 1` + elif [ $1 -eq 1 ]; then + echo "Test FAILED, exiting" + exit 1 + else + echo "Test SKIPPED" + fi +} + +echo "odp_dma_perf: synchronous transfer 1" +echo "====================================" + +${TEST_DIR}/${BIN_NAME}${EXEEXT} -t 0 -g 0 -i 6 -s $SEG_SIZE -T 0 -r $ROUNDS + +check_result $? + +echo "odp_dma_perf: synchronous transfer 2" +echo "====================================" + +${TEST_DIR}/${BIN_NAME}${EXEEXT} -t 0 -g 1 -i 6 -s $SEG_SIZE -T 0 -r $ROUNDS + +check_result $? + +echo "odp_dma_perf: synchronous transfer 3" +echo "====================================" + +${TEST_DIR}/${BIN_NAME}${EXEEXT} -t 0 -g 0 -i 6 -s $SEG_SIZE -T 1 -r $ROUNDS + +check_result $? + +echo "odp_dma_perf: synchronous transfer 4" +echo "====================================" + +${TEST_DIR}/${BIN_NAME}${EXEEXT} -t 0 -g 1 -i 6 -s $SEG_SIZE -T 1 -r $ROUNDS + +check_result $? + +echo "odp_dma_perf: asynchronous transfer 1" +echo "=====================================" + +${TEST_DIR}/${BIN_NAME}${EXEEXT} -t 1 -g 0 -i 6 -s $SEG_SIZE -T 0 -m 0 -r $ROUNDS + +check_result $? + +echo "odp_dma_perf: asynchronous transfer 2" +echo "=====================================" + +${TEST_DIR}/${BIN_NAME}${EXEEXT} -t 1 -g 1 -i 6 -s $SEG_SIZE -T 0 -m 0,0,0,0,0,0 -r $ROUNDS + +check_result $? + +echo "odp_dma_perf: asynchronous transfer 3" +echo "=====================================" + +${TEST_DIR}/${BIN_NAME}${EXEEXT} -t 1 -g 1 -i 6 -s $SEG_SIZE -T 0 -m 0,0,0,0,0,1 -r $ROUNDS + +check_result $? + +echo "odp_dma_perf: asynchronous transfer 4" +echo "=====================================" + +${TEST_DIR}/${BIN_NAME}${EXEEXT} -t 1 -g 0 -i 6 -s $SEG_SIZE -T 1 -m 0 -r $ROUNDS + +check_result $? + +echo "odp_dma_perf: asynchronous transfer 5" +echo "=====================================" + +${TEST_DIR}/${BIN_NAME}${EXEEXT} -t 1 -g 1 -i 6 -s $SEG_SIZE -T 1 -m 0,0,0,0,0,0 -r $ROUNDS + +check_result $? + +echo "odp_dma_perf: asynchronous transfer 6" +echo "=====================================" + +${TEST_DIR}/${BIN_NAME}${EXEEXT} -t 1 -g 1 -i 6 -s $SEG_SIZE -T 1 -m 0,0,0,0,0,1 -r $ROUNDS + +check_result $? + +if [ $TESTS_RUN -eq 0 ]; then + exit 77 +fi + +exit 0 diff --git a/test/performance/odp_lock_perf.c b/test/performance/odp_lock_perf.c index dfc814657..e1c0c039e 100644 --- a/test/performance/odp_lock_perf.c +++ b/test/performance/odp_lock_perf.c @@ -23,6 +23,12 @@ #define TEST_INFO(name, test, validate) { name, test, validate } +typedef enum repeat_t { + REPEAT_NO, + REPEAT_UNTIL_FAIL, + REPEAT_FOREVER, +} repeat_t; + typedef enum place_t { PLACE_PACK, PLACE_SEPARATE, @@ -34,6 +40,7 @@ typedef struct test_options_t { uint32_t num_cpu; uint32_t type; uint64_t num_round; + repeat_t repeat; uint32_t num_counter; place_t place; } test_options_t; @@ -43,6 +50,7 @@ static test_options_t test_options_def = { .num_cpu = 0, .type = 0, .num_round = 100000, + .repeat = REPEAT_NO, .num_counter = 2, .place = 2, }; @@ -201,13 +209,18 @@ static inline void test_ticketlock(test_global_t *g, uint64_t **counter, static inline int validate_generic(test_global_t *g, uint64_t **counter, uint32_t num_counter) { + int status = 0; uint64_t total = (uint64_t)g->test_options.num_cpu * g->test_options.num_round; - for (uint32_t i = 0; i < num_counter; i++) - if (*counter[i] != total) - return 1; + for (uint32_t i = 0; i < num_counter; i++) { + if (*counter[i] != total) { + status = 1; + ODPH_ERR("Error: Counter %d value %" PRIu64 " expected %" PRIu64 "\n", + i, *counter[i], total); + } + } - return 0; + return status; } static void print_usage(void) @@ -225,6 +238,10 @@ static void print_usage(void) " 4: odp_rwlock_recursive_t\n" " 5: odp_ticketlock_t\n" " -r, --num_round Number of rounds (default %" PRIu64 ")\n" + " -e, --repeat Repeat the tests (default %u)\n" + " 0: no repeat, run the tests once\n" + " 1: repeat until failure\n" + " 2: repeat forever\n" " -o, --num_counter Number of counters (default %u)\n" " -p, --place Counter placement (default %d)\n" " 0: pack to same cache line with lock\n" @@ -233,8 +250,8 @@ static void print_usage(void) " -h, --help This help\n" "\n", DEFAULT_MAX_WORKERS, test_options_def.type, - test_options_def.num_round, test_options_def.num_counter, - test_options_def.place); + test_options_def.num_round, test_options_def.repeat, + test_options_def.num_counter, test_options_def.place); } static void print_info(test_options_t *test_options) @@ -243,6 +260,7 @@ static void print_info(test_options_t *test_options) printf(" num cpu %u\n", test_options->num_cpu); printf(" type %u\n", test_options->type); printf(" num rounds %" PRIu64 "\n", test_options->num_round); + printf(" repeat %u\n", test_options->repeat); printf(" num counters %u\n", test_options->num_counter); printf(" place %u\n", test_options->place); printf("\n\n"); @@ -258,13 +276,14 @@ static int parse_options(int argc, char *argv[], test_options_t *test_options) { "num_cpu", required_argument, NULL, 'c' }, { "type", required_argument, NULL, 't' }, { "num_round", required_argument, NULL, 'r' }, + { "repeat", required_argument, NULL, 'e' }, { "num_counter", required_argument, NULL, 'o' }, { "place", required_argument, NULL, 'p' }, { "help", no_argument, NULL, 'h' }, { NULL, 0, NULL, 0 } }; - static const char *shortopts = "+c:t:r:o:p:h"; + static const char *shortopts = "+c:t:r:e:o:p:h"; *test_options = test_options_def; @@ -284,6 +303,9 @@ static int parse_options(int argc, char *argv[], test_options_t *test_options) case 'r': test_options->num_round = atoll(optarg); break; + case 'e': + test_options->repeat = atoi(optarg); + break; case 'o': test_options->num_counter = atoi(optarg); break; @@ -614,34 +636,40 @@ int main(int argc, char **argv) /* Loop all test cases */ num_tests = sizeof(test_suite) / sizeof(test_suite[0]); - for (i = 0; i < num_tests; i++) { - if (test_options.type && test_options.type != (uint32_t)i + 1) - continue; + while (1) { + for (i = 0; i < num_tests; i++) { + if (test_options.type && test_options.type != (uint32_t)i + 1) + continue; - test_global->cur_type = i; + test_global->cur_type = i; - /* Initialize test variables */ - if (init_test(test_global, test_suite[i].name)) { - ODPH_ERR("Failed to initialize test.\n"); - exit(EXIT_FAILURE); - } + /* Initialize test variables */ + if (init_test(test_global, test_suite[i].name)) { + ODPH_ERR("Failed to initialize test.\n"); + exit(EXIT_FAILURE); + } - /* Start workers */ - if (start_workers(test_global, instance, test_suite[i].test_fn)) - exit(EXIT_FAILURE); + /* Start workers */ + if (start_workers(test_global, instance, test_suite[i].test_fn)) + exit(EXIT_FAILURE); - /* Wait workers to exit */ - odph_thread_join(test_global->thread_tbl, - test_global->test_options.num_cpu); + /* Wait workers to exit */ + odph_thread_join(test_global->thread_tbl, + test_global->test_options.num_cpu); - print_stat(test_global); + print_stat(test_global); - /* Validate test results */ - if (validate_results(test_global, test_suite[i].validate_fn)) { - ODPH_ERR("Test %s result validation failed.\n", - test_suite[i].name); - exit(EXIT_FAILURE); + /* Validate test results */ + if (validate_results(test_global, test_suite[i].validate_fn)) { + ODPH_ERR("Test %s result validation failed.\n", + test_suite[i].name); + if (test_options.repeat != REPEAT_FOREVER) + exit(EXIT_FAILURE); + } } + + if (test_options.repeat == REPEAT_NO) + break; } if (odp_shm_free(shm)) { diff --git a/test/performance/odp_pktio_ordered.c b/test/performance/odp_pktio_ordered.c index e35386d52..9a4e3013f 100644 --- a/test/performance/odp_pktio_ordered.c +++ b/test/performance/odp_pktio_ordered.c @@ -140,6 +140,7 @@ typedef struct { int time; /**< Time in seconds to run. */ int accuracy; /**< Statistics print interval */ char *if_str; /**< Storage for interface names */ + int promisc_mode; /**< Promiscuous mode enabled */ } appl_args_t; /** @@ -611,6 +612,20 @@ static int create_pktio(const char *dev, int idx, int num_rx, int num_tx, config.parser.layer = ODP_PROTO_LAYER_L2; odp_pktio_config(pktio, &config); + if (gbl_args->appl.promisc_mode) { + if (!capa.set_op.op.promisc_mode) { + ODPH_ERR("Error: promisc mode set not supported %s\n", + dev); + return -1; + } + + /* Enable promisc mode */ + if (odp_pktio_promisc_mode_set(pktio, true)) { + ODPH_ERR("Error: promisc mode enable failed %s\n", dev); + return -1; + } + } + odp_pktin_queue_param_init(&pktin_param); odp_pktout_queue_param_init(&pktout_param); @@ -823,6 +838,7 @@ static void usage(char *progname) " -a, --accuracy <number> Statistics print interval in seconds\n" " (default is 1 second).\n" " -d, --dst_addr Destination addresses (comma-separated, no spaces)\n" + " -P, --promisc_mode Enable promiscuous mode.\n" " -h, --help Display help and exit.\n\n" "\n", NO_PATH(progname), NO_PATH(progname), MAX_PKTIOS ); @@ -853,11 +869,12 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) {"num_rx_q", required_argument, NULL, 'r'}, {"num_flows", required_argument, NULL, 'f'}, {"extra_input", required_argument, NULL, 'e'}, + {"promisc_mode", no_argument, NULL, 'P'}, {"help", no_argument, NULL, 'h'}, {NULL, 0, NULL, 0} }; - static const char *shortopts = "+c:t:a:i:m:d:r:f:e:h"; + static const char *shortopts = "+c:t:a:i:m:d:r:f:e:Ph"; appl_args->time = 0; /* loop forever if time to run is 0 */ appl_args->accuracy = DEF_STATS_INT; @@ -865,6 +882,7 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) appl_args->num_rx_q = DEF_NUM_RX_QUEUES; appl_args->num_flows = DEF_NUM_FLOWS; appl_args->extra_rounds = DEF_EXTRA_ROUNDS; + appl_args->promisc_mode = 0; while (1) { opt = getopt_long(argc, argv, shortopts, longopts, &long_index); @@ -978,6 +996,9 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) case 'e': appl_args->extra_rounds = atoi(optarg); break; + case 'P': + appl_args->promisc_mode = 1; + break; case 'h': usage(argv[0]); exit(EXIT_SUCCESS); @@ -1018,14 +1039,24 @@ static void print_info(char *progname, appl_args_t *appl_args) odp_sys_info_print(); - printf("Running ODP appl: \"%s\"\n" - "-----------------\n" - "IF-count: %i\n" - "Using IFs: ", + printf("%s options\n" + "-------------------------\n" + "IF-count: %i\n" + "Using IFs: ", progname, appl_args->if_count); for (i = 0; i < appl_args->if_count; ++i) printf(" %s", appl_args->if_names[i]); - printf("\n\n"); + printf("\n" + "Input queues: %d\n" + "Mode: %s\n" + "Flows: %d\n" + "Extra rounds: %d\n" + "Promisc mode: %s\n", appl_args->num_rx_q, + (appl_args->in_mode == SCHED_ATOMIC) ? "PKTIN_SCHED_ATOMIC" : + (appl_args->in_mode == SCHED_PARALLEL ? "PKTIN_SCHED_PARALLEL" : + "PKTIN_SCHED_ORDERED"), appl_args->num_flows, + appl_args->extra_rounds, appl_args->promisc_mode ? + "enabled" : "disabled"); fflush(NULL); } @@ -1069,7 +1100,6 @@ int main(int argc, char *argv[]) int if_count; int ret; int num_workers; - int in_mode; uint32_t queue_size, pool_size; /* Let helper collect its own arguments (e.g. --odph_proc) */ @@ -1263,18 +1293,6 @@ int main(int argc, char *argv[]) } } - in_mode = gbl_args->appl.in_mode; - printf("\nApplication parameters\n" - "----------------------\n" - "Input queues: %d\n" - "Mode: %s\n" - "Flows: %d\n" - "Extra rounds: %d\n\n", gbl_args->appl.num_rx_q, - (in_mode == SCHED_ATOMIC) ? "PKTIN_SCHED_ATOMIC" : - (in_mode == SCHED_PARALLEL ? "PKTIN_SCHED_PARALLEL" : - "PKTIN_SCHED_ORDERED"), gbl_args->appl.num_flows, - gbl_args->appl.extra_rounds); - memset(thread_tbl, 0, sizeof(thread_tbl)); stats = gbl_args->stats; diff --git a/test/performance/odp_random.c b/test/performance/odp_random.c index 7083349ff..622a58c65 100644 --- a/test/performance/odp_random.c +++ b/test/performance/odp_random.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2021, Nokia +/* Copyright (c) 2021-2022, Nokia * * All rights reserved. * @@ -40,7 +40,7 @@ static void print_usage(void) " -t, --threads Number of worker threads (default %u)\n" " -s, --size Size of buffer in bytes (default %u)\n" " -r, --rounds Number of test rounds (default %u)\n" - " Rounded down to nearest multiple of 8\n" + " Divided by 100 for ODP_RANDOM_TRUE\n" " -h, --help This help\n" "\n", options_def.num_threads, options_def.size, options_def.rounds); @@ -116,6 +116,16 @@ static test_shm_t *shm_lookup(void) return shm; } +static uint32_t type_rounds(odp_random_kind_t type) +{ + switch (type) { + case ODP_RANDOM_TRUE: + return options.rounds / 100; + default: + return options.rounds; + } +} + static int test_random(void *p) { (void)p; @@ -124,6 +134,7 @@ static int test_random(void *p) const unsigned long page = ODP_PAGE_SIZE; odp_time_t start; uint64_t nsec; + uint32_t rounds; test_shm_t *shm = shm_lookup(); if (!shm) { @@ -131,6 +142,8 @@ static int test_random(void *p) exit(EXIT_FAILURE); } + rounds = type_rounds(shm->type); + /* One extra page for alignment. */ buf = (uint8_t *)malloc(options.size + page); @@ -145,7 +158,7 @@ static int test_random(void *p) odp_barrier_wait(&shm->barrier); start = odp_time_local(); - for (uint32_t i = 0; i < options.rounds; i++) { + for (uint32_t i = 0; i < rounds; i++) { uint32_t pos = 0; while (pos < options.size) { @@ -178,6 +191,7 @@ static int test_random_test(void *p) odp_time_t start; uint64_t nsec; uint64_t seed = 0; + uint32_t rounds; test_shm_t *shm = shm_lookup(); if (!shm) { @@ -185,6 +199,8 @@ static int test_random_test(void *p) exit(EXIT_FAILURE); } + rounds = type_rounds(shm->type); + /* One extra page for alignment. */ buf = (uint8_t *)malloc(options.size + page); @@ -199,7 +215,7 @@ static int test_random_test(void *p) odp_barrier_wait(&shm->barrier); start = odp_time_local(); - for (uint32_t i = 0; i < options.rounds; i++) { + for (uint32_t i = 0; i < rounds; i++) { uint32_t pos = 0; while (pos < options.size) { @@ -288,11 +304,13 @@ static void test_type(odp_instance_t instance, test_shm_t *shm, printf("odp_random_test_data\n"); } + uint32_t rounds = type_rounds(type); + printf("--------------------\n"); printf("threads: %d size: %u B rounds: %u ", options.num_threads, - options.size, options.rounds); + options.size, rounds); mb = (uint64_t)options.num_threads * (uint64_t)options.size * - (uint64_t)options.rounds; + (uint64_t)rounds; mb /= MB; seconds = (double)nsec / (double)ODP_TIME_SEC_IN_NS; printf("MB: %.3f seconds: %.3f ", mb, seconds); @@ -336,7 +354,7 @@ int main(int argc, char **argv) test_shm_t *shm = NULL; odp_shm_t shm_hdl = odp_shm_reserve(shm_name, sizeof(test_shm_t), 64, - ODP_SHM_SW_ONLY); + 0); if (shm_hdl != ODP_SHM_INVALID) shm = (test_shm_t *)odp_shm_addr(shm_hdl); diff --git a/test/validation/api/atomic/atomic.c b/test/validation/api/atomic/atomic.c index 54bd5ee3e..d4b15cf32 100644 --- a/test/validation/api/atomic/atomic.c +++ b/test/validation/api/atomic/atomic.c @@ -1,4 +1,5 @@ /* Copyright (c) 2014-2018, Linaro Limited + * Copyright (c) 2021-2022 Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -11,14 +12,11 @@ #include <odp_cunit_common.h> #include <unistd.h> -#define VERBOSE 0 -#define MAX_ITERATIONS 1000 - #define ADD_SUB_CNT 5 -#define CNT 50000 -#define U32_INIT_VAL (1UL << 28) -#define U64_INIT_VAL (1ULL << 33) +#define CNT 100000ULL +#define U32_INIT_VAL (1UL << 31) +#define U64_INIT_VAL (1ULL << 63) #define U32_MAGIC 0xa23f65b2 #define U64_MAGIC 0xf2e1c5430cb6a52e @@ -26,9 +24,8 @@ #define UNUSED __attribute__((__unused__)) -#define CHECK_MAX_MIN (1 << 0) -#define CHECK_XCHG (1 << 2) -#define CHECK_CAS_128 (1 << 4) +#define min(a, b) (a < b ? a : b) +#define max(a, b) (a > b ? a : b) typedef __volatile uint32_t volatile_u32_t; typedef __volatile uint64_t volatile_u64_t; @@ -45,59 +42,27 @@ typedef struct { odp_atomic_u32_t a32u_xchg; uint32_t g_num_threads; - uint32_t g_iterations; - uint32_t g_verbose; odp_barrier_t global_barrier; } global_shared_mem_t; -/* Per-thread memory */ -typedef struct { - global_shared_mem_t *global_mem; - - int thread_id; - int thread_core; - - volatile_u64_t delay_counter; -} per_thread_mem_t; - static odp_shm_t global_shm; static global_shared_mem_t *global_mem; /* Initialise per-thread memory */ -static per_thread_mem_t *thread_init(void) +static void thread_init(void) { global_shared_mem_t *global_mem; - per_thread_mem_t *per_thread_mem; odp_shm_t global_shm; - uint32_t per_thread_mem_len; - - per_thread_mem_len = sizeof(per_thread_mem_t); - per_thread_mem = malloc(per_thread_mem_len); - memset(per_thread_mem, 0, per_thread_mem_len); - - per_thread_mem->delay_counter = 1; - - per_thread_mem->thread_id = odp_thread_id(); - per_thread_mem->thread_core = odp_cpu_id(); global_shm = odp_shm_lookup(GLOBAL_SHM_NAME); global_mem = odp_shm_addr(global_shm); CU_ASSERT_PTR_NOT_NULL(global_mem); - - per_thread_mem->global_mem = global_mem; - - return per_thread_mem; -} - -static void thread_finalize(per_thread_mem_t *per_thread_mem) -{ - free(per_thread_mem); } static void test_atomic_inc_32(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -107,7 +72,7 @@ static void test_atomic_inc_32(void) static void test_atomic_inc_64(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -117,7 +82,7 @@ static void test_atomic_inc_64(void) static void test_atomic_dec_32(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -127,7 +92,7 @@ static void test_atomic_dec_32(void) static void test_atomic_dec_64(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -137,7 +102,7 @@ static void test_atomic_dec_64(void) static void test_atomic_fetch_inc_32(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -147,7 +112,7 @@ static void test_atomic_fetch_inc_32(void) static void test_atomic_fetch_inc_64(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -157,7 +122,7 @@ static void test_atomic_fetch_inc_64(void) static void test_atomic_fetch_dec_32(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -167,7 +132,7 @@ static void test_atomic_fetch_dec_32(void) static void test_atomic_fetch_dec_64(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -177,7 +142,7 @@ static void test_atomic_fetch_dec_64(void) static void test_atomic_add_32(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -187,7 +152,7 @@ static void test_atomic_add_32(void) static void test_atomic_add_64(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -197,7 +162,7 @@ static void test_atomic_add_64(void) static void test_atomic_sub_32(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -207,7 +172,7 @@ static void test_atomic_sub_32(void) static void test_atomic_sub_64(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -217,7 +182,7 @@ static void test_atomic_sub_64(void) static void test_atomic_fetch_add_32(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -227,7 +192,7 @@ static void test_atomic_fetch_add_32(void) static void test_atomic_fetch_add_64(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -237,7 +202,7 @@ static void test_atomic_fetch_add_64(void) static void test_atomic_fetch_sub_32(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -247,7 +212,7 @@ static void test_atomic_fetch_sub_32(void) static void test_atomic_fetch_sub_64(void) { - int i; + uint64_t i; odp_barrier_wait(&global_mem->global_barrier); @@ -257,7 +222,7 @@ static void test_atomic_fetch_sub_64(void) static void test_atomic_min_32(void) { - int i; + uint64_t i; uint32_t tmp; odp_barrier_wait(&global_mem->global_barrier); @@ -270,8 +235,7 @@ static void test_atomic_min_32(void) static void test_atomic_min_64(void) { - int i; - uint64_t tmp; + uint64_t i, tmp; odp_barrier_wait(&global_mem->global_barrier); @@ -283,7 +247,7 @@ static void test_atomic_min_64(void) static void test_atomic_max_32(void) { - int i; + uint64_t i; uint32_t tmp; odp_barrier_wait(&global_mem->global_barrier); @@ -296,8 +260,7 @@ static void test_atomic_max_32(void) static void test_atomic_max_64(void) { - int i; - uint64_t tmp; + uint64_t i, tmp; odp_barrier_wait(&global_mem->global_barrier); @@ -309,23 +272,111 @@ static void test_atomic_max_64(void) static void test_atomic_cas_inc_32(void) { - int i; - uint32_t old; + uint64_t i, old_mismatch = 0; + uint32_t old, old_old; odp_atomic_u32_t *a32u = &global_mem->a32u; odp_barrier_wait(&global_mem->global_barrier); for (i = 0; i < CNT; i++) { old = odp_atomic_load_u32(a32u); + old_old = old; - while (odp_atomic_cas_u32(a32u, &old, old + 1) == 0) - ; + while (odp_atomic_cas_u32(a32u, &old, old + 1) == 0) { + if (old == old_old) + old_mismatch++; + + old_old = old; + } + + if (old != old_old) + old_mismatch++; + } + + CU_ASSERT(old_mismatch == 0); +} + +static void test_atomic_cas_acq_inc_32(void) +{ + uint64_t i, old_mismatch = 0; + uint32_t old, old_old; + odp_atomic_u32_t *a32u = &global_mem->a32u; + + odp_barrier_wait(&global_mem->global_barrier); + + for (i = 0; i < CNT; i++) { + old = odp_atomic_load_u32(a32u); + old_old = old; + + while (odp_atomic_cas_acq_u32(a32u, &old, old + 1) == 0) { + if (old == old_old) + old_mismatch++; + + old_old = old; + } + + if (old != old_old) + old_mismatch++; + } + + CU_ASSERT(old_mismatch == 0); +} + +static void test_atomic_cas_rel_inc_32(void) +{ + uint64_t i, old_mismatch = 0; + uint32_t old, old_old; + odp_atomic_u32_t *a32u = &global_mem->a32u; + + odp_barrier_wait(&global_mem->global_barrier); + + for (i = 0; i < CNT; i++) { + old = odp_atomic_load_u32(a32u); + old_old = old; + + while (odp_atomic_cas_rel_u32(a32u, &old, old + 1) == 0) { + if (old == old_old) + old_mismatch++; + + old_old = old; + } + + if (old != old_old) + old_mismatch++; + } + + CU_ASSERT(old_mismatch == 0); +} + +static void test_atomic_cas_acq_rel_inc_32(void) +{ + uint64_t i, old_mismatch = 0; + uint32_t old, old_old; + odp_atomic_u32_t *a32u = &global_mem->a32u; + + odp_barrier_wait(&global_mem->global_barrier); + + for (i = 0; i < CNT; i++) { + old = odp_atomic_load_u32(a32u); + old_old = old; + + while (odp_atomic_cas_acq_rel_u32(a32u, &old, old + 1) == 0) { + if (old == old_old) + old_mismatch++; + + old_old = old; + } + + if (old != old_old) + old_mismatch++; } + + CU_ASSERT(old_mismatch == 0); } static void test_atomic_cas_dec_32(void) { - int i; + uint64_t i; uint32_t old; odp_atomic_u32_t *a32u = &global_mem->a32u; @@ -341,24 +392,107 @@ static void test_atomic_cas_dec_32(void) static void test_atomic_cas_inc_64(void) { - int i; - uint64_t old; + uint64_t i, old, old_old, old_mismatch = 0; odp_atomic_u64_t *a64u = &global_mem->a64u; odp_barrier_wait(&global_mem->global_barrier); for (i = 0; i < CNT; i++) { old = odp_atomic_load_u64(a64u); + old_old = old; - while (odp_atomic_cas_u64(a64u, &old, old + 1) == 0) - ; + while (odp_atomic_cas_u64(a64u, &old, old + 1) == 0) { + if (old == old_old) + old_mismatch++; + + old_old = old; + } + + if (old != old_old) + old_mismatch++; + } + + CU_ASSERT(old_mismatch == 0); +} + +static void test_atomic_cas_acq_inc_64(void) +{ + uint64_t i, old, old_old, old_mismatch = 0; + odp_atomic_u64_t *a64u = &global_mem->a64u; + + odp_barrier_wait(&global_mem->global_barrier); + + for (i = 0; i < CNT; i++) { + old = odp_atomic_load_u64(a64u); + old_old = old; + + while (odp_atomic_cas_acq_u64(a64u, &old, old + 1) == 0) { + if (old == old_old) + old_mismatch++; + + old_old = old; + } + + if (old != old_old) + old_mismatch++; + } + + CU_ASSERT(old_mismatch == 0); +} + +static void test_atomic_cas_rel_inc_64(void) +{ + uint64_t i, old, old_old, old_mismatch = 0; + odp_atomic_u64_t *a64u = &global_mem->a64u; + + odp_barrier_wait(&global_mem->global_barrier); + + for (i = 0; i < CNT; i++) { + old = odp_atomic_load_u64(a64u); + old_old = old; + + while (odp_atomic_cas_rel_u64(a64u, &old, old + 1) == 0) { + if (old == old_old) + old_mismatch++; + + old_old = old; + } + + if (old != old_old) + old_mismatch++; + } + + CU_ASSERT(old_mismatch == 0); +} + +static void test_atomic_cas_acq_rel_inc_64(void) +{ + uint64_t i, old, old_old, old_mismatch = 0; + odp_atomic_u64_t *a64u = &global_mem->a64u; + + odp_barrier_wait(&global_mem->global_barrier); + + for (i = 0; i < CNT; i++) { + old = odp_atomic_load_u64(a64u); + old_old = old; + + while (odp_atomic_cas_acq_rel_u64(a64u, &old, old + 1) == 0) { + if (old == old_old) + old_mismatch++; + + old_old = old; + } + + if (old != old_old) + old_mismatch++; } + + CU_ASSERT(old_mismatch == 0); } static void test_atomic_cas_dec_64(void) { - int i; - uint64_t old; + uint64_t i, old; odp_atomic_u64_t *a64u = &global_mem->a64u; odp_barrier_wait(&global_mem->global_barrier); @@ -371,55 +505,59 @@ static void test_atomic_cas_dec_64(void) } } +#define BUF_SIZE (64 * 1024) + static void test_atomic_xchg_32(void) { uint32_t old, new; - int i; - odp_atomic_u32_t *a32u = &global_mem->a32u; + uint64_t i; odp_atomic_u32_t *a32u_xchg = &global_mem->a32u_xchg; + uint8_t buf[BUF_SIZE]; + uint64_t seed = odp_thread_id(); + uint64_t count_old = 0, count_new = 0; + + odp_random_test_data(buf, BUF_SIZE, &seed); odp_barrier_wait(&global_mem->global_barrier); for (i = 0; i < CNT; i++) { - new = odp_atomic_fetch_inc_u32(a32u); + new = buf[i & (BUF_SIZE - 1)]; old = odp_atomic_xchg_u32(a32u_xchg, new); - - if (old & 0x1) - odp_atomic_xchg_u32(a32u_xchg, 0); - else - odp_atomic_xchg_u32(a32u_xchg, 1); + count_old += old; + count_new += new; } - odp_atomic_sub_u32(a32u, CNT); - odp_atomic_xchg_u32(a32u_xchg, U32_MAGIC); + odp_atomic_add_u32(a32u_xchg, count_old); + odp_atomic_sub_u32(a32u_xchg, count_new); } static void test_atomic_xchg_64(void) { uint64_t old, new; - int i; - odp_atomic_u64_t *a64u = &global_mem->a64u; + uint64_t i; odp_atomic_u64_t *a64u_xchg = &global_mem->a64u_xchg; + uint8_t buf[BUF_SIZE]; + uint64_t seed = odp_thread_id(); + uint64_t count_old = 0, count_new = 0; + + odp_random_test_data(buf, BUF_SIZE, &seed); odp_barrier_wait(&global_mem->global_barrier); for (i = 0; i < CNT; i++) { - new = odp_atomic_fetch_inc_u64(a64u); + new = buf[i & (BUF_SIZE - 1)]; old = odp_atomic_xchg_u64(a64u_xchg, new); - - if (old & 0x1) - odp_atomic_xchg_u64(a64u_xchg, 0); - else - odp_atomic_xchg_u64(a64u_xchg, 1); + count_old += old; + count_new += new; } - odp_atomic_sub_u64(a64u, CNT); - odp_atomic_xchg_u64(a64u_xchg, U64_MAGIC); + odp_atomic_add_u64(a64u_xchg, count_old); + odp_atomic_sub_u64(a64u_xchg, count_new); } static void test_atomic_non_relaxed_32(void) { - int i; + uint64_t i; uint32_t tmp; odp_atomic_u32_t *a32u = &global_mem->a32u; odp_atomic_u32_t *a32u_min = &global_mem->a32u_min; @@ -447,17 +585,14 @@ static void test_atomic_non_relaxed_32(void) ; tmp = odp_atomic_load_u32(a32u_xchg); - /* finally set value for validation */ - while (odp_atomic_cas_acq_rel_u32(a32u_xchg, &tmp, U32_MAGIC) - == 0) + while (odp_atomic_cas_acq_rel_u32(a32u_xchg, &tmp, tmp + 1) == 0) ; } } static void test_atomic_non_relaxed_64(void) { - int i; - uint64_t tmp; + uint64_t i, tmp; odp_atomic_u64_t *a64u = &global_mem->a64u; odp_atomic_u64_t *a64u_min = &global_mem->a64u_min; odp_atomic_u64_t *a64u_max = &global_mem->a64u_max; @@ -484,16 +619,15 @@ static void test_atomic_non_relaxed_64(void) ; tmp = odp_atomic_load_u64(a64u_xchg); - /* finally set value for validation */ - while (odp_atomic_cas_acq_rel_u64(a64u_xchg, &tmp, U64_MAGIC) - == 0) + while (odp_atomic_cas_acq_rel_u64(a64u_xchg, &tmp, tmp + 1) == 0) ; } } static void test_atomic_relaxed_128(void) { - int i, ret; + int ret; + uint64_t i; odp_u128_t old, new; odp_atomic_u128_t *a128u = &global_mem->a128u; @@ -514,7 +648,8 @@ static void test_atomic_relaxed_128(void) static void test_atomic_non_relaxed_128_acq(void) { - int i, ret; + int ret; + uint64_t i; odp_u128_t old, new; odp_atomic_u128_t *a128u = &global_mem->a128u; @@ -535,7 +670,8 @@ static void test_atomic_non_relaxed_128_acq(void) static void test_atomic_non_relaxed_128_rel(void) { - int i, ret; + int ret; + uint64_t i; odp_u128_t old, new; odp_atomic_u128_t *a128u = &global_mem->a128u; @@ -556,7 +692,8 @@ static void test_atomic_non_relaxed_128_rel(void) static void test_atomic_non_relaxed_128_acq_rel(void) { - int i, ret; + int ret; + uint64_t i; odp_u128_t old, new; odp_atomic_u128_t *a128u = &global_mem->a128u; @@ -623,6 +760,42 @@ static void test_atomic_fetch_add_sub_64(void) test_atomic_fetch_sub_64(); } +static void test_atomic_inc_add_32(void) +{ + test_atomic_inc_32(); + test_atomic_fetch_inc_32(); + test_atomic_add_32(); + test_atomic_fetch_add_32(); + test_atomic_cas_inc_32(); +} + +static void test_atomic_inc_add_64(void) +{ + test_atomic_inc_64(); + test_atomic_fetch_inc_64(); + test_atomic_add_64(); + test_atomic_fetch_add_64(); + test_atomic_cas_inc_64(); +} + +static void test_atomic_dec_sub_32(void) +{ + test_atomic_dec_32(); + test_atomic_fetch_dec_32(); + test_atomic_sub_32(); + test_atomic_fetch_sub_32(); + test_atomic_cas_dec_32(); +} + +static void test_atomic_dec_sub_64(void) +{ + test_atomic_dec_64(); + test_atomic_fetch_dec_64(); + test_atomic_sub_64(); + test_atomic_fetch_sub_64(); + test_atomic_cas_dec_64(); +} + static void test_atomic_max_min_32(void) { test_atomic_max_32(); @@ -691,39 +864,105 @@ static void test_atomic_store(void) odp_atomic_store_u128(&global_mem->a128u, a128u_tmp); } -static void test_atomic_validate(int check) +static void test_atomic_validate_init_val_32_64(void) { CU_ASSERT(U32_INIT_VAL == odp_atomic_load_u32(&global_mem->a32u)); CU_ASSERT(U64_INIT_VAL == odp_atomic_load_u64(&global_mem->a64u)); +} - odp_u128_t a128u_tmp; +static void test_atomic_validate_init_val_128(void) +{ + odp_u128_t a128u = odp_atomic_load_u128(&global_mem->a128u); - a128u_tmp = odp_atomic_load_u128(&global_mem->a128u); + CU_ASSERT(U64_INIT_VAL == a128u.u64[0]); + CU_ASSERT(U64_INIT_VAL == a128u.u64[1]); +} - if (check & CHECK_CAS_128) { - uint64_t iterations = 0; +static void test_atomic_validate_init_val(void) +{ + test_atomic_validate_init_val_32_64(); + test_atomic_validate_init_val_128(); +} - iterations = a128u_tmp.u64[0] - a128u_tmp.u64[1]; - CU_ASSERT(iterations == 4 * CNT * global_mem->g_num_threads); - } else { - CU_ASSERT(U64_INIT_VAL == a128u_tmp.u64[0]); - CU_ASSERT(U64_INIT_VAL == a128u_tmp.u64[1]); - } +static void test_atomic_validate_inc_add(void) +{ + test_atomic_validate_init_val_128(); - if (check & CHECK_MAX_MIN) { - CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_max) > - odp_atomic_load_u32(&global_mem->a32u_min)); + /* Two increment tests, one cas increment test and two add tests. */ + const uint64_t total_count = CNT * (3 + 2 * ADD_SUB_CNT) * global_mem->g_num_threads; + const uint32_t a32u = U32_INIT_VAL + total_count; - CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_max) > - odp_atomic_load_u64(&global_mem->a64u_min)); - } + CU_ASSERT(a32u == odp_atomic_load_u32(&global_mem->a32u)); + CU_ASSERT(U64_INIT_VAL + total_count == odp_atomic_load_u64(&global_mem->a64u)); +} - if (check & CHECK_XCHG) { - CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_xchg) == - U32_MAGIC); - CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_xchg) == - U64_MAGIC); - } +static void test_atomic_validate_dec_sub(void) +{ + test_atomic_validate_init_val_128(); + + /* Two decrement tests, one cas decrement test and two sub tests. */ + const uint64_t total_count = CNT * (3 + 2 * ADD_SUB_CNT) * global_mem->g_num_threads; + const uint32_t a32u = U32_INIT_VAL - total_count; + + CU_ASSERT(a32u == odp_atomic_load_u32(&global_mem->a32u)); + CU_ASSERT(U64_INIT_VAL - total_count == odp_atomic_load_u64(&global_mem->a64u)); +} + +static void test_atomic_validate_cas_inc_dec(void) +{ + test_atomic_validate_init_val_32_64(); + + odp_u128_t a128u = odp_atomic_load_u128(&global_mem->a128u); + const uint64_t iterations = a128u.u64[0] - a128u.u64[1]; + + CU_ASSERT(iterations == 4 * CNT * global_mem->g_num_threads); +} + +static void test_atomic_validate_max_min(void) +{ + test_atomic_validate_init_val(); + + const uint64_t total_count = CNT * global_mem->g_num_threads; + /* + * Max is the result of fetch_inc, so the final max value is total_count - 1. In + * a long test, counter may overflow, in which case max is saturated at + * UINT32_MAX, and min at 0. + */ + const uint32_t a32u_max = min(U32_INIT_VAL + total_count - 1, UINT32_MAX); + const uint32_t a32u_min = U32_INIT_VAL + total_count - 1 > UINT32_MAX ? 0 : U32_INIT_VAL; + + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_max) == a32u_max); + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_min) == a32u_min); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_max) == U64_INIT_VAL + total_count - 1); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_min) == U64_INIT_VAL); +} + +static void test_atomic_validate_xchg(void) +{ + test_atomic_validate_init_val(); + + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_xchg) == U32_INIT_VAL); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_xchg) == U64_INIT_VAL); +} + +static void test_atomic_validate_non_relaxed(void) +{ + test_atomic_validate_init_val(); + + const uint64_t total_count = CNT * global_mem->g_num_threads; + /* 3 increments per round. */ + const uint32_t a32u = U32_INIT_VAL + 3 * total_count; + /* 1 increment per round. */ + const uint32_t a32u_max = U32_INIT_VAL + total_count; + const uint32_t a32u_min = U32_INIT_VAL - total_count; + + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_xchg) == a32u); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_xchg) == U64_INIT_VAL + 3 * total_count); + + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_max) == a32u_max); + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_min) == a32u_min); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_max) == U64_INIT_VAL + total_count); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_min) == U64_INIT_VAL - total_count); } static int atomic_init(odp_instance_t *inst) @@ -762,8 +1001,6 @@ static int atomic_init(odp_instance_t *inst) memset(global_mem, 0, sizeof(global_shared_mem_t)); global_mem->g_num_threads = MAX_WORKERS; - global_mem->g_iterations = MAX_ITERATIONS; - global_mem->g_verbose = VERBOSE; workers_count = odp_cpumask_default_worker(&mask, 0); @@ -810,121 +1047,238 @@ static int atomic_term(odp_instance_t inst) } /* Atomic tests */ -static int test_atomic_inc_dec_thread(void *arg UNUSED) + +static int test_atomic_inc_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_inc_32(); + test_atomic_inc_64(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_dec_thread(void *arg UNUSED) { - per_thread_mem_t *per_thread_mem; + thread_init(); + test_atomic_dec_32(); + test_atomic_dec_64(); - per_thread_mem = thread_init(); + return CU_get_number_of_failures(); +} + +static int test_atomic_add_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_add_32(); + test_atomic_add_64(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_sub_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_sub_32(); + test_atomic_sub_64(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_fetch_inc_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_fetch_inc_32(); + test_atomic_fetch_inc_64(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_fetch_dec_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_fetch_dec_32(); + test_atomic_fetch_dec_64(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_fetch_add_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_fetch_add_32(); + test_atomic_fetch_add_64(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_fetch_sub_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_fetch_sub_32(); + test_atomic_fetch_sub_64(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_max_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_max_32(); + test_atomic_max_64(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_min_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_min_32(); + test_atomic_min_64(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_cas_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_cas_inc_32(); + test_atomic_cas_inc_64(); + test_atomic_relaxed_128(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_cas_acq_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_cas_acq_inc_32(); + test_atomic_cas_acq_inc_64(); + test_atomic_non_relaxed_128_acq(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_cas_rel_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_cas_rel_inc_32(); + test_atomic_cas_rel_inc_64(); + test_atomic_non_relaxed_128_rel(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_cas_acq_rel_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_cas_acq_rel_inc_32(); + test_atomic_cas_acq_rel_inc_64(); + test_atomic_non_relaxed_128_acq_rel(); + + return CU_get_number_of_failures(); +} + +static int test_atomic_inc_dec_thread(void *arg UNUSED) +{ + thread_init(); test_atomic_inc_dec_32(); test_atomic_inc_dec_64(); - thread_finalize(per_thread_mem); - return CU_get_number_of_failures(); } static int test_atomic_add_sub_thread(void *arg UNUSED) { - per_thread_mem_t *per_thread_mem; - - per_thread_mem = thread_init(); + thread_init(); test_atomic_add_sub_32(); test_atomic_add_sub_64(); - thread_finalize(per_thread_mem); - return CU_get_number_of_failures(); } static int test_atomic_fetch_inc_dec_thread(void *arg UNUSED) { - per_thread_mem_t *per_thread_mem; - - per_thread_mem = thread_init(); + thread_init(); test_atomic_fetch_inc_dec_32(); test_atomic_fetch_inc_dec_64(); - thread_finalize(per_thread_mem); - return CU_get_number_of_failures(); } static int test_atomic_fetch_add_sub_thread(void *arg UNUSED) { - per_thread_mem_t *per_thread_mem; - - per_thread_mem = thread_init(); + thread_init(); test_atomic_fetch_add_sub_32(); test_atomic_fetch_add_sub_64(); - thread_finalize(per_thread_mem); + return CU_get_number_of_failures(); +} + +static int test_atomic_inc_add_thread(void *arg UNUSED) +{ + thread_init(); + test_atomic_inc_add_32(); + test_atomic_inc_add_64(); return CU_get_number_of_failures(); } -static int test_atomic_max_min_thread(void *arg UNUSED) +static int test_atomic_dec_sub_thread(void *arg UNUSED) { - per_thread_mem_t *per_thread_mem; + thread_init(); + test_atomic_dec_sub_32(); + test_atomic_dec_sub_64(); - per_thread_mem = thread_init(); + return CU_get_number_of_failures(); +} + +static int test_atomic_max_min_thread(void *arg UNUSED) +{ + thread_init(); test_atomic_max_min_32(); test_atomic_max_min_64(); - thread_finalize(per_thread_mem); - return CU_get_number_of_failures(); } static int test_atomic_cas_inc_dec_thread(void *arg UNUSED) { - per_thread_mem_t *per_thread_mem; - - per_thread_mem = thread_init(); + thread_init(); test_atomic_cas_inc_dec_32(); test_atomic_cas_inc_dec_64(); test_atomic_cas_inc_128(); - thread_finalize(per_thread_mem); - return CU_get_number_of_failures(); } static int test_atomic_xchg_thread(void *arg UNUSED) { - per_thread_mem_t *per_thread_mem; - - per_thread_mem = thread_init(); + thread_init(); test_atomic_xchg_32(); test_atomic_xchg_64(); - thread_finalize(per_thread_mem); - return CU_get_number_of_failures(); } static int test_atomic_non_relaxed_thread(void *arg UNUSED) { - per_thread_mem_t *per_thread_mem; - - per_thread_mem = thread_init(); + thread_init(); test_atomic_non_relaxed_32(); test_atomic_non_relaxed_64(); - thread_finalize(per_thread_mem); - return CU_get_number_of_failures(); } -static void test_atomic_functional(int func_ptr(void *), int check) +static void test_atomic_functional(int test_fn(void *), void validate_fn(void)) { pthrd_arg arg; arg.numthrds = global_mem->g_num_threads; test_atomic_init(); test_atomic_store(); - odp_cunit_thread_create(func_ptr, &arg); + odp_cunit_thread_create(test_fn, &arg); odp_cunit_thread_exit(&arg); - test_atomic_validate(check); + validate_fn(); } static void test_atomic_op_lock_free_set(void) @@ -1077,45 +1431,231 @@ static void test_atomic_op_lock_free_128(void) } } +static void atomic_test_atomic_init(void) +{ + uint64_t i; + odp_atomic_u128_t *a128u = &global_mem->a128u; + + for (i = 0; i < CNT; i++) { + odp_u128_t a128u_tmp; + + odp_atomic_init_u32(&global_mem->a32u, i); + odp_atomic_init_u64(&global_mem->a64u, i); + odp_atomic_init_u32(&global_mem->a32u_min, i); + odp_atomic_init_u32(&global_mem->a32u_max, i); + odp_atomic_init_u64(&global_mem->a64u_min, i); + odp_atomic_init_u64(&global_mem->a64u_max, i); + odp_atomic_init_u32(&global_mem->a32u_xchg, i); + odp_atomic_init_u64(&global_mem->a64u_xchg, i); + + a128u_tmp.u64[0] = i; + a128u_tmp.u64[1] = i; + odp_atomic_init_u128(&global_mem->a128u, a128u_tmp); + + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u) == i); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u) == i); + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_min) == i); + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_max) == i); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_min) == i); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_max) == i); + CU_ASSERT(odp_atomic_load_u32(&global_mem->a32u_xchg) == i); + CU_ASSERT(odp_atomic_load_u64(&global_mem->a64u_xchg) == i); + + a128u_tmp = odp_atomic_load_u128(a128u); + CU_ASSERT(a128u_tmp.u64[0] == i); + CU_ASSERT(a128u_tmp.u64[1] == i); + } +} + +static void test_atomic_validate_inc(void) +{ + const uint64_t total_count = CNT * global_mem->g_num_threads; + const uint32_t a32u = U32_INIT_VAL + total_count; + + CU_ASSERT(a32u == odp_atomic_load_u32(&global_mem->a32u)); + CU_ASSERT(U64_INIT_VAL + total_count == odp_atomic_load_u64(&global_mem->a64u)); +} + +static void atomic_test_atomic_inc(void) +{ + test_atomic_functional(test_atomic_inc_thread, test_atomic_validate_inc); +} + +static void test_atomic_validate_dec(void) +{ + const uint64_t total_count = CNT * global_mem->g_num_threads; + const uint32_t a32u = U32_INIT_VAL - total_count; + + CU_ASSERT(a32u == odp_atomic_load_u32(&global_mem->a32u)); + CU_ASSERT(U64_INIT_VAL - total_count == odp_atomic_load_u64(&global_mem->a64u)); +} + +static void atomic_test_atomic_dec(void) +{ + test_atomic_functional(test_atomic_dec_thread, test_atomic_validate_dec); +} + +static void test_atomic_validate_add(void) +{ + const uint64_t total_count = CNT * ADD_SUB_CNT * global_mem->g_num_threads; + const uint32_t a32u = U32_INIT_VAL + total_count; + + CU_ASSERT(a32u == odp_atomic_load_u32(&global_mem->a32u)); + CU_ASSERT(U64_INIT_VAL + total_count == odp_atomic_load_u64(&global_mem->a64u)); +} + +static void atomic_test_atomic_add(void) +{ + test_atomic_functional(test_atomic_add_thread, test_atomic_validate_add); +} + +static void test_atomic_validate_sub(void) +{ + const uint64_t total_count = CNT * ADD_SUB_CNT * global_mem->g_num_threads; + const uint32_t a32u = U32_INIT_VAL - total_count; + + CU_ASSERT(a32u == odp_atomic_load_u32(&global_mem->a32u)); + CU_ASSERT(U64_INIT_VAL - total_count == odp_atomic_load_u64(&global_mem->a64u)); +} + +static void atomic_test_atomic_sub(void) +{ + test_atomic_functional(test_atomic_sub_thread, test_atomic_validate_sub); +} + +static void atomic_test_atomic_fetch_inc(void) +{ + test_atomic_functional(test_atomic_fetch_inc_thread, test_atomic_validate_inc); +} + +static void atomic_test_atomic_fetch_dec(void) +{ + test_atomic_functional(test_atomic_fetch_dec_thread, test_atomic_validate_dec); +} + +static void atomic_test_atomic_fetch_add(void) +{ + test_atomic_functional(test_atomic_fetch_add_thread, test_atomic_validate_add); +} + +static void atomic_test_atomic_fetch_sub(void) +{ + test_atomic_functional(test_atomic_fetch_sub_thread, test_atomic_validate_sub); +} + +static void test_atomic_validate_max(void) +{ + const uint64_t total_count = CNT * global_mem->g_num_threads - 1; + /* In a long test, counter may overflow, in which case max is saturated at UINT32_MAX. */ + const uint32_t a32u_max = min(U32_INIT_VAL + total_count, UINT32_MAX); + + CU_ASSERT(a32u_max == odp_atomic_load_u32(&global_mem->a32u_max)); + CU_ASSERT(U64_INIT_VAL + total_count == odp_atomic_load_u64(&global_mem->a64u_max)); +} + +static void atomic_test_atomic_max(void) +{ + test_atomic_functional(test_atomic_max_thread, test_atomic_validate_max); +} + +static void test_atomic_validate_min(void) +{ + const uint64_t total_count = CNT * global_mem->g_num_threads - 1; + /* In a long test, counter may underflow, in which case min is saturated at 0. */ + const uint32_t a32u_min = max((int64_t)U32_INIT_VAL - (int64_t)total_count, 0); + + CU_ASSERT(a32u_min == odp_atomic_load_u32(&global_mem->a32u_min)); + CU_ASSERT(U64_INIT_VAL - total_count == odp_atomic_load_u64(&global_mem->a64u_min)); +} + +static void atomic_test_atomic_min(void) +{ + test_atomic_functional(test_atomic_min_thread, test_atomic_validate_min); +} + +static void test_atomic_validate_cas_128(void) +{ + odp_u128_t a128u = odp_atomic_load_u128(&global_mem->a128u); + const uint64_t iterations = a128u.u64[0] - a128u.u64[1]; + + CU_ASSERT(iterations == CNT * global_mem->g_num_threads); +} + +static void test_atomic_validate_cas(void) +{ + test_atomic_validate_inc(); + test_atomic_validate_cas_128(); +} + +static void atomic_test_atomic_cas(void) +{ + test_atomic_functional(test_atomic_cas_thread, test_atomic_validate_cas); +} + +static void atomic_test_atomic_cas_acq(void) +{ + test_atomic_functional(test_atomic_cas_acq_thread, test_atomic_validate_cas); +} + +static void atomic_test_atomic_cas_rel(void) +{ + test_atomic_functional(test_atomic_cas_rel_thread, test_atomic_validate_cas); +} + +static void atomic_test_atomic_cas_acq_rel(void) +{ + test_atomic_functional(test_atomic_cas_acq_rel_thread, test_atomic_validate_cas); +} + static void atomic_test_atomic_inc_dec(void) { - test_atomic_functional(test_atomic_inc_dec_thread, 0); + test_atomic_functional(test_atomic_inc_dec_thread, test_atomic_validate_init_val); } static void atomic_test_atomic_add_sub(void) { - test_atomic_functional(test_atomic_add_sub_thread, 0); + test_atomic_functional(test_atomic_add_sub_thread, test_atomic_validate_init_val); } static void atomic_test_atomic_fetch_inc_dec(void) { - test_atomic_functional(test_atomic_fetch_inc_dec_thread, 0); + test_atomic_functional(test_atomic_fetch_inc_dec_thread, test_atomic_validate_init_val); } static void atomic_test_atomic_fetch_add_sub(void) { - test_atomic_functional(test_atomic_fetch_add_sub_thread, 0); + test_atomic_functional(test_atomic_fetch_add_sub_thread, test_atomic_validate_init_val); +} + +static void atomic_test_atomic_inc_add(void) +{ + test_atomic_functional(test_atomic_inc_add_thread, test_atomic_validate_inc_add); +} + +static void atomic_test_atomic_dec_sub(void) +{ + test_atomic_functional(test_atomic_dec_sub_thread, test_atomic_validate_dec_sub); } static void atomic_test_atomic_max_min(void) { - test_atomic_functional(test_atomic_max_min_thread, CHECK_MAX_MIN); + test_atomic_functional(test_atomic_max_min_thread, test_atomic_validate_max_min); } static void atomic_test_atomic_cas_inc_dec(void) { - test_atomic_functional(test_atomic_cas_inc_dec_thread, CHECK_CAS_128); + test_atomic_functional(test_atomic_cas_inc_dec_thread, test_atomic_validate_cas_inc_dec); } static void atomic_test_atomic_xchg(void) { - test_atomic_functional(test_atomic_xchg_thread, CHECK_XCHG); + test_atomic_functional(test_atomic_xchg_thread, test_atomic_validate_xchg); } static void atomic_test_atomic_non_relaxed(void) { test_atomic_functional(test_atomic_non_relaxed_thread, - CHECK_MAX_MIN | CHECK_XCHG); + test_atomic_validate_non_relaxed); } static void atomic_test_atomic_op_lock_free(void) @@ -1126,10 +1666,27 @@ static void atomic_test_atomic_op_lock_free(void) } odp_testinfo_t atomic_suite_atomic[] = { + ODP_TEST_INFO(atomic_test_atomic_init), + ODP_TEST_INFO(atomic_test_atomic_inc), + ODP_TEST_INFO(atomic_test_atomic_dec), + ODP_TEST_INFO(atomic_test_atomic_add), + ODP_TEST_INFO(atomic_test_atomic_sub), + ODP_TEST_INFO(atomic_test_atomic_fetch_inc), + ODP_TEST_INFO(atomic_test_atomic_fetch_dec), + ODP_TEST_INFO(atomic_test_atomic_fetch_add), + ODP_TEST_INFO(atomic_test_atomic_fetch_sub), + ODP_TEST_INFO(atomic_test_atomic_max), + ODP_TEST_INFO(atomic_test_atomic_min), + ODP_TEST_INFO(atomic_test_atomic_cas), + ODP_TEST_INFO(atomic_test_atomic_cas_acq), + ODP_TEST_INFO(atomic_test_atomic_cas_rel), + ODP_TEST_INFO(atomic_test_atomic_cas_acq_rel), ODP_TEST_INFO(atomic_test_atomic_inc_dec), ODP_TEST_INFO(atomic_test_atomic_add_sub), ODP_TEST_INFO(atomic_test_atomic_fetch_inc_dec), ODP_TEST_INFO(atomic_test_atomic_fetch_add_sub), + ODP_TEST_INFO(atomic_test_atomic_inc_add), + ODP_TEST_INFO(atomic_test_atomic_dec_sub), ODP_TEST_INFO(atomic_test_atomic_max_min), ODP_TEST_INFO(atomic_test_atomic_cas_inc_dec), ODP_TEST_INFO(atomic_test_atomic_xchg), diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index f620d44a8..dcdca1e28 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -1,5 +1,5 @@ /* Copyright (c) 2014-2018, Linaro Limited - * Copyright (c) 2021, Nokia + * Copyright (c) 2021-2022, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -26,6 +26,31 @@ struct suite_context_s { static struct suite_context_s suite_context; +static void test_default_values(void) +{ + odp_crypto_session_param_t param; + + memset(¶m, 0x55, sizeof(param)); + odp_crypto_session_param_init(¶m); + + CU_ASSERT_EQUAL(param.op, ODP_CRYPTO_OP_ENCODE); + CU_ASSERT_EQUAL(param.auth_cipher_text, false); + CU_ASSERT_EQUAL(param.pref_mode, ODP_CRYPTO_SYNC); + CU_ASSERT_EQUAL(param.op_mode, ODP_CRYPTO_SYNC); + CU_ASSERT_EQUAL(param.cipher_alg, ODP_CIPHER_ALG_NULL); + CU_ASSERT_EQUAL(param.cipher_iv_len, 0); + CU_ASSERT_EQUAL(param.auth_alg, ODP_AUTH_ALG_NULL); + CU_ASSERT_EQUAL(param.auth_iv_len, 0); + CU_ASSERT_EQUAL(param.auth_aad_len, 0); + +#if ODP_DEPRECATED_API + CU_ASSERT_EQUAL(param.cipher_iv.data, NULL); + CU_ASSERT_EQUAL(param.cipher_iv.length, 0); + CU_ASSERT_EQUAL(param.auth_iv.data, NULL); + CU_ASSERT_EQUAL(param.auth_iv.length, 0); +#endif +} + static int packet_cmp_mem_bits(odp_packet_t pkt, uint32_t offset, uint8_t *s, uint32_t len) { @@ -581,6 +606,12 @@ static void alg_test_execute(const alg_test_param_t *param) } } +typedef enum { + PACKET_IV, + OLD_PACKET_IV, + OLD_SESSION_IV, +} iv_test_mode_t; + /* Basic algorithm run function for async inplace mode. * Creates a session from input parameters and runs one operation * on input_vec. Checks the output of the crypto operation against @@ -594,7 +625,7 @@ static void alg_test(odp_crypto_op_t op, odp_cipher_alg_t cipher_alg, odp_auth_alg_t auth_alg, crypto_test_reference_t *ref, - odp_bool_t ovr_iv, + iv_test_mode_t iv_mode, odp_bool_t bit_mode) { unsigned int initial_num_failures = CU_get_number_of_failures(); @@ -607,8 +638,6 @@ static void alg_test(odp_crypto_op_t op, odp_crypto_session_param_t ses_params; uint8_t cipher_key_data[ref->cipher_key_length]; uint8_t auth_key_data[ref->auth_key_length]; - uint8_t cipher_iv_data[ref->cipher_iv_length]; - uint8_t auth_iv_data[ref->auth_iv_length]; odp_crypto_key_t cipher_key = { .data = cipher_key_data, .length = ref->cipher_key_length @@ -617,22 +646,27 @@ static void alg_test(odp_crypto_op_t op, .data = auth_key_data, .length = ref->auth_key_length }; + alg_test_param_t test_param; +#if ODP_DEPRECATED_API + uint8_t cipher_iv_data[ref->cipher_iv_length]; + uint8_t auth_iv_data[ref->auth_iv_length]; odp_crypto_iv_t cipher_iv = { - .data = ovr_iv ? NULL : cipher_iv_data, .length = ref->cipher_iv_length }; odp_crypto_iv_t auth_iv = { - .data = ovr_iv ? NULL : auth_iv_data, .length = ref->auth_iv_length }; - alg_test_param_t test_param; - memcpy(cipher_key_data, ref->cipher_key, ref->cipher_key_length); - memcpy(auth_key_data, ref->auth_key, ref->auth_key_length); - if (!ovr_iv) { + if (iv_mode == OLD_SESSION_IV) { memcpy(cipher_iv_data, ref->cipher_iv, ref->cipher_iv_length); memcpy(auth_iv_data, ref->auth_iv, ref->auth_iv_length); + cipher_iv.data = cipher_iv_data; + auth_iv.data = auth_iv_data; } +#endif + + memcpy(cipher_key_data, ref->cipher_key, ref->cipher_key_length); + memcpy(auth_key_data, ref->auth_key, ref->auth_key_length); /* Create a crypto session */ odp_crypto_session_param_init(&ses_params); @@ -645,15 +679,41 @@ static void alg_test(odp_crypto_op_t op, ses_params.compl_queue = suite_context.queue; ses_params.output_pool = suite_context.pool; ses_params.cipher_key = cipher_key; - ses_params.cipher_iv = cipher_iv; - ses_params.auth_iv = auth_iv; + if (iv_mode == PACKET_IV) { + ses_params.cipher_iv_len = ref->cipher_iv_length; + ses_params.auth_iv_len = ref->auth_iv_length; + } else { +#if ODP_DEPRECATED_API + ses_params.cipher_iv = cipher_iv; + ses_params.auth_iv = auth_iv; +#endif + } ses_params.auth_key = auth_key; ses_params.auth_digest_len = ref->digest_length; ses_params.auth_aad_len = ref->aad_length; rc = odp_crypto_session_create(&ses_params, &session, &status); + /* + * In some cases an individual algorithm cannot be used alone, + * i.e. with the null cipher/auth algorithm. + */ + if (rc == ODP_CRYPTO_SES_ERR_ALG_COMBO) { + printf("\n Unsupported algorithm combination: %s, %s\n", + cipher_alg_name(cipher_alg), + auth_alg_name(auth_alg)); + return; + } + /* + * We do not allow ODP_CRYPTO_SES_ERR_ALG_ORDER since we do + * not combine individual non-null crypto and auth algorithms + * with each other in the tests. Both orders should work when + * only one algorithm is used (i.e. the other one is null). + * + * We do not allow ODP_CRYPTO_SES_ERR_PARAMS until needed for + * some ODP implementation. + */ CU_ASSERT_FATAL(!rc); - CU_ASSERT(status == ODP_CRYPTO_SES_CREATE_ERR_NONE); + CU_ASSERT(status == ODP_CRYPTO_SES_ERR_NONE); CU_ASSERT(odp_crypto_session_to_u64(session) != odp_crypto_session_to_u64(ODP_CRYPTO_SESSION_INVALID)); @@ -663,8 +723,10 @@ static void alg_test(odp_crypto_op_t op, */ memset(cipher_key_data, 0, sizeof(cipher_key_data)); memset(auth_key_data, 0, sizeof(auth_key_data)); +#if ODP_DEPRECATED_API memset(cipher_iv_data, 0, sizeof(cipher_iv_data)); memset(auth_iv_data, 0, sizeof(auth_iv_data)); +#endif memset(&ses_params, 0, sizeof(ses_params)); memset(&test_param, 0, sizeof(test_param)); @@ -672,7 +734,7 @@ static void alg_test(odp_crypto_op_t op, test_param.op = op; test_param.auth_alg = auth_alg; test_param.ref = ref; - test_param.override_iv = ovr_iv; + test_param.override_iv = (iv_mode != OLD_SESSION_IV); test_param.bit_mode = bit_mode; alg_test_execute(&test_param); @@ -717,10 +779,8 @@ static void check_alg(odp_crypto_op_t op, odp_auth_alg_t auth_alg, crypto_test_reference_t *ref, size_t count, - odp_bool_t ovr_iv, odp_bool_t bit_mode) { - odp_crypto_capability_t capa; int rc, i; int cipher_num = odp_crypto_cipher_capability(cipher_alg, NULL, 0); int auth_num = odp_crypto_auth_capability(auth_alg, NULL, 0); @@ -738,134 +798,6 @@ static void check_alg(odp_crypto_op_t op, odp_bool_t cipher_tested[cipher_num]; odp_bool_t auth_tested[auth_num]; - rc = odp_crypto_capability(&capa); - CU_ASSERT(!rc); - - if (cipher_alg == ODP_CIPHER_ALG_3DES_CBC && - !(capa.ciphers.bit.trides_cbc)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_3DES_ECB && - !(capa.ciphers.bit.trides_ecb)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_AES_CBC && - !(capa.ciphers.bit.aes_cbc)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_AES_CTR && - !(capa.ciphers.bit.aes_ctr)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_AES_ECB && - !(capa.ciphers.bit.aes_ecb)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_AES_CFB128 && - !(capa.ciphers.bit.aes_cfb128)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_AES_XTS && - !(capa.ciphers.bit.aes_xts)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_AES_GCM && - !(capa.ciphers.bit.aes_gcm)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_AES_CCM && - !(capa.ciphers.bit.aes_ccm)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_CHACHA20_POLY1305 && - !(capa.ciphers.bit.chacha20_poly1305)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_KASUMI_F8 && - !(capa.ciphers.bit.kasumi_f8)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_SNOW3G_UEA2 && - !(capa.ciphers.bit.snow3g_uea2)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_AES_EEA2 && - !(capa.ciphers.bit.aes_eea2)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_ZUC_EEA3 && - !(capa.ciphers.bit.zuc_eea3)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_DES && - !(capa.ciphers.bit.des)) - rc = -1; - if (cipher_alg == ODP_CIPHER_ALG_NULL && - !(capa.ciphers.bit.null)) - rc = -1; - - CU_ASSERT(!rc); - CU_ASSERT((~capa.ciphers.all_bits & capa.hw_ciphers.all_bits) == 0); - - if (auth_alg == ODP_AUTH_ALG_AES_GCM && - !(capa.auths.bit.aes_gcm)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_AES_GMAC && - !(capa.auths.bit.aes_gmac)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_AES_CMAC && - !(capa.auths.bit.aes_cmac)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_AES_CCM && - !(capa.auths.bit.aes_ccm)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_CHACHA20_POLY1305 && - !(capa.auths.bit.chacha20_poly1305)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_KASUMI_F9 && - !(capa.auths.bit.kasumi_f9)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_SNOW3G_UIA2 && - !(capa.auths.bit.snow3g_uia2)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_AES_EIA2 && - !(capa.auths.bit.aes_eia2)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_ZUC_EIA3 && - !(capa.auths.bit.zuc_eia3)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_MD5_HMAC && - !(capa.auths.bit.md5_hmac)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_NULL && - !(capa.auths.bit.null)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_SHA1_HMAC && - !(capa.auths.bit.sha1_hmac)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_SHA224_HMAC && - !(capa.auths.bit.sha224_hmac)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_SHA256_HMAC && - !(capa.auths.bit.sha256_hmac)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_SHA384_HMAC && - !(capa.auths.bit.sha384_hmac)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_SHA512_HMAC && - !(capa.auths.bit.sha512_hmac)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_AES_XCBC_MAC && - !(capa.auths.bit.aes_xcbc_mac)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_MD5 && - !(capa.auths.bit.md5)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_SHA1 && - !(capa.auths.bit.sha1)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_SHA224 && - !(capa.auths.bit.sha224)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_SHA256 && - !(capa.auths.bit.sha256)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_SHA384 && - !(capa.auths.bit.sha384)) - rc = -1; - if (auth_alg == ODP_AUTH_ALG_SHA512 && - !(capa.auths.bit.sha512)) - rc = -1; - - CU_ASSERT(!rc); - CU_ASSERT((~capa.auths.all_bits & capa.hw_auths.all_bits) == 0); - rc = odp_crypto_cipher_capability(cipher_alg, cipher_capa, cipher_num); CU_ASSERT_FATAL(rc == cipher_num); @@ -926,7 +858,18 @@ static void check_alg(odp_crypto_op_t op, continue; } - alg_test(op, cipher_alg, auth_alg, &ref[idx], ovr_iv, bit_mode); + /* test with per-packet IV */ + alg_test(op, cipher_alg, auth_alg, &ref[idx], + PACKET_IV, bit_mode); +#if ODP_DEPRECATED_API + /* test with per-packet IV using the old API*/ + alg_test(op, cipher_alg, auth_alg, &ref[idx], + OLD_PACKET_IV, bit_mode); + + /* test with per-session IV */ + alg_test(op, cipher_alg, auth_alg, &ref[idx], + OLD_SESSION_IV, bit_mode); +#endif cipher_tested[cipher_idx] = true; auth_tested[auth_idx] = true; @@ -1169,6 +1112,19 @@ static int check_alg_support(odp_cipher_alg_t cipher, odp_auth_alg_t auth) return ODP_TEST_ACTIVE; } +static void test_capability(void) +{ + odp_crypto_capability_t capa = {.max_sessions = 1}; + int rc; + + rc = odp_crypto_capability(&capa); + CU_ASSERT(!rc); + if (capa.max_sessions > 0) + CU_ASSERT(capa.sync_mode || capa.async_mode); + CU_ASSERT((~capa.ciphers.all_bits & capa.hw_ciphers.all_bits) == 0); + CU_ASSERT((~capa.auths.all_bits & capa.hw_auths.all_bits) == 0); +} + static int check_alg_null(void) { return check_alg_support(ODP_CIPHER_ALG_NULL, ODP_AUTH_ALG_NULL); @@ -1182,7 +1138,6 @@ static void crypto_test_enc_alg_null(void) ODP_AUTH_ALG_NULL, null_reference, ARRAY_SIZE(null_reference), - false, false); } @@ -1193,7 +1148,6 @@ static void crypto_test_dec_alg_null(void) ODP_AUTH_ALG_NULL, null_reference, ARRAY_SIZE(null_reference), - false, false); } @@ -1209,18 +1163,6 @@ static void crypto_test_enc_alg_3des_cbc(void) ODP_AUTH_ALG_NULL, tdes_cbc_reference, ARRAY_SIZE(tdes_cbc_reference), - false, - false); -} - -static void crypto_test_enc_alg_3des_cbc_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_3DES_CBC, - ODP_AUTH_ALG_NULL, - tdes_cbc_reference, - ARRAY_SIZE(tdes_cbc_reference), - true, false); } @@ -1231,18 +1173,6 @@ static void crypto_test_dec_alg_3des_cbc(void) ODP_AUTH_ALG_NULL, tdes_cbc_reference, ARRAY_SIZE(tdes_cbc_reference), - false, - false); -} - -static void crypto_test_dec_alg_3des_cbc_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_3DES_CBC, - ODP_AUTH_ALG_NULL, - tdes_cbc_reference, - ARRAY_SIZE(tdes_cbc_reference), - true, false); } @@ -1258,7 +1188,6 @@ static void crypto_test_enc_alg_3des_ecb(void) ODP_AUTH_ALG_NULL, tdes_ecb_reference, ARRAY_SIZE(tdes_ecb_reference), - false, false); } @@ -1269,7 +1198,6 @@ static void crypto_test_dec_alg_3des_ecb(void) ODP_AUTH_ALG_NULL, tdes_ecb_reference, ARRAY_SIZE(tdes_ecb_reference), - false, false); } @@ -1286,18 +1214,6 @@ static void crypto_test_enc_alg_chacha20_poly1305(void) ODP_AUTH_ALG_CHACHA20_POLY1305, chacha20_poly1305_reference, ARRAY_SIZE(chacha20_poly1305_reference), - false, - false); -} - -static void crypto_test_enc_alg_chacha20_poly1305_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_CHACHA20_POLY1305, - ODP_AUTH_ALG_CHACHA20_POLY1305, - chacha20_poly1305_reference, - ARRAY_SIZE(chacha20_poly1305_reference), - true, false); } @@ -1308,18 +1224,6 @@ static void crypto_test_dec_alg_chacha20_poly1305(void) ODP_AUTH_ALG_CHACHA20_POLY1305, chacha20_poly1305_reference, ARRAY_SIZE(chacha20_poly1305_reference), - false, - false); -} - -static void crypto_test_dec_alg_chacha20_poly1305_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_CHACHA20_POLY1305, - ODP_AUTH_ALG_CHACHA20_POLY1305, - chacha20_poly1305_reference, - ARRAY_SIZE(chacha20_poly1305_reference), - true, false); } @@ -1335,18 +1239,6 @@ static void crypto_test_enc_alg_aes_gcm(void) ODP_AUTH_ALG_AES_GCM, aes_gcm_reference, ARRAY_SIZE(aes_gcm_reference), - false, - false); -} - -static void crypto_test_enc_alg_aes_gcm_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_AES_GCM, - ODP_AUTH_ALG_AES_GCM, - aes_gcm_reference, - ARRAY_SIZE(aes_gcm_reference), - true, false); } @@ -1357,18 +1249,6 @@ static void crypto_test_dec_alg_aes_gcm(void) ODP_AUTH_ALG_AES_GCM, aes_gcm_reference, ARRAY_SIZE(aes_gcm_reference), - false, - false); -} - -static void crypto_test_dec_alg_aes_gcm_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_AES_GCM, - ODP_AUTH_ALG_AES_GCM, - aes_gcm_reference, - ARRAY_SIZE(aes_gcm_reference), - true, false); } @@ -1384,18 +1264,6 @@ static void crypto_test_enc_alg_aes_ccm(void) ODP_AUTH_ALG_AES_CCM, aes_ccm_reference, ARRAY_SIZE(aes_ccm_reference), - false, - false); -} - -static void crypto_test_enc_alg_aes_ccm_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_AES_CCM, - ODP_AUTH_ALG_AES_CCM, - aes_ccm_reference, - ARRAY_SIZE(aes_ccm_reference), - true, false); } @@ -1406,18 +1274,6 @@ static void crypto_test_dec_alg_aes_ccm(void) ODP_AUTH_ALG_AES_CCM, aes_ccm_reference, ARRAY_SIZE(aes_ccm_reference), - false, - false); -} - -static void crypto_test_dec_alg_aes_ccm_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_AES_CCM, - ODP_AUTH_ALG_AES_CCM, - aes_ccm_reference, - ARRAY_SIZE(aes_ccm_reference), - true, false); } @@ -1433,18 +1289,6 @@ static void crypto_test_enc_alg_aes_cbc(void) ODP_AUTH_ALG_NULL, aes_cbc_reference, ARRAY_SIZE(aes_cbc_reference), - false, - false); -} - -static void crypto_test_enc_alg_aes_cbc_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_AES_CBC, - ODP_AUTH_ALG_NULL, - aes_cbc_reference, - ARRAY_SIZE(aes_cbc_reference), - true, false); } @@ -1455,18 +1299,6 @@ static void crypto_test_dec_alg_aes_cbc(void) ODP_AUTH_ALG_NULL, aes_cbc_reference, ARRAY_SIZE(aes_cbc_reference), - false, - false); -} - -static void crypto_test_dec_alg_aes_cbc_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_AES_CBC, - ODP_AUTH_ALG_NULL, - aes_cbc_reference, - ARRAY_SIZE(aes_cbc_reference), - true, false); } @@ -1482,18 +1314,6 @@ static void crypto_test_enc_alg_aes_ctr(void) ODP_AUTH_ALG_NULL, aes_ctr_reference, ARRAY_SIZE(aes_ctr_reference), - false, - false); -} - -static void crypto_test_enc_alg_aes_ctr_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_AES_CTR, - ODP_AUTH_ALG_NULL, - aes_ctr_reference, - ARRAY_SIZE(aes_ctr_reference), - true, false); } @@ -1504,18 +1324,6 @@ static void crypto_test_dec_alg_aes_ctr(void) ODP_AUTH_ALG_NULL, aes_ctr_reference, ARRAY_SIZE(aes_ctr_reference), - false, - false); -} - -static void crypto_test_dec_alg_aes_ctr_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_AES_CTR, - ODP_AUTH_ALG_NULL, - aes_ctr_reference, - ARRAY_SIZE(aes_ctr_reference), - true, false); } @@ -1531,7 +1339,6 @@ static void crypto_test_enc_alg_aes_ecb(void) ODP_AUTH_ALG_NULL, aes_ecb_reference, ARRAY_SIZE(aes_ecb_reference), - false, false); } @@ -1542,7 +1349,6 @@ static void crypto_test_dec_alg_aes_ecb(void) ODP_AUTH_ALG_NULL, aes_ecb_reference, ARRAY_SIZE(aes_ecb_reference), - false, false); } @@ -1558,18 +1364,6 @@ static void crypto_test_enc_alg_aes_cfb128(void) ODP_AUTH_ALG_NULL, aes_cfb128_reference, ARRAY_SIZE(aes_cfb128_reference), - false, - false); -} - -static void crypto_test_enc_alg_aes_cfb128_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_AES_CFB128, - ODP_AUTH_ALG_NULL, - aes_cfb128_reference, - ARRAY_SIZE(aes_cfb128_reference), - true, false); } @@ -1580,18 +1374,6 @@ static void crypto_test_dec_alg_aes_cfb128(void) ODP_AUTH_ALG_NULL, aes_cfb128_reference, ARRAY_SIZE(aes_cfb128_reference), - false, - false); -} - -static void crypto_test_dec_alg_aes_cfb128_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_AES_CFB128, - ODP_AUTH_ALG_NULL, - aes_cfb128_reference, - ARRAY_SIZE(aes_cfb128_reference), - true, false); } @@ -1607,18 +1389,6 @@ static void crypto_test_enc_alg_aes_xts(void) ODP_AUTH_ALG_NULL, aes_xts_reference, ARRAY_SIZE(aes_xts_reference), - false, - false); -} - -static void crypto_test_enc_alg_aes_xts_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_AES_XTS, - ODP_AUTH_ALG_NULL, - aes_xts_reference, - ARRAY_SIZE(aes_xts_reference), - true, false); } @@ -1629,18 +1399,6 @@ static void crypto_test_dec_alg_aes_xts(void) ODP_AUTH_ALG_NULL, aes_xts_reference, ARRAY_SIZE(aes_xts_reference), - false, - false); -} - -static void crypto_test_dec_alg_aes_xts_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_AES_XTS, - ODP_AUTH_ALG_NULL, - aes_xts_reference, - ARRAY_SIZE(aes_xts_reference), - true, false); } @@ -1656,18 +1414,6 @@ static void crypto_test_enc_alg_kasumi_f8(void) ODP_AUTH_ALG_NULL, kasumi_f8_reference, ARRAY_SIZE(kasumi_f8_reference), - false, - true); -} - -static void crypto_test_enc_alg_kasumi_f8_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_KASUMI_F8, - ODP_AUTH_ALG_NULL, - kasumi_f8_reference, - ARRAY_SIZE(kasumi_f8_reference), - true, true); } @@ -1678,18 +1424,6 @@ static void crypto_test_dec_alg_kasumi_f8(void) ODP_AUTH_ALG_NULL, kasumi_f8_reference, ARRAY_SIZE(kasumi_f8_reference), - false, - true); -} - -static void crypto_test_dec_alg_kasumi_f8_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_KASUMI_F8, - ODP_AUTH_ALG_NULL, - kasumi_f8_reference, - ARRAY_SIZE(kasumi_f8_reference), - true, true); } @@ -1705,18 +1439,6 @@ static void crypto_test_enc_alg_snow3g_uea2(void) ODP_AUTH_ALG_NULL, snow3g_uea2_reference, ARRAY_SIZE(snow3g_uea2_reference), - false, - true); -} - -static void crypto_test_enc_alg_snow3g_uea2_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_SNOW3G_UEA2, - ODP_AUTH_ALG_NULL, - snow3g_uea2_reference, - ARRAY_SIZE(snow3g_uea2_reference), - true, true); } @@ -1727,18 +1449,6 @@ static void crypto_test_dec_alg_snow3g_uea2(void) ODP_AUTH_ALG_NULL, snow3g_uea2_reference, ARRAY_SIZE(snow3g_uea2_reference), - false, - true); -} - -static void crypto_test_dec_alg_snow3g_uea2_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_SNOW3G_UEA2, - ODP_AUTH_ALG_NULL, - snow3g_uea2_reference, - ARRAY_SIZE(snow3g_uea2_reference), - true, true); } @@ -1755,18 +1465,6 @@ static void crypto_test_enc_alg_aes_eea2(void) ODP_AUTH_ALG_NULL, aes_eea2_reference, ARRAY_SIZE(aes_eea2_reference), - false, - true); -} - -static void crypto_test_enc_alg_aes_eea2_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_AES_EEA2, - ODP_AUTH_ALG_NULL, - aes_eea2_reference, - ARRAY_SIZE(aes_eea2_reference), - true, true); } @@ -1777,18 +1475,6 @@ static void crypto_test_dec_alg_aes_eea2(void) ODP_AUTH_ALG_NULL, aes_eea2_reference, ARRAY_SIZE(aes_eea2_reference), - false, - true); -} - -static void crypto_test_dec_alg_aes_eea2_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_AES_EEA2, - ODP_AUTH_ALG_NULL, - aes_eea2_reference, - ARRAY_SIZE(aes_eea2_reference), - true, true); } @@ -1804,18 +1490,6 @@ static void crypto_test_enc_alg_zuc_eea3(void) ODP_AUTH_ALG_NULL, zuc_eea3_reference, ARRAY_SIZE(zuc_eea3_reference), - false, - true); -} - -static void crypto_test_enc_alg_zuc_eea3_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_ZUC_EEA3, - ODP_AUTH_ALG_NULL, - zuc_eea3_reference, - ARRAY_SIZE(zuc_eea3_reference), - true, true); } @@ -1826,18 +1500,6 @@ static void crypto_test_dec_alg_zuc_eea3(void) ODP_AUTH_ALG_NULL, zuc_eea3_reference, ARRAY_SIZE(zuc_eea3_reference), - false, - true); -} - -static void crypto_test_dec_alg_zuc_eea3_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_ZUC_EEA3, - ODP_AUTH_ALG_NULL, - zuc_eea3_reference, - ARRAY_SIZE(zuc_eea3_reference), - true, true); } @@ -1853,7 +1515,6 @@ static void crypto_test_gen_alg_hmac_md5(void) ODP_AUTH_ALG_MD5_HMAC, hmac_md5_reference, ARRAY_SIZE(hmac_md5_reference), - false, false); } @@ -1864,7 +1525,6 @@ static void crypto_test_check_alg_hmac_md5(void) ODP_AUTH_ALG_MD5_HMAC, hmac_md5_reference, ARRAY_SIZE(hmac_md5_reference), - false, false); } @@ -1880,7 +1540,6 @@ static void crypto_test_gen_alg_hmac_sha1(void) ODP_AUTH_ALG_SHA1_HMAC, hmac_sha1_reference, ARRAY_SIZE(hmac_sha1_reference), - false, false); } @@ -1891,7 +1550,6 @@ static void crypto_test_check_alg_hmac_sha1(void) ODP_AUTH_ALG_SHA1_HMAC, hmac_sha1_reference, ARRAY_SIZE(hmac_sha1_reference), - false, false); } @@ -1907,7 +1565,6 @@ static void crypto_test_gen_alg_hmac_sha224(void) ODP_AUTH_ALG_SHA224_HMAC, hmac_sha224_reference, ARRAY_SIZE(hmac_sha224_reference), - false, false); } @@ -1918,7 +1575,6 @@ static void crypto_test_check_alg_hmac_sha224(void) ODP_AUTH_ALG_SHA224_HMAC, hmac_sha224_reference, ARRAY_SIZE(hmac_sha224_reference), - false, false); } @@ -1934,7 +1590,6 @@ static void crypto_test_gen_alg_hmac_sha256(void) ODP_AUTH_ALG_SHA256_HMAC, hmac_sha256_reference, ARRAY_SIZE(hmac_sha256_reference), - false, false); } @@ -1945,7 +1600,6 @@ static void crypto_test_check_alg_hmac_sha256(void) ODP_AUTH_ALG_SHA256_HMAC, hmac_sha256_reference, ARRAY_SIZE(hmac_sha256_reference), - false, false); } @@ -1961,7 +1615,6 @@ static void crypto_test_gen_alg_hmac_sha384(void) ODP_AUTH_ALG_SHA384_HMAC, hmac_sha384_reference, ARRAY_SIZE(hmac_sha384_reference), - false, false); } @@ -1972,7 +1625,6 @@ static void crypto_test_check_alg_hmac_sha384(void) ODP_AUTH_ALG_SHA384_HMAC, hmac_sha384_reference, ARRAY_SIZE(hmac_sha384_reference), - false, false); } @@ -1988,7 +1640,6 @@ static void crypto_test_gen_alg_hmac_sha512(void) ODP_AUTH_ALG_SHA512_HMAC, hmac_sha512_reference, ARRAY_SIZE(hmac_sha512_reference), - false, false); } @@ -1999,7 +1650,6 @@ static void crypto_test_check_alg_hmac_sha512(void) ODP_AUTH_ALG_SHA512_HMAC, hmac_sha512_reference, ARRAY_SIZE(hmac_sha512_reference), - false, false); } @@ -2016,7 +1666,6 @@ static void crypto_test_gen_alg_aes_xcbc(void) ODP_AUTH_ALG_AES_XCBC_MAC, aes_xcbc_reference, ARRAY_SIZE(aes_xcbc_reference), - false, false); } @@ -2027,7 +1676,6 @@ static void crypto_test_check_alg_aes_xcbc(void) ODP_AUTH_ALG_AES_XCBC_MAC, aes_xcbc_reference, ARRAY_SIZE(aes_xcbc_reference), - false, false); } @@ -2043,18 +1691,6 @@ static void crypto_test_gen_alg_aes_gmac(void) ODP_AUTH_ALG_AES_GMAC, aes_gmac_reference, ARRAY_SIZE(aes_gmac_reference), - false, - false); -} - -static void crypto_test_gen_alg_aes_gmac_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_NULL, - ODP_AUTH_ALG_AES_GMAC, - aes_gmac_reference, - ARRAY_SIZE(aes_gmac_reference), - true, false); } @@ -2065,18 +1701,6 @@ static void crypto_test_check_alg_aes_gmac(void) ODP_AUTH_ALG_AES_GMAC, aes_gmac_reference, ARRAY_SIZE(aes_gmac_reference), - false, - false); -} - -static void crypto_test_check_alg_aes_gmac_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_NULL, - ODP_AUTH_ALG_AES_GMAC, - aes_gmac_reference, - ARRAY_SIZE(aes_gmac_reference), - false, false); } @@ -2092,7 +1716,6 @@ static void crypto_test_gen_alg_aes_cmac(void) ODP_AUTH_ALG_AES_CMAC, aes_cmac_reference, ARRAY_SIZE(aes_cmac_reference), - false, false); } @@ -2103,7 +1726,6 @@ static void crypto_test_check_alg_aes_cmac(void) ODP_AUTH_ALG_AES_CMAC, aes_cmac_reference, ARRAY_SIZE(aes_cmac_reference), - false, false); } @@ -2119,18 +1741,6 @@ static void crypto_test_gen_alg_kasumi_f9(void) ODP_AUTH_ALG_KASUMI_F9, kasumi_f9_reference, ARRAY_SIZE(kasumi_f9_reference), - false, - true); -} - -static void crypto_test_gen_alg_kasumi_f9_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_NULL, - ODP_AUTH_ALG_KASUMI_F9, - kasumi_f9_reference, - ARRAY_SIZE(kasumi_f9_reference), - true, true); } @@ -2141,18 +1751,6 @@ static void crypto_test_check_alg_kasumi_f9(void) ODP_AUTH_ALG_KASUMI_F9, kasumi_f9_reference, ARRAY_SIZE(kasumi_f9_reference), - false, - true); -} - -static void crypto_test_check_alg_kasumi_f9_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_NULL, - ODP_AUTH_ALG_KASUMI_F9, - kasumi_f9_reference, - ARRAY_SIZE(kasumi_f9_reference), - true, true); } @@ -2168,18 +1766,6 @@ static void crypto_test_gen_alg_snow3g_uia2(void) ODP_AUTH_ALG_SNOW3G_UIA2, snow3g_uia2_reference, ARRAY_SIZE(snow3g_uia2_reference), - false, - true); -} - -static void crypto_test_gen_alg_snow3g_uia2_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_NULL, - ODP_AUTH_ALG_SNOW3G_UIA2, - snow3g_uia2_reference, - ARRAY_SIZE(snow3g_uia2_reference), - true, true); } @@ -2190,18 +1776,6 @@ static void crypto_test_check_alg_snow3g_uia2(void) ODP_AUTH_ALG_SNOW3G_UIA2, snow3g_uia2_reference, ARRAY_SIZE(snow3g_uia2_reference), - false, - true); -} - -static void crypto_test_check_alg_snow3g_uia2_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_NULL, - ODP_AUTH_ALG_SNOW3G_UIA2, - snow3g_uia2_reference, - ARRAY_SIZE(snow3g_uia2_reference), - true, true); } @@ -2218,18 +1792,6 @@ static void crypto_test_gen_alg_aes_eia2(void) ODP_AUTH_ALG_AES_EIA2, aes_eia2_reference, ARRAY_SIZE(aes_eia2_reference), - false, - true); -} - -static void crypto_test_gen_alg_aes_eia2_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_NULL, - ODP_AUTH_ALG_AES_EIA2, - aes_eia2_reference, - ARRAY_SIZE(aes_eia2_reference), - true, true); } @@ -2240,18 +1802,6 @@ static void crypto_test_check_alg_aes_eia2(void) ODP_AUTH_ALG_AES_EIA2, aes_eia2_reference, ARRAY_SIZE(aes_eia2_reference), - false, - true); -} - -static void crypto_test_check_alg_aes_eia2_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_NULL, - ODP_AUTH_ALG_AES_EIA2, - aes_eia2_reference, - ARRAY_SIZE(aes_eia2_reference), - true, true); } @@ -2267,18 +1817,6 @@ static void crypto_test_gen_alg_zuc_eia3(void) ODP_AUTH_ALG_ZUC_EIA3, zuc_eia3_reference, ARRAY_SIZE(zuc_eia3_reference), - false, - true); -} - -static void crypto_test_gen_alg_zuc_eia3_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_ENCODE, - ODP_CIPHER_ALG_NULL, - ODP_AUTH_ALG_ZUC_EIA3, - zuc_eia3_reference, - ARRAY_SIZE(zuc_eia3_reference), - true, true); } @@ -2289,18 +1827,6 @@ static void crypto_test_check_alg_zuc_eia3(void) ODP_AUTH_ALG_ZUC_EIA3, zuc_eia3_reference, ARRAY_SIZE(zuc_eia3_reference), - false, - true); -} - -static void crypto_test_check_alg_zuc_eia3_ovr_iv(void) -{ - check_alg(ODP_CRYPTO_OP_DECODE, - ODP_CIPHER_ALG_NULL, - ODP_AUTH_ALG_ZUC_EIA3, - zuc_eia3_reference, - ARRAY_SIZE(zuc_eia3_reference), - true, true); } @@ -2316,7 +1842,6 @@ static void crypto_test_gen_alg_md5(void) ODP_AUTH_ALG_MD5, md5_reference, ARRAY_SIZE(md5_reference), - false, false); } @@ -2327,7 +1852,6 @@ static void crypto_test_check_alg_md5(void) ODP_AUTH_ALG_MD5, md5_reference, ARRAY_SIZE(md5_reference), - false, false); } @@ -2343,7 +1867,6 @@ static void crypto_test_gen_alg_sha1(void) ODP_AUTH_ALG_SHA1, sha1_reference, ARRAY_SIZE(sha1_reference), - false, false); } @@ -2354,7 +1877,6 @@ static void crypto_test_check_alg_sha1(void) ODP_AUTH_ALG_SHA1, sha1_reference, ARRAY_SIZE(sha1_reference), - false, false); } @@ -2370,7 +1892,6 @@ static void crypto_test_gen_alg_sha224(void) ODP_AUTH_ALG_SHA224, sha224_reference, ARRAY_SIZE(sha224_reference), - false, false); } @@ -2381,7 +1902,6 @@ static void crypto_test_check_alg_sha224(void) ODP_AUTH_ALG_SHA224, sha224_reference, ARRAY_SIZE(sha224_reference), - false, false); } @@ -2397,7 +1917,6 @@ static void crypto_test_gen_alg_sha256(void) ODP_AUTH_ALG_SHA256, sha256_reference, ARRAY_SIZE(sha256_reference), - false, false); } @@ -2408,7 +1927,6 @@ static void crypto_test_check_alg_sha256(void) ODP_AUTH_ALG_SHA256, sha256_reference, ARRAY_SIZE(sha256_reference), - false, false); } @@ -2424,7 +1942,6 @@ static void crypto_test_gen_alg_sha384(void) ODP_AUTH_ALG_SHA384, sha384_reference, ARRAY_SIZE(sha384_reference), - false, false); } @@ -2435,7 +1952,6 @@ static void crypto_test_check_alg_sha384(void) ODP_AUTH_ALG_SHA384, sha384_reference, ARRAY_SIZE(sha384_reference), - false, false); } @@ -2451,7 +1967,6 @@ static void crypto_test_gen_alg_sha512(void) ODP_AUTH_ALG_SHA512, sha512_reference, ARRAY_SIZE(sha512_reference), - false, false); } @@ -2462,7 +1977,6 @@ static void crypto_test_check_alg_sha512(void) ODP_AUTH_ALG_SHA512, sha512_reference, ARRAY_SIZE(sha512_reference), - false, false); } @@ -2619,6 +2133,8 @@ static int crypto_suite_term(void) } odp_testinfo_t crypto_suite[] = { + ODP_TEST_INFO(test_capability), + ODP_TEST_INFO(test_default_values), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_null, check_alg_null), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_null, @@ -2627,10 +2143,6 @@ odp_testinfo_t crypto_suite[] = { check_alg_3des_cbc), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_3des_cbc, check_alg_3des_cbc), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_3des_cbc_ovr_iv, - check_alg_3des_cbc), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_3des_cbc_ovr_iv, - check_alg_3des_cbc), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_3des_ecb, check_alg_3des_ecb), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_3des_ecb, @@ -2639,18 +2151,10 @@ odp_testinfo_t crypto_suite[] = { check_alg_aes_cbc), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_cbc, check_alg_aes_cbc), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_cbc_ovr_iv, - check_alg_aes_cbc), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_cbc_ovr_iv, - check_alg_aes_cbc), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_ctr, check_alg_aes_ctr), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_ctr, check_alg_aes_ctr), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_ctr_ovr_iv, - check_alg_aes_ctr), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_ctr_ovr_iv, - check_alg_aes_ctr), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_ecb, check_alg_aes_ecb), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_ecb, @@ -2659,74 +2163,38 @@ odp_testinfo_t crypto_suite[] = { check_alg_aes_cfb128), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_cfb128, check_alg_aes_cfb128), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_cfb128_ovr_iv, - check_alg_aes_cfb128), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_cfb128_ovr_iv, - check_alg_aes_cfb128), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_xts, check_alg_aes_xts), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_xts, check_alg_aes_xts), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_xts_ovr_iv, - check_alg_aes_xts), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_xts_ovr_iv, - check_alg_aes_xts), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_kasumi_f8, check_alg_kasumi_f8), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_kasumi_f8, check_alg_kasumi_f8), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_kasumi_f8_ovr_iv, - check_alg_kasumi_f8), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_kasumi_f8_ovr_iv, - check_alg_kasumi_f8), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_snow3g_uea2, check_alg_snow3g_uea2), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_snow3g_uea2, check_alg_snow3g_uea2), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_snow3g_uea2_ovr_iv, - check_alg_snow3g_uea2), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_snow3g_uea2_ovr_iv, - check_alg_snow3g_uea2), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_eea2, check_alg_aes_eea2), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_eea2, check_alg_aes_eea2), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_eea2_ovr_iv, - check_alg_aes_eea2), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_eea2_ovr_iv, - check_alg_aes_eea2), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_zuc_eea3, check_alg_zuc_eea3), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_zuc_eea3, check_alg_zuc_eea3), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_zuc_eea3_ovr_iv, - check_alg_zuc_eea3), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_zuc_eea3_ovr_iv, - check_alg_zuc_eea3), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_gcm, check_alg_aes_gcm), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_gcm_ovr_iv, - check_alg_aes_gcm), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_gcm, check_alg_aes_gcm), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_gcm_ovr_iv, - check_alg_aes_gcm), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_ccm, check_alg_aes_ccm), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_aes_ccm_ovr_iv, - check_alg_aes_ccm), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_ccm, check_alg_aes_ccm), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_aes_ccm_ovr_iv, - check_alg_aes_ccm), ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_chacha20_poly1305, check_alg_chacha20_poly1305), - ODP_TEST_INFO_CONDITIONAL(crypto_test_enc_alg_chacha20_poly1305_ovr_iv, - check_alg_chacha20_poly1305), ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_chacha20_poly1305, check_alg_chacha20_poly1305), - ODP_TEST_INFO_CONDITIONAL(crypto_test_dec_alg_chacha20_poly1305_ovr_iv, - check_alg_chacha20_poly1305), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_hmac_md5, check_alg_hmac_md5), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_hmac_md5, @@ -2757,12 +2225,8 @@ odp_testinfo_t crypto_suite[] = { check_alg_aes_xcbc), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_gmac, check_alg_aes_gmac), - ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_gmac_ovr_iv, - check_alg_aes_gmac), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_gmac, check_alg_aes_gmac), - ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_gmac_ovr_iv, - check_alg_aes_gmac), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_cmac, check_alg_aes_cmac), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_cmac, @@ -2771,34 +2235,18 @@ odp_testinfo_t crypto_suite[] = { check_alg_kasumi_f9), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_kasumi_f9, check_alg_kasumi_f9), - ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_kasumi_f9_ovr_iv, - check_alg_kasumi_f9), - ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_kasumi_f9_ovr_iv, - check_alg_kasumi_f9), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_snow3g_uia2, check_alg_snow3g_uia2), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_snow3g_uia2, check_alg_snow3g_uia2), - ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_snow3g_uia2_ovr_iv, - check_alg_snow3g_uia2), - ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_snow3g_uia2_ovr_iv, - check_alg_snow3g_uia2), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_eia2, check_alg_aes_eia2), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_eia2, check_alg_aes_eia2), - ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_aes_eia2_ovr_iv, - check_alg_aes_eia2), - ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_aes_eia2_ovr_iv, - check_alg_aes_eia2), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_zuc_eia3, check_alg_zuc_eia3), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_zuc_eia3, check_alg_zuc_eia3), - ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_zuc_eia3_ovr_iv, - check_alg_zuc_eia3), - ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_zuc_eia3_ovr_iv, - check_alg_zuc_eia3), ODP_TEST_INFO_CONDITIONAL(crypto_test_gen_alg_md5, check_alg_md5), ODP_TEST_INFO_CONDITIONAL(crypto_test_check_alg_md5, diff --git a/test/validation/api/ipsec/ipsec.c b/test/validation/api/ipsec/ipsec.c index cd1824fb1..32318e356 100644 --- a/test/validation/api/ipsec/ipsec.c +++ b/test/validation/api/ipsec/ipsec.c @@ -267,34 +267,12 @@ int ipsec_check_ah_aes_gmac_128(void) return ipsec_check_ah(ODP_AUTH_ALG_AES_GMAC, 128); } -int ipsec_check_ah_aes_gmac_192(void) -{ - return ipsec_check_ah(ODP_AUTH_ALG_AES_GMAC, 192); -} - -int ipsec_check_ah_aes_gmac_256(void) -{ - return ipsec_check_ah(ODP_AUTH_ALG_AES_GMAC, 256); -} - int ipsec_check_esp_null_aes_gmac_128(void) { return ipsec_check_esp(ODP_CIPHER_ALG_NULL, 0, ODP_AUTH_ALG_AES_GMAC, 128); } -int ipsec_check_esp_null_aes_gmac_192(void) -{ - return ipsec_check_esp(ODP_CIPHER_ALG_NULL, 0, - ODP_AUTH_ALG_AES_GMAC, 192); -} - -int ipsec_check_esp_null_aes_gmac_256(void) -{ - return ipsec_check_esp(ODP_CIPHER_ALG_NULL, 0, - ODP_AUTH_ALG_AES_GMAC, 256); -} - int ipsec_check_esp_chacha20_poly1305(void) { return ipsec_check_esp(ODP_CIPHER_ALG_CHACHA20_POLY1305, 256, @@ -336,8 +314,8 @@ int ipsec_check_esp_null_aes_xcbc(void) } void ipsec_sa_param_fill(odp_ipsec_sa_param_t *param, - odp_bool_t in, - odp_bool_t ah, + odp_ipsec_dir_t dir, + odp_ipsec_protocol_t proto, uint32_t spi, odp_ipsec_tunnel_param_t *tun, odp_cipher_alg_t cipher_alg, @@ -348,18 +326,16 @@ void ipsec_sa_param_fill(odp_ipsec_sa_param_t *param, const odp_crypto_key_t *auth_key_extra) { odp_ipsec_sa_param_init(param); - param->dir = in ? ODP_IPSEC_DIR_INBOUND : - ODP_IPSEC_DIR_OUTBOUND; - if (in) { + param->dir = dir; + if (dir == ODP_IPSEC_DIR_INBOUND) { param->inbound.lookup_mode = ODP_IPSEC_LOOKUP_SPI; param->inbound.antireplay_ws = capa.max_antireplay_ws; } - param->proto = ah ? ODP_IPSEC_AH : - ODP_IPSEC_ESP; + param->proto = proto; if (tun) { param->mode = ODP_IPSEC_MODE_TUNNEL; - if (!in) + if (dir == ODP_IPSEC_DIR_OUTBOUND) param->outbound.tunnel = *tun; } else { param->mode = ODP_IPSEC_MODE_TRANSPORT; diff --git a/test/validation/api/ipsec/ipsec.h b/test/validation/api/ipsec/ipsec.h index cbb533913..a2bb478a3 100644 --- a/test/validation/api/ipsec/ipsec.h +++ b/test/validation/api/ipsec/ipsec.h @@ -105,8 +105,8 @@ typedef struct { } ipsec_test_part; void ipsec_sa_param_fill(odp_ipsec_sa_param_t *param, - odp_bool_t in, - odp_bool_t ah, + odp_ipsec_dir_t dir, + odp_ipsec_protocol_t proto, uint32_t spi, odp_ipsec_tunnel_param_t *tun, odp_cipher_alg_t cipher_alg, @@ -145,11 +145,7 @@ int ipsec_check_esp_aes_ctr_128_null(void); int ipsec_check_esp_aes_gcm_128(void); int ipsec_check_esp_aes_gcm_256(void); int ipsec_check_ah_aes_gmac_128(void); -int ipsec_check_ah_aes_gmac_192(void); -int ipsec_check_ah_aes_gmac_256(void); int ipsec_check_esp_null_aes_gmac_128(void); -int ipsec_check_esp_null_aes_gmac_192(void); -int ipsec_check_esp_null_aes_gmac_256(void); int ipsec_check_esp_chacha20_poly1305(void); int ipsec_check_test_sa_update_seq_num(void); int ipsec_check_esp_aes_gcm_128_reass_ipv4(void); diff --git a/test/validation/api/ipsec/ipsec_test_in.c b/test/validation/api/ipsec/ipsec_test_in.c index 508d7aaa5..e72c01c94 100644 --- a/test/validation/api/ipsec/ipsec_test_in.c +++ b/test/validation/api/ipsec/ipsec_test_in.c @@ -55,7 +55,7 @@ static void test_in_ipv4_ah_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, true, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -90,7 +90,7 @@ static void test_in_ipv4_ah_sha256_tun_ipv4(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, true, 123, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -125,7 +125,7 @@ static void test_in_ipv4_ah_sha256_tun_ipv6(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, true, 123, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -157,7 +157,7 @@ static void test_in_ipv4_ah_sha256_tun_ipv4_notun(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, true, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -190,7 +190,7 @@ static void test_in_ipv4_esp_null_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -222,7 +222,7 @@ static void test_in_ipv4_esp_aes_cbc_null(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_AES_CBC, &key_a5_128, ODP_AUTH_ALG_NULL, NULL, NULL, NULL); @@ -254,7 +254,7 @@ static void test_in_ipv4_esp_aes_cbc_sha1(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_AES_CBC, &key_a5_128, ODP_AUTH_ALG_SHA1_HMAC, &key_5a_160, NULL, NULL); @@ -286,7 +286,7 @@ static void test_in_ipv4_esp_aes_cbc_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_AES_CBC, &key_a5_128, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -318,7 +318,7 @@ static void test_in_ipv4_esp_aes_cbc_sha384(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_AES_CBC, &key_a5_128, ODP_AUTH_ALG_SHA384_HMAC, &key_5a_384, NULL, NULL); @@ -350,7 +350,7 @@ static void test_in_ipv4_esp_aes_cbc_sha512(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_AES_CBC, &key_a5_128, ODP_AUTH_ALG_SHA512_HMAC, &key_5a_512, NULL, NULL); @@ -382,7 +382,7 @@ static void test_in_ipv4_esp_aes_ctr_null(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_AES_CTR, &key_a5_128, ODP_AUTH_ALG_NULL, NULL, &key_mcgrew_gcm_salt_3, NULL); @@ -414,7 +414,7 @@ static void test_in_ipv4_ah_sha256_lookup(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, true, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -449,7 +449,7 @@ static void test_in_ipv4_esp_null_sha256_lookup(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -487,7 +487,7 @@ static void test_in_ipv4_esp_null_sha256_tun_ipv4(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 123, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -522,7 +522,7 @@ static void test_in_ipv4_esp_null_sha256_tun_ipv6(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 123, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -554,7 +554,7 @@ static void test_in_ipv4_esp_udp_null_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -587,7 +587,7 @@ static void test_in_ipv4_esp_udp_null_sha256_lookup(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -623,7 +623,7 @@ static void test_in_ipv4_ah_sha256_noreplay(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, true, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -674,7 +674,7 @@ static void test_in_ipv4_ah_sha256_replay(void) memset(&test_repl, 0, sizeof(ipsec_test_part)); ipsec_sa_param_fill(¶m, - true, true, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -726,7 +726,7 @@ static void test_in_ipv4_esp_null_sha256_noreplay(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -777,7 +777,7 @@ static void test_in_ipv4_esp_null_sha256_replay(void) memset(&test_repl, 0, sizeof(ipsec_test_part)); ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -837,7 +837,7 @@ static void test_in_ipv4_ah_esp_pkt(void) return; ipsec_sa_param_fill(¶m, - true, true, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -869,7 +869,7 @@ static void test_in_ipv4_esp_ah_pkt(void) return; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -896,7 +896,7 @@ static void test_in_ipv4_ah_esp_pkt_lookup(void) memset(&test, 0, sizeof(ipsec_test_part)); ipsec_sa_param_fill(¶m, - true, true, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -924,7 +924,7 @@ static void test_in_ipv4_esp_ah_pkt_lookup(void) memset(&test, 0, sizeof(ipsec_test_part)); ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -952,7 +952,7 @@ static void test_in_ipv4_ah_sha256_bad1(void) memset(&test, 0, sizeof(ipsec_test_part)); ipsec_sa_param_fill(¶m, - true, true, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -979,7 +979,7 @@ static void test_in_ipv4_ah_sha256_bad2(void) memset(&test, 0, sizeof(ipsec_test_part)); ipsec_sa_param_fill(¶m, - true, true, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1006,7 +1006,7 @@ static void test_in_ipv4_esp_null_sha256_bad1(void) memset(&test, 0, sizeof(ipsec_test_part)); ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1030,7 +1030,7 @@ static void test_in_ipv4_rfc3602_5_esp(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 0x4321, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 0x4321, NULL, ODP_CIPHER_ALG_AES_CBC, &key_rfc3602, ODP_AUTH_ALG_NULL, NULL, NULL, NULL); @@ -1062,7 +1062,7 @@ static void test_in_ipv4_rfc3602_6_esp(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 0x4321, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 0x4321, NULL, ODP_CIPHER_ALG_AES_CBC, &key_rfc3602, ODP_AUTH_ALG_NULL, NULL, NULL, NULL); @@ -1097,7 +1097,8 @@ static void test_in_ipv4_rfc3602_7_esp(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 0x8765, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x8765, &tunnel, ODP_CIPHER_ALG_AES_CBC, &key_rfc3602_2, ODP_AUTH_ALG_NULL, NULL, NULL, NULL); @@ -1132,7 +1133,8 @@ static void test_in_ipv4_rfc3602_8_esp(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 0x8765, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x8765, &tunnel, ODP_CIPHER_ALG_AES_CBC, &key_rfc3602_2, ODP_AUTH_ALG_NULL, NULL, NULL, NULL); @@ -1167,7 +1169,8 @@ static void test_in_ipv4_mcgrew_gcm_2_esp(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 0xa5f8, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0xa5f8, &tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_2, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_2, NULL); @@ -1202,7 +1205,8 @@ static void test_in_ipv4_mcgrew_gcm_3_esp(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 0x4a2cbfe3, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x4a2cbfe3, &tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_3, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_3, NULL); @@ -1237,7 +1241,8 @@ static void test_in_ipv4_mcgrew_gcm_4_esp(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 0x00000000, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x00000000, &tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_4, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_4, NULL); @@ -1277,7 +1282,8 @@ static void test_in_ipv4_mcgrew_gcm_12_esp(void) return; ipsec_sa_param_fill(¶m, - true, false, 0x335467ae, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x335467ae, &tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_12, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_12, NULL); @@ -1309,7 +1315,8 @@ static void test_in_ipv4_mcgrew_gcm_12_esp_notun(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 0x335467ae, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x335467ae, NULL, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_12, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_12, NULL); @@ -1344,7 +1351,8 @@ static void test_in_ipv4_mcgrew_gcm_15_esp(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 0x00004321, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x00004321, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_AES_GMAC, &key_mcgrew_gcm_15, NULL, &key_mcgrew_gcm_salt_15); @@ -1379,7 +1387,8 @@ static void test_in_ipv4_rfc7634_chacha(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 0x01020304, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x01020304, &tunnel, ODP_CIPHER_ALG_CHACHA20_POLY1305, &key_rfc7634, ODP_AUTH_ALG_CHACHA20_POLY1305, NULL, &key_rfc7634_salt, NULL); @@ -1411,7 +1420,7 @@ static void test_in_ipv4_ah_aes_gmac_128(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, true, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_AES_GMAC, &key_a5_128, NULL, &key_mcgrew_gcm_salt_2); @@ -1443,7 +1452,7 @@ static void test_in_ipv4_esp_null_aes_gmac_128(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_AES_GMAC, &key_a5_128, NULL, &key_mcgrew_gcm_salt_2); @@ -1475,7 +1484,7 @@ static void test_in_ipv6_ah_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, true, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1510,7 +1519,7 @@ static void test_in_ipv6_ah_sha256_tun_ipv4(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, true, 123, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1545,7 +1554,7 @@ static void test_in_ipv6_ah_sha256_tun_ipv6(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, true, 123, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_AH, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1577,7 +1586,7 @@ static void test_in_ipv6_esp_null_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1612,7 +1621,7 @@ static void test_in_ipv6_esp_null_sha256_tun_ipv4(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 123, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1647,7 +1656,7 @@ static void test_in_ipv6_esp_null_sha256_tun_ipv6(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 123, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1679,7 +1688,7 @@ static void test_in_ipv6_esp_udp_null_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1712,7 +1721,7 @@ static void test_in_ipv6_esp_udp_null_sha256_lookup(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1753,7 +1762,7 @@ static void test_ipsec_sa_print(void) odp_ipsec_sa_t in_sa; ipsec_sa_param_fill(¶m_in, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_AES_CBC, &key_a5_128, ODP_AUTH_ALG_SHA1_HMAC, &key_5a_160, NULL, NULL); @@ -1918,7 +1927,6 @@ static void test_in_ipv4_esp_reass_success(void) uint32_t src = IPV4ADDR(10, 0, 11, 2); uint32_t dst = IPV4ADDR(10, 0, 22, 2); odp_ipsec_sa_t out_sa, in_sa; - odp_ipsec_capability_t capa; memset(&in_tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); memset(&out_tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); @@ -1927,16 +1935,16 @@ static void test_in_ipv4_esp_reass_success(void) out_tunnel.ipv4.src_addr = &src; out_tunnel.ipv4.dst_addr = &dst; - CU_ASSERT(odp_ipsec_capability(&capa) == 0); - ipsec_sa_param_fill(¶m_out, - false, false, 0x4a2cbfe7, &out_tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, + 0x4a2cbfe7, &out_tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_4, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_4, NULL); ipsec_sa_param_fill(¶m_in, - true, false, 0x4a2cbfe7, &in_tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x4a2cbfe7, &in_tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_4, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_4, NULL); @@ -1974,7 +1982,6 @@ static void test_in_ipv4_esp_reass_incomp(void) uint32_t src = IPV4ADDR(10, 0, 11, 2); uint32_t dst = IPV4ADDR(10, 0, 22, 2); odp_ipsec_sa_t out_sa, in_sa; - odp_ipsec_capability_t capa; memset(&in_tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); memset(&out_tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); @@ -1983,16 +1990,16 @@ static void test_in_ipv4_esp_reass_incomp(void) out_tunnel.ipv4.src_addr = &src; out_tunnel.ipv4.dst_addr = &dst; - CU_ASSERT(odp_ipsec_capability(&capa) == 0); - ipsec_sa_param_fill(¶m_out, - false, false, 0x4a2cbfe7, &out_tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, + 0x4a2cbfe7, &out_tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_4, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_4, NULL); ipsec_sa_param_fill(¶m_in, - true, false, 0x4a2cbfe7, &in_tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x4a2cbfe7, &in_tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_4, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_4, NULL); @@ -2102,7 +2109,6 @@ static void test_in_ipv6_esp_reass_success(void) odp_ipsec_tunnel_param_t in_tunnel, out_tunnel; odp_ipsec_sa_param_t param_in, param_out; odp_ipsec_sa_t out_sa, in_sa; - odp_ipsec_capability_t capa; uint8_t src[16] = { 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x11, 0x43, 0xff, 0xfe, 0x4a, 0xd7, 0x0a, @@ -2119,16 +2125,16 @@ static void test_in_ipv6_esp_reass_success(void) out_tunnel.ipv6.dst_addr = &dst; out_tunnel.ipv6.hlimit = 64; - CU_ASSERT(odp_ipsec_capability(&capa) == 0); - ipsec_sa_param_fill(¶m_out, - false, false, 0x4a2cbfe7, &out_tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, + 0x4a2cbfe7, &out_tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_4, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_4, NULL); ipsec_sa_param_fill(¶m_in, - true, false, 0x4a2cbfe7, &in_tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x4a2cbfe7, &in_tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_4, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_4, NULL); @@ -2163,7 +2169,6 @@ static void test_in_ipv6_esp_reass_incomp(void) odp_ipsec_tunnel_param_t in_tunnel, out_tunnel; odp_ipsec_sa_param_t param_in, param_out; odp_ipsec_sa_t out_sa, in_sa; - odp_ipsec_capability_t capa; uint8_t src[16] = { 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x02, 0x11, 0x43, 0xff, 0xfe, 0x4a, 0xd7, 0x0a, @@ -2179,16 +2184,16 @@ static void test_in_ipv6_esp_reass_incomp(void) out_tunnel.ipv6.src_addr = &src; out_tunnel.ipv6.dst_addr = &dst; - CU_ASSERT(odp_ipsec_capability(&capa) == 0); - ipsec_sa_param_fill(¶m_out, - false, false, 0x4a2cbfe7, &out_tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, + 0x4a2cbfe7, &out_tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_4, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_4, NULL); ipsec_sa_param_fill(¶m_in, - true, false, 0x4a2cbfe7, &in_tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x4a2cbfe7, &in_tunnel, ODP_CIPHER_ALG_AES_GCM, &key_mcgrew_gcm_4, ODP_AUTH_ALG_AES_GCM, NULL, &key_mcgrew_gcm_salt_4, NULL); @@ -2218,7 +2223,8 @@ static void test_in_ipv4_null_aes_xcbc_esp(void) memset(&tunnel, 0, sizeof(odp_ipsec_tunnel_param_t)); ipsec_sa_param_fill(¶m, - true, false, 0x100, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 0x100, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_AES_XCBC_MAC, &key_auth_aes_xcbc_128, NULL, NULL); @@ -2245,15 +2251,7 @@ static void test_in_ipv4_null_aes_xcbc_esp(void) ipsec_sa_destroy(sa); } -static void ipsec_test_capability(void) -{ - odp_ipsec_capability_t capa; - - CU_ASSERT(odp_ipsec_capability(&capa) == 0); -} - odp_testinfo_t ipsec_in_suite[] = { - ODP_TEST_INFO(ipsec_test_capability), ODP_TEST_INFO_CONDITIONAL(test_in_ipv4_rfc3602_5_esp, ipsec_check_esp_aes_cbc_128_null), ODP_TEST_INFO_CONDITIONAL(test_in_ipv4_rfc3602_6_esp, diff --git a/test/validation/api/ipsec/ipsec_test_out.c b/test/validation/api/ipsec/ipsec_test_out.c index 799988c38..4e3230844 100644 --- a/test/validation/api/ipsec/ipsec_test_out.c +++ b/test/validation/api/ipsec/ipsec_test_out.c @@ -25,6 +25,8 @@ typedef struct { enum ipsec_test_stats stats; } ipsec_test_flags; +static void test_out_in_all(const ipsec_test_flags *flags); + struct cipher_param { const char *name; odp_cipher_alg_t algo; @@ -72,6 +74,16 @@ static struct auth_param auths[] = { ALG(ODP_AUTH_ALG_AES_XCBC_MAC, &key_5a_128, NULL) }; +/* + * Integrity algorithms that can be used in AH but not in ESP as + * individual algorithms (combined with a cipher). + */ +static struct auth_param ah_auths[] = { + ALG(ODP_AUTH_ALG_AES_GMAC, &key_a5_128, &key_mcgrew_gcm_salt_2), + ALG(ODP_AUTH_ALG_AES_GMAC, &key_a5_192, &key_mcgrew_gcm_salt_2), + ALG(ODP_AUTH_ALG_AES_GMAC, &key_a5_256, &key_mcgrew_gcm_salt_2), +}; + struct cipher_auth_comb_param { struct cipher_param cipher; struct auth_param auth; @@ -126,7 +138,7 @@ static void test_out_ipv4_ah_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - false, true, 123, NULL, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -165,7 +177,7 @@ static void test_out_ipv4_ah_sha256_tun_ipv4(void) tunnel.ipv4.ttl = 64; ipsec_sa_param_fill(¶m, - false, true, 123, &tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_AH, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -210,7 +222,7 @@ static void test_out_ipv4_ah_sha256_tun_ipv6(void) tunnel.ipv6.hlimit = 64; ipsec_sa_param_fill(¶m, - false, true, 123, &tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_AH, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -240,7 +252,7 @@ static void test_out_ipv4_esp_null_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - false, false, 123, NULL, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -279,7 +291,7 @@ static void test_out_ipv4_esp_null_sha256_tun_ipv4(void) tunnel.ipv4.ttl = 64; ipsec_sa_param_fill(¶m, - false, false, 123, &tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -325,7 +337,7 @@ static void test_out_ipv4_esp_null_sha256_tun_ipv6(void) tunnel.ipv6.hlimit = 64; ipsec_sa_param_fill(¶m, - false, false, 123, &tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -483,6 +495,7 @@ static void test_out_in_common(const ipsec_test_flags *flags, }; odp_ipsec_sa_param_t param; odp_ipsec_stats_t stats; + odp_ipsec_protocol_t proto = flags->ah ? ODP_IPSEC_AH : ODP_IPSEC_ESP; odp_ipsec_sa_t sa_out; odp_ipsec_sa_t sa_in; odp_proto_l3_type_t out_l3_type = ODP_PROTO_L3_TYPE_IPV4; @@ -514,7 +527,7 @@ static void test_out_in_common(const ipsec_test_flags *flags, } ipsec_sa_param_fill(¶m, - false, flags->ah, 123, tun_ptr, + ODP_IPSEC_DIR_OUTBOUND, proto, 123, tun_ptr, cipher, cipher_key, auth, auth_key, cipher_key_extra, auth_key_extra); @@ -527,7 +540,7 @@ static void test_out_in_common(const ipsec_test_flags *flags, CU_ASSERT_NOT_EQUAL_FATAL(ODP_IPSEC_SA_INVALID, sa_out); ipsec_sa_param_fill(¶m, - true, flags->ah, 123, tun_ptr, + ODP_IPSEC_DIR_INBOUND, proto, 123, tun_ptr, cipher, cipher_key, auth, auth_key, cipher_key_extra, auth_key_extra); @@ -665,21 +678,22 @@ static void test_esp_out_in(struct cipher_param *cipher, cipher->key_extra, auth->key_extra); } -static void test_esp_out_in_all(ipsec_test_flags *flags) +static void test_esp_out_in_all(const ipsec_test_flags *flags_in) { uint32_t c; uint32_t a; + ipsec_test_flags flags = *flags_in; - flags->ah = false; + flags.ah = false; for (c = 0; c < ARRAY_SIZE(ciphers); c++) for (a = 0; a < ARRAY_SIZE(auths); a++) - test_esp_out_in(&ciphers[c], &auths[a], flags); + test_esp_out_in(&ciphers[c], &auths[a], &flags); for (c = 0; c < ARRAY_SIZE(cipher_auth_comb); c++) test_esp_out_in(&cipher_auth_comb[c].cipher, &cipher_auth_comb[c].auth, - flags); + &flags); } /* @@ -703,25 +717,26 @@ static int is_out_mode_inline(void) return suite_context.outbound_op_mode == ODP_IPSEC_OP_MODE_INLINE; } -static void test_esp_out_in_all_hdr_in_packet(void) +static void test_inline_hdr_in_packet(void) { ipsec_test_flags flags = { .part_flags.inline_hdr_in_packet = true, }; - test_esp_out_in_all(&flags); + test_out_in_all(&flags); } -static void test_ah_out_in(struct auth_param *auth) +static void test_ah_out_in(struct auth_param *auth, + const ipsec_test_flags *flags_in) { int auth_keylen = auth->key ? 8 * auth->key->length : 0; - ipsec_test_flags flags; + ipsec_test_flags flags = *flags_in; if (ipsec_check_ah(auth->algo, auth_keylen) != ODP_TEST_ACTIVE) return; - printf("\n %s (keylen %d) ", auth->name, auth_keylen); + if (flags.display_algo) + printf("\n %s (keylen %d) ", auth->name, auth_keylen); - memset(&flags, 0, sizeof(flags)); flags.ah = true; test_out_in_common(&flags, ODP_CIPHER_ALG_NULL, NULL, @@ -729,22 +744,41 @@ static void test_ah_out_in(struct auth_param *auth) NULL, auth->key_extra); } -static void test_ah_out_in_all(void) +static void test_ah_out_in_all(const ipsec_test_flags *flags) { uint32_t a; for (a = 0; a < ARRAY_SIZE(auths); a++) - test_ah_out_in(&auths[a]); + test_ah_out_in(&auths[a], flags); + for (a = 0; a < ARRAY_SIZE(ah_auths); a++) + test_ah_out_in(&ah_auths[a], flags); +} + +static void test_ah_out_in_all_basic(void) +{ + ipsec_test_flags flags; + + memset(&flags, 0, sizeof(flags)); + flags.display_algo = true; + + test_ah_out_in_all(&flags); + printf("\n "); } +static void test_out_in_all(const ipsec_test_flags *flags) +{ + test_esp_out_in_all(flags); + test_ah_out_in_all(flags); +} + static void test_out_ipv4_esp_udp_null_sha256(void) { odp_ipsec_sa_param_t param; odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - false, false, 123, NULL, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -769,42 +803,6 @@ static void test_out_ipv4_esp_udp_null_sha256(void) ipsec_sa_destroy(sa); } -static void test_out_ipv4_ah_aes_gmac_128(void) -{ - ipsec_test_flags flags; - - memset(&flags, 0, sizeof(flags)); - flags.ah = true; - - test_out_in_common(&flags, ODP_CIPHER_ALG_NULL, NULL, - ODP_AUTH_ALG_AES_GMAC, &key_a5_128, - NULL, &key_mcgrew_gcm_salt_2); -} - -static void test_out_ipv4_ah_aes_gmac_192(void) -{ - ipsec_test_flags flags; - - memset(&flags, 0, sizeof(flags)); - flags.ah = true; - - test_out_in_common(&flags, ODP_CIPHER_ALG_NULL, NULL, - ODP_AUTH_ALG_AES_GMAC, &key_a5_192, - NULL, &key_mcgrew_gcm_salt_2); -} - -static void test_out_ipv4_ah_aes_gmac_256(void) -{ - ipsec_test_flags flags; - - memset(&flags, 0, sizeof(flags)); - flags.ah = true; - - test_out_in_common(&flags, ODP_CIPHER_ALG_NULL, NULL, - ODP_AUTH_ALG_AES_GMAC, &key_a5_256, - NULL, &key_mcgrew_gcm_salt_2); -} - static void test_out_ipv4_ah_sha256_frag_check(void) { odp_ipsec_sa_param_t param; @@ -816,7 +814,7 @@ static void test_out_ipv4_ah_sha256_frag_check(void) memset(&test2, 0, sizeof(ipsec_test_part)); ipsec_sa_param_fill(¶m, - false, true, 123, NULL, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -856,7 +854,7 @@ static void test_out_ipv4_ah_sha256_frag_check_2(void) memset(&test, 0, sizeof(ipsec_test_part)); ipsec_sa_param_fill(¶m, - false, true, 123, NULL, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -903,7 +901,7 @@ static void test_out_ipv4_esp_null_sha256_frag_check(void) memset(&test2, 0, sizeof(ipsec_test_part)); ipsec_sa_param_fill(¶m, - false, false, 123, NULL, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -944,7 +942,7 @@ static void test_out_ipv4_esp_null_sha256_frag_check_2(void) memset(&test, 0, sizeof(ipsec_test_part)); ipsec_sa_param_fill(¶m, - false, false, 123, NULL, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -987,7 +985,7 @@ static void test_out_ipv6_ah_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - false, true, 123, NULL, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_AH, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1026,7 +1024,7 @@ static void test_out_ipv6_ah_sha256_tun_ipv4(void) tunnel.ipv4.ttl = 64; ipsec_sa_param_fill(¶m, - false, true, 123, &tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_AH, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1071,7 +1069,7 @@ static void test_out_ipv6_ah_sha256_tun_ipv6(void) tunnel.ipv6.hlimit = 64; ipsec_sa_param_fill(¶m, - false, true, 123, &tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_AH, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1101,7 +1099,7 @@ static void test_out_ipv6_esp_null_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - false, false, 123, NULL, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1140,7 +1138,7 @@ static void test_out_ipv6_esp_null_sha256_tun_ipv4(void) tunnel.ipv4.ttl = 64; ipsec_sa_param_fill(¶m, - false, false, 123, &tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1186,7 +1184,7 @@ static void test_out_ipv6_esp_null_sha256_tun_ipv6(void) tunnel.ipv6.hlimit = 64; ipsec_sa_param_fill(¶m, - false, false, 123, &tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1217,7 +1215,7 @@ static void test_out_ipv6_esp_udp_null_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - false, false, 123, NULL, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1265,7 +1263,7 @@ static void test_out_dummy_esp_null_sha256_tun(odp_ipsec_tunnel_param_t tunnel) return; ipsec_sa_param_fill(¶m, - false, false, 123, &tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1275,7 +1273,7 @@ static void test_out_dummy_esp_null_sha256_tun(odp_ipsec_tunnel_param_t tunnel) CU_ASSERT_NOT_EQUAL_FATAL(ODP_IPSEC_SA_INVALID, sa); ipsec_sa_param_fill(¶m, - true, false, 123, &tunnel, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1353,7 +1351,7 @@ static void test_out_ipv4_udp_esp_null_sha256(void) odp_ipsec_sa_t sa; ipsec_sa_param_fill(¶m, - false, false, 123, NULL, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_SHA256_HMAC, &key_5a_256, NULL, NULL); @@ -1394,7 +1392,8 @@ static void test_out_ipv4_null_aes_xcbc(void) tunnel.ipv4.ttl = 64; ipsec_sa_param_fill(¶m, - false, false, 0x100, &tunnel, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, + 0x100, &tunnel, ODP_CIPHER_ALG_NULL, NULL, ODP_AUTH_ALG_AES_XCBC_MAC, &key_auth_aes_xcbc_128, NULL, NULL); @@ -1431,12 +1430,9 @@ static void test_sa_info(void) odp_ipsec_sa_param_t param_in; odp_ipsec_sa_info_t info_out; odp_ipsec_sa_info_t info_in; - odp_ipsec_capability_t capa; odp_ipsec_sa_t sa_out; odp_ipsec_sa_t sa_in; - CU_ASSERT_EQUAL(0, odp_ipsec_capability(&capa)); - memset(&tunnel_out, 0, sizeof(tunnel_out)); memset(&tunnel_in, 0, sizeof(tunnel_in)); @@ -1445,7 +1441,8 @@ static void test_sa_info(void) tunnel_out.ipv4.dst_addr = &dst; ipsec_sa_param_fill(¶m_out, - false, false, 123, &tunnel_out, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, + 123, &tunnel_out, ODP_CIPHER_ALG_AES_CBC, &key_a5_128, ODP_AUTH_ALG_SHA1_HMAC, &key_5a_160, NULL, NULL); @@ -1455,7 +1452,8 @@ static void test_sa_info(void) CU_ASSERT_NOT_EQUAL_FATAL(ODP_IPSEC_SA_INVALID, sa_out); ipsec_sa_param_fill(¶m_in, - true, false, 123, &tunnel_in, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + 123, &tunnel_in, ODP_CIPHER_ALG_AES_CBC, &key_a5_128, ODP_AUTH_ALG_SHA1_HMAC, &key_5a_160, NULL, NULL); @@ -1557,7 +1555,7 @@ static void test_sa_info(void) * mode SA and ODP_IPSEC_DSTADD_SPI lookup mode. */ ipsec_sa_param_fill(¶m_in, - true, false, 123, NULL, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, 123, NULL, ODP_CIPHER_ALG_AES_CBC, &key_a5_128, ODP_AUTH_ALG_SHA1_HMAC, &key_5a_160, NULL, NULL); @@ -1588,7 +1586,7 @@ static void test_test_sa_update_seq_num(void) flags.display_algo = true; flags.part_flags.test_sa_seq_num = true; - test_esp_out_in_all(&flags); + test_out_in_all(&flags); printf("\n "); } @@ -1664,15 +1662,15 @@ static void test_ipsec_stats(void) printf("\n Stats : success"); flags.stats = IPSEC_TEST_STATS_SUCCESS; - test_esp_out_in_all(&flags); + test_out_in_all(&flags); printf("\n Stats : proto err"); flags.stats = IPSEC_TEST_STATS_PROTO_ERR; - test_esp_out_in_all(&flags); + test_out_in_all(&flags); printf("\n Stats : auth err"); flags.stats = IPSEC_TEST_STATS_AUTH_ERR; - test_esp_out_in_all(&flags); + test_out_in_all(&flags); printf("\n "); } @@ -1793,7 +1791,8 @@ static void test_max_num_sa(void) tun_dst = 0x0a800000 + n; ipsec_sa_param_fill(¶m, - false, false, spi_start + n, &tun, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, + spi_start + n, &tun, ODP_CIPHER_ALG_AES_CBC, &cipher_key, ODP_AUTH_ALG_SHA1_HMAC, &auth_key, NULL, NULL); @@ -1801,7 +1800,8 @@ static void test_max_num_sa(void) CU_ASSERT_FATAL(sa_out[n] != ODP_IPSEC_SA_INVALID); ipsec_sa_param_fill(¶m, - true, false, spi_start + n, &tun, + ODP_IPSEC_DIR_INBOUND, ODP_IPSEC_ESP, + spi_start + n, &tun, ODP_CIPHER_ALG_AES_CBC, &cipher_key, ODP_AUTH_ALG_SHA1_HMAC, &auth_key, NULL, NULL); @@ -1820,7 +1820,8 @@ static void test_max_num_sa(void) tun_dst = 0x0a800000 + n; ipsec_sa_param_fill(¶m, - false, false, spi_start + n, &tun, + ODP_IPSEC_DIR_OUTBOUND, ODP_IPSEC_ESP, + spi_start + n, &tun, ODP_CIPHER_ALG_AES_CBC, &cipher_key, ODP_AUTH_ALG_SHA1_HMAC, &auth_key, NULL, NULL); @@ -1860,12 +1861,6 @@ odp_testinfo_t ipsec_out_suite[] = { ipsec_check_esp_null_sha256), ODP_TEST_INFO_CONDITIONAL(test_out_ipv4_esp_udp_null_sha256, ipsec_check_esp_null_sha256), - ODP_TEST_INFO_CONDITIONAL(test_out_ipv4_ah_aes_gmac_128, - ipsec_check_ah_aes_gmac_128), - ODP_TEST_INFO_CONDITIONAL(test_out_ipv4_ah_aes_gmac_192, - ipsec_check_ah_aes_gmac_192), - ODP_TEST_INFO_CONDITIONAL(test_out_ipv4_ah_aes_gmac_256, - ipsec_check_ah_aes_gmac_256), ODP_TEST_INFO_CONDITIONAL(test_out_ipv4_ah_sha256_frag_check, ipsec_check_ah_sha256), ODP_TEST_INFO_CONDITIONAL(test_out_ipv4_ah_sha256_frag_check_2, @@ -1901,9 +1896,9 @@ odp_testinfo_t ipsec_out_suite[] = { ODP_TEST_INFO_CONDITIONAL(test_test_sa_update_seq_num, ipsec_check_test_sa_update_seq_num), ODP_TEST_INFO(test_esp_out_in_all_basic), - ODP_TEST_INFO_CONDITIONAL(test_esp_out_in_all_hdr_in_packet, + ODP_TEST_INFO_CONDITIONAL(test_inline_hdr_in_packet, is_out_mode_inline), - ODP_TEST_INFO(test_ah_out_in_all), + ODP_TEST_INFO(test_ah_out_in_all_basic), ODP_TEST_INFO(test_ipsec_stats), ODP_TEST_INFO(test_udp_encap), ODP_TEST_INFO_CONDITIONAL(test_max_num_sa, diff --git a/test/validation/api/packet/packet.c b/test/validation/api/packet/packet.c index f638ddd8c..1ddff1ae1 100644 --- a/test/validation/api/packet/packet.c +++ b/test/validation/api/packet/packet.c @@ -3265,6 +3265,52 @@ static void packet_test_max_pools(void) CU_ASSERT(odp_pool_destroy(pool[i]) == 0); } +static void packet_test_user_area(void) +{ + odp_pool_param_t param; + odp_packet_t pkt; + odp_pool_t pool; + + memcpy(¶m, &default_param, sizeof(odp_pool_param_t)); + + param.pkt.uarea_size = 0; + pool = odp_pool_create("zero_uarea", ¶m); + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + pkt = odp_packet_alloc(pool, param.pkt.len); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT(odp_packet_user_area(pkt) == NULL); + CU_ASSERT(odp_packet_user_area_size(pkt) == 0); + odp_packet_free(pkt); + CU_ASSERT(odp_pool_destroy(pool) == 0); + + param.pkt.uarea_size = 1; + pool = odp_pool_create("one_uarea", ¶m); + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + pkt = odp_packet_alloc(pool, param.pkt.len); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT_FATAL(odp_packet_user_area(pkt) != NULL); + CU_ASSERT(odp_packet_user_area_size(pkt) == 1); + *(char *)odp_packet_user_area(pkt) = 0; + CU_ASSERT_FATAL(odp_packet_is_valid(pkt) == 1); + odp_packet_free(pkt); + CU_ASSERT(odp_pool_destroy(pool) == 0); + + if (pool_capa.pkt.max_uarea_size) + param.pkt.uarea_size = pool_capa.pkt.max_uarea_size; + else + param.pkt.uarea_size = 512; + pool = odp_pool_create("max_uarea", ¶m); + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + pkt = odp_packet_alloc(pool, param.pkt.len); + CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + CU_ASSERT_FATAL(odp_packet_user_area(pkt) != NULL); + CU_ASSERT(odp_packet_user_area_size(pkt) == param.pkt.uarea_size); + memset(odp_packet_user_area(pkt), 0, param.pkt.uarea_size); + CU_ASSERT_FATAL(odp_packet_is_valid(pkt) == 1); + odp_packet_free(pkt); + CU_ASSERT(odp_pool_destroy(pool) == 0); +} + static int packet_parse_suite_init(void) { int num_test_pkt, i; @@ -4254,6 +4300,7 @@ odp_testinfo_t packet_suite[] = { ODP_TEST_INFO(packet_test_offset), ODP_TEST_INFO(packet_test_ref), ODP_TEST_INFO(packet_test_max_pools), + ODP_TEST_INFO(packet_test_user_area), ODP_TEST_INFO_NULL, }; diff --git a/test/validation/api/pktio/pktio.c b/test/validation/api/pktio/pktio.c index 10a2297ef..dbb6f5371 100644 --- a/test/validation/api/pktio/pktio.c +++ b/test/validation/api/pktio/pktio.c @@ -4139,7 +4139,9 @@ static int create_pool(const char *iface, int num) odp_pool_param_init(¶ms); set_pool_len(¶ms, &pool_capa); - params.pkt.num = PKT_BUF_NUM; + /* Allocate enough buffers taking into consideration core starvation + * due to caching */ + params.pkt.num = PKT_BUF_NUM + params.pkt.cache_size; params.type = ODP_POOL_PACKET; snprintf(pool_name, sizeof(pool_name), "pkt_pool_%s_%d", diff --git a/test/validation/api/pool/pool.c b/test/validation/api/pool/pool.c index 866f93020..8dad89d81 100644 --- a/test/validation/api/pool/pool.c +++ b/test/validation/api/pool/pool.c @@ -1,6 +1,6 @@ /* Copyright (c) 2014-2018, Linaro Limited * Copyright (c) 2020, Marvell - * Copyright (c) 2020-2021, Nokia + * Copyright (c) 2020-2022, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -42,6 +42,27 @@ static odp_pool_capability_t global_pool_capa; static odp_pool_param_t default_pool_param; static odp_pool_ext_capability_t global_pool_ext_capa; +static void pool_test_param_init(void) +{ + odp_pool_param_t param; + + odp_pool_param_init(¶m); + + CU_ASSERT(param.buf.cache_size >= global_pool_capa.buf.min_cache_size && + param.buf.cache_size <= global_pool_capa.buf.max_cache_size); + + CU_ASSERT(param.pkt.max_num == 0); + CU_ASSERT(param.pkt.num_subparam == 0); + CU_ASSERT(param.pkt.cache_size >= global_pool_capa.pkt.min_cache_size && + param.pkt.cache_size <= global_pool_capa.pkt.max_cache_size); + + CU_ASSERT(param.tmo.cache_size >= global_pool_capa.tmo.min_cache_size && + param.tmo.cache_size <= global_pool_capa.tmo.max_cache_size); + + CU_ASSERT(param.vector.cache_size >= global_pool_capa.vector.min_cache_size && + param.vector.cache_size <= global_pool_capa.vector.max_cache_size); +} + static void pool_create_destroy(odp_pool_param_t *param) { odp_pool_t pool; @@ -1737,6 +1758,7 @@ static int check_pool_ext_segment_support(void) } odp_testinfo_t pool_suite[] = { + ODP_TEST_INFO(pool_test_param_init), ODP_TEST_INFO(pool_test_create_destroy_buffer), ODP_TEST_INFO(pool_test_create_destroy_packet), ODP_TEST_INFO(pool_test_create_destroy_timeout), diff --git a/test/validation/api/queue/queue.c b/test/validation/api/queue/queue.c index 7b39da433..ec6863628 100644 --- a/test/validation/api/queue/queue.c +++ b/test/validation/api/queue/queue.c @@ -84,7 +84,9 @@ static int queue_suite_init(void) odp_pool_param_init(¶ms); params.buf.size = 4; - params.buf.num = MAX_NUM_EVENT; + /* Allocate enough buffers taking into consideration core starvation + * due to caching */ + params.buf.num = MAX_NUM_EVENT + params.buf.cache_size; params.type = ODP_POOL_BUFFER; pool = odp_pool_create("msg_pool", ¶ms); diff --git a/test/validation/api/random/Makefile.am b/test/validation/api/random/Makefile.am index e24ce0af7..743ecf1ff 100644 --- a/test/validation/api/random/Makefile.am +++ b/test/validation/api/random/Makefile.am @@ -2,3 +2,4 @@ include ../Makefile.inc test_PROGRAMS = random_main random_main_SOURCES = random.c +LDADD += -lm diff --git a/test/validation/api/random/random.c b/test/validation/api/random/random.c index 481ceb303..97e367678 100644 --- a/test/validation/api/random/random.c +++ b/test/validation/api/random/random.c @@ -1,4 +1,5 @@ /* Copyright (c) 2015-2018, Linaro Limited + * Copyright (c) 2021-2022, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -7,7 +8,7 @@ #include <odp_api.h> #include <odp_cunit_common.h> -static void random_test_get_size(void) +static void random_test_get_size(odp_random_kind_t kind) { /* odp_random_data may fail to return data on every call (i.e. lack of * entropy). Therefore loop with some sane loop timeout value. Note that @@ -24,7 +25,7 @@ static void random_test_get_size(void) do { ret = odp_random_data(buf + bytes, sizeof(buf) - bytes, - ODP_RANDOM_BASIC); + kind); bytes += ret; if (ret < 0 || bytes >= sizeof(buf)) break; @@ -36,6 +37,21 @@ static void random_test_get_size(void) CU_ASSERT(bytes == (int32_t)sizeof(buf)); } +static void random_test_get_size_basic(void) +{ + random_test_get_size(ODP_RANDOM_BASIC); +} + +static void random_test_get_size_crypto(void) +{ + random_test_get_size(ODP_RANDOM_CRYPTO); +} + +static void random_test_get_size_true(void) +{ + random_test_get_size(ODP_RANDOM_TRUE); +} + static void random_test_kind(void) { int32_t rc; @@ -80,10 +96,424 @@ static void random_test_repeat(void) CU_ASSERT(memcmp(buf1, buf2, sizeof(buf1)) == 0); } +static void random_data(uint8_t *buf, uint32_t len, odp_random_kind_t kind) +{ + static uint64_t seed; + + switch (kind) { + case ODP_RANDOM_BASIC: + case ODP_RANDOM_CRYPTO: + case ODP_RANDOM_TRUE: + for (uint32_t i = 0; i < len;) { + int32_t r = odp_random_data(buf + i, len - i, kind); + + CU_ASSERT_FATAL(r >= 0); + i += r; + } + break; + default: + CU_ASSERT_FATAL(odp_random_test_data(buf, len, &seed) == + (int32_t)len); + } +} + +static void random_test_align_and_overflow(odp_random_kind_t kind) +{ + uint8_t ODP_ALIGNED_CACHE buf[64]; + + for (int align = 8; align < 16; align++) { + for (int len = 1; len <= 16; len++) { + memset(buf, 1, sizeof(buf)); + random_data(buf + align, len, kind); + CU_ASSERT(buf[align - 1] == 1); + CU_ASSERT(buf[align + len] == 1); + } + } +} + +static void random_test_align_and_overflow_test(void) +{ + random_test_align_and_overflow(-1); +} + +static void random_test_align_and_overflow_basic(void) +{ + random_test_align_and_overflow(ODP_RANDOM_BASIC); +} + +static void random_test_align_and_overflow_crypto(void) +{ + random_test_align_and_overflow(ODP_RANDOM_CRYPTO); +} + +static void random_test_align_and_overflow_true(void) +{ + random_test_align_and_overflow(ODP_RANDOM_TRUE); +} + +/* + * Randomness tests + * + * The purpose of the following tests is to check that random data looks random. + * Some of the tests are based on [1]. + * + * [1] Special Publication 800-22 revision 1a: A Statistical Test Suite for + * Random and Pseudorandom Number Generators for Cryptographic Applications + * National Institute of Standards and Technology (NIST), April 2010 + * https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-22r1a.pdf + */ + +/* + * Alpha for P-value tests. This does not affect the tests that use a + * precomputed critical value. + */ +static const double alpha = 0.00000001; + +static uint32_t random_bits(int n, odp_random_kind_t kind) +{ + static uint8_t buf[32 * 1024]; + const int size = sizeof(buf); + static int cur_n; + static odp_random_kind_t cur_kind; + static int bit; + uint32_t r = 0; + + if (n != cur_n || kind != cur_kind) { + cur_n = n; + cur_kind = kind; + bit = size * 8; + } + + for (int i = 0; i < n; ) { + if (bit >= size * 8) { + random_data(buf, size, kind); + bit = 0; + } + if (n - i >= 8 && !(bit & 7)) { + /* Full byte. */ + r <<= 8; + r |= buf[bit / 8]; + bit += 8; + i += 8; + continue; + } + /* Single bit. */ + r <<= 1; + r |= (buf[bit / 8] >> (7 - (bit & 7))) & 1; + bit++; + i++; + } + + return r; +} + +static const char *res_str(int pass) +{ + return pass ? "pass" : "FAIL"; +} + +/* + * Pearson's chi-squared goodness-of-fit test for uniform distribution. The test + * is run with multiple different bit block lengths. The null hypothesis is that + * each possible bit pattern is equally likely. If the chi-squared statistic is + * equal to or larger than the critical value, we conclude that the data is + * biased. + */ +static void random_test_frequency(odp_random_kind_t kind) +{ + /* Mean number of hits per cell. */ + const uint32_t expected = 50; + + /* From LibreOffice CHISQ.INV.RT(0.00000001; df). */ + const double critical[] = { + 32.8413, 40.1300, 50.8129, 68.0293, + 97.0285, 147.463, 237.614, 402.685, + 711.187, 1297.50, 2426.64, 4623.37, + 8929.74, 17419.3, 34224.0, 67587.1, + }; + + printf("\n\n"); + + for (int bits = 1; bits <= 8; bits++) { + const uint32_t cells = 1 << bits; + const uint64_t num = expected * cells; + uint64_t f[256] = { 0 }; + + for (uint64_t i = 0; i < num; i++) + f[random_bits(bits, kind)]++; + + double chisq = 0, crit = critical[bits - 1]; + + for (uint64_t i = 0; i < cells; i++) { + double dif = (double)f[i] - expected; + + chisq += dif * dif / expected; + } + + printf("bits %d ; chisq %g ; df %u ; crit %g ; %s\n", + bits, chisq, cells - 1, crit, res_str(chisq < crit)); + + CU_ASSERT(chisq < crit); + } + + printf("\n"); +} + +static void random_test_frequency_crypto(void) +{ + random_test_frequency(ODP_RANDOM_CRYPTO); +} + +static void random_test_frequency_true(void) +{ + random_test_frequency(ODP_RANDOM_TRUE); +} + +/* + * Pearson's chi-squared test for independence. The null hypothesis is that the + * values of different bytes are independent. If the chi-squared statistic is + * equal to or greater than the critical value, we conclude that the bytes in + * the byte pairs selected from the data are not independent. + */ +static void random_test_independence(odp_random_kind_t kind) +{ + /* Mean number of hits per cell. */ + const uint32_t expected = 100; + + /* LibreOffice CHISQ.INV.RT(0.00000001; 255*255) */ + const double critical = 67069.2; + + printf("\n\n"); + printf("critical value: %g\n", critical); + + for (int lag = 1; lag <= 8; lag++) { + const uint32_t cells = 256 * 256; + const uint64_t num = expected * cells; + const int size = 32 * 1024; + int pos = size; + uint8_t buf[size]; + uint64_t freq[256][256] = { { 0 } }; + uint32_t row[256] = { 0 }, col[256] = { 0 }; + + for (uint64_t i = 0; i < num; i++) { + if (pos + lag >= size) { + random_data(buf, size, kind); + pos = 0; + } + + uint8_t r = buf[pos], c = buf[pos + lag]; + + freq[r][c]++; + row[r]++; + col[c]++; + pos++; + } + + double chisq = 0; + + for (int i = 0; i < 256; i++) { + for (int j = 0; j < 256; j++) { + double expected = + (double)row[i] * (double)col[j] / (double)num; + double diff = + (double)freq[i][j] - expected; + chisq += diff * diff / expected; + } + } + + printf("lag %d ; chisq %g ; %s\n", + lag, chisq, res_str(chisq < critical)); + + CU_ASSERT(chisq < critical); + } + + printf("\n"); +} + +static void random_test_independence_crypto(void) +{ + random_test_independence(ODP_RANDOM_CRYPTO); +} + +/* + * Sec. 2.3 Runs Test [1]. The test is run with several different n values. A + * few long runs may go unnoticed if n is large, while longer period + * non-randomness may go unnoticed if n is small. + */ +static void random_test_runs(odp_random_kind_t kind) +{ + printf("\n\n"); + printf("alpha: %g\n", alpha); + + for (int n = 128; n <= 1024 * 1024; n *= 2) { + double pi, P_value; + int bit = random_bits(1, kind); + uint64_t ones = bit, V = 1; + + for (int i = 1; i < n; i++) { + int prev_bit = bit; + + bit = random_bits(1, kind); + ones += bit; + V += (bit != prev_bit); + } + + pi = (double)ones / n; + + /* + * Skip the prerequisite frequency test (Sec. 2.3.4 + * step (2)), since it's effectively the same as + * random_test_frequency() with bits = 1. + */ + + P_value = erfc(fabs(V - 2 * n * pi * (1 - pi)) / + (2 * sqrt(2 * n) * pi * (1 - pi))); + printf("n %d ; pi %g ; V %" PRIu64 " ; P_value %g ; %s\n", + n, pi, V, P_value, res_str(P_value >= alpha)); + + CU_ASSERT(P_value >= alpha); + } + + printf("\n"); +} + +static void random_test_runs_crypto(void) +{ + random_test_runs(ODP_RANDOM_CRYPTO); +} + +static void random_test_runs_true(void) +{ + random_test_runs(ODP_RANDOM_TRUE); +} + +static int mx_bit(uint32_t *m, int r, int c) +{ + return (m[r] >> c) & 1; +} + +static int mx_rank(uint32_t *m, int rows, int cols) +{ + int rank = 0; + + for (int r = 0, c = 0; r < rows && c < cols; ) { + int swapped = r; + + if (!mx_bit(m, r, c)) { + for (int sr = r + 1; sr < rows; sr++) { + if (mx_bit(m, sr, c)) { + uint32_t t = m[r]; + + m[r] = m[sr]; + m[sr] = t; + swapped = sr; + break; + } + } + if (!mx_bit(m, r, c)) { + c++; + continue; + } + } + + rank++; + + for (int sr = swapped + 1; sr < rows; sr++) { + if (mx_bit(m, sr, c)) + m[sr] ^= m[r]; + } + + r++; + } + + return rank; +} + +/* + * Sec. 2.5 Binary Matrix Rank Test [1]. + */ +static void random_test_matrix_rank(odp_random_kind_t kind) +{ + const int N = 100; /* [1] recommends at least 38. */ + const double p[3] = { 0.2888, 0.5776, 0.1336 }; + + printf("\n\n"); + printf("alpha: %g\n", alpha); + printf("N: %d\n", N); + + int F[3] = { 0 }; + + for (int i = 0; i < N; i++) { + uint32_t mx[32]; + + random_data((uint8_t *)mx, sizeof(mx), kind); + + switch (mx_rank(mx, 32, 32)) { + case 32: + F[0]++; + break; + case 31: + F[1]++; + break; + default: + F[2]++; + } + } + + double chisq, P_value; + + chisq = pow(F[0] - p[0] * N, 2) / (p[0] * N) + + pow(F[1] - p[1] * N, 2) / (p[1] * N) + + pow(F[2] - p[2] * N, 2) / (p[2] * N); + P_value = exp(-chisq / 2); + + printf("P_value %g ; %s\n", P_value, res_str(P_value >= alpha)); + + CU_ASSERT(P_value >= alpha); +} + +static void random_test_matrix_rank_crypto(void) +{ + random_test_matrix_rank(ODP_RANDOM_CRYPTO); +} + +static void random_test_matrix_rank_true(void) +{ + random_test_matrix_rank(ODP_RANDOM_TRUE); +} + +static int check_kind_basic(void) +{ + return odp_random_max_kind() >= ODP_RANDOM_BASIC; +} + +static int check_kind_crypto(void) +{ + return odp_random_max_kind() >= ODP_RANDOM_CRYPTO; +} + +static int check_kind_true(void) +{ + return odp_random_max_kind() >= ODP_RANDOM_TRUE; +} + odp_testinfo_t random_suite[] = { - ODP_TEST_INFO(random_test_get_size), + ODP_TEST_INFO_CONDITIONAL(random_test_get_size_basic, check_kind_basic), + ODP_TEST_INFO_CONDITIONAL(random_test_get_size_crypto, check_kind_crypto), + ODP_TEST_INFO_CONDITIONAL(random_test_get_size_true, check_kind_true), ODP_TEST_INFO(random_test_kind), ODP_TEST_INFO(random_test_repeat), + ODP_TEST_INFO(random_test_align_and_overflow_test), + ODP_TEST_INFO_CONDITIONAL(random_test_align_and_overflow_basic, check_kind_basic), + ODP_TEST_INFO_CONDITIONAL(random_test_align_and_overflow_crypto, check_kind_crypto), + ODP_TEST_INFO_CONDITIONAL(random_test_align_and_overflow_true, check_kind_true), + ODP_TEST_INFO_CONDITIONAL(random_test_frequency_crypto, check_kind_crypto), + ODP_TEST_INFO_CONDITIONAL(random_test_frequency_true, check_kind_true), + ODP_TEST_INFO_CONDITIONAL(random_test_independence_crypto, check_kind_crypto), + ODP_TEST_INFO_CONDITIONAL(random_test_runs_crypto, check_kind_crypto), + ODP_TEST_INFO_CONDITIONAL(random_test_runs_true, check_kind_true), + ODP_TEST_INFO_CONDITIONAL(random_test_matrix_rank_crypto, check_kind_crypto), + ODP_TEST_INFO_CONDITIONAL(random_test_matrix_rank_true, check_kind_true), ODP_TEST_INFO_NULL, }; diff --git a/test/validation/api/timer/timer.c b/test/validation/api/timer/timer.c index 09dcd8c95..20d36bff7 100644 --- a/test/validation/api/timer/timer.c +++ b/test/validation/api/timer/timer.c @@ -19,6 +19,8 @@ #define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define MAX_TIMER_POOLS 1024 + /* Timeout range in milliseconds (ms) */ #define RANGE_MS 2000 @@ -478,6 +480,77 @@ static void timer_pool_create_destroy(void) CU_ASSERT(odp_queue_destroy(queue) == 0); } +static void timer_pool_create_max(void) +{ + odp_timer_capability_t capa; + odp_timer_pool_param_t tp_param; + odp_queue_param_t queue_param; + odp_queue_t queue; + uint32_t i; + int ret; + uint64_t tmo_ns = ODP_TIME_SEC_IN_NS; + uint64_t res_ns = ODP_TIME_SEC_IN_NS / 10; + + memset(&capa, 0, sizeof(capa)); + ret = odp_timer_capability(ODP_CLOCK_DEFAULT, &capa); + CU_ASSERT_FATAL(ret == 0); + + uint32_t num = capa.max_pools; + + if (num > MAX_TIMER_POOLS) + num = MAX_TIMER_POOLS; + + odp_timer_pool_t tp[num]; + odp_timer_t timer[num]; + + if (capa.max_tmo.max_tmo < tmo_ns) { + tmo_ns = capa.max_tmo.max_tmo; + res_ns = capa.max_tmo.res_ns; + } + + odp_queue_param_init(&queue_param); + + if (capa.queue_type_sched) + queue_param.type = ODP_QUEUE_TYPE_SCHED; + + queue = odp_queue_create("timer_queue", &queue_param); + CU_ASSERT_FATAL(queue != ODP_QUEUE_INVALID); + + odp_timer_pool_param_init(&tp_param); + + tp_param.res_ns = res_ns; + tp_param.min_tmo = tmo_ns / 2; + tp_param.max_tmo = tmo_ns; + tp_param.num_timers = 1; + + for (i = 0; i < num; i++) { + tp[i] = odp_timer_pool_create("test_max", &tp_param); + if (tp[i] == ODP_TIMER_POOL_INVALID) + ODPH_ERR("Timer pool create failed: %u / %u\n", i, num); + + CU_ASSERT_FATAL(tp[i] != ODP_TIMER_POOL_INVALID); + } + + odp_timer_pool_start(); + + for (i = 0; i < num; i++) { + timer[i] = odp_timer_alloc(tp[i], queue, USER_PTR); + + if (timer[i] == ODP_TIMER_INVALID) + ODPH_ERR("Timer alloc failed: %u / %u\n", i, num); + + CU_ASSERT_FATAL(timer[i] != ODP_TIMER_INVALID); + } + + for (i = 0; i < num; i++) + CU_ASSERT(odp_timer_free(timer[i]) == ODP_EVENT_INVALID); + + for (i = 0; i < num; i++) + odp_timer_pool_destroy(tp[i]); + + CU_ASSERT(odp_queue_destroy(queue) == 0); +} + static void timer_pool_max_res(void) { odp_timer_capability_t capa; @@ -1836,6 +1909,7 @@ odp_testinfo_t timer_suite[] = { ODP_TEST_INFO(timer_test_timeout_pool_alloc), ODP_TEST_INFO(timer_test_timeout_pool_free), ODP_TEST_INFO(timer_pool_create_destroy), + ODP_TEST_INFO(timer_pool_create_max), ODP_TEST_INFO(timer_pool_max_res), ODP_TEST_INFO(timer_pool_tick_info), ODP_TEST_INFO_CONDITIONAL(timer_test_tmo_event_plain, diff --git a/test/validation/api/traffic_mngr/traffic_mngr.c b/test/validation/api/traffic_mngr/traffic_mngr.c index 0899272ba..2c1e79819 100644 --- a/test/validation/api/traffic_mngr/traffic_mngr.c +++ b/test/validation/api/traffic_mngr/traffic_mngr.c @@ -1,4 +1,6 @@ /* Copyright (c) 2015-2018, Linaro Limited + * Copyright (c) 2022, Marvell + * Copyright (c) 2022, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -336,6 +338,11 @@ static uint32_t cpu_tcp_seq_num; static int8_t suite_inactive; +static uint64_t tm_shaper_min_rate; +static uint64_t tm_shaper_max_rate; +static uint32_t tm_shaper_min_burst; +static uint32_t tm_shaper_max_burst; + static void busy_wait(uint64_t nanoseconds) { odp_time_t start_time, end_time; @@ -382,6 +389,18 @@ static odp_bool_t approx_eq64(uint64_t val, uint64_t correct) return false; } +static uint64_t +clamp_rate(uint64_t rate) +{ + return MIN(MAX(rate, tm_shaper_min_rate), tm_shaper_max_rate); +} + +static uint32_t +clamp_burst(uint32_t burst) +{ + return MIN(MAX(burst, tm_shaper_min_burst), tm_shaper_max_burst); +} + static int test_overall_capabilities(void) { odp_tm_level_capabilities_t *per_level; @@ -443,6 +462,18 @@ static int test_overall_capabilities(void) CU_ASSERT(per_level->max_priority != 0); return -1; } + + if (per_level->tm_node_shaper_supported) { + CU_ASSERT(per_level->max_burst > 0); + CU_ASSERT(per_level->min_rate > 0); + CU_ASSERT(per_level->max_rate > 0); + } + + if (per_level->tm_node_shaper_packet_mode) { + CU_ASSERT(per_level->max_burst_packets > 0); + CU_ASSERT(per_level->min_rate_packets > 0); + CU_ASSERT(per_level->max_rate_packets > 0); + } } /* At least one pkt priority mode needs to be supported */ @@ -1150,10 +1181,12 @@ static uint32_t send_pkts(odp_tm_queue_t tm_queue, uint32_t num_pkts) xmt_pkt_desc = &xmt_pkt_descs[xmt_pkt_idx]; /* Alternate calling with odp_tm_enq and odp_tm_enq_with_cnt */ - if ((idx & 1) == 0) + if ((idx & 1) == 0) { rc = odp_tm_enq(tm_queue, odp_pkt); - else + CU_ASSERT(rc <= 0); + } else { rc = odp_tm_enq_with_cnt(tm_queue, odp_pkt); + } xmt_pkt_desc->xmt_idx = xmt_pkt_idx; if (0 <= rc) { @@ -2257,13 +2290,39 @@ static int traffic_mngr_suite_init(void) if (egress_capa.max_levels < NUM_LEVELS) goto skip_tests; + tm_shaper_min_rate = egress_capa.per_level[0].min_rate; + tm_shaper_max_rate = egress_capa.per_level[0].max_rate; + tm_shaper_min_burst = egress_capa.per_level[0].min_burst; + tm_shaper_max_burst = egress_capa.per_level[0].max_burst; + for (j = 0; j < NUM_LEVELS; j++) { + odp_tm_level_capabilities_t *per_level = + &egress_capa.per_level[j]; + /* Per node fanin */ - if (egress_capa.per_level[j].max_fanin_per_node < - FANIN_RATIO) + if (per_level->max_fanin_per_node < FANIN_RATIO) break; + + if (j == 0) + continue; + + if (per_level->min_rate > tm_shaper_min_rate) + tm_shaper_min_rate = per_level->min_rate; + + if (per_level->min_burst > tm_shaper_min_burst) + tm_shaper_min_burst = per_level->min_burst; + + if (per_level->max_rate < tm_shaper_max_rate) + tm_shaper_max_rate = per_level->max_rate; + + if (per_level->max_burst < tm_shaper_max_burst) + tm_shaper_max_burst = per_level->max_burst; } + if (tm_shaper_min_rate > tm_shaper_max_rate || + tm_shaper_min_burst > tm_shaper_max_burst) + goto skip_tests; + if (j != NUM_LEVELS) goto skip_tests; @@ -2345,16 +2404,16 @@ static void check_shaper_profile(char *shaper_name, uint32_t shaper_idx) rc = odp_tm_shaper_params_read(profile, &shaper_params); CU_ASSERT(rc == 0); CU_ASSERT(approx_eq64(shaper_params.commit_rate, - shaper_idx * MIN_COMMIT_BW)); + clamp_rate(shaper_idx * MIN_COMMIT_BW))); CU_ASSERT(approx_eq64(shaper_params.peak_rate, - shaper_idx * MIN_PEAK_BW)); + clamp_rate(shaper_idx * MIN_PEAK_BW))); CU_ASSERT(approx_eq32(shaper_params.commit_burst, - shaper_idx * MIN_COMMIT_BURST)); + clamp_burst(shaper_idx * MIN_COMMIT_BURST))); CU_ASSERT(approx_eq32(shaper_params.peak_burst, - shaper_idx * MIN_PEAK_BURST)); + clamp_burst(shaper_idx * MIN_PEAK_BURST))); CU_ASSERT(shaper_params.shaper_len_adjust == SHAPER_LEN_ADJ); - CU_ASSERT(shaper_params.dual_rate == 0); + CU_ASSERT(shaper_params.dual_rate == true); } static void traffic_mngr_test_shaper_profile(void) @@ -2366,15 +2425,15 @@ static void traffic_mngr_test_shaper_profile(void) odp_tm_shaper_params_init(&shaper_params); shaper_params.shaper_len_adjust = SHAPER_LEN_ADJ; - shaper_params.dual_rate = 0; + shaper_params.dual_rate = true; for (idx = 1; idx <= NUM_SHAPER_TEST_PROFILES; idx++) { snprintf(shaper_name, sizeof(shaper_name), "shaper_profile_%" PRIu32, idx); - shaper_params.commit_rate = idx * MIN_COMMIT_BW; - shaper_params.peak_rate = idx * MIN_PEAK_BW; - shaper_params.commit_burst = idx * MIN_COMMIT_BURST; - shaper_params.peak_burst = idx * MIN_PEAK_BURST; + shaper_params.commit_rate = clamp_rate(idx * MIN_COMMIT_BW); + shaper_params.peak_rate = clamp_rate(idx * MIN_PEAK_BW); + shaper_params.commit_burst = clamp_burst(idx * MIN_COMMIT_BURST); + shaper_params.peak_burst = clamp_burst(idx * MIN_PEAK_BURST); profile = odp_tm_shaper_create(shaper_name, &shaper_params); CU_ASSERT_FATAL(profile != ODP_TM_INVALID); @@ -2615,14 +2674,17 @@ static void traffic_mngr_test_wred_profile(void) static int set_shaper(const char *node_name, const char *shaper_name, - const uint64_t commit_bps, - const uint64_t commit_burst_in_bits) + uint64_t commit_bps, + uint64_t commit_burst_in_bits) { odp_tm_shaper_params_t shaper_params; odp_tm_shaper_t shaper_profile; odp_tm_node_t tm_node; int rc; + commit_bps = clamp_rate(commit_bps); + commit_burst_in_bits = clamp_burst(commit_burst_in_bits); + tm_node = find_tm_node(0, node_name); if (tm_node == ODP_TM_INVALID) { ODPH_ERR("find_tm_node(%s) failed\n", node_name); @@ -2645,6 +2707,11 @@ static int set_shaper(const char *node_name, CU_ASSERT_FATAL(odp_tm_stop(odp_tm_systems[0]) == 0); } + if (!shaper_name) { + shaper_profile = ODP_TM_INVALID; + goto skip_profile; + } + /* First see if a shaper profile already exists with this name, in * which case we use that profile, else create a new one. */ shaper_profile = odp_tm_shaper_lookup(shaper_name); @@ -2657,6 +2724,7 @@ static int set_shaper(const char *node_name, num_shaper_profiles++; } +skip_profile: rc = odp_tm_node_shaper_config(tm_node, shaper_profile); if (!dynamic_shaper_update) { @@ -2686,6 +2754,14 @@ static int traffic_mngr_check_shaper(void) return ODP_TEST_INACTIVE; } + /* This test needs 1 Mbps, 4 Mbps, 10 Mpbs, 40 Mbps, 100 Mbps */ + if ((tm_shaper_min_rate > 100 * MBPS) || (tm_shaper_max_rate < 1 * MBPS)) + return ODP_TEST_INACTIVE; + + /* All the subtests run with burst of 10000 bits */ + if ((tm_shaper_min_burst > 10000) || tm_shaper_max_burst < 10000) + return ODP_TEST_INACTIVE; + return ODP_TEST_ACTIVE; } @@ -2701,6 +2777,15 @@ static int traffic_mngr_check_scheduler(void) return ODP_TEST_INACTIVE; } + /* Scheduler test test_sched_queue_priority() depends on rate of + * 64 Kbps and burst of 5600. + */ + if ((tm_shaper_min_rate > 64 * 1000) || + (tm_shaper_max_rate < 64 * 1000) || + (tm_shaper_min_burst > 5600) || + (tm_shaper_max_burst < 5600)) + return ODP_TEST_INACTIVE; + return ODP_TEST_ACTIVE; } @@ -2813,7 +2898,7 @@ static int test_shaper_bw(const char *shaper_name, } /* Disable the shaper, so as to get the pkts out quicker. */ - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); flush_leftover_pkts(odp_tm_systems[0], rcv_pktin); CU_ASSERT(odp_tm_is_idle(odp_tm_systems[0])); return ret_code; @@ -2949,7 +3034,7 @@ static int test_sched_queue_priority(const char *shaper_name, * start/stop. */ if (dynamic_shaper_update) - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); num_rcv_pkts = receive_pkts(odp_tm_systems[0], rcv_pktin, pkt_cnt + 4, 64 * 1000); @@ -2968,7 +3053,7 @@ static int test_sched_queue_priority(const char *shaper_name, CU_ASSERT(pkts_in_order == pkt_cnt); /* Disable shaper in case it is still enabled */ - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); flush_leftover_pkts(odp_tm_systems[0], rcv_pktin); CU_ASSERT(odp_tm_is_idle(odp_tm_systems[0])); return 0; @@ -3062,7 +3147,7 @@ static int test_sched_node_priority(const char *shaper_name, * start/stop. */ if (dynamic_shaper_update) - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); num_rcv_pkts = receive_pkts(odp_tm_systems[0], rcv_pktin, pkts_sent, 64 * 1000); @@ -3075,7 +3160,7 @@ static int test_sched_node_priority(const char *shaper_name, CU_ASSERT(pkts_in_order == total_pkt_cnt); /* Disable shaper in case it is still enabled */ - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); flush_leftover_pkts(odp_tm_systems[0], rcv_pktin); CU_ASSERT(odp_tm_is_idle(odp_tm_systems[0])); return 0; @@ -3162,7 +3247,7 @@ static int test_sched_wfq(const char *sched_base_name, * start/stop. */ if (dynamic_shaper_update) - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); num_rcv_pkts = receive_pkts(odp_tm_systems[0], rcv_pktin, pkt_cnt + 4, 64 * 1000); @@ -3175,7 +3260,7 @@ static int test_sched_wfq(const char *sched_base_name, } /* Disable shaper in case it is still enabled */ - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); flush_leftover_pkts(odp_tm_systems[0], rcv_pktin); CU_ASSERT(odp_tm_is_idle(odp_tm_systems[0])); return 0; @@ -3279,7 +3364,7 @@ static int test_threshold(const char *threshold_name, 1 * GBPS); /* Disable the shaper, so as to get the pkts out quicker. */ - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); flush_leftover_pkts(odp_tm_systems[0], rcv_pktin); CU_ASSERT(odp_tm_is_idle(odp_tm_systems[0])); @@ -3438,7 +3523,7 @@ static int test_byte_wred(const char *wred_name, * start/stop. */ if (dynamic_shaper_update) - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); num_rcv_pkts = receive_pkts(odp_tm_systems[0], rcv_pktin, num_fill_pkts + pkts_sent, 64 * 1000); @@ -3450,7 +3535,7 @@ static int test_byte_wred(const char *wred_name, return -1; /* Disable shaper in case it is still enabled */ - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); flush_leftover_pkts(odp_tm_systems[0], rcv_pktin); CU_ASSERT(odp_tm_is_idle(odp_tm_systems[0])); @@ -3531,7 +3616,7 @@ static int test_pkt_wred(const char *wred_name, * start/stop. */ if (dynamic_shaper_update) - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); ret = receive_pkts(odp_tm_systems[0], rcv_pktin, num_fill_pkts + pkts_sent, 64 * 1000); @@ -3547,7 +3632,7 @@ static int test_pkt_wred(const char *wred_name, return -1; /* Disable shaper in case it is still enabled */ - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); flush_leftover_pkts(odp_tm_systems[0], rcv_pktin); CU_ASSERT(odp_tm_is_idle(odp_tm_systems[0])); @@ -3622,7 +3707,7 @@ static int test_query_functions(const char *shaper_name, CU_ASSERT(expected_byte_cnt < query_info.total_byte_cnt); /* Disable the shaper, so as to get the pkts out quicker. */ - set_shaper(node_name, shaper_name, 0, 0); + set_shaper(node_name, NULL, 0, 0); num_rcv_pkts = receive_pkts(odp_tm_systems[0], rcv_pktin, num_pkts, commit_bps); @@ -4166,6 +4251,83 @@ static int test_fanin_info(const char *node_name) return walk_tree_backwards(node_desc->node); } +static void traffic_mngr_test_default_values(void) +{ + odp_tm_requirements_t req; + odp_tm_shaper_params_t shaper; + odp_tm_sched_params_t sched; + odp_tm_threshold_params_t threshold; + odp_tm_wred_params_t wred; + odp_tm_node_params_t node; + odp_tm_queue_params_t queue; + int n; + + memset(&req, 0xff, sizeof(req)); + odp_tm_requirements_init(&req); + CU_ASSERT_EQUAL(req.num_levels, 0); + CU_ASSERT(!req.tm_queue_shaper_needed); + CU_ASSERT(!req.tm_queue_wred_needed); + CU_ASSERT(!req.tm_queue_dual_slope_needed); + CU_ASSERT(!req.tm_queue_threshold_needed); + CU_ASSERT(!req.vlan_marking_needed); + CU_ASSERT(!req.ecn_marking_needed); + CU_ASSERT(!req.drop_prec_marking_needed); + for (n = 0; n < ODP_NUM_PACKET_COLORS; n++) + CU_ASSERT(!req.marking_colors_needed[n]); + CU_ASSERT_EQUAL(req.pkt_prio_mode, ODP_TM_PKT_PRIO_MODE_PRESERVE); + for (n = 0; n < ODP_TM_MAX_LEVELS; n++) { + odp_tm_level_requirements_t *l_req = &req.per_level[n]; + + CU_ASSERT(!l_req->tm_node_shaper_needed); + CU_ASSERT(!l_req->tm_node_wred_needed); + CU_ASSERT(!l_req->tm_node_dual_slope_needed); + CU_ASSERT(!l_req->fair_queuing_needed); + CU_ASSERT(!l_req->weights_needed); + CU_ASSERT(!l_req->tm_node_threshold_needed); + } + + memset(&shaper, 0xff, sizeof(shaper)); + odp_tm_shaper_params_init(&shaper); + CU_ASSERT_EQUAL(shaper.shaper_len_adjust, 0); + CU_ASSERT(!shaper.dual_rate); + CU_ASSERT(!shaper.packet_mode); + + memset(&sched, 0xff, sizeof(sched)); + odp_tm_sched_params_init(&sched); + for (n = 0; n < ODP_TM_MAX_PRIORITIES; n++) + CU_ASSERT_EQUAL(sched.sched_modes[n], ODP_TM_BYTE_BASED_WEIGHTS); + + memset(&threshold, 0xff, sizeof(threshold)); + odp_tm_threshold_params_init(&threshold); + CU_ASSERT(!threshold.enable_max_pkts); + CU_ASSERT(!threshold.enable_max_bytes); + + memset(&wred, 0xff, sizeof(wred)); + odp_tm_wred_params_init(&wred); + CU_ASSERT(!wred.enable_wred); + CU_ASSERT(!wred.use_byte_fullness); + + memset(&node, 0xff, sizeof(node)); + odp_tm_node_params_init(&node); + CU_ASSERT_EQUAL(node.shaper_profile, ODP_TM_INVALID); + CU_ASSERT_EQUAL(node.threshold_profile, ODP_TM_INVALID); + for (n = 0; n < ODP_NUM_PACKET_COLORS; n++) + CU_ASSERT_EQUAL(node.wred_profile[n], ODP_TM_INVALID); + + memset(&queue, 0xff, sizeof(queue)); + odp_tm_queue_params_init(&queue); + CU_ASSERT_EQUAL(queue.shaper_profile, ODP_TM_INVALID); + CU_ASSERT_EQUAL(queue.threshold_profile, ODP_TM_INVALID); + for (n = 0; n < ODP_NUM_PACKET_COLORS; n++) + CU_ASSERT_EQUAL(queue.wred_profile[n], ODP_TM_INVALID); + CU_ASSERT_EQUAL(queue.priority, 0); + CU_ASSERT(queue.ordered_enqueue); + /* re-check ordered_enqueue to notice if it is not set at all */ + memset(&queue, 0, sizeof(queue)); + odp_tm_queue_params_init(&queue); + CU_ASSERT(queue.ordered_enqueue); +} + static void traffic_mngr_test_capabilities(void) { CU_ASSERT(test_overall_capabilities() == 0); @@ -4180,26 +4342,45 @@ static void traffic_mngr_test_tm_create(void) static void traffic_mngr_test_shaper(void) { - CU_ASSERT(!odp_cunit_ret(test_shaper_bw("bw1", - "node_1_1_1", - 0, - MBPS * 1))); - CU_ASSERT(!odp_cunit_ret(test_shaper_bw("bw4", - "node_1_1_1", - 1, - 4 * MBPS))); - CU_ASSERT(!odp_cunit_ret(test_shaper_bw("bw10", - "node_1_1_1", - 2, - 10 * MBPS))); - CU_ASSERT(!odp_cunit_ret(test_shaper_bw("bw40", - "node_1_1_1", - 3, - 40 * MBPS))); - CU_ASSERT(!odp_cunit_ret(test_shaper_bw("bw100", - "node_1_1_2", - 0, - 100 * MBPS))); + if ((tm_shaper_min_rate <= 1 * MBPS) && + (tm_shaper_max_rate >= 1 * MBPS)) { + CU_ASSERT(!odp_cunit_ret(test_shaper_bw("bw1", + "node_1_1_1", + 0, + MBPS * 1))); + } + + if ((tm_shaper_min_rate <= 4 * MBPS) && + (tm_shaper_max_rate >= 4 * MBPS)) { + CU_ASSERT(!odp_cunit_ret(test_shaper_bw("bw4", + "node_1_1_1", + 1, + 4 * MBPS))); + } + + if ((tm_shaper_min_rate <= 10 * MBPS) && + (tm_shaper_max_rate >= 10 * MBPS)) { + CU_ASSERT(!odp_cunit_ret(test_shaper_bw("bw10", + "node_1_1_1", + 2, + 10 * MBPS))); + } + + if ((tm_shaper_min_rate <= 40 * MBPS) && + (tm_shaper_max_rate >= 40 * MBPS)) { + CU_ASSERT(!odp_cunit_ret(test_shaper_bw("bw40", + "node_1_1_1", + 3, + 40 * MBPS))); + } + + if ((tm_shaper_min_rate <= 100 * MBPS) && + (tm_shaper_max_rate >= 100 * MBPS)) { + CU_ASSERT(!odp_cunit_ret(test_shaper_bw("bw100", + "node_1_1_2", + 0, + 100 * MBPS))); + } } static void traffic_mngr_test_scheduler(void) @@ -4318,6 +4499,34 @@ static int traffic_mngr_check_wred(void) return ODP_TEST_ACTIVE; } +static int traffic_mngr_check_byte_wred(void) +{ + /* Check if wred is part of created odp_tm_t capabilities */ + if (!tm_capabilities.tm_queue_wred_supported) + return ODP_TEST_INACTIVE; + + if ((tm_shaper_min_rate > 64 * 1000) || + (tm_shaper_max_rate < 64 * 1000) || + (tm_shaper_min_burst > 8 * PKT_BUF_SIZE) || + (tm_shaper_max_burst < 8 * PKT_BUF_SIZE)) + return ODP_TEST_INACTIVE; + return ODP_TEST_ACTIVE; +} + +static int traffic_mngr_check_pkt_wred(void) +{ + /* Check if wred is part of created odp_tm_t capabilities */ + if (!tm_capabilities.tm_queue_wred_supported) + return ODP_TEST_INACTIVE; + + if ((tm_shaper_min_rate > 64 * 1000) || + (tm_shaper_max_rate < 64 * 1000) || + (tm_shaper_min_burst > 1000) || + (tm_shaper_max_burst < 1000)) + return ODP_TEST_INACTIVE; + return ODP_TEST_ACTIVE; +} + static void traffic_mngr_test_byte_wred(void) { CU_ASSERT(test_byte_wred("byte_wred_30G", "byte_bw_30G", @@ -4378,6 +4587,13 @@ static int traffic_mngr_check_query(void) if ((tm_capabilities.tm_queue_query_flags & query_flags) != query_flags) return ODP_TEST_INACTIVE; + /* This test uses 64 Kbps rate and a 1000 bit burst size */ + if (tm_shaper_min_rate > 64 * 1000 || + tm_shaper_max_rate < 64 * 1000 || + tm_shaper_min_burst > 1000 || + tm_shaper_max_burst < 1000) + return ODP_TEST_INACTIVE; + return ODP_TEST_ACTIVE; } @@ -4454,6 +4670,7 @@ static void traffic_mngr_test_destroy(void) } odp_testinfo_t traffic_mngr_suite[] = { + ODP_TEST_INFO(traffic_mngr_test_default_values), ODP_TEST_INFO(traffic_mngr_test_capabilities), ODP_TEST_INFO(traffic_mngr_test_tm_create), ODP_TEST_INFO(traffic_mngr_test_shaper_profile), @@ -4469,9 +4686,9 @@ odp_testinfo_t traffic_mngr_suite[] = { ODP_TEST_INFO_CONDITIONAL(traffic_mngr_test_thresholds, traffic_mngr_check_thresholds), ODP_TEST_INFO_CONDITIONAL(traffic_mngr_test_byte_wred, - traffic_mngr_check_wred), + traffic_mngr_check_byte_wred), ODP_TEST_INFO_CONDITIONAL(traffic_mngr_test_pkt_wred, - traffic_mngr_check_wred), + traffic_mngr_check_pkt_wred), ODP_TEST_INFO_CONDITIONAL(traffic_mngr_test_query, traffic_mngr_check_query), ODP_TEST_INFO_CONDITIONAL(traffic_mngr_test_queue_stats, |