From patchwork Mon Dec 21 12:17:53 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 58813 Delivered-To: patch@linaro.org Received: by 10.112.89.199 with SMTP id bq7csp2560925lbb; Mon, 21 Dec 2015 04:19:17 -0800 (PST) X-Received: by 10.50.78.105 with SMTP id a9mr17528564igx.18.1450700357610; Mon, 21 Dec 2015 04:19:17 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j14si29987622ioo.186.2015.12.21.04.19.16; Mon, 21 Dec 2015 04:19:17 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 73D3A615BF; Mon, 21 Dec 2015 12:19:16 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=RwzkiLlf; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 2B8686173C; Mon, 21 Dec 2015 12:18:18 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 69AF5615FA; Mon, 21 Dec 2015 12:18:10 +0000 (UTC) Received: from mail-lf0-f47.google.com (mail-lf0-f47.google.com [209.85.215.47]) by lists.linaro.org (Postfix) with ESMTPS id EB5BE61569 for ; Mon, 21 Dec 2015 12:18:05 +0000 (UTC) Received: by mail-lf0-f47.google.com with SMTP id p203so110979246lfa.0 for ; Mon, 21 Dec 2015 04:18:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GnEcC7/m21CtVAdR9OM+Z2YuSbUjZjQP6k+hlMWpCfc=; b=RwzkiLlfdDtcP4pJO/lsD9yJTDijbzL11I6E+KMFRPOQmFIYd2hymsGzUfkSh9ieKw Nqy3bwsUn247ZzkoQ9rqQm362Cuu6yBF5vhRSGZf9cbLJEZAuzJnRQ7qFCPQzauqImvy DndvkS7nPwuaL3qy8Lgw9Ec/VSE6Kpi6tWu98= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=GnEcC7/m21CtVAdR9OM+Z2YuSbUjZjQP6k+hlMWpCfc=; b=YSzTOUCZVNK9uEQPjlzevdqsnNaWOums1eIeOYRqwYH5THNobmTrHEhLKb2FmZX08p MeTZx1tyu1rWXyUeN98bLiDpcvE/7LpNQCVW+GYWUz8tOQ8RcVHUYjJm+BA4CW//Xccn 9ntfr25nxyUD14LHQNDtLQpIwseuRh5oTXNfbxQ0/d5PE4SuSX35w6Orcdl6QAjB+/kD lM9IjvtQFxjdfZEVWYO7wXQmmJ7NCUTpXVKQfMnDcxOb59layLuVDNUIJMZtZ01DGpnE spSGNy4YLea7SjROpAFwNidipqZ14EmqBUvEjWB3SQjCHNM2nLpvogL2R5lfIsV6wPio yvww== X-Gm-Message-State: ALoCoQkr7vBwK2ShWBQ0Q4KC+4/47rqQhNmKIFCcykW8nn/4PFG+jomseTpuBAFrkuKWXNjJ/j23WAve9BaoQrhghtBtODsKEQ== X-Received: by 10.25.147.209 with SMTP id v200mr6153929lfd.102.1450700284902; Mon, 21 Dec 2015 04:18:04 -0800 (PST) Received: from localhost.localdomain ([195.238.92.128]) by smtp.gmail.com with ESMTPSA id 99sm680093lfp.30.2015.12.21.04.18.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Dec 2015 04:18:03 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Mon, 21 Dec 2015 14:17:53 +0200 Message-Id: <1450700273-20473-3-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1450700273-20473-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1450700273-20473-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Cc: petri.savolainen@nokia.com Subject: [lng-odp] [API-NEXT PATCH v2 2/2] validation: time: update to tes global time API X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Mostly global time API is tested in the same way, so reuse existent functions. Signed-off-by: Ivan Khoronzhuk --- test/validation/time/time.c | 189 +++++++++++++++++++++++++++++++++----------- test/validation/time/time.h | 26 +++--- 2 files changed, 159 insertions(+), 56 deletions(-) diff --git a/test/validation/time/time.c b/test/validation/time/time.c index add1be8..8b469b0 100644 --- a/test/validation/time/time.c +++ b/test/validation/time/time.c @@ -14,9 +14,14 @@ #define MAX_TIME_RATE 15000000000 #define DELAY_TOLERANCE 20000000 /* deviation for delay */ -static uint64_t res; +static uint64_t local_res; +static uint64_t global_res; -void time_test_odp_constants(void) +typedef odp_time_t time_cb(void); +typedef uint64_t time_res_cb(void); +typedef odp_time_t time_from_ns_cb(uint64_t ns); + +void time_test_constants(void) { uint64_t ns; @@ -26,11 +31,11 @@ void time_test_odp_constants(void) CU_ASSERT(ns == ODP_TIME_USEC_IN_NS); } -void time_test_res(void) +static void time_test_res(time_res_cb time_res, uint64_t res) { uint64_t rate; - rate = odp_time_local_res(); + rate = time_res(); CU_ASSERT(rate > MIN_TIME_RATE); CU_ASSERT(rate < MAX_TIME_RATE); @@ -38,15 +43,25 @@ void time_test_res(void) res = res ? res : 1; } +void time_test_local_res(void) +{ + time_test_res(odp_time_local_res, local_res); +} + +void time_test_global_res(void) +{ + time_test_res(odp_time_global_res, global_res); +} + /* check that related conversions come back to the same value */ -void time_test_odp_conversion(void) +static void time_test_conversion(time_from_ns_cb time_from_ns, uint64_t res) { uint64_t ns1, ns2; odp_time_t time; uint64_t upper_limit, lower_limit; ns1 = 100; - time = odp_time_local_from_ns(ns1); + time = time_from_ns(ns1); ns2 = odp_time_to_ns(time); @@ -57,7 +72,7 @@ void time_test_odp_conversion(void) CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit)); ns1 = 60 * 11 * ODP_TIME_SEC_IN_NS; - time = odp_time_local_from_ns(ns1); + time = time_from_ns(ns1); ns2 = odp_time_to_ns(time); @@ -72,25 +87,35 @@ void time_test_odp_conversion(void) CU_ASSERT(ns1 == 0); } -void time_test_monotony(void) +void time_test_local_conversion(void) +{ + time_test_conversion(odp_time_local_from_ns, local_res); +} + +void time_test_global_conversion(void) +{ + time_test_conversion(odp_time_global_from_ns, global_res); +} + +static void time_test_monotony(time_cb time) { volatile uint64_t count = 0; odp_time_t t1, t2, t3; uint64_t ns1, ns2, ns3; - t1 = odp_time_local(); + t1 = time(); while (count < BUSY_LOOP_CNT) { count++; }; - t2 = odp_time_local(); + t2 = time(); while (count < BUSY_LOOP_CNT_LONG) { count++; }; - t3 = odp_time_local(); + t3 = time(); ns1 = odp_time_to_ns(t1); ns2 = odp_time_to_ns(t2); @@ -100,25 +125,35 @@ void time_test_monotony(void) CU_ASSERT(ns3 > ns2); } -void time_test_odp_cmp(void) +void time_test_local_monotony(void) +{ + time_test_monotony(odp_time_local); +} + +void time_test_global_monotony(void) +{ + time_test_monotony(odp_time_global); +} + +static void time_test_cmp(time_cb time, time_from_ns_cb time_from_ns) { /* volatile to stop optimization of busy loop */ volatile int count = 0; odp_time_t t1, t2, t3; - t1 = odp_time_local(); + t1 = time(); while (count < BUSY_LOOP_CNT) { count++; }; - t2 = odp_time_local(); + t2 = time(); while (count < BUSY_LOOP_CNT * 2) { count++; }; - t3 = odp_time_local(); + t3 = time(); CU_ASSERT(odp_time_cmp(t2, t1) > 0); CU_ASSERT(odp_time_cmp(t3, t2) > 0); @@ -130,18 +165,30 @@ void time_test_odp_cmp(void) CU_ASSERT(odp_time_cmp(t2, t2) == 0); CU_ASSERT(odp_time_cmp(t3, t3) == 0); - t2 = odp_time_local_from_ns(60 * 10 * ODP_TIME_SEC_IN_NS); - t1 = odp_time_local_from_ns(3); + t2 = time_from_ns(60 * 10 * ODP_TIME_SEC_IN_NS); + t1 = time_from_ns(3); CU_ASSERT(odp_time_cmp(t2, t1) > 0); CU_ASSERT(odp_time_cmp(t1, t2) < 0); - t1 = odp_time_local_from_ns(0); + t1 = time_from_ns(0); CU_ASSERT(odp_time_cmp(t1, ODP_TIME_NULL) == 0); } +void time_test_local_cmp(void) +{ + time_test_cmp(odp_time_local, odp_time_local_from_ns); +} + +void time_test_global_cmp(void) +{ + time_test_cmp(odp_time_global, odp_time_global_from_ns); +} + /* check that a time difference gives a reasonable result */ -void time_test_odp_diff(void) +static void time_test_diff(time_cb time, + time_from_ns_cb time_from_ns, + uint64_t res) { /* volatile to stop optimization of busy loop */ volatile int count = 0; @@ -150,13 +197,13 @@ void time_test_odp_diff(void) uint64_t upper_limit, lower_limit; /* test timestamp diff */ - t1 = odp_time_local(); + t1 = time(); while (count < BUSY_LOOP_CNT) { count++; }; - t2 = odp_time_local(); + t2 = time(); CU_ASSERT(odp_time_cmp(t2, t1) > 0); diff = odp_time_diff(t2, t1); @@ -173,7 +220,7 @@ void time_test_odp_diff(void) /* test timestamp and interval diff */ ns1 = 54; - t1 = odp_time_local_from_ns(ns1); + t1 = time_from_ns(ns1); ns = ns2 - ns1; diff = odp_time_diff(t2, t1); @@ -188,7 +235,7 @@ void time_test_odp_diff(void) ns2 = 60 * 10 * ODP_TIME_SEC_IN_NS; ns = ns2 - ns1; - t2 = odp_time_local_from_ns(ns2); + t2 = time_from_ns(ns2); diff = odp_time_diff(t2, t1); CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) > 0); nsdiff = odp_time_to_ns(diff); @@ -205,17 +252,29 @@ void time_test_odp_diff(void) CU_ASSERT(odp_time_cmp(t2, diff) == 0); } +void time_test_local_diff(void) +{ + time_test_diff(odp_time_local, odp_time_local_from_ns, local_res); +} + +void time_test_global_diff(void) +{ + time_test_diff(odp_time_global, odp_time_global_from_ns, global_res); +} + /* check that a time sum gives a reasonable result */ -void time_test_odp_sum(void) +static void time_test_sum(time_cb time, + time_from_ns_cb time_from_ns, + uint64_t res) { odp_time_t sum, t1, t2; uint64_t nssum, ns1, ns2, ns; uint64_t upper_limit, lower_limit; /* sum timestamp and interval */ - t1 = odp_time_local(); + t1 = time(); ns2 = 103; - t2 = odp_time_local_from_ns(ns2); + t2 = time_from_ns(ns2); ns1 = odp_time_to_ns(t1); ns = ns1 + ns2; @@ -229,7 +288,7 @@ void time_test_odp_sum(void) /* sum intervals */ ns1 = 60 * 13 * ODP_TIME_SEC_IN_NS; - t1 = odp_time_local_from_ns(ns1); + t1 = time_from_ns(ns1); ns = ns1 + ns2; sum = odp_time_sum(t2, t1); @@ -245,32 +304,50 @@ void time_test_odp_sum(void) CU_ASSERT(odp_time_cmp(t2, sum) == 0); } -void time_test_wait_until(void) +void time_test_local_sum(void) +{ + time_test_sum(odp_time_local, odp_time_local_from_ns, local_res); +} + +void time_test_global_sum(void) +{ + time_test_sum(odp_time_global, odp_time_global_from_ns, global_res); +} + +static void time_test_wait_until(time_cb time, time_from_ns_cb time_from_ns) { int i; odp_time_t lower_limit, upper_limit; odp_time_t start_time, end_time, wait; - odp_time_t second = odp_time_local_from_ns(ODP_TIME_SEC_IN_NS); + odp_time_t second = time_from_ns(ODP_TIME_SEC_IN_NS); - start_time = odp_time_local(); + start_time = time(); wait = start_time; for (i = 1; i < 6; i++) { wait = odp_time_sum(wait, second); odp_time_wait_until(wait); printf("%d..", i); } - end_time = odp_time_local(); + end_time = time(); wait = odp_time_diff(end_time, start_time); - lower_limit = odp_time_local_from_ns(5 * ODP_TIME_SEC_IN_NS - - DELAY_TOLERANCE); - upper_limit = odp_time_local_from_ns(5 * ODP_TIME_SEC_IN_NS + - DELAY_TOLERANCE); + lower_limit = time_from_ns(5 * ODP_TIME_SEC_IN_NS - DELAY_TOLERANCE); + upper_limit = time_from_ns(5 * ODP_TIME_SEC_IN_NS + DELAY_TOLERANCE); CU_ASSERT(odp_time_cmp(wait, lower_limit) >= 0); CU_ASSERT(odp_time_cmp(wait, upper_limit) <= 0); } +void time_test_local_wait_until(void) +{ + time_test_wait_until(odp_time_local, odp_time_local_from_ns); +} + +void time_test_global_wait_until(void) +{ + time_test_wait_until(odp_time_global, odp_time_global_from_ns); +} + void time_test_wait_ns(void) { int i; @@ -295,13 +372,13 @@ void time_test_wait_ns(void) CU_ASSERT(odp_time_cmp(diff, upper_limit) <= 0); } -void time_test_odp_to_u64(void) +static void time_test_to_u64(time_cb time) { volatile int count = 0; uint64_t val1, val2; odp_time_t t1, t2; - t1 = odp_time_local(); + t1 = time(); val1 = odp_time_to_u64(t1); CU_ASSERT(val1 > 0); @@ -310,7 +387,7 @@ void time_test_odp_to_u64(void) count++; }; - t2 = odp_time_local(); + t2 = time(); val2 = odp_time_to_u64(t2); CU_ASSERT(val2 > 0); @@ -320,17 +397,35 @@ void time_test_odp_to_u64(void) CU_ASSERT(val1 == 0); } +void time_test_local_to_u64(void) +{ + time_test_to_u64(odp_time_local); +} + +void time_test_global_to_u64(void) +{ + time_test_to_u64(odp_time_global); +} + odp_testinfo_t time_suite_time[] = { - ODP_TEST_INFO(time_test_odp_constants), - ODP_TEST_INFO(time_test_res), - ODP_TEST_INFO(time_test_odp_conversion), - ODP_TEST_INFO(time_test_monotony), - ODP_TEST_INFO(time_test_odp_cmp), - ODP_TEST_INFO(time_test_odp_diff), - ODP_TEST_INFO(time_test_odp_sum), - ODP_TEST_INFO(time_test_wait_until), + ODP_TEST_INFO(time_test_constants), + ODP_TEST_INFO(time_test_local_res), + ODP_TEST_INFO(time_test_local_conversion), + ODP_TEST_INFO(time_test_local_monotony), + ODP_TEST_INFO(time_test_local_cmp), + ODP_TEST_INFO(time_test_local_diff), + ODP_TEST_INFO(time_test_local_sum), + ODP_TEST_INFO(time_test_local_wait_until), ODP_TEST_INFO(time_test_wait_ns), - ODP_TEST_INFO(time_test_odp_to_u64), + ODP_TEST_INFO(time_test_local_to_u64), + ODP_TEST_INFO(time_test_global_res), + ODP_TEST_INFO(time_test_global_conversion), + ODP_TEST_INFO(time_test_global_monotony), + ODP_TEST_INFO(time_test_global_cmp), + ODP_TEST_INFO(time_test_global_diff), + ODP_TEST_INFO(time_test_global_sum), + ODP_TEST_INFO(time_test_global_wait_until), + ODP_TEST_INFO(time_test_global_to_u64), ODP_TEST_INFO_NULL }; diff --git a/test/validation/time/time.h b/test/validation/time/time.h index c2330f8..d75b0f5 100644 --- a/test/validation/time/time.h +++ b/test/validation/time/time.h @@ -10,16 +10,24 @@ #include /* test functions: */ -void time_test_odp_constants(void); -void time_test_res(void); -void time_test_odp_conversion(void); -void time_test_monotony(void); -void time_test_odp_cmp(void); -void time_test_odp_diff(void); -void time_test_odp_sum(void); -void time_test_wait_until(void); +void time_test_constants(void); +void time_test_local_res(void); +void time_test_global_res(void); +void time_test_local_conversion(void); +void time_test_global_conversion(void); +void time_test_local_monotony(void); +void time_test_global_monotony(void); +void time_test_local_cmp(void); +void time_test_global_cmp(void); +void time_test_local_diff(void); +void time_test_global_diff(void); +void time_test_local_sum(void); +void time_test_global_sum(void); +void time_test_local_wait_until(void); +void time_test_global_wait_until(void); void time_test_wait_ns(void); -void time_test_odp_to_u64(void); +void time_test_local_to_u64(void); +void time_test_global_to_u64(void); /* test arrays: */ extern odp_testinfo_t time_suite_time[];