From 119fb9b349e1b271218127793ecd0d031dd83812 Mon Sep 17 00:00:00 2001 From: Anoob Joseph Date: Mon, 12 Jun 2023 10:38:59 +0000 Subject: test: ipsecfwd: update CFLAGS with libconfig Update CFLAGS with libconfig CFLAGS. The app has dependency on libconfig and CFLAGS should be updated. Fixes: 249739742fcf ("test: ipsecfwd: utilize libconfig") Signed-off-by: Anoob Joseph Reviewed-by: Tuomas Taipale --- test/performance/Makefile.am | 1 + 1 file changed, 1 insertion(+) (limited to 'test') diff --git a/test/performance/Makefile.am b/test/performance/Makefile.am index 194dc6359..9d9c2dfd1 100644 --- a/test/performance/Makefile.am +++ b/test/performance/Makefile.am @@ -84,6 +84,7 @@ odp_timer_perf_SOURCES = odp_timer_perf.c if LIBCONFIG odp_ipsecfwd_SOURCES = odp_ipsecfwd.c +AM_CFLAGS += $(LIBCONFIG_CFLAGS) endif # l2fwd test depends on generator example -- cgit v1.2.3 From 29803e20c688c6afc23166bd31431aa79a3f6e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jere=20Lepp=C3=A4nen?= Date: Wed, 14 Jun 2023 14:05:43 +0300 Subject: validation: timer: test periodic timer re-use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cancel an active periodic timer, wait for the last timeout, and then start the timer again. Signed-off-by: Jere Leppänen Reviewed-by: Petri Savolainen --- test/validation/api/timer/timer.c | 197 ++++++++++++++++++++------------------ 1 file changed, 106 insertions(+), 91 deletions(-) (limited to 'test') diff --git a/test/validation/api/timer/timer.c b/test/validation/api/timer/timer.c index dad99ab41..bba5390bb 100644 --- a/test/validation/api/timer/timer.c +++ b/test/validation/api/timer/timer.c @@ -2701,7 +2701,7 @@ static void timer_test_periodic_capa(void) } } -static void timer_test_periodic(odp_queue_type_t queue_type, int use_first) +static void timer_test_periodic(odp_queue_type_t queue_type, int use_first, int rounds) { odp_timer_capability_t timer_capa; odp_timer_periodic_capability_t periodic_capa; @@ -2720,8 +2720,8 @@ static void timer_test_periodic(odp_queue_type_t queue_type, int use_first) double freq, freq_out, min_freq, max_freq; int ret; const char *user_ctx = "User context"; - int num_tmo = 0; - int done = 0; + int num_tmo; + int done; const int num = 200; /* Test frequency: 1x 100Hz, or 1x min/max_base_freq */ const uint64_t multiplier = 1; @@ -2829,127 +2829,135 @@ static void timer_test_periodic(odp_queue_type_t queue_type, int use_first) queue = odp_queue_create("timeout_queue", &queue_param); CU_ASSERT_FATAL(queue != ODP_QUEUE_INVALID); - tmo = odp_timeout_alloc(pool); - ev = odp_timeout_to_event(tmo); - CU_ASSERT_FATAL(ev != ODP_EVENT_INVALID); - timer = odp_timer_alloc(timer_pool, queue, user_ctx); CU_ASSERT_FATAL(timer != ODP_TIMER_INVALID); memset(&start_param, 0, sizeof(odp_timer_periodic_start_t)); - cur_tick = odp_timer_current_tick(timer_pool); offset_ns = period_ns / 2; - tick = cur_tick + odp_timer_ns_to_tick(timer_pool, offset_ns); if (use_first) { /* First tick moves timer to start before the first period */ duration_ns -= (period_ns - offset_ns); - start_param.first_tick = tick; } - start_param.freq_multiplier = multiplier; - start_param.tmo_ev = ev; + for (int round = 0; round < rounds; round++) { + num_tmo = 0; + done = 0; - ODPH_DBG("Periodic timer start:\n"); - ODPH_DBG(" Current tick: %" PRIu64 "\n", cur_tick); - ODPH_DBG(" First tick: %" PRIu64 "\n", start_param.first_tick); - ODPH_DBG(" Multiplier: %" PRIu64 "\n", start_param.freq_multiplier); - ODPH_DBG(" Period: %" PRIu64 " nsec\n", period_ns); - ODPH_DBG("Expected duration: %" PRIu64 " nsec\n", duration_ns); + tmo = odp_timeout_alloc(pool); + ev = odp_timeout_to_event(tmo); + CU_ASSERT_FATAL(ev != ODP_EVENT_INVALID); - ret = odp_timer_periodic_start(timer, &start_param); + cur_tick = odp_timer_current_tick(timer_pool); + tick = cur_tick + odp_timer_ns_to_tick(timer_pool, offset_ns); - if (ret == ODP_TIMER_TOO_NEAR) - ODPH_ERR("First tick too near\n"); - else if (ret == ODP_TIMER_TOO_FAR) - ODPH_ERR("First tick too far\n"); - else if (ret == ODP_TIMER_FAIL) - ODPH_ERR("Periodic timer start failed\n"); + if (use_first) + start_param.first_tick = tick; - CU_ASSERT_FATAL(ret == ODP_TIMER_SUCCESS); + start_param.freq_multiplier = multiplier; + start_param.tmo_ev = ev; - t1 = odp_time_local(); + ODPH_DBG("Periodic timer start:\n"); + ODPH_DBG(" Current tick: %" PRIu64 "\n", cur_tick); + ODPH_DBG(" First tick: %" PRIu64 "\n", start_param.first_tick); + ODPH_DBG(" Multiplier: %" PRIu64 "\n", start_param.freq_multiplier); + ODPH_DBG(" Period: %" PRIu64 " nsec\n", period_ns); + ODPH_DBG("Expected duration: %" PRIu64 " nsec\n", duration_ns); - /* Wait for timeouts. Make sure that scheduler context is not held when - * exiting the loop. */ - while (1) { - if (queue_type == ODP_QUEUE_TYPE_SCHED) - ev = odp_schedule(NULL, ODP_SCHED_NO_WAIT); - else - ev = odp_queue_deq(queue); + ret = odp_timer_periodic_start(timer, &start_param); - if (ev == ODP_EVENT_INVALID) { - t2 = odp_time_local(); - diff_ns = odp_time_diff_ns(t2, t1); - if (diff_ns > (10 * duration_ns)) - break; + if (ret == ODP_TIMER_TOO_NEAR) + ODPH_ERR("First tick too near\n"); + else if (ret == ODP_TIMER_TOO_FAR) + ODPH_ERR("First tick too far\n"); + else if (ret == ODP_TIMER_FAIL) + ODPH_ERR("Periodic timer start failed\n"); - if (num_tmo >= num) - break; + CU_ASSERT_FATAL(ret == ODP_TIMER_SUCCESS); - continue; - } + t1 = odp_time_local(); - CU_ASSERT(odp_event_type(ev) == ODP_EVENT_TIMEOUT); + /* Wait for timeouts. Make sure that scheduler context is not held when + * exiting the loop. */ + while (1) { + if (queue_type == ODP_QUEUE_TYPE_SCHED) + ev = odp_schedule(NULL, ODP_SCHED_NO_WAIT); + else + ev = odp_queue_deq(queue); - if (odp_event_type(ev) != ODP_EVENT_TIMEOUT) { - odp_event_free(ev); - continue; - } + if (ev == ODP_EVENT_INVALID) { + t2 = odp_time_local(); + diff_ns = odp_time_diff_ns(t2, t1); + if (diff_ns > (10 * duration_ns)) + break; - CU_ASSERT(odp_timer_periodic_ack(timer, ev) == 0); - num_tmo++; - } + if (num_tmo >= num) + break; - CU_ASSERT(num_tmo == num); + continue; + } - /* Allow +-30% error on test duration */ - CU_ASSERT((diff_ns > 0.7 * duration_ns) && (diff_ns < 1.3 * duration_ns)); + CU_ASSERT(odp_event_type(ev) == ODP_EVENT_TIMEOUT); - /* Stop periodic timer */ - ret = odp_timer_periodic_cancel(timer); - CU_ASSERT_FATAL(ret == 0); + if (odp_event_type(ev) != ODP_EVENT_TIMEOUT) { + odp_event_free(ev); + continue; + } - ODPH_DBG("Measured duration: %" PRIu64 " nsec\n", diff_ns); + CU_ASSERT(odp_timer_periodic_ack(timer, ev) == 0); + num_tmo++; + } - t1 = odp_time_local(); - while (1) { - if (queue_type == ODP_QUEUE_TYPE_SCHED) - ev = odp_schedule(NULL, ODP_SCHED_NO_WAIT); - else - ev = odp_queue_deq(queue); + CU_ASSERT(num_tmo == num); - if (ev == ODP_EVENT_INVALID) { - t2 = odp_time_local(); - diff_ns = odp_time_diff_ns(t2, t1); - if (diff_ns > (10 * duration_ns)) - break; + /* Allow +-30% error on test duration */ + CU_ASSERT((diff_ns > 0.7 * duration_ns) && (diff_ns < 1.3 * duration_ns)); - if (done) - break; + /* Stop periodic timer */ + ret = odp_timer_periodic_cancel(timer); + CU_ASSERT_FATAL(ret == 0); - continue; - } + ODPH_DBG("Measured duration: %" PRIu64 " nsec\n", diff_ns); - CU_ASSERT(odp_event_type(ev) == ODP_EVENT_TIMEOUT); + t1 = odp_time_local(); + while (1) { + if (queue_type == ODP_QUEUE_TYPE_SCHED) + ev = odp_schedule(NULL, ODP_SCHED_NO_WAIT); + else + ev = odp_queue_deq(queue); - if (odp_event_type(ev) != ODP_EVENT_TIMEOUT) { - odp_event_free(ev); - continue; - } + if (ev == ODP_EVENT_INVALID) { + t2 = odp_time_local(); + diff_ns = odp_time_diff_ns(t2, t1); + if (diff_ns > (10 * duration_ns)) + break; - ret = odp_timer_periodic_ack(timer, ev); - CU_ASSERT(ret == 1 || ret == 2); + if (done) + break; - if (ret == 2) { - odp_event_free(ev); - done = 1; + continue; + } + + CU_ASSERT(odp_event_type(ev) == ODP_EVENT_TIMEOUT); + + if (odp_event_type(ev) != ODP_EVENT_TIMEOUT) { + odp_event_free(ev); + continue; + } + + ret = odp_timer_periodic_ack(timer, ev); + CU_ASSERT(ret == 1 || ret == 2); + + if (ret == 2) { + odp_event_free(ev); + done = 1; + } } - } - /* Check that ack() returned 2 on the last event */ - CU_ASSERT(done); - CU_ASSERT(ret == 2); + /* Check that ack() returned 2 on the last event */ + CU_ASSERT(done); + CU_ASSERT(ret == 2); + } CU_ASSERT(odp_timer_free(timer) == ODP_EVENT_INVALID); odp_timer_pool_destroy(timer_pool); @@ -2959,22 +2967,27 @@ static void timer_test_periodic(odp_queue_type_t queue_type, int use_first) static void timer_test_periodic_sched(void) { - timer_test_periodic(ODP_QUEUE_TYPE_SCHED, 0); + timer_test_periodic(ODP_QUEUE_TYPE_SCHED, 0, 1); } static void timer_test_periodic_plain(void) { - timer_test_periodic(ODP_QUEUE_TYPE_PLAIN, 0); + timer_test_periodic(ODP_QUEUE_TYPE_PLAIN, 0, 1); } static void timer_test_periodic_sched_first(void) { - timer_test_periodic(ODP_QUEUE_TYPE_SCHED, FIRST_TICK); + timer_test_periodic(ODP_QUEUE_TYPE_SCHED, FIRST_TICK, 1); } static void timer_test_periodic_plain_first(void) { - timer_test_periodic(ODP_QUEUE_TYPE_PLAIN, FIRST_TICK); + timer_test_periodic(ODP_QUEUE_TYPE_PLAIN, FIRST_TICK, 1); +} + +static void timer_test_periodic_reuse(void) +{ + timer_test_periodic(ODP_QUEUE_TYPE_SCHED, 0, 2); } odp_testinfo_t timer_suite[] = { @@ -3062,6 +3075,8 @@ odp_testinfo_t timer_suite[] = { check_periodic_plain_support), ODP_TEST_INFO_CONDITIONAL(timer_test_periodic_plain_first, check_periodic_plain_support), + ODP_TEST_INFO_CONDITIONAL(timer_test_periodic_reuse, + check_periodic_sched_support), ODP_TEST_INFO_NULL, }; -- cgit v1.2.3 From d6059228fedfc3d5b6a263afa50207c90daf318e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jere=20Lepp=C3=A4nen?= Date: Wed, 14 Jun 2023 16:17:07 +0300 Subject: validation: timer: test timer re-use with different event types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a timer expires, start the timer again. Test this with timeout, buffer and packet events. Signed-off-by: Jere Leppänen Reviewed-by: Petri Savolainen --- test/validation/api/timer/timer.c | 153 ++++++++++++++++++++++---------------- 1 file changed, 89 insertions(+), 64 deletions(-) (limited to 'test') diff --git a/test/validation/api/timer/timer.c b/test/validation/api/timer/timer.c index bba5390bb..8becddc9c 100644 --- a/test/validation/api/timer/timer.c +++ b/test/validation/api/timer/timer.c @@ -1323,7 +1323,7 @@ static void timer_pool_tick_info(void) } static void timer_test_event_type(odp_queue_type_t queue_type, - odp_event_type_t event_type) + odp_event_type_t event_type, int rounds) { odp_pool_t pool; odp_pool_param_t pool_param; @@ -1401,79 +1401,83 @@ static void timer_test_event_type(odp_queue_type_t queue_type, ODPH_DBG(" user_ptr %p\n\n", (const void *)user_ctx); for (i = 0; i < num; i++) { - if (event_type == ODP_EVENT_BUFFER) { - buf = odp_buffer_alloc(pool); - ev = odp_buffer_to_event(buf); - } else if (event_type == ODP_EVENT_PACKET) { - pkt = odp_packet_alloc(pool, 10); - ev = odp_packet_to_event(pkt); - } else { - tmo = odp_timeout_alloc(pool); - ev = odp_timeout_to_event(tmo); - } - - CU_ASSERT(ev != ODP_EVENT_INVALID); - timer[i] = odp_timer_alloc(timer_pool, queue, user_ctx); CU_ASSERT_FATAL(timer[i] != ODP_TIMER_INVALID); - - start_param.tick_type = ODP_TIMER_TICK_REL; - start_param.tick = (i + 1) * period_tick; - start_param.tmo_ev = ev; - - ret = odp_timer_start(timer[i], &start_param); - - if (ret == ODP_TIMER_TOO_NEAR) - ODPH_DBG("Timer set failed. Too near %i.\n", i); - else if (ret == ODP_TIMER_TOO_FAR) - ODPH_DBG("Timer set failed. Too far %i.\n", i); - else if (ret == ODP_TIMER_FAIL) - ODPH_DBG("Timer set failed %i\n", i); - - CU_ASSERT(ret == ODP_TIMER_SUCCESS); } - if (test_print) { - printf("\n"); - odp_timer_pool_print(timer_pool); - odp_timer_print(timer[0]); - } + for (int round = 0; round < rounds; round++) { + for (i = 0; i < num; i++) { + if (event_type == ODP_EVENT_BUFFER) { + buf = odp_buffer_alloc(pool); + ev = odp_buffer_to_event(buf); + } else if (event_type == ODP_EVENT_PACKET) { + pkt = odp_packet_alloc(pool, 10); + ev = odp_packet_to_event(pkt); + } else { + tmo = odp_timeout_alloc(pool); + ev = odp_timeout_to_event(tmo); + } - ev = ODP_EVENT_INVALID; - num_tmo = 0; - t1 = odp_time_local(); + CU_ASSERT(ev != ODP_EVENT_INVALID); - /* Wait for timers. Make sure that scheduler context is not held when - * exiting the loop. */ - do { - if (queue_type == ODP_QUEUE_TYPE_SCHED) - ev = odp_schedule(NULL, ODP_SCHED_NO_WAIT); - else - ev = odp_queue_deq(queue); + start_param.tick_type = ODP_TIMER_TICK_REL; + start_param.tick = (i + 1) * period_tick; + start_param.tmo_ev = ev; - if (ev == ODP_EVENT_INVALID) { - t2 = odp_time_local(); - if (odp_time_diff_ns(t2, t1) > (10 * duration_ns)) - break; + ret = odp_timer_start(timer[i], &start_param); - continue; - } + if (ret == ODP_TIMER_TOO_NEAR) + ODPH_DBG("Timer set failed. Too near %i.\n", i); + else if (ret == ODP_TIMER_TOO_FAR) + ODPH_DBG("Timer set failed. Too far %i.\n", i); + else if (ret == ODP_TIMER_FAIL) + ODPH_DBG("Timer set failed %i\n", i); - CU_ASSERT(odp_event_type(ev) == event_type); + CU_ASSERT(ret == ODP_TIMER_SUCCESS); + } if (test_print) { - test_print = 0; - tmo = odp_timeout_from_event(ev); - odp_timeout_print(tmo); printf("\n"); + odp_timer_pool_print(timer_pool); + odp_timer_print(timer[0]); } - odp_event_free(ev); - num_tmo++; + ev = ODP_EVENT_INVALID; + num_tmo = 0; + t1 = odp_time_local(); - } while (num_tmo < num || ev != ODP_EVENT_INVALID); + /* Wait for timers. Make sure that scheduler context is not held when + * exiting the loop. */ + do { + if (queue_type == ODP_QUEUE_TYPE_SCHED) + ev = odp_schedule(NULL, ODP_SCHED_NO_WAIT); + else + ev = odp_queue_deq(queue); - CU_ASSERT(num_tmo == num); + if (ev == ODP_EVENT_INVALID) { + t2 = odp_time_local(); + if (odp_time_diff_ns(t2, t1) > (10 * duration_ns)) + break; + + continue; + } + + CU_ASSERT(odp_event_type(ev) == event_type); + + if (test_print) { + test_print = 0; + tmo = odp_timeout_from_event(ev); + odp_timeout_print(tmo); + printf("\n"); + } + + odp_event_free(ev); + num_tmo++; + + } while (num_tmo < num || ev != ODP_EVENT_INVALID); + + CU_ASSERT(num_tmo == num); + } for (i = 0; i < num; i++) CU_ASSERT(odp_timer_free(timer[i]) == ODP_EVENT_INVALID); @@ -1485,32 +1489,47 @@ static void timer_test_event_type(odp_queue_type_t queue_type, static void timer_test_tmo_event_plain(void) { - timer_test_event_type(ODP_QUEUE_TYPE_PLAIN, ODP_EVENT_TIMEOUT); + timer_test_event_type(ODP_QUEUE_TYPE_PLAIN, ODP_EVENT_TIMEOUT, 1); } static void timer_test_tmo_event_sched(void) { - timer_test_event_type(ODP_QUEUE_TYPE_SCHED, ODP_EVENT_TIMEOUT); + timer_test_event_type(ODP_QUEUE_TYPE_SCHED, ODP_EVENT_TIMEOUT, 1); } static void timer_test_buf_event_plain(void) { - timer_test_event_type(ODP_QUEUE_TYPE_PLAIN, ODP_EVENT_BUFFER); + timer_test_event_type(ODP_QUEUE_TYPE_PLAIN, ODP_EVENT_BUFFER, 1); } static void timer_test_buf_event_sched(void) { - timer_test_event_type(ODP_QUEUE_TYPE_SCHED, ODP_EVENT_BUFFER); + timer_test_event_type(ODP_QUEUE_TYPE_SCHED, ODP_EVENT_BUFFER, 1); } static void timer_test_pkt_event_plain(void) { - timer_test_event_type(ODP_QUEUE_TYPE_PLAIN, ODP_EVENT_PACKET); + timer_test_event_type(ODP_QUEUE_TYPE_PLAIN, ODP_EVENT_PACKET, 1); } static void timer_test_pkt_event_sched(void) { - timer_test_event_type(ODP_QUEUE_TYPE_SCHED, ODP_EVENT_PACKET); + timer_test_event_type(ODP_QUEUE_TYPE_SCHED, ODP_EVENT_PACKET, 1); +} + +static void timer_test_tmo_event_reuse(void) +{ + timer_test_event_type(ODP_QUEUE_TYPE_SCHED, ODP_EVENT_TIMEOUT, 2); +} + +static void timer_test_buf_event_reuse(void) +{ + timer_test_event_type(ODP_QUEUE_TYPE_SCHED, ODP_EVENT_BUFFER, 2); +} + +static void timer_test_pkt_event_reuse(void) +{ + timer_test_event_type(ODP_QUEUE_TYPE_SCHED, ODP_EVENT_PACKET, 2); } static void timer_test_queue_type(odp_queue_type_t queue_type, int priv, int exp_relax) @@ -3032,6 +3051,12 @@ odp_testinfo_t timer_suite[] = { check_plain_queue_support), ODP_TEST_INFO_CONDITIONAL(timer_test_pkt_event_sched, check_sched_queue_support), + ODP_TEST_INFO_CONDITIONAL(timer_test_tmo_event_reuse, + check_sched_queue_support), + ODP_TEST_INFO_CONDITIONAL(timer_test_buf_event_reuse, + check_sched_queue_support), + ODP_TEST_INFO_CONDITIONAL(timer_test_pkt_event_reuse, + check_sched_queue_support), ODP_TEST_INFO(timer_test_cancel), ODP_TEST_INFO_CONDITIONAL(timer_test_max_res_min_tmo_plain, check_plain_queue_support), -- cgit v1.2.3 From a61183da473f281eaaceabd856703027fe75804e Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Fri, 16 Jun 2023 14:32:47 +0300 Subject: test: stress: fix maybe-uninitialized error from gcc-13 Avoid invalid maybe-uninitialized error from GCC 13.1, when ODP is configured with debug mode enabled. Signed-off-by: Matias Elo Reviewed-by: Petri Savolainen Reported-by: Carl Wallen --- test/performance/odp_stress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/performance/odp_stress.c b/test/performance/odp_stress.c index 15b44c113..d5e3142f6 100644 --- a/test/performance/odp_stress.c +++ b/test/performance/odp_stress.c @@ -213,7 +213,7 @@ static int worker_thread(void *arg) odp_timer_start_t start_param; odp_time_t t1, t2, max_time; odp_time_t work_t1, work_t2; - uint8_t *src, *dst; + uint8_t *src = NULL, *dst = NULL; thread_arg_t *thread_arg = arg; int worker_idx = thread_arg->worker_idx; test_global_t *global = thread_arg->global; -- cgit v1.2.3 From f19642434e62248471996274aabb73a799c1a6ad Mon Sep 17 00:00:00 2001 From: Petri Savolainen Date: Fri, 30 Jun 2023 15:44:16 +0300 Subject: validation: time: improve time monotony test Add strict time stamp monotony tests. Check that strict time stamp calls maintain their order. Check that time keeping starts from zero. Check that converted nsec time and nsec time function calls use the same time base (values are close enough). Signed-off-by: Petri Savolainen Reviewed-by: Matias Elo --- test/validation/api/time/time.c | 145 +++++++++++++++++++++++++++++++++------- 1 file changed, 122 insertions(+), 23 deletions(-) (limited to 'test') diff --git a/test/validation/api/time/time.c b/test/validation/api/time/time.c index 22189ce03..7664ec542 100644 --- a/test/validation/api/time/time.c +++ b/test/validation/api/time/time.c @@ -216,58 +216,157 @@ static void time_test_monotony(void) { volatile uint64_t count = 0; odp_time_t l_t1, l_t2, l_t3; + odp_time_t ls_t1, ls_t2, ls_t3; odp_time_t g_t1, g_t2, g_t3; - uint64_t lns_t1, lns_t2, lns_t3; - uint64_t gns_t1, gns_t2, gns_t3; + odp_time_t gs_t1, gs_t2, gs_t3; + uint64_t l_ns1, l_ns2, l_ns3; + uint64_t ls_ns1, ls_ns2, ls_ns3; + uint64_t g_ns1, g_ns2, g_ns3; + uint64_t gs_ns1, gs_ns2, gs_ns3; uint64_t ns1, ns2, ns3; + uint64_t s_ns1, s_ns2, s_ns3; - l_t1 = odp_time_local(); - g_t1 = odp_time_global(); - lns_t1 = odp_time_local_ns(); - gns_t1 = odp_time_global_ns(); + l_t1 = odp_time_local(); + ls_t1 = odp_time_local_strict(); + l_ns1 = odp_time_local_ns(); + ls_ns1 = odp_time_local_strict_ns(); + + g_t1 = odp_time_global(); + gs_t1 = odp_time_global_strict(); + g_ns1 = odp_time_global_ns(); + gs_ns1 = odp_time_global_strict_ns(); while (count < BUSY_LOOP_CNT) { count++; }; - l_t2 = odp_time_local(); - g_t2 = odp_time_global(); - lns_t2 = odp_time_local_ns(); - gns_t2 = odp_time_global_ns(); + l_t2 = odp_time_local(); + ls_t2 = odp_time_local_strict(); + l_ns2 = odp_time_local_ns(); + ls_ns2 = odp_time_local_strict_ns(); + + g_t2 = odp_time_global(); + gs_t2 = odp_time_global_strict(); + g_ns2 = odp_time_global_ns(); + gs_ns2 = odp_time_global_strict_ns(); count = 0; while (count < BUSY_LOOP_CNT) { count++; }; - l_t3 = odp_time_local(); - g_t3 = odp_time_global(); - lns_t3 = odp_time_local_ns(); - gns_t3 = odp_time_global_ns(); + l_t3 = odp_time_local(); + ls_t3 = odp_time_local_strict(); + l_ns3 = odp_time_local_ns(); + ls_ns3 = odp_time_local_strict_ns(); + + g_t3 = odp_time_global(); + gs_t3 = odp_time_global_strict(); + g_ns3 = odp_time_global_ns(); + gs_ns3 = odp_time_global_strict_ns(); + + /* Local time tests + * ---------------- */ ns1 = odp_time_to_ns(l_t1); ns2 = odp_time_to_ns(l_t2); ns3 = odp_time_to_ns(l_t3); - /* Local time assertions */ + s_ns1 = odp_time_to_ns(ls_t1); + s_ns2 = odp_time_to_ns(ls_t2); + s_ns3 = odp_time_to_ns(ls_t3); + + /* Time counting starts from zero. Assuming that the ODP instance has run + * less than 10 minutes before running this test case. */ + CU_ASSERT(ns1 < 10 * ODP_TIME_MIN_IN_NS); + CU_ASSERT(s_ns1 < 10 * ODP_TIME_MIN_IN_NS); + CU_ASSERT(l_ns1 < 10 * ODP_TIME_MIN_IN_NS); + CU_ASSERT(ls_ns1 < 10 * ODP_TIME_MIN_IN_NS); + + /* Time stamp */ CU_ASSERT(ns2 > ns1); CU_ASSERT(ns3 > ns2); + /* Strict time stamp */ + CU_ASSERT(s_ns2 > s_ns1); + CU_ASSERT(s_ns3 > s_ns2); + + /* Nsec time */ + CU_ASSERT(l_ns2 > l_ns1); + CU_ASSERT(l_ns3 > l_ns2); + + /* Strict nsec time */ + CU_ASSERT(ls_ns2 > ls_ns1); + CU_ASSERT(ls_ns3 > ls_ns2); + + /* Strict time stamp order is maintained */ + CU_ASSERT(ls_ns1 >= s_ns1); + CU_ASSERT(ls_ns2 >= s_ns2); + CU_ASSERT(ls_ns3 >= s_ns3); + + /* Time in nanoseconds have the same time base. Allow less than 100 msec error + * between time stamp converted to nsec and nsec time. */ + CU_ASSERT((ls_ns1 - s_ns1) < (100 * ODP_TIME_MSEC_IN_NS)); + CU_ASSERT((ls_ns2 - s_ns2) < (100 * ODP_TIME_MSEC_IN_NS)); + CU_ASSERT((ls_ns3 - s_ns3) < (100 * ODP_TIME_MSEC_IN_NS)); + + /* Global time tests + * ----------------- */ + ns1 = odp_time_to_ns(g_t1); ns2 = odp_time_to_ns(g_t2); ns3 = odp_time_to_ns(g_t3); - /* Global time assertions */ + s_ns1 = odp_time_to_ns(gs_t1); + s_ns2 = odp_time_to_ns(gs_t2); + s_ns3 = odp_time_to_ns(gs_t3); + + /* Time counting starts from zero. Assuming that the ODP instance has run + * less than 10 minutes before running this test case. */ + CU_ASSERT(ns1 < 10 * ODP_TIME_MIN_IN_NS); + CU_ASSERT(s_ns1 < 10 * ODP_TIME_MIN_IN_NS); + CU_ASSERT(g_ns1 < 10 * ODP_TIME_MIN_IN_NS); + CU_ASSERT(gs_ns1 < 10 * ODP_TIME_MIN_IN_NS); + + /* Time stamp */ CU_ASSERT(ns2 > ns1); CU_ASSERT(ns3 > ns2); - /* Local time in nsec */ - CU_ASSERT(lns_t2 > lns_t1); - CU_ASSERT(lns_t3 > lns_t2); - - /* Global time in nsec */ - CU_ASSERT(gns_t2 > gns_t1); - CU_ASSERT(gns_t3 > gns_t2); + /* Strict time stamp */ + CU_ASSERT(s_ns2 > s_ns1); + CU_ASSERT(s_ns3 > s_ns2); + + /* Nsec time */ + CU_ASSERT(g_ns2 > g_ns1); + CU_ASSERT(g_ns3 > g_ns2); + + /* Strict nsec time */ + CU_ASSERT(gs_ns2 > gs_ns1); + CU_ASSERT(gs_ns3 > gs_ns2); + + /* Strict time stamp order is maintained */ + CU_ASSERT(gs_ns1 >= s_ns1); + CU_ASSERT(gs_ns2 >= s_ns2); + CU_ASSERT(gs_ns3 >= s_ns3); + + /* Time in nanoseconds have the same time base. Allow less than 100 msec error + * between time stamp converted to nsec and nsec time. */ + CU_ASSERT((gs_ns1 - s_ns1) < (100 * ODP_TIME_MSEC_IN_NS)); + CU_ASSERT((gs_ns2 - s_ns2) < (100 * ODP_TIME_MSEC_IN_NS)); + CU_ASSERT((gs_ns3 - s_ns3) < (100 * ODP_TIME_MSEC_IN_NS)); + + /* Tight error margin cannot be used due to possible OS interrupts during the test. + * Record all time stamp values into the log to help debugging their relative order and + * accuracy. */ + printf("\n Time stamp values in nsec:\n"); + printf(" odp_time_local(): %" PRIu64 "\n", odp_time_to_ns(l_t1)); + printf(" odp_time_local_strict(): %" PRIu64 "\n", odp_time_to_ns(ls_t1)); + printf(" odp_time_local_ns(): %" PRIu64 "\n", l_ns1); + printf(" odp_time_local_strict_ns(): %" PRIu64 "\n", ls_ns1); + printf(" odp_time_global(): %" PRIu64 "\n", odp_time_to_ns(g_t1)); + printf(" odp_time_global_strict(): %" PRIu64 "\n", odp_time_to_ns(gs_t1)); + printf(" odp_time_global_ns(): %" PRIu64 "\n", g_ns1); + printf(" odp_time_global_strict_ns(): %" PRIu64 "\n\n", gs_ns1); } static void time_test_cmp(time_cb time_cur, time_from_ns_cb time_from_ns) -- cgit v1.2.3 From e99c7f11409bd9f353beae793d1aef5677c370e8 Mon Sep 17 00:00:00 2001 From: Janne Peltonen Date: Tue, 4 Jul 2023 11:04:05 +0300 Subject: validation: crypto: fix hash_result_in_auth_range flag in bit mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The range comparison that checks whether hash result location overlaps auth range incorrectly assumes that auth range is always in bytes. Since current linux-gen does not support bit mode auths, the bug went unnoticed. Fix the bug by scaling the hash result location to the right range units in the comparison. Signed-off-by: Janne Peltonen Reviewed-by: Jere Leppänen --- test/validation/api/crypto/odp_crypto_test_inp.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index d7e2bd16b..e6a6dca82 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -254,6 +254,7 @@ static void alg_test_ses(odp_crypto_op_t op, { unsigned int initial_num_failures = CU_get_number_of_failures(); const uint32_t reflength = ref_length_in_bytes(ref); + const uint32_t auth_scale = is_bit_mode_auth ? 8 : 1; hash_test_mode_t hash_mode = HASH_NO_OVERLAP; odp_crypto_session_t session; int rc; @@ -261,8 +262,8 @@ static void alg_test_ses(odp_crypto_op_t op, uint32_t max_shift; crypto_op_test_param_t test_param; - if (digest_offset >= auth_range.offset && - digest_offset < auth_range.offset + auth_range.length) + if (digest_offset * auth_scale >= auth_range.offset && + digest_offset * auth_scale < auth_range.offset + auth_range.length) hash_mode = HASH_OVERLAP; session = session_create(op, op_type, order, ref, hash_mode); -- cgit v1.2.3 From 35859896bfac4cc8266d7d1cf7bf7e14e48d5205 Mon Sep 17 00:00:00 2001 From: Janne Peltonen Date: Tue, 4 Jul 2023 11:04:07 +0300 Subject: validation: crypto: fix checking if hash result is in cipher range MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The validation test allows certain crypto operation failures when the hash location is within the cipher range. Checking whether the hash location is in the cipher range does not work correctly if the cipher is in bit mode, resulting in the validation test being stricter than intended in certain cases. Fix the logic of checking whether the hash is in the cipher range. Signed-off-by: Janne Peltonen Reviewed-by: Jere Leppänen --- test/validation/api/crypto/crypto_op_test.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/validation/api/crypto/crypto_op_test.c b/test/validation/api/crypto/crypto_op_test.c index 4ad333488..ffb65aada 100644 --- a/test/validation/api/crypto/crypto_op_test.c +++ b/test/validation/api/crypto/crypto_op_test.c @@ -472,6 +472,23 @@ static void check_output_packet_data(odp_packet_t pkt, expected_t *ex) } } +static int is_digest_in_cipher_range(const crypto_op_test_param_t *param, + const odp_crypto_packet_op_param_t *op_params) +{ + /* + * Do not use op_params.hash_result_offset here as it refers to + * the output packet which (in the OOP case) might be shifted + * relative to the input packet. + */ + uint32_t d_offset = param->digest_offset; + + if (param->is_bit_mode_cipher) + d_offset *= 8; + + return d_offset >= op_params->cipher_range.offset && + d_offset < op_params->cipher_range.offset + op_params->cipher_range.length; +} + void test_crypto_op(const crypto_op_test_param_t *param) { odp_bool_t ok = false; @@ -548,8 +565,7 @@ void test_crypto_op(const crypto_op_test_param_t *param) if (param->ref->cipher != ODP_CIPHER_ALG_NULL && param->ref->auth != ODP_AUTH_ALG_NULL && - param->digest_offset >= op_params.cipher_range.offset && - param->digest_offset < op_params.cipher_range.offset + op_params.cipher_range.length) { + is_digest_in_cipher_range(param, &op_params)) { /* * Not all implementations support digest offset in cipher * range, so allow crypto op failure without further checks -- cgit v1.2.3 From 87fdba5b1666d5ff252df4916d7841fc8c4b9362 Mon Sep 17 00:00:00 2001 From: Janne Peltonen Date: Tue, 4 Jul 2023 11:04:08 +0300 Subject: validation: crypto: separate session & operation test parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Group session specific test parameters to their own structure within crypto_op_test_param_t to separate them from parameters that can vary between operations. This does not change any functionality but enhances readability. Signed-off-by: Janne Peltonen Reviewed-by: Jere Leppänen --- test/validation/api/crypto/crypto_op_test.c | 48 ++++++++++++------------ test/validation/api/crypto/crypto_op_test.h | 10 +++-- test/validation/api/crypto/odp_crypto_test_inp.c | 27 ++++++------- 3 files changed, 43 insertions(+), 42 deletions(-) (limited to 'test') diff --git a/test/validation/api/crypto/crypto_op_test.c b/test/validation/api/crypto/crypto_op_test.c index ffb65aada..33c9ab9f2 100644 --- a/test/validation/api/crypto/crypto_op_test.c +++ b/test/validation/api/crypto/crypto_op_test.c @@ -179,8 +179,8 @@ static void prepare_crypto_ranges(const crypto_op_test_param_t *param, odp_packet_data_range_t *auth_range) { odp_packet_data_range_t zero_range = {.offset = 0, .length = 0}; - uint32_t c_scale = param->is_bit_mode_cipher ? 8 : 1; - uint32_t a_scale = param->is_bit_mode_auth ? 8 : 1; + uint32_t c_scale = param->session.cipher_range_in_bits ? 8 : 1; + uint32_t a_scale = param->session.auth_range_in_bits ? 8 : 1; *cipher_range = param->cipher_range; *auth_range = param->auth_range; @@ -217,7 +217,7 @@ static int prepare_input_packet(const crypto_op_test_param_t *param, write_header_and_trailer(pkt, param->header_len, param->trailer_len); - if (param->op == ODP_CRYPTO_OP_ENCODE) { + if (param->session.op == ODP_CRYPTO_OP_ENCODE) { odp_packet_copy_from_mem(pkt, param->header_len, reflength, ref->plaintext); } else { @@ -322,7 +322,7 @@ static void prepare_ignore_info(const crypto_op_test_param_t *param, * Leftover bits in the last byte of the cipher range of bit mode * ciphers have undefined values. */ - if (param->is_bit_mode_cipher && + if (param->session.cipher_range_in_bits && param->ref->cipher != ODP_CIPHER_ALG_NULL) { uint8_t leftover_bits = ref_length_in_bits(param->ref) % 8; @@ -338,10 +338,10 @@ static void prepare_ignore_info(const crypto_op_test_param_t *param, * undefined values. */ if (param->ref->auth != ODP_AUTH_ALG_NULL && - param->op == ODP_CRYPTO_OP_DECODE) { + param->session.op == ODP_CRYPTO_OP_DECODE) { uint32_t offs = param->digest_offset; - if (param->op_type != ODP_CRYPTO_OP_TYPE_OOP || + if (param->session.op_type != ODP_CRYPTO_OP_TYPE_OOP || is_in_range(offs, cipher_offset, cipher_len) || is_in_range(offs, auth_offset, auth_len)) { add_ignored_range(ignore, @@ -351,11 +351,11 @@ static void prepare_ignore_info(const crypto_op_test_param_t *param, } /* Decrypted bytes are undefined if authentication fails. */ - if (param->op == ODP_CRYPTO_OP_DECODE && + if (param->session.op == ODP_CRYPTO_OP_DECODE && param->wrong_digest) { add_ignored_range(ignore, cipher_offset + shift, cipher_len); /* In OOP case, auth range may not get copied */ - if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP) + if (param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP) add_ignored_range(ignore, auth_offset + shift, auth_len); } } @@ -372,20 +372,22 @@ static void prepare_expected_data(const crypto_op_test_param_t *param, uint32_t cipher_len = cipher_range->length; uint32_t auth_offset = auth_range->offset; uint32_t auth_len = auth_range->length; - const int32_t shift = param->op_type == ODP_CRYPTO_OP_TYPE_OOP ? param->oop_shift : 0; - const odp_packet_t base_pkt = param->op_type == ODP_CRYPTO_OP_TYPE_OOP ? pkt_out : pkt_in; + const int32_t shift = param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP ? param->oop_shift + : 0; + const odp_packet_t base_pkt = param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP ? pkt_out + : pkt_in; int rc; uint32_t cipher_offset_in_ref = param->cipher_range.offset; - if (param->op == ODP_CRYPTO_OP_ENCODE) + if (param->session.op == ODP_CRYPTO_OP_ENCODE) digest_offset += shift; - if (param->is_bit_mode_cipher) { + if (param->session.cipher_range_in_bits) { cipher_offset_in_ref /= 8; cipher_offset /= 8; cipher_len = (cipher_len + 7) / 8; } - if (param->is_bit_mode_auth) { + if (param->session.auth_range_in_bits) { auth_offset /= 8; auth_len = (auth_len + 7) / 8; } @@ -405,14 +407,14 @@ static void prepare_expected_data(const crypto_op_test_param_t *param, rc = odp_packet_copy_to_mem(base_pkt, 0, ex->len, ex->data); CU_ASSERT(rc == 0); - if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP && auth_len > 0) { + if (param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP && auth_len > 0) { /* copy auth range from input packet */ rc = odp_packet_copy_to_mem(pkt_in, auth_offset, auth_len, ex->data + auth_offset + shift); CU_ASSERT(rc == 0); } - if (param->op == ODP_CRYPTO_OP_ENCODE) { + if (param->session.op == ODP_CRYPTO_OP_ENCODE) { /* copy hash first */ memcpy(ex->data + digest_offset, param->ref->digest, @@ -482,7 +484,7 @@ static int is_digest_in_cipher_range(const crypto_op_test_param_t *param, */ uint32_t d_offset = param->digest_offset; - if (param->is_bit_mode_cipher) + if (param->session.cipher_range_in_bits) d_offset *= 8; return d_offset >= op_params->cipher_range.offset && @@ -498,7 +500,7 @@ void test_crypto_op(const crypto_op_test_param_t *param) test_packet_md_t md_in, md_out, md_out_orig; expected_t expected; odp_crypto_packet_op_param_t op_params = { - .session = param->session, + .session = param->session.session, .cipher_iv_ptr = param->ref->cipher_iv, .auth_iv_ptr = param->ref->auth_iv, .hash_result_offset = param->digest_offset, @@ -512,14 +514,14 @@ void test_crypto_op(const crypto_op_test_param_t *param) */ if (param->wrong_digest && (param->ref->auth == ODP_AUTH_ALG_NULL || - param->op == ODP_CRYPTO_OP_ENCODE)) + param->session.op == ODP_CRYPTO_OP_ENCODE)) return; prepare_crypto_ranges(param, &op_params.cipher_range, &op_params.auth_range); if (prepare_input_packet(param, &pkt)) return; - if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP) { + if (param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP) { prepare_oop_output_packet(param, &pkt_out, odp_packet_len(pkt)); pkt_copy = odp_packet_copy(pkt, suite_context.pool); @@ -530,8 +532,8 @@ void test_crypto_op(const crypto_op_test_param_t *param) prepare_expected_data(param, &op_params.cipher_range, &op_params.auth_range, pkt, pkt_out, &expected); - if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP && - param->op == ODP_CRYPTO_OP_ENCODE) { + if (param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP && + param->session.op == ODP_CRYPTO_OP_ENCODE) { /* * In this type of sessions digest offset is an offset to the output * packet, so apply the shift. @@ -542,12 +544,12 @@ void test_crypto_op(const crypto_op_test_param_t *param) test_packet_set_md(pkt); test_packet_get_md(pkt, &md_in); - if (crypto_op(pkt, &pkt_out, &ok, &op_params, param->op_type)) + if (crypto_op(pkt, &pkt_out, &ok, &op_params, param->session.op_type)) return; test_packet_get_md(pkt_out, &md_out); - if (param->op_type == ODP_CRYPTO_OP_TYPE_OOP) { + if (param->session.op_type == ODP_CRYPTO_OP_TYPE_OOP) { test_packet_md_t md; /* check that input packet has not changed */ diff --git a/test/validation/api/crypto/crypto_op_test.h b/test/validation/api/crypto/crypto_op_test.h index 4b2f66c47..4f5957820 100644 --- a/test/validation/api/crypto/crypto_op_test.h +++ b/test/validation/api/crypto/crypto_op_test.h @@ -12,17 +12,21 @@ #include #include "test_vectors.h" -typedef struct crypto_op_test_param_t { +typedef struct crypto_session_t { odp_crypto_session_t session; odp_crypto_op_t op; odp_crypto_op_type_t op_type; + odp_bool_t cipher_range_in_bits; + odp_bool_t auth_range_in_bits; +} crypto_session_t; + +typedef struct crypto_op_test_param_t { + crypto_session_t session; int32_t oop_shift; crypto_test_reference_t *ref; odp_packet_data_range_t cipher_range; odp_packet_data_range_t auth_range; uint32_t digest_offset; - odp_bool_t is_bit_mode_cipher; - odp_bool_t is_bit_mode_auth; odp_bool_t adjust_segmentation; odp_bool_t wrong_digest; uint32_t first_seg_len; diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index e6a6dca82..86eca8e2b 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -53,15 +53,10 @@ static void test_default_values(void) static void print_alg_test_param(const crypto_op_test_param_t *p) { - const char *cipher_mode = p->is_bit_mode_cipher ? "bit" : "byte"; + const char *cipher_mode = p->session.cipher_range_in_bits ? "bit" : "byte"; + const char *auth_mode = p->session.auth_range_in_bits ? "bit" : "byte"; - - - - - const char *auth_mode = p->is_bit_mode_auth ? "bit" : "byte"; - - switch (p->op_type) { + switch (p->session.op_type) { case ODP_CRYPTO_OP_TYPE_LEGACY: printf("legacy "); break; @@ -72,7 +67,7 @@ static void print_alg_test_param(const crypto_op_test_param_t *p) printf("out-of-place "); break; } - printf("%s\n", p->op == ODP_CRYPTO_OP_ENCODE ? "encode" : "decode"); + printf("%s\n", p->session.op == ODP_CRYPTO_OP_ENCODE ? "encode" : "decode"); printf("cipher: %s, %s mode\n", cipher_alg_name(p->ref->cipher), cipher_mode); printf(" key length: %d, iv length: %d\n", @@ -93,7 +88,7 @@ static void print_alg_test_param(const crypto_op_test_param_t *p) printf("header length: %d, trailer length: %d\n", p->header_len, p->trailer_len); if (p->adjust_segmentation) printf("segmentation adjusted, first_seg_len: %d\n", p->first_seg_len); - if (p->op_type == ODP_CRYPTO_OP_TYPE_OOP) + if (p->session.op_type == ODP_CRYPTO_OP_TYPE_OOP) printf("oop_shift: %d\n", p->oop_shift); } @@ -122,7 +117,7 @@ static void alg_test_op(crypto_op_test_param_t *param) for (uint32_t n = 0; n < ARRAY_SIZE(oop_shifts); n++) { if (oop_shifts[n] != 0 && - param->op_type != ODP_CRYPTO_OP_TYPE_OOP) + param->session.op_type != ODP_CRYPTO_OP_TYPE_OOP) continue; if ((int32_t)param->header_len + oop_shifts[n] < 0) continue; @@ -271,14 +266,14 @@ static void alg_test_ses(odp_crypto_op_t op, return; memset(&test_param, 0, sizeof(test_param)); - test_param.session = session; - test_param.op = op; - test_param.op_type = op_type; + test_param.session.session = session; + test_param.session.op = op; + test_param.session.op_type = op_type; + test_param.session.cipher_range_in_bits = is_bit_mode_cipher; + test_param.session.auth_range_in_bits = is_bit_mode_auth; test_param.ref = ref; test_param.cipher_range = cipher_range; test_param.auth_range = auth_range; - test_param.is_bit_mode_cipher = is_bit_mode_cipher; - test_param.is_bit_mode_auth = is_bit_mode_auth; test_param.digest_offset = digest_offset; alg_test_op(&test_param); -- cgit v1.2.3 From 2ccd3aebb00c4af401f82ddd6763809dd49ac418 Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Tue, 27 Jun 2023 16:54:52 +0300 Subject: validation: event: add test for odp_event_user_area_and_flag() Add validation test for the new odp_event_user_area_and_flag() function. Signed-off-by: Matias Elo Reviewed-by: Petri Savolainen --- test/validation/api/buffer/buffer.c | 3 +++ test/validation/api/dma/dma.c | 3 +++ test/validation/api/ipsec/ipsec.c | 3 +++ test/validation/api/packet/packet.c | 11 +++++++++++ test/validation/api/pktio/pktio.c | 6 +++++- test/validation/api/timer/timer.c | 3 +++ 6 files changed, 28 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/validation/api/buffer/buffer.c b/test/validation/api/buffer/buffer.c index ef26ea6e0..1d0cc9d01 100644 --- a/test/validation/api/buffer/buffer.c +++ b/test/validation/api/buffer/buffer.c @@ -537,6 +537,7 @@ static void buffer_test_user_area(void) for (i = 0; i < num; i++) { odp_event_t ev; + int flag; buffer[i] = odp_buffer_alloc(pool); @@ -550,6 +551,8 @@ static void buffer_test_user_area(void) ev = odp_buffer_to_event(buffer[i]); CU_ASSERT(odp_event_user_area(ev) == addr); + CU_ASSERT(odp_event_user_area_and_flag(ev, &flag) == addr); + CU_ASSERT(flag < 0); prev = addr; memset(addr, 0, size); diff --git a/test/validation/api/dma/dma.c b/test/validation/api/dma/dma.c index 6c8eeb00c..69b6af793 100644 --- a/test/validation/api/dma/dma.c +++ b/test/validation/api/dma/dma.c @@ -432,6 +432,7 @@ static void test_dma_compl_user_area(void) for (i = 0; i < num; i++) { odp_event_t ev; + int flag; compl_evs[i] = odp_dma_compl_alloc(pool); @@ -445,6 +446,8 @@ static void test_dma_compl_user_area(void) ev = odp_dma_compl_to_event(compl_evs[i]); CU_ASSERT(odp_event_user_area(ev) == addr); + CU_ASSERT(odp_event_user_area_and_flag(ev, &flag) == addr); + CU_ASSERT(flag < 0); prev = addr; memset(addr, 0, size); diff --git a/test/validation/api/ipsec/ipsec.c b/test/validation/api/ipsec/ipsec.c index ea2685666..87688838b 100644 --- a/test/validation/api/ipsec/ipsec.c +++ b/test/validation/api/ipsec/ipsec.c @@ -447,6 +447,7 @@ static void ipsec_status_event_handle(odp_event_t ev_status, odp_ipsec_sa_t sa, enum ipsec_test_sa_expiry sa_expiry) { + int flag; odp_ipsec_status_t status = { .id = 0, .sa = ODP_IPSEC_SA_INVALID, @@ -460,6 +461,8 @@ static void ipsec_status_event_handle(odp_event_t ev_status, /* No user area for IPsec status events */ CU_ASSERT(odp_event_user_area(ev_status) == NULL); + CU_ASSERT(odp_event_user_area_and_flag(ev_status, &flag) == NULL); + CU_ASSERT(flag < 0); CU_ASSERT_EQUAL(0, odp_ipsec_status(&status, ev_status)); CU_ASSERT_EQUAL(ODP_IPSEC_STATUS_WARN, status.id); diff --git a/test/validation/api/packet/packet.c b/test/validation/api/packet/packet.c index 4f087c5a0..b7a4d14cf 100644 --- a/test/validation/api/packet/packet.c +++ b/test/validation/api/packet/packet.c @@ -3268,6 +3268,7 @@ static void packet_vector_test_user_area(void) for (i = 0; i < num; i++) { odp_event_t ev; + int flag; pktv[i] = odp_packet_vector_alloc(pool); @@ -3281,6 +3282,8 @@ static void packet_vector_test_user_area(void) ev = odp_packet_vector_to_event(pktv[i]); CU_ASSERT(odp_event_user_area(ev) == addr); + CU_ASSERT(odp_event_user_area_and_flag(ev, &flag) == addr); + CU_ASSERT(flag == 0); prev = addr; memset(addr, 0, size); @@ -3454,6 +3457,7 @@ static void packet_test_user_area(void) odp_packet_t pkt; odp_pool_t pool; odp_event_t ev; + int flag; memcpy(¶m, &default_param, sizeof(odp_pool_param_t)); @@ -3471,6 +3475,8 @@ static void packet_test_user_area(void) } ev = odp_packet_to_event(pkt); CU_ASSERT(odp_event_user_area(ev) == odp_packet_user_area(pkt)); + CU_ASSERT(odp_event_user_area_and_flag(ev, &flag) == odp_packet_user_area(pkt)); + CU_ASSERT(flag == 0); odp_packet_free(pkt); CU_ASSERT(odp_pool_destroy(pool) == 0); @@ -3486,6 +3492,8 @@ static void packet_test_user_area(void) CU_ASSERT_FATAL(odp_packet_user_area(pkt) != NULL); ev = odp_packet_to_event(pkt); CU_ASSERT(odp_event_user_area(ev) == odp_packet_user_area(pkt)); + CU_ASSERT(odp_event_user_area_and_flag(ev, &flag) == odp_packet_user_area(pkt)); + CU_ASSERT(flag == 0); 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); @@ -3497,9 +3505,12 @@ static void packet_test_user_area(void) CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); pkt = odp_packet_alloc(pool, param.pkt.len); CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); + odp_packet_user_flag_set(pkt, 1); CU_ASSERT_FATAL(odp_packet_user_area(pkt) != NULL); ev = odp_packet_to_event(pkt); CU_ASSERT(odp_event_user_area(ev) == odp_packet_user_area(pkt)); + CU_ASSERT(odp_event_user_area_and_flag(ev, &flag) == odp_packet_user_area(pkt)); + CU_ASSERT(flag > 0); 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); diff --git a/test/validation/api/pktio/pktio.c b/test/validation/api/pktio/pktio.c index f412a01c4..fa752c0a2 100644 --- a/test/validation/api/pktio/pktio.c +++ b/test/validation/api/pktio/pktio.c @@ -3513,7 +3513,7 @@ static void pktio_test_pktout_compl_event(bool use_plain_queue) pktio_info_t pktio_rx_info; odp_pktio_config_t config; odp_queue_param_t qparam; - int ret, i, num_rx = 0; + int flag, ret, i, num_rx = 0; odp_event_t ev; uint64_t wait; @@ -3647,6 +3647,8 @@ static void pktio_test_pktout_compl_event(bool use_plain_queue) /* No user area for TX completion events */ CU_ASSERT(odp_event_user_area(ev) == NULL); + CU_ASSERT(odp_event_user_area_and_flag(ev, &flag) == NULL); + CU_ASSERT(flag < 0); /* Alternatively call event free / compl free */ if (i % 2) @@ -3685,6 +3687,8 @@ static void pktio_test_pktout_compl_event(bool use_plain_queue) /* No user area for TX completion events */ CU_ASSERT(odp_event_user_area(ev) == NULL); + CU_ASSERT(odp_event_user_area_and_flag(ev, &flag) == NULL); + CU_ASSERT(flag < 0); /* Check that sequence number is found */ CU_ASSERT(j < TX_BATCH_LEN); diff --git a/test/validation/api/timer/timer.c b/test/validation/api/timer/timer.c index 8becddc9c..caa8ddd03 100644 --- a/test/validation/api/timer/timer.c +++ b/test/validation/api/timer/timer.c @@ -518,6 +518,7 @@ static void timer_test_timeout_user_area(void) for (i = 0; i < num; i++) { odp_event_t ev; + int flag; tmo[i] = odp_timeout_alloc(pool); @@ -532,6 +533,8 @@ static void timer_test_timeout_user_area(void) ev = odp_timeout_to_event(tmo[i]); CU_ASSERT(odp_event_user_area(ev) == addr); + CU_ASSERT(odp_event_user_area_and_flag(ev, &flag) == addr); + CU_ASSERT(flag < 0); prev = addr; memset(addr, 0, size); -- cgit v1.2.3 From 39d6a049b0988feba27e4b93021349a0618e026e Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Wed, 28 Jun 2023 08:21:35 +0300 Subject: validation: timer: add test for odp_timeout_to_event_multi() Add validation test for the new odp_timeout_to_event_multi() function. Signed-off-by: Matias Elo Reviewed-by: Petri Savolainen --- test/validation/api/timer/timer.c | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test') diff --git a/test/validation/api/timer/timer.c b/test/validation/api/timer/timer.c index caa8ddd03..1927156ba 100644 --- a/test/validation/api/timer/timer.c +++ b/test/validation/api/timer/timer.c @@ -453,6 +453,50 @@ static void timer_test_timeout_pool_alloc(void) CU_ASSERT(odp_pool_destroy(pool) == 0); } +static void timer_test_timeout_from_event(void) +{ + odp_pool_t pool; + odp_pool_param_t param; + uint32_t i; + const uint32_t num = 10; + uint32_t num_alloc = 0; + odp_timeout_t tmo_tbl[num]; + odp_timeout_t tmo2_tbl[num]; + odp_event_t ev_tbl[num]; + + odp_pool_param_init(¶m); + param.type = ODP_POOL_TIMEOUT; + param.tmo.num = num; + + pool = odp_pool_create("test_timeout_from_event", ¶m); + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + + for (i = 0; i < num; i++) { + tmo_tbl[i] = odp_timeout_alloc(pool); + if (tmo_tbl[i] == ODP_TIMEOUT_INVALID) + break; + ev_tbl[i] = odp_timeout_to_event(tmo_tbl[i]); + num_alloc++; + } + + CU_ASSERT(num_alloc == num); + + for (i = 0; i < num_alloc; i++) { + odp_timeout_t tmo = odp_timeout_from_event(ev_tbl[i]); + + CU_ASSERT(odp_timeout_to_u64(tmo) == odp_timeout_to_u64(tmo_tbl[i])); + } + + odp_timeout_from_event_multi(tmo2_tbl, ev_tbl, num_alloc); + for (i = 0; i < num_alloc; i++) + CU_ASSERT(odp_timeout_to_u64(tmo2_tbl[i]) == odp_timeout_to_u64(tmo_tbl[i])); + + for (i = 0; i < num_alloc; i++) + odp_timeout_free(tmo_tbl[i]); + + CU_ASSERT_FATAL(odp_pool_destroy(pool) == 0); +} + static void timer_test_timeout_pool_free(void) { odp_pool_t pool; @@ -3016,6 +3060,7 @@ odp_testinfo_t timer_suite[] = { ODP_TEST_INFO(timer_test_capa), ODP_TEST_INFO(timer_test_param_init), ODP_TEST_INFO(timer_test_timeout_pool_alloc), + ODP_TEST_INFO(timer_test_timeout_from_event), ODP_TEST_INFO(timer_test_timeout_pool_free), ODP_TEST_INFO(timer_test_timeout_user_area), ODP_TEST_INFO(timer_pool_create_destroy), -- cgit v1.2.3 From b321ab25e836a4511fa4fadb19f945589ac073cc Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Tue, 27 Jun 2023 16:04:23 +0300 Subject: validation: event: add test for odp_event_types_multi() Add validation test for the new odp_event_types_multi() function. Signed-off-by: Matias Elo Reviewed-by: Petri Savolainen --- test/validation/api/event/event.c | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'test') diff --git a/test/validation/api/event/event.c b/test/validation/api/event/event.c index 1d6422f96..f6ad86365 100644 --- a/test/validation/api/event/event.c +++ b/test/validation/api/event/event.c @@ -1,4 +1,5 @@ /* Copyright (c) 2017-2018, Linaro Limited + * Copyright (c) 2023, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -349,6 +350,50 @@ static void event_test_type_multi(void) CU_ASSERT(odp_pool_destroy(pkt_pool) == 0); } +static void event_test_types_multi(void) +{ + odp_pool_t buf_pool, pkt_pool; + odp_event_t buf_event[NUM_TYPE_TEST]; + odp_event_t pkt_event[NUM_TYPE_TEST]; + odp_event_t event[2 * NUM_TYPE_TEST]; + odp_event_type_t event_types[2 * NUM_TYPE_TEST]; + odp_event_subtype_t event_subtypes[2 * NUM_TYPE_TEST]; + int i; + + type_test_init(&buf_pool, &pkt_pool, buf_event, pkt_event, event); + + /* Only buffers */ + odp_event_types_multi(buf_event, event_types, event_subtypes, NUM_TYPE_TEST); + for (i = 0; i < NUM_TYPE_TEST; i++) { + CU_ASSERT(event_types[i] == ODP_EVENT_BUFFER); + CU_ASSERT(event_subtypes[i] == ODP_EVENT_NO_SUBTYPE); + } + + /* Only packets */ + odp_event_types_multi(pkt_event, event_types, event_subtypes, NUM_TYPE_TEST); + for (i = 0; i < NUM_TYPE_TEST; i++) { + CU_ASSERT(event_types[i] == ODP_EVENT_PACKET); + CU_ASSERT(event_subtypes[i] == ODP_EVENT_PACKET_BASIC); + } + + /* Mixed events: B P BB PP BBB PPP */ + odp_event_types_multi(event, event_types, NULL, 2 * NUM_TYPE_TEST); + for (i = 0; i < 2 * NUM_TYPE_TEST; i++) { + if (i == 0 || i == 2 || i == 3 || i == 6 || i == 7 || i == 8) { + /* CU_ASSERT requires extra brackets */ + CU_ASSERT(event_types[i] == ODP_EVENT_BUFFER); + } else { + CU_ASSERT(event_types[i] == ODP_EVENT_PACKET); + } + } + + odp_event_free_multi(buf_event, NUM_TYPE_TEST); + odp_event_free_multi(pkt_event, NUM_TYPE_TEST); + + CU_ASSERT(odp_pool_destroy(buf_pool) == 0); + CU_ASSERT(odp_pool_destroy(pkt_pool) == 0); +} + static void event_test_filter_packet(void) { odp_pool_t buf_pool, pkt_pool; @@ -400,6 +445,7 @@ odp_testinfo_t event_suite[] = { ODP_TEST_INFO(event_test_free_multi), ODP_TEST_INFO(event_test_free_multi_mixed), ODP_TEST_INFO(event_test_type_multi), + ODP_TEST_INFO(event_test_types_multi), ODP_TEST_INFO(event_test_filter_packet), ODP_TEST_INFO(event_test_is_valid), ODP_TEST_INFO_NULL, -- cgit v1.2.3 From b8f9d95c0db83ac25aa307117da5e168058784e6 Mon Sep 17 00:00:00 2001 From: Matias Elo Date: Tue, 20 Jun 2023 15:30:04 +0300 Subject: validation: shm: fix maybe-uninitialized warnings Fix 'maybe-uninitialized' warnings, which would otherwise appear after the following logging change commits. Signed-off-by: Matias Elo Reviewed-by: Tuomas Taipale Reviewed-by: Petri Savolainen --- test/validation/api/shmem/shmem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/validation/api/shmem/shmem.c b/test/validation/api/shmem/shmem.c index 86d070a4a..257e0214e 100644 --- a/test/validation/api/shmem/shmem.c +++ b/test/validation/api/shmem/shmem.c @@ -99,7 +99,7 @@ static int run_test_basic_thread(void *arg ODP_UNUSED) odp_shm_print_all(); CU_ASSERT(TEST_SHARE_FOO == shared_test_data->foo); CU_ASSERT(TEST_SHARE_BAR == shared_test_data->bar); - CU_ASSERT(0 == odp_shm_info(shm, &info)); + CU_ASSERT_FATAL(0 == odp_shm_info(shm, &info)); CU_ASSERT(0 == strcmp(MEM_NAME, info.name)); CU_ASSERT(0 == info.flags); CU_ASSERT(shared_test_data == info.addr); -- cgit v1.2.3 From cbea6ef9d48c1140359ff5a4927f40d3427576c1 Mon Sep 17 00:00:00 2001 From: Janne Peltonen Date: Tue, 4 Jul 2023 11:04:10 +0300 Subject: test: performance: crypto: use byte mode with all algorithms MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit With new enough ODP API version use byte mode even with algorithms that support bit mode. With older API version do the range unit conversion as before. Signed-off-by: Janne Peltonen Reviewed-by: Jere Leppänen Reviewed-by: Anoob Joseph --- test/performance/odp_crypto.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/performance/odp_crypto.c b/test/performance/odp_crypto.c index 52af6d2fc..fed3ebad8 100644 --- a/test/performance/odp_crypto.c +++ b/test/performance/odp_crypto.c @@ -1,5 +1,5 @@ /* Copyright (c) 2015-2018, Linaro Limited - * Copyright (c) 2022, Nokia + * Copyright (c) 2023, Nokia * All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause @@ -1170,6 +1170,12 @@ static int run_measure_one_config(test_run_arg_t *arg) rc = 1; } +#if ODP_VERSION_API >= ODP_VERSION_API_NUM(1, 42, 0) + /* Bit mode ciphers can now be used in byte mode. */ + config->cipher_in_bit_mode = 0; + config->auth_in_bit_mode = 0; +#endif + if (rc == 0) rc = create_session_from_config(&session, config, cargs); if (rc) { -- cgit v1.2.3 From 4538eea621d2422672827de6ab3561f8b2921406 Mon Sep 17 00:00:00 2001 From: Janne Peltonen Date: Tue, 4 Jul 2023 11:04:14 +0300 Subject: validation: crypto: test the configurable bit mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test bit mode that is now configurable at session creation time. Test algorithms that support bit mode in both bit and byte mode and other algorithms in byte mode only. Test the test vectors that have lengths not divisible by byte in bit mode only. Signed-off-by: Janne Peltonen Reviewed-by: Jere Leppänen Reviewed-by: Anoob Joseph --- test/validation/api/crypto/odp_crypto_test_inp.c | 205 +++++++++++++---------- 1 file changed, 114 insertions(+), 91 deletions(-) (limited to 'test') diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index 86eca8e2b..85e9d067f 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -36,6 +36,8 @@ static void test_defaults(uint8_t fill) CU_ASSERT_EQUAL(param.op, ODP_CRYPTO_OP_ENCODE); CU_ASSERT_EQUAL(param.op_type, ODP_CRYPTO_OP_TYPE_LEGACY); + CU_ASSERT_EQUAL(param.cipher_range_in_bits, false); + CU_ASSERT_EQUAL(param.auth_range_in_bits, false); CU_ASSERT_EQUAL(param.auth_cipher_text, false); CU_ASSERT_EQUAL(param.op_mode, ODP_CRYPTO_SYNC); CU_ASSERT_EQUAL(param.cipher_alg, ODP_CIPHER_ALG_NULL); @@ -145,13 +147,11 @@ typedef enum { AUTH_PLAINTEXT } alg_order_t; -static odp_crypto_session_t session_create(odp_crypto_op_t op, - odp_crypto_op_type_t op_type, - alg_order_t order, - crypto_test_reference_t *ref, - hash_test_mode_t hash_mode) +static int session_create(crypto_session_t *session, + alg_order_t order, + crypto_test_reference_t *ref, + hash_test_mode_t hash_mode) { - odp_crypto_session_t session = ODP_CRYPTO_SESSION_INVALID; int rc; odp_crypto_ses_create_err_t status; odp_crypto_session_param_t ses_params; @@ -171,8 +171,10 @@ static odp_crypto_session_t session_create(odp_crypto_op_t op, /* Create a crypto session */ odp_crypto_session_param_init(&ses_params); - ses_params.op = op; - ses_params.op_type = op_type; + ses_params.op = session->op; + ses_params.op_type = session->op_type; + ses_params.cipher_range_in_bits = session->cipher_range_in_bits; + ses_params.auth_range_in_bits = session->auth_range_in_bits; ses_params.auth_cipher_text = (order == AUTH_CIPHERTEXT); ses_params.op_mode = suite_context.op_mode; ses_params.cipher_alg = ref->cipher; @@ -186,7 +188,7 @@ static odp_crypto_session_t session_create(odp_crypto_op_t op, ses_params.auth_digest_len = ref->digest_length; ses_params.auth_aad_len = ref->aad_length; ses_params.hash_result_in_auth_range = (hash_mode == HASH_OVERLAP); - rc = odp_crypto_session_create(&ses_params, &session, &status); + rc = odp_crypto_session_create(&ses_params, &session->session, &status); if (rc < 0 && status == ODP_CRYPTO_SES_ERR_ALG_COMBO) { if (!combo_warning_shown) { @@ -195,7 +197,7 @@ static odp_crypto_session_t session_create(odp_crypto_op_t op, cipher_alg_name(ref->cipher), auth_alg_name(ref->auth)); } - return ODP_CRYPTO_SESSION_INVALID; + return -1; } /* @@ -209,21 +211,21 @@ static odp_crypto_session_t session_create(odp_crypto_op_t op, cipher_alg_name(ref->cipher), auth_alg_name(ref->auth), ses_params.auth_cipher_text); - return ODP_CRYPTO_SESSION_INVALID; + return -1; } /* For now, allow out-of-place sessions not to be supported. */ if (rc < 0 && status == ODP_CRYPTO_SES_ERR_PARAMS && - op_type == ODP_CRYPTO_OP_TYPE_OOP) { + ses_params.op_type == ODP_CRYPTO_OP_TYPE_OOP) { if (!oop_warning_shown) printf("\n Skipping ODP_CRYPTO_OP_TYPE_OOP tests\n"); oop_warning_shown = 1; - return ODP_CRYPTO_SESSION_INVALID; + return -1; } CU_ASSERT_FATAL(!rc); CU_ASSERT(status == ODP_CRYPTO_SES_ERR_NONE); - CU_ASSERT(odp_crypto_session_to_u64(session) != + CU_ASSERT(odp_crypto_session_to_u64(session->session) != odp_crypto_session_to_u64(ODP_CRYPTO_SESSION_INVALID)); /* @@ -234,7 +236,7 @@ static odp_crypto_session_t session_create(odp_crypto_op_t op, memset(auth_key_data, 0, sizeof(auth_key_data)); memset(&ses_params, 0, sizeof(ses_params)); - return session; + return 0; } static void alg_test_ses(odp_crypto_op_t op, @@ -244,14 +246,13 @@ static void alg_test_ses(odp_crypto_op_t op, odp_packet_data_range_t cipher_range, odp_packet_data_range_t auth_range, uint32_t digest_offset, - odp_bool_t is_bit_mode_cipher, - odp_bool_t is_bit_mode_auth) + odp_bool_t cipher_range_in_bits, + odp_bool_t auth_range_in_bits) { unsigned int initial_num_failures = CU_get_number_of_failures(); const uint32_t reflength = ref_length_in_bytes(ref); - const uint32_t auth_scale = is_bit_mode_auth ? 8 : 1; + const uint32_t auth_scale = auth_range_in_bits ? 8 : 1; hash_test_mode_t hash_mode = HASH_NO_OVERLAP; - odp_crypto_session_t session; int rc; uint32_t seg_len; uint32_t max_shift; @@ -261,16 +262,13 @@ static void alg_test_ses(odp_crypto_op_t op, digest_offset * auth_scale < auth_range.offset + auth_range.length) hash_mode = HASH_OVERLAP; - session = session_create(op, op_type, order, ref, hash_mode); - if (session == ODP_CRYPTO_SESSION_INVALID) - return; - memset(&test_param, 0, sizeof(test_param)); - test_param.session.session = session; test_param.session.op = op; test_param.session.op_type = op_type; - test_param.session.cipher_range_in_bits = is_bit_mode_cipher; - test_param.session.auth_range_in_bits = is_bit_mode_auth; + test_param.session.cipher_range_in_bits = cipher_range_in_bits; + test_param.session.auth_range_in_bits = auth_range_in_bits; + if (session_create(&test_param.session, order, ref, hash_mode)) + return; test_param.ref = ref; test_param.cipher_range = cipher_range; test_param.auth_range = auth_range; @@ -315,18 +313,18 @@ static void alg_test_ses(odp_crypto_op_t op, alg_test_op(&test_param); } - rc = odp_crypto_session_destroy(session); + rc = odp_crypto_session_destroy(test_param.session.session); CU_ASSERT(!rc); } -static void alg_test(odp_crypto_op_t op, - alg_order_t order, - crypto_test_reference_t *ref, - odp_packet_data_range_t cipher_range, - odp_packet_data_range_t auth_range, - uint32_t digest_offset, - odp_bool_t is_bit_mode_cipher, - odp_bool_t is_bit_mode_auth) +static void alg_test_op_types(odp_crypto_op_t op, + alg_order_t order, + crypto_test_reference_t *ref, + odp_packet_data_range_t cipher_range, + odp_packet_data_range_t auth_range, + uint32_t digest_offset, + odp_bool_t cipher_range_in_bits, + odp_bool_t auth_range_in_bits) { odp_crypto_op_type_t op_types[] = { ODP_CRYPTO_OP_TYPE_LEGACY, @@ -342,8 +340,47 @@ static void alg_test(odp_crypto_op_t op, cipher_range, auth_range, digest_offset, - is_bit_mode_cipher, - is_bit_mode_auth); + cipher_range_in_bits, + auth_range_in_bits); + } +} + +static void alg_test(odp_crypto_op_t op, + alg_order_t order, + crypto_test_reference_t *ref, + odp_packet_data_range_t cipher_bit_range, + odp_packet_data_range_t auth_bit_range, + uint32_t digest_offset, + odp_bool_t is_bit_mode_cipher, + odp_bool_t is_bit_mode_auth) +{ + odp_packet_data_range_t cipher_range; + odp_packet_data_range_t auth_range; + + for (int cr_in_bits = 0; cr_in_bits <= 1; cr_in_bits++) { + if (!cr_in_bits && cipher_bit_range.length % 8 != 0) + continue; + if (cr_in_bits && !is_bit_mode_cipher) + continue; + for (int ar_in_bits = 0; ar_in_bits <= 1; ar_in_bits++) { + if (!ar_in_bits && auth_bit_range.length % 8 != 0) + continue; + if (ar_in_bits && !is_bit_mode_auth) + continue; + + cipher_range = cipher_bit_range; + auth_range = auth_bit_range; + if (!cr_in_bits) { + cipher_range.offset /= 8; + cipher_range.length /= 8; + } + if (!ar_in_bits) { + auth_range.offset /= 8; + auth_range.length /= 8; + } + alg_test_op_types(op, order, ref, cipher_range, auth_range, + digest_offset, cr_in_bits, ar_in_bits); + } } } @@ -400,8 +437,8 @@ static void check_alg(odp_crypto_op_t op, odp_bool_t is_bit_mode_cipher = false; odp_bool_t is_bit_mode_auth = false; uint32_t digest_offs = ref_length_in_bytes(&ref[idx]); - odp_packet_data_range_t cipher_range = {.offset = 0}; - odp_packet_data_range_t auth_range = {.offset = 0}; + odp_packet_data_range_t cipher_bit_range = {.offset = 0}; + odp_packet_data_range_t auth_bit_range = {.offset = 0}; if (ref_length_in_bits(&ref[idx]) % 8 != 0) bit_mode_needed = true; @@ -461,18 +498,14 @@ static void check_alg(odp_crypto_op_t op, continue; } - cipher_range.length = is_bit_mode_cipher ? - ref_length_in_bits(&ref[idx]) : - ref_length_in_bytes(&ref[idx]); - auth_range.length = is_bit_mode_auth ? - ref_length_in_bits(&ref[idx]) : - ref_length_in_bytes(&ref[idx]); + cipher_bit_range.length = ref_length_in_bits(&ref[idx]); + auth_bit_range.length = ref_length_in_bits(&ref[idx]); alg_test(op, AUTH_PLAINTEXT, &ref[idx], - cipher_range, auth_range, digest_offs, + cipher_bit_range, auth_bit_range, digest_offs, is_bit_mode_cipher, is_bit_mode_auth); alg_test(op, AUTH_CIPHERTEXT, &ref[idx], - cipher_range, auth_range, digest_offs, + cipher_bit_range, auth_bit_range, digest_offs, is_bit_mode_cipher, is_bit_mode_auth); cipher_tested[cipher_idx] = true; @@ -533,7 +566,7 @@ static int create_hash_test_reference(odp_auth_alg_t auth, uint32_t digest_offset, uint8_t digest_fill) { - odp_crypto_session_t session; + crypto_session_t session; int rc; odp_packet_t pkt; odp_bool_t ok; @@ -566,33 +599,33 @@ static int create_hash_test_reference(odp_auth_alg_t auth, rc = odp_packet_copy_from_mem(pkt, 0, auth_bytes, ref->plaintext); CU_ASSERT(rc == 0); - session = session_create(ODP_CRYPTO_OP_ENCODE, - ODP_CRYPTO_OP_TYPE_LEGACY, - AUTH_PLAINTEXT, ref, HASH_NO_OVERLAP); - if (session == ODP_CRYPTO_SESSION_INVALID) + session.op = ODP_CRYPTO_OP_ENCODE; + session.op_type = ODP_CRYPTO_OP_TYPE_LEGACY; + session.cipher_range_in_bits = false; + session.auth_range_in_bits = false; + if (session_create(&session, AUTH_PLAINTEXT, ref, HASH_NO_OVERLAP)) return -1; odp_crypto_packet_op_param_t op_params = { - .session = session, + .session = session.session, .cipher_iv_ptr = ref->cipher_iv, .auth_iv_ptr = ref->auth_iv, .hash_result_offset = enc_digest_offset, .aad_ptr = ref->aad, .cipher_range = {.offset = 0, .length = 0}, - .auth_range = { .offset = 0, - .length = capa->bit_mode ? auth_bytes * 8 : auth_bytes }, + .auth_range = { .offset = 0, .length = auth_bytes }, .dst_offset_shift = 0, }; rc = crypto_op(pkt, &pkt, &ok, &op_params, ODP_CRYPTO_OP_TYPE_LEGACY); CU_ASSERT(rc == 0); if (rc) { - (void)odp_crypto_session_destroy(session); + (void)odp_crypto_session_destroy(session.session); return -1; } CU_ASSERT(ok); - rc = odp_crypto_session_destroy(session); + rc = odp_crypto_session_destroy(session.session); CU_ASSERT(rc == 0); /* copy the processed packet to the ciphertext packet in ref */ @@ -620,8 +653,8 @@ static void test_auth_hash_in_auth_range(odp_auth_alg_t auth, { static crypto_test_reference_t ref = {.length = 0}; uint32_t digest_offset = 13; - const odp_packet_data_range_t cipher_range = {.offset = 0, .length = 0}; - odp_packet_data_range_t auth_range; + const odp_packet_data_range_t cipher_bit_range = {.offset = 0, .length = 0}; + odp_packet_data_range_t auth_bit_range; if (!full_test && capa->digest_len % 4 != 0) return; @@ -633,10 +666,8 @@ static void test_auth_hash_in_auth_range(odp_auth_alg_t auth, if (create_hash_test_reference(auth, capa, &ref, digest_offset, 0)) return; - auth_range.offset = 0; - auth_range.length = capa->bit_mode ? - ref_length_in_bits(&ref) : - ref_length_in_bytes(&ref); + auth_bit_range.offset = 0; + auth_bit_range.length = ref_length_in_bits(&ref); /* * Decode the ciphertext packet. @@ -648,7 +679,7 @@ static void test_auth_hash_in_auth_range(odp_auth_alg_t auth, alg_test(ODP_CRYPTO_OP_DECODE, order, &ref, - cipher_range, auth_range, + cipher_bit_range, auth_bit_range, digest_offset, false, capa->bit_mode); @@ -660,10 +691,8 @@ static void test_auth_hash_in_auth_range(odp_auth_alg_t auth, if (create_hash_test_reference(auth, capa, &ref, digest_offset, 1)) return; - auth_range.offset = 0; - auth_range.length = capa->bit_mode ? - ref_length_in_bits(&ref) : - ref_length_in_bytes(&ref); + auth_bit_range.offset = 0; + auth_bit_range.length = ref_length_in_bits(&ref); /* * Encode the plaintext packet. @@ -675,7 +704,7 @@ static void test_auth_hash_in_auth_range(odp_auth_alg_t auth, alg_test(ODP_CRYPTO_OP_ENCODE, order, &ref, - cipher_range, auth_range, + cipher_bit_range, auth_bit_range, digest_offset, false, capa->bit_mode); @@ -759,7 +788,7 @@ static int crypto_encode_ref(crypto_test_reference_t *ref, odp_packet_data_range_t zero_range = {.offset = 0, .length = 0}; odp_packet_t pkt; int rc; - odp_crypto_session_t session; + crypto_session_t session; odp_bool_t ok; pkt = odp_packet_alloc(suite_context.pool, ref->length); @@ -768,13 +797,11 @@ static int crypto_encode_ref(crypto_test_reference_t *ref, rc = odp_packet_copy_from_mem(pkt, 0, ref->length, ref->plaintext); CU_ASSERT(rc == 0); - session = session_create(ODP_CRYPTO_OP_ENCODE, - ODP_CRYPTO_OP_TYPE_LEGACY, - AUTH_PLAINTEXT, - ref, - HASH_OVERLAP); - - if (session == ODP_CRYPTO_SESSION_INVALID) { + session.op = ODP_CRYPTO_OP_ENCODE; + session.op_type = ODP_CRYPTO_OP_TYPE_LEGACY; + session.cipher_range_in_bits = false; + session.auth_range_in_bits = false; + if (session_create(&session, AUTH_PLAINTEXT, ref, HASH_OVERLAP)) { odp_packet_free(pkt); return 1; } @@ -789,7 +816,7 @@ static int crypto_encode_ref(crypto_test_reference_t *ref, CU_ASSERT_FATAL(hash_result_offset + ref->digest_length <= ref->length); odp_crypto_packet_op_param_t op_params = { - .session = session, + .session = session.session, .cipher_iv_ptr = ref->cipher_iv, .auth_iv_ptr = ref->auth_iv, .hash_result_offset = hash_result_offset, @@ -801,12 +828,12 @@ static int crypto_encode_ref(crypto_test_reference_t *ref, rc = crypto_op(pkt, &pkt, &ok, &op_params, ODP_CRYPTO_OP_TYPE_LEGACY); CU_ASSERT(rc == 0); if (rc) { - (void)odp_crypto_session_destroy(session); + (void)odp_crypto_session_destroy(session.session); return -1; } CU_ASSERT(ok); - rc = odp_crypto_session_destroy(session); + rc = odp_crypto_session_destroy(session.session); CU_ASSERT(rc == 0); rc = odp_packet_copy_to_mem(pkt, 0, ref->length, ref->ciphertext); @@ -830,8 +857,8 @@ typedef struct crypto_suite_t { */ static int create_combined_ref(const crypto_suite_t *suite, crypto_test_reference_t *ref, - odp_packet_data_range_t *cipher_range, - odp_packet_data_range_t *auth_range, + const odp_packet_data_range_t *cipher_range, + const odp_packet_data_range_t *auth_range, uint32_t digest_offset) { uint32_t total_len; @@ -857,15 +884,6 @@ static int create_combined_ref(const crypto_suite_t *suite, ref->is_length_in_bits = false; ref->length = total_len; - if (suite->cipher_capa->bit_mode) { - cipher_range->offset *= 8; - cipher_range->length *= 8; - } - if (suite->auth_capa->bit_mode) { - auth_range->offset *= 8; - auth_range->length *= 8; - } - if (ref->auth_key_length > MAX_KEY_LEN || ref->auth_iv_length > MAX_IV_LEN || total_len > MAX_DATA_LEN || @@ -1185,6 +1203,11 @@ static void test_combo(const crypto_suite_t *suite, if (rc) return; + cipher_range.offset *= 8; + cipher_range.length *= 8; + auth_range.offset *= 8; + auth_range.length *= 8; + alg_test(ODP_CRYPTO_OP_ENCODE, suite->order, &ref, -- cgit v1.2.3 From 95e4221faad20a71c4a1a93f626322cc747ec5ed Mon Sep 17 00:00:00 2001 From: Janne Peltonen Date: Tue, 4 Jul 2023 11:04:20 +0300 Subject: validation: crypto: test null alg packet data copying with OOP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add null algorithms in the cipher+auth combination tests and do not zero their range before crypto operation to check that the data copying done by the OOP operation is done like with other algorithms. Signed-off-by: Janne Peltonen Reviewed-by: Jere Leppänen Reviewed-by: Anoob Joseph --- test/validation/api/crypto/crypto_op_test.c | 13 ++----------- test/validation/api/crypto/odp_crypto_test_inp.c | 4 +++- 2 files changed, 5 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/validation/api/crypto/crypto_op_test.c b/test/validation/api/crypto/crypto_op_test.c index 33c9ab9f2..b54300c84 100644 --- a/test/validation/api/crypto/crypto_op_test.c +++ b/test/validation/api/crypto/crypto_op_test.c @@ -178,7 +178,6 @@ static void prepare_crypto_ranges(const crypto_op_test_param_t *param, odp_packet_data_range_t *cipher_range, odp_packet_data_range_t *auth_range) { - odp_packet_data_range_t zero_range = {.offset = 0, .length = 0}; uint32_t c_scale = param->session.cipher_range_in_bits ? 8 : 1; uint32_t a_scale = param->session.auth_range_in_bits ? 8 : 1; @@ -186,11 +185,6 @@ static void prepare_crypto_ranges(const crypto_op_test_param_t *param, *auth_range = param->auth_range; cipher_range->offset += c_scale * param->header_len; auth_range->offset += a_scale * param->header_len; - - if (param->ref->cipher == ODP_CIPHER_ALG_NULL) - *cipher_range = zero_range; - if (param->ref->auth == ODP_AUTH_ALG_NULL) - *auth_range = zero_range; } static int prepare_input_packet(const crypto_op_test_param_t *param, @@ -391,13 +385,10 @@ static void prepare_expected_data(const crypto_op_test_param_t *param, auth_offset /= 8; auth_len = (auth_len + 7) / 8; } - if (param->ref->cipher == ODP_CIPHER_ALG_NULL) - cipher_len = 0; - if (param->ref->auth == ODP_AUTH_ALG_NULL || - param->ref->auth == ODP_AUTH_ALG_AES_GCM || + if (param->ref->auth == ODP_AUTH_ALG_AES_GCM || param->ref->auth == ODP_AUTH_ALG_AES_CCM || param->ref->auth == ODP_AUTH_ALG_CHACHA20_POLY1305) { - /* auth range is ignored with null and AEAD algorithms */ + /* auth range is ignored with AEAD algorithms */ auth_len = 0; } diff --git a/test/validation/api/crypto/odp_crypto_test_inp.c b/test/validation/api/crypto/odp_crypto_test_inp.c index 85e9d067f..0cc01b8e4 100644 --- a/test/validation/api/crypto/odp_crypto_test_inp.c +++ b/test/validation/api/crypto/odp_crypto_test_inp.c @@ -714,6 +714,7 @@ static void test_auth_hash_in_auth_range(odp_auth_alg_t auth, * Cipher algorithms that are not AEAD algorithms */ static odp_cipher_alg_t cipher_algs[] = { + ODP_CIPHER_ALG_NULL, ODP_CIPHER_ALG_DES, ODP_CIPHER_ALG_3DES_CBC, ODP_CIPHER_ALG_3DES_ECB, @@ -729,10 +730,11 @@ static odp_cipher_alg_t cipher_algs[] = { }; /* - * Authentication algorithms and hashes that use auth_range + * Authentication algorithms and hashes that may use auth_range * parameter. AEAD algorithms are excluded. */ static odp_auth_alg_t auth_algs[] = { + ODP_AUTH_ALG_NULL, ODP_AUTH_ALG_MD5_HMAC, ODP_AUTH_ALG_SHA1_HMAC, ODP_AUTH_ALG_SHA224_HMAC, -- cgit v1.2.3 From 0b311eb1da975a3f846577cc9bd7150a7af54d29 Mon Sep 17 00:00:00 2001 From: Janne Peltonen Date: Tue, 4 Jul 2023 16:47:51 +0300 Subject: validation: crypto: allow OOP failure with non-zero null alg ranges MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow out-of-place crypto operations to fail if the null cipher or auth algorithm has non-zero-length range. Allow failure indication only via odp_crypto_op_result(). Allowing odp_crypto_op()/odp_crypto_op_enq() returning a failure can be done later if actually needed by some implementation. Signed-off-by: Janne Peltonen Reviewed-by: Jere Leppänen Reviewed-by: Anoob Joseph --- test/validation/api/crypto/crypto_op_test.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/validation/api/crypto/crypto_op_test.c b/test/validation/api/crypto/crypto_op_test.c index b54300c84..1d883f6b8 100644 --- a/test/validation/api/crypto/crypto_op_test.c +++ b/test/validation/api/crypto/crypto_op_test.c @@ -498,6 +498,7 @@ void test_crypto_op(const crypto_op_test_param_t *param) .aad_ptr = param->ref->aad, .dst_offset_shift = param->oop_shift, }; + odp_bool_t failure_allowed = false; /* * Test detection of wrong digest value in input packet @@ -518,6 +519,14 @@ void test_crypto_op(const crypto_op_test_param_t *param) pkt_copy = odp_packet_copy(pkt, suite_context.pool); CU_ASSERT_FATAL(pkt_copy != ODP_PACKET_INVALID); test_packet_get_md(pkt_out, &md_out_orig); + + /* Non-zero-length ranges do not have to be supported. */ + if ((param->ref->cipher == ODP_CIPHER_ALG_NULL && + op_params.cipher_range.length != 0)) + failure_allowed = true; + if ((param->ref->auth == ODP_AUTH_ALG_NULL && + op_params.auth_range.length != 0)) + failure_allowed = true; } prepare_expected_data(param, &op_params.cipher_range, &op_params.auth_range, @@ -564,10 +573,12 @@ void test_crypto_op(const crypto_op_test_param_t *param) * range, so allow crypto op failure without further checks * in this case. */ - if (!ok) - goto out; + failure_allowed = true; } + if (!ok && failure_allowed) + goto out; + if (param->wrong_digest) { CU_ASSERT(!ok); } else { -- cgit v1.2.3 From 6b70fd666ffd9a545be5a4e0f037579ae7dfa17b Mon Sep 17 00:00:00 2001 From: Tuomas Taipale Date: Mon, 26 Jun 2023 12:45:06 +0000 Subject: validation: add tests for pool user area initialization Add pool, external pool and dma specific tests for user area initialization. Signed-off-by: Tuomas Taipale Reviewed-by: Petri Savolainen --- test/validation/api/dma/dma.c | 73 +++++++++- test/validation/api/pool/pool.c | 293 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 365 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/validation/api/dma/dma.c b/test/validation/api/dma/dma.c index 69b6af793..05771e3cb 100644 --- a/test/validation/api/dma/dma.c +++ b/test/validation/api/dma/dma.c @@ -19,6 +19,8 @@ #define MULTI 1 #define RESULT 1 #define USER_DATA 0xdeadbeef +#define ELEM_NUM 10 +#define UAREA 0xaa #define MIN(a, b) (a < b ? a : b) @@ -39,6 +41,11 @@ typedef struct global_t { } global_t; +typedef struct { + uint32_t count; + uint8_t mark[ELEM_NUM]; +} uarea_init_t; + static global_t global; static int dma_suite_init(void) @@ -234,6 +241,8 @@ static void test_dma_param(uint8_t fill) memset(&dma_pool_param, fill, sizeof(dma_pool_param)); odp_dma_pool_param_init(&dma_pool_param); + CU_ASSERT(dma_pool_param.uarea_init.init_fn == NULL); + CU_ASSERT(dma_pool_param.uarea_init.args == NULL); CU_ASSERT(dma_pool_param.uarea_size == 0); CU_ASSERT(dma_pool_param.cache_size <= global.dma_capa.pool.max_cache_size); CU_ASSERT(dma_pool_param.cache_size >= global.dma_capa.pool.min_cache_size); @@ -417,7 +426,7 @@ static void test_dma_compl_pool_max_pools(void) static void test_dma_compl_user_area(void) { odp_dma_pool_param_t dma_pool_param; - uint32_t num = MIN(10, global.dma_capa.pool.max_num), + uint32_t num = MIN(ELEM_NUM, global.dma_capa.pool.max_num), size = global.dma_capa.pool.max_uarea_size, i; odp_pool_t pool; odp_dma_compl_t compl_evs[num]; @@ -461,6 +470,56 @@ static void test_dma_compl_user_area(void) CU_ASSERT(odp_pool_destroy(pool) == 0); } +static void init_event_uarea(void *uarea, uint32_t size, void *args, uint32_t index) +{ + uarea_init_t *data = args; + + data->count++; + data->mark[index] = 1; + memset(uarea, UAREA, size); +} + +static void test_dma_compl_user_area_init(void) +{ + odp_dma_pool_param_t dma_pool_param; + uint32_t num = MIN(ELEM_NUM, global.dma_capa.pool.max_num), i; + odp_pool_t pool; + uarea_init_t data; + odp_dma_compl_t compl_evs[num]; + uint8_t *uarea; + + memset(&data, 0, sizeof(uarea_init_t)); + odp_dma_pool_param_init(&dma_pool_param); + dma_pool_param.uarea_init.init_fn = init_event_uarea; + dma_pool_param.uarea_init.args = &data; + dma_pool_param.num = num; + dma_pool_param.uarea_size = 1; + pool = odp_dma_pool_create(NULL, &dma_pool_param); + + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + CU_ASSERT(data.count == num); + + for (i = 0; i < num; i++) { + CU_ASSERT(data.mark[i] == 1); + + compl_evs[i] = odp_dma_compl_alloc(pool); + + CU_ASSERT(compl_evs[i] != ODP_DMA_COMPL_INVALID); + + if (compl_evs[i] == ODP_DMA_COMPL_INVALID) + break; + + uarea = odp_dma_compl_user_area(compl_evs[i]); + + CU_ASSERT(*uarea == UAREA); + } + + for (uint32_t j = 0; j < i; j++) + odp_dma_compl_free(compl_evs[j]); + + odp_pool_destroy(pool); +} + static void init_source(uint8_t *src, uint32_t len) { uint32_t i; @@ -1174,6 +1233,17 @@ static int check_event_user_area(void) return ODP_TEST_INACTIVE; } +static int check_event_user_area_init(void) +{ + if (global.disabled) + return ODP_TEST_INACTIVE; + + if (global.dma_capa.pool.max_uarea_size > 0 && global.dma_capa.pool.uarea_persistence) + return ODP_TEST_ACTIVE; + + return ODP_TEST_INACTIVE; +} + static int check_scheduled(void) { if (global.disabled) @@ -1571,6 +1641,7 @@ odp_testinfo_t dma_suite[] = { ODP_TEST_INFO_CONDITIONAL(test_dma_compl_pool_same_name, check_event), ODP_TEST_INFO_CONDITIONAL(test_dma_compl_pool_max_pools, check_event), ODP_TEST_INFO_CONDITIONAL(test_dma_compl_user_area, check_event_user_area), + ODP_TEST_INFO_CONDITIONAL(test_dma_compl_user_area_init, check_event_user_area_init), ODP_TEST_INFO_CONDITIONAL(test_dma_addr_to_addr_sync, check_sync), ODP_TEST_INFO_CONDITIONAL(test_dma_addr_to_addr_sync_mtrs, check_sync), ODP_TEST_INFO_CONDITIONAL(test_dma_addr_to_addr_sync_mseg, check_sync), diff --git a/test/validation/api/pool/pool.c b/test/validation/api/pool/pool.c index b335f194c..5176bb96f 100644 --- a/test/validation/api/pool/pool.c +++ b/test/validation/api/pool/pool.c @@ -20,8 +20,11 @@ #define VEC_LEN 32 #define PKT_LEN 400 #define PKT_NUM 500 +#define ELEM_NUM 10 +#define ELEM_SIZE 128 #define CACHE_SIZE 32 #define MAX_NUM_DEFAULT (10 * 1024 * 1024) +#define UAREA 0xaa #define EXT_NUM_BUF 10 #define EXT_BUF_SIZE 2048 @@ -31,6 +34,8 @@ #define EXT_HEADROOM 16 #define MAGIC_U8 0x7a +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) + typedef struct { odp_barrier_t init_barrier; odp_atomic_u32_t index; @@ -38,6 +43,11 @@ typedef struct { odp_pool_t pool; } global_shared_mem_t; +typedef struct { + uint32_t count; + uint8_t mark[ELEM_NUM]; +} uarea_init_t; + static global_shared_mem_t *global_mem; static odp_pool_capability_t global_pool_capa; @@ -51,6 +61,9 @@ static void test_param_init(uint8_t fill) memset(¶m, fill, sizeof(param)); odp_pool_param_init(¶m); + CU_ASSERT(param.uarea_init.init_fn == NULL); + CU_ASSERT(param.uarea_init.args == NULL); + CU_ASSERT(param.buf.uarea_size == 0); CU_ASSERT(param.buf.cache_size >= global_pool_capa.buf.min_cache_size && param.buf.cache_size <= global_pool_capa.buf.max_cache_size); @@ -146,6 +159,218 @@ static void pool_test_create_destroy_vector(void) pool_create_destroy(¶m); } +static int pool_check_buffer_uarea_init(void) +{ + if (global_pool_capa.buf.max_uarea_size == 0 || !global_pool_capa.buf.uarea_persistence) + return ODP_TEST_INACTIVE; + + return ODP_TEST_ACTIVE; +} + +static int pool_check_packet_uarea_init(void) +{ + if (global_pool_capa.pkt.max_uarea_size == 0 || !global_pool_capa.pkt.uarea_persistence) + return ODP_TEST_INACTIVE; + + return ODP_TEST_ACTIVE; +} + +static int pool_check_vector_uarea_init(void) +{ + if (global_pool_capa.vector.max_uarea_size == 0 || + !global_pool_capa.vector.uarea_persistence) + return ODP_TEST_INACTIVE; + + return ODP_TEST_ACTIVE; +} + +static int pool_check_timeout_uarea_init(void) +{ + if (global_pool_capa.tmo.max_uarea_size == 0 || !global_pool_capa.tmo.uarea_persistence) + return ODP_TEST_INACTIVE; + + return ODP_TEST_ACTIVE; +} + +static void init_event_uarea(void *uarea, uint32_t size, void *args, uint32_t index) +{ + uarea_init_t *data = args; + + data->count++; + data->mark[index] = 1; + memset(uarea, UAREA, size); +} + +static void pool_test_buffer_uarea_init(void) +{ + odp_pool_param_t param; + uint32_t num = MIN(global_pool_capa.buf.max_num, ELEM_NUM), + size = MIN(global_pool_capa.buf.max_size, ELEM_SIZE), i; + odp_pool_t pool; + uarea_init_t data; + odp_buffer_t bufs[num]; + uint8_t *uarea; + + memset(&data, 0, sizeof(uarea_init_t)); + odp_pool_param_init(¶m); + param.type = ODP_POOL_BUFFER; + param.uarea_init.init_fn = init_event_uarea; + param.uarea_init.args = &data; + param.buf.num = num; + param.buf.size = size; + param.buf.uarea_size = 1; + pool = odp_pool_create(NULL, ¶m); + + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + CU_ASSERT(data.count == num); + + for (i = 0; i < num; i++) { + CU_ASSERT(data.mark[i] == 1); + + bufs[i] = odp_buffer_alloc(pool); + + CU_ASSERT(bufs[i] != ODP_BUFFER_INVALID); + + if (bufs[i] == ODP_BUFFER_INVALID) + break; + + uarea = odp_buffer_user_area(bufs[i]); + + CU_ASSERT(*uarea == UAREA); + } + + odp_buffer_free_multi(bufs, i); + odp_pool_destroy(pool); +} + +static void pool_test_packet_uarea_init(void) +{ + odp_pool_param_t param; + uint32_t num = MIN(global_pool_capa.pkt.max_num, ELEM_NUM), + size = MIN(global_pool_capa.pkt.max_len, ELEM_SIZE), i; + odp_pool_t pool; + uarea_init_t data; + odp_packet_t pkts[num]; + uint8_t *uarea; + + memset(&data, 0, sizeof(uarea_init_t)); + odp_pool_param_init(¶m); + param.type = ODP_POOL_PACKET; + param.uarea_init.init_fn = init_event_uarea; + param.uarea_init.args = &data; + param.pkt.num = num; + param.pkt.len = size; + param.pkt.uarea_size = 1; + pool = odp_pool_create(NULL, ¶m); + + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + CU_ASSERT(data.count == num); + + for (i = 0; i < num; i++) { + CU_ASSERT(data.mark[i] == 1); + + pkts[i] = odp_packet_alloc(pool, ELEM_SIZE); + + CU_ASSERT(pkts[i] != ODP_PACKET_INVALID); + + if (pkts[i] == ODP_PACKET_INVALID) + break; + + uarea = odp_packet_user_area(pkts[i]); + + CU_ASSERT(*uarea == UAREA); + } + + odp_packet_free_multi(pkts, i); + odp_pool_destroy(pool); +} + +static void pool_test_vector_uarea_init(void) +{ + odp_pool_param_t param; + uint32_t num = MIN(global_pool_capa.vector.max_num, ELEM_NUM), + size = MIN(global_pool_capa.vector.max_size, ELEM_NUM), i; + odp_pool_t pool; + uarea_init_t data; + odp_packet_vector_t vecs[num]; + uint8_t *uarea; + + memset(&data, 0, sizeof(uarea_init_t)); + odp_pool_param_init(¶m); + param.type = ODP_POOL_VECTOR; + param.uarea_init.init_fn = init_event_uarea; + param.uarea_init.args = &data; + param.vector.num = num; + param.vector.max_size = size; + param.vector.uarea_size = 1; + pool = odp_pool_create(NULL, ¶m); + + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + CU_ASSERT(data.count == num); + + for (i = 0; i < num; i++) { + CU_ASSERT(data.mark[i] == 1); + + vecs[i] = odp_packet_vector_alloc(pool); + + CU_ASSERT(vecs[i] != ODP_PACKET_VECTOR_INVALID); + + if (vecs[i] == ODP_PACKET_VECTOR_INVALID) + break; + + uarea = odp_packet_vector_user_area(vecs[i]); + + CU_ASSERT(*uarea == UAREA); + } + + for (uint32_t j = 0; j < i; j++) + odp_packet_vector_free(vecs[j]); + + odp_pool_destroy(pool); +} + +static void pool_test_timeout_uarea_init(void) +{ + odp_pool_param_t param; + uint32_t num = MIN(global_pool_capa.tmo.max_num, ELEM_NUM), i; + odp_pool_t pool; + uarea_init_t data; + odp_timeout_t tmos[num]; + uint8_t *uarea; + + memset(&data, 0, sizeof(uarea_init_t)); + odp_pool_param_init(¶m); + param.type = ODP_POOL_TIMEOUT; + param.uarea_init.init_fn = init_event_uarea; + param.uarea_init.args = &data; + param.tmo.num = num; + param.tmo.uarea_size = 1; + pool = odp_pool_create(NULL, ¶m); + + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + CU_ASSERT(data.count == num); + + for (i = 0; i < num; i++) { + CU_ASSERT(data.mark[i] == 1); + + tmos[i] = odp_timeout_alloc(pool); + + CU_ASSERT(tmos[i] != ODP_TIMEOUT_INVALID); + + if (tmos[i] == ODP_TIMEOUT_INVALID) + break; + + uarea = odp_timeout_user_area(tmos[i]); + + CU_ASSERT(*uarea == UAREA); + } + + for (uint32_t j = 0; j < i; j++) + odp_timeout_free(tmos[j]); + + odp_pool_destroy(pool); +} + static void pool_test_lookup_info_print(void) { odp_pool_t pool; @@ -1505,6 +1730,8 @@ static void test_ext_param_init(uint8_t fill) odp_pool_ext_param_init(ODP_POOL_PACKET, ¶m); CU_ASSERT(param.type == ODP_POOL_PACKET); + CU_ASSERT(param.uarea_init.init_fn == NULL); + CU_ASSERT(param.uarea_init.args == NULL); CU_ASSERT(param.cache_size >= global_pool_ext_capa.min_cache_size && param.cache_size <= global_pool_ext_capa.max_cache_size); CU_ASSERT(param.stats.all == 0); @@ -1791,6 +2018,57 @@ static void test_packet_pool_ext_alloc(void) packet_pool_ext_alloc(PKT_LEN_NORMAL); } +static void test_packet_pool_ext_uarea_init(void) +{ + odp_pool_ext_capability_t capa; + odp_pool_ext_param_t param; + uint32_t num = ELEM_NUM, i; + odp_pool_t pool; + uarea_init_t data; + odp_shm_t shm; + uint8_t *uarea; + + CU_ASSERT_FATAL(odp_pool_ext_capability(ODP_POOL_PACKET, &capa) == 0); + + memset(&data, 0, sizeof(uarea_init_t)); + pool_ext_init_packet_pool_param(¶m); + param.uarea_init.init_fn = init_event_uarea; + param.uarea_init.args = &data; + num = MIN(num, param.pkt.num_buf); + param.pkt.num_buf = num; + param.pkt.uarea_size = 1; + pool = odp_pool_ext_create(NULL, ¶m); + + CU_ASSERT_FATAL(pool != ODP_POOL_INVALID); + + void *buf[num]; + odp_packet_t pkts[num]; + + shm = populate_pool(pool, &capa, buf, num, param.pkt.buf_size); + + CU_ASSERT_FATAL(shm != ODP_SHM_INVALID); + CU_ASSERT(data.count == num); + + for (i = 0; i < num; i++) { + CU_ASSERT(data.mark[i] == 1); + + pkts[i] = odp_packet_alloc(pool, (param.pkt.buf_size - param.pkt.headroom) / 2); + + CU_ASSERT(pkts[i] != ODP_PACKET_INVALID); + + if (pkts[i] == ODP_PACKET_INVALID) + break; + + uarea = odp_packet_user_area(pkts[i]); + + CU_ASSERT(*uarea == UAREA); + } + + odp_packet_free_multi(pkts, i); + odp_pool_destroy(pool); + odp_shm_free(shm); +} + static void test_packet_pool_ext_alloc_max(void) { packet_pool_ext_alloc(PKT_LEN_MAX); @@ -1961,6 +2239,15 @@ static int check_pool_ext_support(void) return ODP_TEST_ACTIVE; } +static int check_pool_ext_uarea_init_support(void) +{ + if (global_pool_ext_capa.max_pools == 0 || !global_pool_ext_capa.pkt.uarea_persistence || + global_pool_ext_capa.pkt.max_uarea_size == 0) + return ODP_TEST_INACTIVE; + + return ODP_TEST_ACTIVE; +} + static int check_pool_ext_segment_support(void) { if (global_pool_ext_capa.max_pools == 0 || global_pool_ext_capa.pkt.max_segs_per_pkt < 2) @@ -1975,6 +2262,10 @@ odp_testinfo_t pool_suite[] = { ODP_TEST_INFO(pool_test_create_destroy_packet), ODP_TEST_INFO(pool_test_create_destroy_timeout), ODP_TEST_INFO(pool_test_create_destroy_vector), + ODP_TEST_INFO_CONDITIONAL(pool_test_buffer_uarea_init, pool_check_buffer_uarea_init), + ODP_TEST_INFO_CONDITIONAL(pool_test_packet_uarea_init, pool_check_packet_uarea_init), + ODP_TEST_INFO_CONDITIONAL(pool_test_vector_uarea_init, pool_check_vector_uarea_init), + ODP_TEST_INFO_CONDITIONAL(pool_test_timeout_uarea_init, pool_check_timeout_uarea_init), ODP_TEST_INFO(pool_test_lookup_info_print), ODP_TEST_INFO(pool_test_same_name_buf), ODP_TEST_INFO(pool_test_same_name_pkt), @@ -2022,6 +2313,8 @@ odp_testinfo_t pool_ext_suite[] = { ODP_TEST_INFO_CONDITIONAL(test_packet_pool_ext_info, check_pool_ext_support), ODP_TEST_INFO_CONDITIONAL(test_packet_pool_ext_populate, check_pool_ext_support), ODP_TEST_INFO_CONDITIONAL(test_packet_pool_ext_alloc, check_pool_ext_support), + ODP_TEST_INFO_CONDITIONAL(test_packet_pool_ext_uarea_init, + check_pool_ext_uarea_init_support), ODP_TEST_INFO_CONDITIONAL(test_packet_pool_ext_alloc_max, check_pool_ext_support), ODP_TEST_INFO_CONDITIONAL(test_packet_pool_ext_alloc_seg, check_pool_ext_segment_support), ODP_TEST_INFO_CONDITIONAL(test_packet_pool_ext_disassemble, check_pool_ext_segment_support), -- cgit v1.2.3 From 114321a5d89d965e99e68c0e3c07d98fcb3fd67f Mon Sep 17 00:00:00 2001 From: Petri Savolainen Date: Wed, 28 Jun 2023 12:46:20 +0300 Subject: validation: barrier: use new memory barriers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call the new memory barrier functions to verify their implementation. Signed-off-by: Petri Savolainen Reviewed-by: Matias Elo Reviewed-by: Jere Leppänen --- test/validation/api/barrier/barrier.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/validation/api/barrier/barrier.c b/test/validation/api/barrier/barrier.c index 610b5db70..e4fba770f 100644 --- a/test/validation/api/barrier/barrier.c +++ b/test/validation/api/barrier/barrier.c @@ -283,6 +283,9 @@ static void barrier_test_memory_barrier(void) volatile int b = 0; volatile int c = 0; volatile int d = 0; + volatile int e = 0; + volatile int f = 0; + volatile int g = 0; /* Call all memory barriers to verify that those are implemented */ a = 1; @@ -292,9 +295,15 @@ static void barrier_test_memory_barrier(void) c = 1; odp_mb_full(); d = 1; + odp_mb_sync(); + e = 1; + odp_mb_sync_load(); + f = 1; + odp_mb_sync_store(); + g = 1; /* Avoid "variable set but not used" warning */ - temp_result = a + b + c + d; + temp_result = a + b + c + d + e + f + g; } static int barrier_init(odp_instance_t *inst) -- cgit v1.2.3