From patchwork Wed Jan 3 22:00:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 123350 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp10694155qgn; Wed, 3 Jan 2018 14:06:14 -0800 (PST) X-Google-Smtp-Source: ACJfBoubHrvxK1xh12wkqG3wRvY2bQHokdsm6vi6Bsb1br5by5wLadFa/L0lDNPyMOn4q26DtwVB X-Received: by 10.200.3.23 with SMTP id q23mr4024551qtg.229.1515017174775; Wed, 03 Jan 2018 14:06:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1515017174; cv=none; d=google.com; s=arc-20160816; b=qMUDdqUdNqFzT2B74p7qqAJAb2ULTn3TTeF098Rk48molVjI86Zc8Y9AxefyqL+dsi CNf9Ea/VIOqg+8qh1KRYnNQndwtOmWk0PN1JqI4DVGHv4usYljSQBCr49si8bp8dy9zi lM7SykVDbnONxMjoBicOlNjEahRAUQQRZTt+QOWqyCw4RraXN6FiKLrQc78cwLEwaZ/e wopSv5UAo9ZOn6rG698y8KNvFJ25JVbeVMfEX4Luw8mR+VtSm/BTl+BO81ukJVpDEv1w n3wG8dH5z7B6NnHnPlAbwzIpKpIPvmUlN/R8EiGScrzJ7p/aK/GndM9tExeH/AEtM+Zx 6y2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=9vKKSm1G7EOOzITGtFMDX4639fBGdyLALN2WnpepgIk=; b=Y5oVMq5RBvmIVG5VxHRaP70/LoBeqGS/ZcIPiVXYMtvpxz+hrOjNb/DgqtJVCqhJu2 p60l4m+EINCtkanUCFqhGC4A8mjthjO06Kx/tfl//hF7hERKFhV6Cis9d4VdA5tiMYmT frHg7+PV01uo7EfLSKMo2Zel14EfXqBfEo3MYyNAKZ1Ef5Uu46NYmXVsIikyu66YWc7L 9blbbVirL4fF6FzMlzy+EdPZJXIY5qkNM13Itk3/LLpGK/V3cipPfSouM/662FqpTRyr Chw6AC79DN7QQI+qh4LaKzh1p3FTEvRw6hft2i/s8LuoiK35lIJKdMfNhu6oaoq8ik2c KseA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id k31si1580650qkh.409.2018.01.03.14.06.14; Wed, 03 Jan 2018 14:06:14 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 5C70E60B51; Wed, 3 Jan 2018 22:06:14 +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.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 397A1614F0; Wed, 3 Jan 2018 22:00:58 +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 984C760912; Wed, 3 Jan 2018 22:00:26 +0000 (UTC) Received: from forward102j.mail.yandex.net (forward102j.mail.yandex.net [5.45.198.243]) by lists.linaro.org (Postfix) with ESMTPS id 2067E607E4 for ; Wed, 3 Jan 2018 22:00:18 +0000 (UTC) Received: from mxback9o.mail.yandex.net (mxback9o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::23]) by forward102j.mail.yandex.net (Yandex) with ESMTP id D989456019FE for ; Thu, 4 Jan 2018 01:00:16 +0300 (MSK) Received: from smtp3p.mail.yandex.net (smtp3p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:8]) by mxback9o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id lAUUWWTb1k-0GlKEfbV; Thu, 04 Jan 2018 01:00:16 +0300 Received: by smtp3p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id hqAp3CL4cC-0G4WXUp7; Thu, 04 Jan 2018 01:00:16 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 4 Jan 2018 01:00:07 +0300 Message-Id: <1515016810-26637-11-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515016810-26637-1-git-send-email-odpbot@yandex.ru> References: <1515016810-26637-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 377 Subject: [lng-odp] [PATCH v11 10/13] validation: time: use gettimeofday() instead of clock() 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Dmitry Eremin-Solenikov ODP test for time API uses clock() to compare time against. However clock() returns processor time used by program, which can differ between runs. Use gettimeofday() as a time source to compare against. Signed-off-by: Dmitry Eremin-Solenikov --- /** Email created from pull request 377 (lumag:misc-fixes) ** https://github.com/Linaro/odp/pull/377 ** Patch: https://github.com/Linaro/odp/pull/377.patch ** Base sha: 49ebafae0edebbc750742d8874ad0a7588286dea ** Merge commit sha: 3c1b82834c36bc66d397aedd2f80da45160eae2d **/ test/validation/api/time/time.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/test/validation/api/time/time.c b/test/validation/api/time/time.c index c8f90dbac..ccbc7e3ba 100644 --- a/test/validation/api/time/time.c +++ b/test/validation/api/time/time.c @@ -9,7 +9,7 @@ #include #include "odp_cunit_common.h" #include "time_test.h" -#include +#include #define BUSY_LOOP_CNT 30000000 /* used for t > min resolution */ #define BUSY_LOOP_CNT_LONG 6000000000 /* used for t > 4 sec */ @@ -423,11 +423,12 @@ static void time_test_accuracy(time_cb time_cur, time_from_ns_cb time_from_ns) { int i; odp_time_t t1, t2, wait, diff; - clock_t c1, c2; + struct timeval tv1, tv2, tvdiff; double sec_t, sec_c; odp_time_t sec = time_from_ns(ODP_TIME_SEC_IN_NS); - c1 = clock(); + i = gettimeofday(&tv1, NULL); + CU_ASSERT(i == 0); t1 = time_cur(); wait = odp_time_sum(t1, sec); @@ -436,12 +437,21 @@ static void time_test_accuracy(time_cb time_cur, time_from_ns_cb time_from_ns) wait = odp_time_sum(wait, sec); } + i = gettimeofday(&tv2, NULL); + CU_ASSERT(i == 0); t2 = time_cur(); - c2 = clock(); + + if (tv2.tv_usec < tv1.tv_usec) { + tvdiff.tv_usec = 1000000 + tv2.tv_usec - tv1.tv_usec; + tvdiff.tv_sec = tv2.tv_sec - 1 - tv1.tv_sec; + } else { + tvdiff.tv_usec = tv2.tv_usec - tv1.tv_usec; + tvdiff.tv_sec = tv2.tv_sec - tv1.tv_sec; + } diff = odp_time_diff(t2, t1); sec_t = ((double)odp_time_to_ns(diff)) / ODP_TIME_SEC_IN_NS; - sec_c = ((double)(c2 - c1)) / CLOCKS_PER_SEC; + sec_c = ((double)(tvdiff.tv_usec) / 1000000) + tvdiff.tv_sec; /* Check that ODP time is within +-5% of system time */ CU_ASSERT(sec_t < sec_c * 1.05);