aboutsummaryrefslogtreecommitdiff
path: root/test/validation/api/system/system.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/validation/api/system/system.c')
-rw-r--r--test/validation/api/system/system.c366
1 files changed, 4 insertions, 362 deletions
diff --git a/test/validation/api/system/system.c b/test/validation/api/system/system.c
index 3f7e0497d..63a0a7e2a 100644
--- a/test/validation/api/system/system.c
+++ b/test/validation/api/system/system.c
@@ -1,7 +1,5 @@
-/* Copyright (c) 2015-2018, Linaro Limited
- * All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright (c) 2015-2018 Linaro Limited
*/
#include <ctype.h>
@@ -27,8 +25,8 @@ static void test_version_api_str(void)
char version_string[128];
char *s = version_string;
- strncpy(version_string, odp_version_api_str(),
- sizeof(version_string) - 1);
+ odph_strcpy(version_string, odp_version_api_str(),
+ sizeof(version_string));
while (*s) {
if (isdigit((int)*s) || (strncmp(s, ".", 1) == 0)) {
@@ -77,186 +75,6 @@ static void test_version_macro(void)
ODP_VERSION_API);
}
-static void system_test_odp_cpu_count(void)
-{
- int cpus;
-
- cpus = odp_cpu_count();
- CU_ASSERT(0 < cpus);
-}
-
-static void system_test_cpu_cycles(void)
-{
- uint64_t c2, c1, diff, max;
-
- c1 = odp_cpu_cycles();
- odp_time_wait_ns(WAIT_TIME);
- c2 = odp_cpu_cycles();
-
- CU_ASSERT(c2 != c1);
-
- max = odp_cpu_cycles_max();
-
- /* With 10 usec delay, diff should be small compared to the maximum.
- * Otherwise, counter is going backwards. */
- if (c2 > c1) {
- diff = c2 - c1;
- CU_ASSERT(diff < (max - diff));
- }
-
- /* Same applies also when there was a wrap. */
- if (c2 < c1) {
- diff = max - c1 + c2;
- CU_ASSERT(diff < (max - diff));
- }
-}
-
-static void system_test_cpu_cycles_max(void)
-{
- uint64_t c2, c1;
- uint64_t max1, max2;
-
- max1 = odp_cpu_cycles_max();
- odp_time_wait_ns(WAIT_TIME);
- max2 = odp_cpu_cycles_max();
-
- CU_ASSERT(max1 >= UINT32_MAX / 2);
- CU_ASSERT(max1 == max2);
-
- c1 = odp_cpu_cycles();
- odp_time_wait_ns(WAIT_TIME);
- c2 = odp_cpu_cycles();
-
- CU_ASSERT(c1 <= max1 && c2 <= max1);
-}
-
-static void system_test_cpu_cycles_resolution(void)
-{
- int i;
- uint64_t res;
- uint64_t c2, c1, max;
- uint64_t test_cycles = odp_cpu_hz() / 100; /* CPU cycles in 10 msec */
-
- max = odp_cpu_cycles_max();
-
- res = odp_cpu_cycles_resolution();
- CU_ASSERT(res != 0);
- CU_ASSERT(res < max / 1024);
-
- for (i = 0; i < RES_TRY_NUM; i++) {
- c1 = odp_cpu_cycles();
- odp_time_wait_ns(10 * ODP_TIME_MSEC_IN_NS + i);
- c2 = odp_cpu_cycles();
-
- /* Diff may be zero with low resolution */
- if (test_cycles && test_cycles > res) {
- uint64_t diff = odp_cpu_cycles_diff(c2, c1);
-
- CU_ASSERT(diff >= res);
- }
-
- }
-}
-
-static void system_test_cpu_cycles_diff(void)
-{
- uint64_t c2, c1, max;
- uint64_t tmp, diff, res;
-
- res = odp_cpu_cycles_resolution();
- max = odp_cpu_cycles_max();
-
- c1 = res;
- c2 = 2 * res;
- diff = odp_cpu_cycles_diff(c2, c1);
- CU_ASSERT(diff == res);
-
- c1 = odp_cpu_cycles();
- odp_time_wait_ns(WAIT_TIME);
- c2 = odp_cpu_cycles();
- diff = odp_cpu_cycles_diff(c2, c1);
- CU_ASSERT(diff > 0);
- CU_ASSERT(diff < (max - diff));
-
- /* check resolution for wrap */
- c1 = max - 2 * res;
- do
- c2 = odp_cpu_cycles();
- while (c1 < c2);
-
- diff = odp_cpu_cycles_diff(c1, c1);
- CU_ASSERT(diff == 0);
-
- /* wrap */
- tmp = c2 + (max - c1) + res;
- diff = odp_cpu_cycles_diff(c2, c1);
- CU_ASSERT(diff == tmp);
-
- /* no wrap, revert args */
- tmp = c1 - c2;
- diff = odp_cpu_cycles_diff(c1, c2);
- CU_ASSERT(diff == tmp);
-}
-
-static void system_test_cpu_cycles_long_period(void)
-{
- int i;
- int periods = PERIODS_100_MSEC;
- uint64_t max_period_duration = 100 * ODP_TIME_MSEC_IN_NS + periods - 1;
- uint64_t c2, c1, c3, max;
- uint64_t tmp, diff, res;
-
- res = odp_cpu_cycles_resolution();
- max = odp_cpu_cycles_max();
-
- c3 = odp_cpu_cycles();
-
- CU_ASSERT(c3 <= max);
- /*
- * If the cycle counter is not close to wrapping around during
- * the test, then speed up the test by not trying to see the wrap
- * around too hard. Assume cycle counter frequency of less than 10 GHz.
- */
- CU_ASSERT(odp_cpu_hz_max() < 10ULL * ODP_TIME_SEC_IN_NS);
- if (max - c3 > 10 * periods * max_period_duration)
- periods = 10;
-
- printf("\n Testing CPU cycles for %i seconds... ", periods / 10);
-
- for (i = 0; i < periods; i++) {
- c1 = odp_cpu_cycles();
- odp_time_wait_ns(100 * ODP_TIME_MSEC_IN_NS + i);
- c2 = odp_cpu_cycles();
-
- CU_ASSERT(c2 != c1);
- CU_ASSERT(c1 <= max && c2 <= max);
-
- if (c2 > c1)
- tmp = c2 - c1;
- else
- tmp = c2 + (max - c1) + res;
-
- diff = odp_cpu_cycles_diff(c2, c1);
- CU_ASSERT(diff == tmp);
-
- /* wrap is detected and verified */
- if (c2 < c1)
- break;
- }
-
- /* wrap was detected, no need to continue */
- if (i < periods) {
- printf("wrap was detected.\n");
- return;
- }
-
- /* wrap has to be detected if possible */
- CU_ASSERT(max > UINT32_MAX);
- CU_ASSERT((max - c3) > UINT32_MAX);
-
- printf("wrap was not detected.\n");
-}
-
static void system_test_odp_sys_cache_line_size(void)
{
uint64_t cache_size;
@@ -277,32 +95,6 @@ static void system_test_odp_sys_cache_line_size(void)
2 * ODP_CACHE_LINE_SIZE);
}
-static void system_test_odp_cpu_model_str(void)
-{
- char model[128];
-
- snprintf(model, 128, "%s", odp_cpu_model_str());
- CU_ASSERT(strlen(model) > 0);
- CU_ASSERT(strlen(model) < 127);
-}
-
-static void system_test_odp_cpu_model_str_id(void)
-{
- char model[128];
- odp_cpumask_t mask;
- int i, num, cpu;
-
- num = odp_cpumask_all_available(&mask);
- cpu = odp_cpumask_first(&mask);
-
- for (i = 0; i < num; i++) {
- snprintf(model, 128, "%s", odp_cpu_model_str_id(cpu));
- CU_ASSERT(strlen(model) > 0);
- CU_ASSERT(strlen(model) < 127);
- cpu = odp_cpumask_next(&mask, cpu);
- }
-}
-
static void system_test_odp_sys_page_size(void)
{
uint64_t page;
@@ -343,135 +135,6 @@ static void system_test_odp_sys_huge_page_size_all(void)
}
}
-static int system_check_cycle_counter(void)
-{
- if (odp_cpu_cycles_max() == 0) {
- printf("Cycle counter is not supported, skipping test\n");
- return ODP_TEST_INACTIVE;
- }
-
- return ODP_TEST_ACTIVE;
-}
-
-static int system_check_odp_cpu_hz(void)
-{
- if (odp_cpu_hz() == 0) {
- printf("odp_cpu_hz() is not supported, skipping test\n");
- return ODP_TEST_INACTIVE;
- }
-
- return ODP_TEST_ACTIVE;
-}
-
-static void system_test_odp_cpu_hz(void)
-{
- uint64_t hz = odp_cpu_hz();
-
- /* Test value sanity: less than 10GHz */
- CU_ASSERT(hz < 10 * GIGA_HZ);
-
- /* larger than 1kHz */
- CU_ASSERT(hz > 1 * KILO_HZ);
-}
-
-static int system_check_odp_cpu_hz_id(void)
-{
- uint64_t hz;
- odp_cpumask_t mask;
- int i, num, cpu;
-
- num = odp_cpumask_all_available(&mask);
- cpu = odp_cpumask_first(&mask);
-
- for (i = 0; i < num; i++) {
- hz = odp_cpu_hz_id(cpu);
- if (hz == 0) {
- printf("odp_cpu_hz_id() is not supported by CPU %d, skipping test\n", cpu);
- return ODP_TEST_INACTIVE;
- }
- cpu = odp_cpumask_next(&mask, cpu);
- }
-
- return ODP_TEST_ACTIVE;
-}
-
-static void system_test_odp_cpu_hz_id(void)
-{
- uint64_t hz;
- odp_cpumask_t mask;
- int i, num, cpu;
-
- num = odp_cpumask_all_available(&mask);
- cpu = odp_cpumask_first(&mask);
-
- for (i = 0; i < num; i++) {
- hz = odp_cpu_hz_id(cpu);
- /* Test value sanity: less than 10GHz */
- CU_ASSERT(hz < 10 * GIGA_HZ);
- /* larger than 1kHz */
- CU_ASSERT(hz > 1 * KILO_HZ);
- cpu = odp_cpumask_next(&mask, cpu);
- }
-}
-
-static int system_check_odp_cpu_hz_max(void)
-{
- if (odp_cpu_hz_max() == 0) {
- printf("odp_cpu_hz_max() is not supported, skipping test\n");
- return ODP_TEST_INACTIVE;
- }
- return ODP_TEST_ACTIVE;
-}
-
-static void system_test_odp_cpu_hz_max(void)
-{
- uint64_t hz = odp_cpu_hz_max();
-
- /* Sanity check value */
- CU_ASSERT(hz > 1 * KILO_HZ);
- CU_ASSERT(hz < 20 * GIGA_HZ);
-}
-
-static int system_check_odp_cpu_hz_max_id(void)
-{
- uint64_t hz;
- odp_cpumask_t mask;
- int i, num, cpu;
-
- num = odp_cpumask_all_available(&mask);
- cpu = odp_cpumask_first(&mask);
-
- for (i = 0; i < num; i++) {
- hz = odp_cpu_hz_max_id(cpu);
- if (hz == 0) {
- printf("odp_cpu_hz_max_id() is not supported by CPU %d, skipping test\n",
- cpu);
- return ODP_TEST_INACTIVE;
- }
- cpu = odp_cpumask_next(&mask, cpu);
- }
-
- return ODP_TEST_ACTIVE;
-}
-
-static void system_test_odp_cpu_hz_max_id(void)
-{
- uint64_t hz;
- odp_cpumask_t mask;
- int i, num, cpu;
-
- num = odp_cpumask_all_available(&mask);
- cpu = odp_cpumask_first(&mask);
-
- for (i = 0; i < num; i++) {
- hz = odp_cpu_hz_max_id(cpu);
- /* Sanity check value */
- CU_ASSERT(hz > 1 * KILO_HZ);
- CU_ASSERT(hz < 20 * GIGA_HZ);
- cpu = odp_cpumask_next(&mask, cpu);
- }
-}
-
static void system_test_info_print(void)
{
printf("\n\nCalling system info print...\n");
@@ -645,31 +308,10 @@ odp_testinfo_t system_suite[] = {
ODP_TEST_INFO(test_version_api_str),
ODP_TEST_INFO(test_version_str),
ODP_TEST_INFO(test_version_macro),
- ODP_TEST_INFO(system_test_odp_cpu_count),
ODP_TEST_INFO(system_test_odp_sys_cache_line_size),
- ODP_TEST_INFO(system_test_odp_cpu_model_str),
- ODP_TEST_INFO(system_test_odp_cpu_model_str_id),
ODP_TEST_INFO(system_test_odp_sys_page_size),
ODP_TEST_INFO(system_test_odp_sys_huge_page_size),
ODP_TEST_INFO(system_test_odp_sys_huge_page_size_all),
- ODP_TEST_INFO_CONDITIONAL(system_test_odp_cpu_hz,
- system_check_odp_cpu_hz),
- ODP_TEST_INFO_CONDITIONAL(system_test_odp_cpu_hz_id,
- system_check_odp_cpu_hz_id),
- ODP_TEST_INFO_CONDITIONAL(system_test_odp_cpu_hz_max,
- system_check_odp_cpu_hz_max),
- ODP_TEST_INFO_CONDITIONAL(system_test_odp_cpu_hz_max_id,
- system_check_odp_cpu_hz_max_id),
- ODP_TEST_INFO_CONDITIONAL(system_test_cpu_cycles,
- system_check_cycle_counter),
- ODP_TEST_INFO_CONDITIONAL(system_test_cpu_cycles_max,
- system_check_cycle_counter),
- ODP_TEST_INFO_CONDITIONAL(system_test_cpu_cycles_resolution,
- system_check_cycle_counter),
- ODP_TEST_INFO_CONDITIONAL(system_test_cpu_cycles_diff,
- system_check_cycle_counter),
- ODP_TEST_INFO_CONDITIONAL(system_test_cpu_cycles_long_period,
- system_check_cycle_counter),
ODP_TEST_INFO(system_test_info),
ODP_TEST_INFO(system_test_meminfo),
ODP_TEST_INFO(system_test_info_print),