From patchwork Fri Dec 4 17:51:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 57718 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp703071lbb; Fri, 4 Dec 2015 09:56:28 -0800 (PST) X-Received: by 10.55.75.137 with SMTP id y131mr19439052qka.69.1449251788213; Fri, 04 Dec 2015 09:56:28 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id l50si7817561qgf.74.2015.12.04.09.56.27; Fri, 04 Dec 2015 09:56:28 -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.20150623.gappssmtp.com Received: by lists.linaro.org (Postfix, from userid 109) id D03D062D67; Fri, 4 Dec 2015 17:56:27 +0000 (UTC) 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 B539562D85; Fri, 4 Dec 2015 17:52:59 +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 0526A62D63; Fri, 4 Dec 2015 17:52:52 +0000 (UTC) Received: from mail-lf0-f42.google.com (mail-lf0-f42.google.com [209.85.215.42]) by lists.linaro.org (Postfix) with ESMTPS id E9E2162D63 for ; Fri, 4 Dec 2015 17:51:52 +0000 (UTC) Received: by lfaz4 with SMTP id z4so117225703lfa.0 for ; Fri, 04 Dec 2015 09:51:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KwZWKZJnhHvTc0+myIIytcpKXYLU35buGHToTaWlZGE=; b=NsoC/o/8xV2INdfmcV7Bg2iyT7LN2YXv/0q9leQpftSTu4dADv2tcLzz6T3cR/AUAM Rx8f6MqOQcOJ7soD5WhffIiLbEO+RhMJ7PGB3yfci+MyB+W7PVyYCD/V3xxwcSl89wVQ ye60fdt4CQew8xA2gA2LsQbpQASItyISa0IpwWNQpMcJTOkWz6tDLhEzhzc9QA1Opyma pPrp20ipTxZLck+fRi1SCNojvg2FiS9jFi6mT3h0ztNffhsc+9gQ4uOSQ0ql+Ug2GCqI gLkiVOQ6QFliyvAKc/v21JI4W1aN9MLlt+eV0lL/rX6qg1IVs3yDwbbzv8MFYit7YjNJ 8JXg== 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=KwZWKZJnhHvTc0+myIIytcpKXYLU35buGHToTaWlZGE=; b=fWHZfVslyaPRprCw2Ehc/2Ovj/hm5J7I6hBcw5Dg4bG6DAGFxaPAVQaRQF0ug9Kkqe QBFWLIzgpgLNl/akD9RTK4anI9f0XuAEnxrjj0nEh3xDri6xmRW0WXb4IOZCDjdR0y4J OkneE/ELVJN/QyWyIkKci9KJIqxYFV5IkY2EdJFmf5IMw1otIl5RCKphVQdWV0JcD8BE tWsAYaRsRIjAO3UD1578vV0/uM2WU/qBbXMIpYq2x6oKU+QdXbYuJcGBAnE0CDPFyQCX 5//xGXQMkaptZnlpo/kfhTVx0bEUGtFSjp0JvrXiEutVKKnfHkFhQAMkZOv+tp7it5rH xSQg== X-Gm-Message-State: ALoCoQm22BDRIcAEXFgrku1PAn/fu6cmx5Q4N7aF0xXfMSNDkAXP7GXMgZK2eS2cNbvsHDf/HXEX X-Received: by 10.25.10.131 with SMTP id 125mr9204527lfk.78.1449251511844; Fri, 04 Dec 2015 09:51:51 -0800 (PST) Received: from localhost.localdomain ([212.90.60.8]) by smtp.gmail.com with ESMTPSA id rm5sm2483518lbb.20.2015.12.04.09.51.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 04 Dec 2015 09:51:50 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Fri, 4 Dec 2015 19:51:32 +0200 Message-Id: <1449251494-23210-8-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449251494-23210-1-git-send-email-ivan.khoronzhuk@linaro.org> References: <1449251494-23210-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH v7 7/9] validation: time: align tests with current 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" Add test for odp_time_sum, odp_time_cmp, odp_time_to_u64 APIs. Sophisticate a little tests for odp_time_diff, odp_time_local_from_ns, odp_time_local_to_ns APIs. Check time on monotony. Reviewed-by: Petri Savolainen Signed-off-by: Ivan Khoronzhuk --- test/validation/time/time.c | 228 +++++++++++++++++++++++++++++++++++++++----- test/validation/time/time.h | 7 +- 2 files changed, 210 insertions(+), 25 deletions(-) diff --git a/test/validation/time/time.c b/test/validation/time/time.c index 3d05a6f..0303eb3 100644 --- a/test/validation/time/time.c +++ b/test/validation/time/time.c @@ -9,7 +9,107 @@ #include "time.h" #define TOLERANCE 1 -#define BUSY_LOOP_CNT 100 +#define BUSY_LOOP_CNT 30000000 /* used for t > min resolution */ +#define BUSY_LOOP_CNT_LONG 12000000000 /* used for t > 4 sec */ + + +/* check that related conversions come back to the same value */ +void time_test_odp_conversion(void) +{ + uint64_t ns1, ns2; + odp_time_t time; + uint64_t upper_limit, lower_limit; + + ns1 = 100; + time = odp_time_local_from_ns(ns1); + + ns2 = odp_time_to_ns(time); + + /* need to check within arithmetic tolerance that the same + * value in ns is returned after conversions */ + upper_limit = ns1 + TOLERANCE; + lower_limit = ns1 - TOLERANCE; + CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit)); + + ns1 = 60 * 11 * ODP_TIME_SEC_IN_NS; + time = odp_time_local_from_ns(ns1); + + ns2 = odp_time_to_ns(time); + + /* need to check within arithmetic tolerance that the same + * value in ns is returned after conversions */ + upper_limit = ns1 + TOLERANCE; + lower_limit = ns1 - TOLERANCE; + CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit)); +} + +void time_test_monotony(void) +{ + volatile unsigned long count = 0; + odp_time_t t1, t2, t3; + uint64_t ns1, ns2, ns3; + + t1 = odp_time_local(); + + while (count < BUSY_LOOP_CNT) { + count++; + }; + + t2 = odp_time_local(); + + while (count < BUSY_LOOP_CNT_LONG) { + count++; + }; + + t3 = odp_time_local(); + + ns1 = odp_time_to_ns(t1); + ns2 = odp_time_to_ns(t2); + ns3 = odp_time_to_ns(t3); + + CU_ASSERT(ns2 > ns1); + CU_ASSERT(ns3 > ns2); +} + +void time_test_odp_cmp(void) +{ + /* volatile to stop optimization of busy loop */ + volatile int count = 0; + odp_time_t t1, t2, t3; + + t1 = odp_time_local(); + + while (count < BUSY_LOOP_CNT) { + count++; + }; + + t2 = odp_time_local(); + + while (count < BUSY_LOOP_CNT * 2) { + count++; + }; + + t3 = odp_time_local(); + + CU_ASSERT(odp_time_cmp(t2, t1) > 0); + CU_ASSERT(odp_time_cmp(t3, t2) > 0); + CU_ASSERT(odp_time_cmp(t3, t1) > 0); + CU_ASSERT(odp_time_cmp(t1, t2) < 0); + CU_ASSERT(odp_time_cmp(t2, t3) < 0); + CU_ASSERT(odp_time_cmp(t1, t3) < 0); + CU_ASSERT(odp_time_cmp(t1, t1) == 0); + 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); + + CU_ASSERT(odp_time_cmp(t2, t1) > 0); + CU_ASSERT(odp_time_cmp(t1, t2) < 0); + + t1 = odp_time_local_from_ns(0); + CU_ASSERT(odp_time_cmp(t1, ODP_TIME_NULL) == 0); +} /* check that a time difference gives a reasonable result */ void time_test_odp_diff(void) @@ -17,7 +117,10 @@ void time_test_odp_diff(void) /* volatile to stop optimization of busy loop */ volatile int count = 0; odp_time_t diff, t1, t2; + uint64_t nsdiff, ns1, ns2, ns; + uint64_t upper_limit, lower_limit; + /* test timestamp diff */ t1 = odp_time_local(); while (count < BUSY_LOOP_CNT) { @@ -29,43 +132,122 @@ void time_test_odp_diff(void) diff = odp_time_diff(t2, t1); CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) > 0); -} -/* check that a negative time difference gives a reasonable result */ -void time_test_odp_negative_diff(void) -{ - odp_time_t diff, t1, t2; + ns1 = odp_time_to_ns(t1); + ns2 = odp_time_to_ns(t2); + ns = ns2 - ns1; + nsdiff = odp_time_to_ns(diff); - t1 = odp_time_local_from_ns(10); - t2 = odp_time_local_from_ns(5); + upper_limit = ns + TOLERANCE; + lower_limit = ns - TOLERANCE; + CU_ASSERT((nsdiff <= upper_limit) && (nsdiff >= lower_limit)); + + /* test timestamp and interval diff */ + ns1 = 54; + t1 = odp_time_local_from_ns(ns1); + ns = ns2 - ns1; + + diff = odp_time_diff(t2, t1); + CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) > 0); + nsdiff = odp_time_to_ns(diff); + + upper_limit = ns + TOLERANCE; + lower_limit = ns - TOLERANCE; + CU_ASSERT((nsdiff <= upper_limit) && (nsdiff >= lower_limit)); + + /* test interval diff */ + ns2 = 60 * 10 * ODP_TIME_SEC_IN_NS; + ns = ns2 - ns1; + + t2 = odp_time_local_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); + + upper_limit = ns + TOLERANCE; + lower_limit = ns - TOLERANCE; + CU_ASSERT((nsdiff <= upper_limit) && (nsdiff >= lower_limit)); + + /* same time has to diff to 0 */ + diff = odp_time_diff(t2, t2); + CU_ASSERT(odp_time_cmp(diff, ODP_TIME_NULL) == 0); + + diff = odp_time_diff(t2, ODP_TIME_NULL); + CU_ASSERT(odp_time_cmp(t2, diff) == 0); } -/* check that related conversions come back to the same value */ -void time_test_odp_conversion(void) +/* check that a time sum gives a reasonable result */ +void time_test_odp_sum(void) { - uint64_t ns1, ns2; - odp_time_t time; + odp_time_t sum, t1, t2; + uint64_t nssum, ns1, ns2, ns; uint64_t upper_limit, lower_limit; - ns1 = 100; - time = odp_time_local_from_ns(ns1); - CU_ASSERT(odp_time_cmp(time, ODP_TIME_NULL) > 0); + /* sum timestamp and interval */ + t1 = odp_time_local(); + ns2 = 103; + t2 = odp_time_local_from_ns(ns2); + ns1 = odp_time_to_ns(t1); + ns = ns1 + ns2; - ns2 = odp_time_to_ns(time); + sum = odp_time_sum(t2, t1); + CU_ASSERT(odp_time_cmp(sum, ODP_TIME_NULL) > 0); + nssum = odp_time_to_ns(sum); - /* need to check within arithmetic tolerance that the same - * value in ns is returned after conversions */ - upper_limit = ns1 + TOLERANCE; - lower_limit = ns1 - TOLERANCE; - CU_ASSERT((ns2 <= upper_limit) && (ns2 >= lower_limit)); + upper_limit = ns + TOLERANCE; + lower_limit = ns - TOLERANCE; + CU_ASSERT((nssum <= upper_limit) && (nssum >= lower_limit)); + + /* sum intervals */ + ns1 = 60 * 13 * ODP_TIME_SEC_IN_NS; + t1 = odp_time_local_from_ns(ns1); + ns = ns1 + ns2; + + sum = odp_time_sum(t2, t1); + CU_ASSERT(odp_time_cmp(sum, ODP_TIME_NULL) > 0); + nssum = odp_time_to_ns(sum); + + upper_limit = ns + TOLERANCE; + lower_limit = ns - TOLERANCE; + CU_ASSERT((nssum <= upper_limit) && (nssum >= lower_limit)); + + /* test on 0 */ + sum = odp_time_sum(t2, ODP_TIME_NULL); + CU_ASSERT(odp_time_cmp(t2, sum) == 0); +} + +void time_test_odp_to_u64(void) +{ + volatile int count = 0; + uint64_t val1, val2; + odp_time_t t1, t2; + + t1 = odp_time_local(); + + val1 = odp_time_to_u64(t1); + CU_ASSERT(val1 > 0); + + while (count < BUSY_LOOP_CNT) { + count++; + }; + + t2 = odp_time_local(); + val2 = odp_time_to_u64(t2); + CU_ASSERT(val2 > 0); + + CU_ASSERT(val2 > val1); + + val1 = odp_time_to_u64(ODP_TIME_NULL); + CU_ASSERT(val1 == 0); } odp_testinfo_t time_suite_time[] = { - ODP_TEST_INFO(time_test_odp_diff), - ODP_TEST_INFO(time_test_odp_negative_diff), 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_odp_to_u64), ODP_TEST_INFO_NULL }; diff --git a/test/validation/time/time.h b/test/validation/time/time.h index b4e613c..b0c67b7 100644 --- a/test/validation/time/time.h +++ b/test/validation/time/time.h @@ -10,9 +10,12 @@ #include /* test functions: */ -void time_test_odp_diff(void); void time_test_odp_conversion(void); -void time_test_odp_negative_diff(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_odp_to_u64(void); /* test arrays: */ extern odp_testinfo_t time_suite_time[];