From patchwork Mon Jan 15 10:00:12 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: 124487 Delivered-To: patch@linaro.org Received: by 10.46.64.148 with SMTP id r20csp617348lje; Mon, 15 Jan 2018 02:07:55 -0800 (PST) X-Google-Smtp-Source: ACJfBosL6p2XYcsfzcLrcrqshJWGrDUfjxNMN9vU9iTwLm76WH9dq5+cucVkpTXXCw4jukuu7qV7 X-Received: by 10.55.163.150 with SMTP id m144mr18208730qke.256.1516010875072; Mon, 15 Jan 2018 02:07:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516010875; cv=none; d=google.com; s=arc-20160816; b=lUES1x8XtWoanfo4A8AmjQu8cE7NWlDnxltDvTdTFTwYpVFQFso4t1N8boFIh/Ek0M tsUhIn4lAK0QMtSdh7+i1v2eh3BI/V43D+cEoO4+gLULhDrN59CsDYEFQfmLZd7ytCpD 3XFam/0zQDN74phNzLvJUcZ0pyLNTTeh2FW+OT4W60r4d8c5B0QyCSHWVXqE/XL3Nn7t B5SpqHNkJhjlmPQjoo1ZEB1vXiEKFwVVk7oHsN5h0Nfeo6/xGwSnrbkokNEvslyYQfek TutKJDBqOFFDeHcCfTMyzEpJypB4oCmeU3VuSnE0fmnNe8eWpLQFh2C+nlo5lpNKhPIu 7E4A== 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=Y8Ew6fMY2GOwxTVtPc/wXC3D40yU/QMP18zyy0psWkw=; b=sgQOZVkyPKYPCjjRZ/xMhEkqNidUQBXD1KiGkJePzouTpn1VpxjffL7SGBt783xhGt qqUXr3lgGn1EfnuTRdHfgeST5rdUxCxKs+l0LmMrFZUuZsgS1aM9Gk2t3tR0lP/Ldj3T K3AjefBH+jRL5q05m2vTpRs4LErCbVYYNXcFsheDg90cx36OCrktaMRxPbW++cs0YA8l rSWSO21W05dNHO93Mgf785YO5clmrQLMr3HAZ1HAGYWy+LafpztDH7axzTrQOiFj+UKx 9BKWsGJlymv1hGAQW0gWj/buVFxs+JSg4lvONS0ANrastfm5GWG2qkPSZZiawuD6KJGo Kkww== 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 85si171670qks.352.2018.01.15.02.07.54; Mon, 15 Jan 2018 02:07:55 -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 9695961781; Mon, 15 Jan 2018 10:07:54 +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_H2 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 05E1B617B2; Mon, 15 Jan 2018 10:01:47 +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 74EE06177D; Mon, 15 Jan 2018 10:01:38 +0000 (UTC) Received: from forward102p.mail.yandex.net (forward102p.mail.yandex.net [77.88.28.102]) by lists.linaro.org (Postfix) with ESMTPS id CE45C61781 for ; Mon, 15 Jan 2018 10:00:25 +0000 (UTC) Received: from mxback10o.mail.yandex.net (mxback10o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::24]) by forward102p.mail.yandex.net (Yandex) with ESMTP id 6D1F74301F41 for ; Mon, 15 Jan 2018 13:00:24 +0300 (MSK) Received: from smtp4j.mail.yandex.net (smtp4j.mail.yandex.net [2a02:6b8:0:1619::15:6]) by mxback10o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id ml0q4HNp0W-0OvmWqn0; Mon, 15 Jan 2018 13:00:24 +0300 Received: by smtp4j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id ZqkoG8NoF8-0NrKq9D4; Mon, 15 Jan 2018 13:00:24 +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: Mon, 15 Jan 2018 13:00:12 +0300 Message-Id: <1516010417-3323-11-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516010417-3323-1-git-send-email-odpbot@yandex.ru> References: <1516010417-3323-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 377 Subject: [lng-odp] [PATCH v13 10/15] validation: time: use clock_gettime() 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 clock_gettime() as a time source to compare against. Signed-off-by: Dmitry Eremin-Solenikov Fixes: https://bugs.linaro.org/show_bug.cgi?id=3572 --- /** 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: 634b380b63de53c65b92c214d91aaf03785d69db ** Merge commit sha: 9dbaba7b2769979792f04d62a6c8accf0c6b13df **/ test/validation/api/time/time.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/test/validation/api/time/time.c b/test/validation/api/time/time.c index c8f90dbac..d7d5b790e 100644 --- a/test/validation/api/time/time.c +++ b/test/validation/api/time/time.c @@ -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 timespec ts1, ts2, tsdiff; double sec_t, sec_c; odp_time_t sec = time_from_ns(ODP_TIME_SEC_IN_NS); - c1 = clock(); + i = clock_gettime(CLOCK_MONOTONIC, &ts1); + 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 = clock_gettime(CLOCK_MONOTONIC, &ts2); + CU_ASSERT(i == 0); t2 = time_cur(); - c2 = clock(); + + if (ts2.tv_nsec < ts1.tv_nsec) { + tsdiff.tv_nsec = 1000000000L + ts2.tv_nsec - ts1.tv_nsec; + tsdiff.tv_sec = ts2.tv_sec - 1 - ts1.tv_sec; + } else { + tsdiff.tv_nsec = ts2.tv_nsec - ts1.tv_nsec; + tsdiff.tv_sec = ts2.tv_sec - ts1.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)(tsdiff.tv_nsec) / 1000000000L) + tsdiff.tv_sec; /* Check that ODP time is within +-5% of system time */ CU_ASSERT(sec_t < sec_c * 1.05);