From patchwork Mon Dec 29 16:08:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 42645 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 90AEF25B8B for ; Mon, 29 Dec 2014 16:09:23 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id l15sf8228128wiw.0 for ; Mon, 29 Dec 2014 08:09:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=/sJQ4w9pjKuuoPZ9UFFv6JfCswEMO5epsh0cM2DnJtQ=; b=VVaedawZmpYykSHjwG/0pLvl6VFD3oMS+qDFV9i56ZFSyvsCeOxmbLEV7SoDs/AZk7 qcYfdw5dGdryU+5bZJE89Sh5E32/aOb4bVDufTmGoJCcpnUrkc7AiffLPHs35BLPA9PP iS/iHExBDt2oEqbGTU6ZG4Z20SyC7k3JsSVbrHHCh+IX4RWw/TPpxxwFXmqA4ci7ptOI WXnq4Ulh4NBFjGtqS/tPPBp4mVPfvlbCUpYBiviy0JUQQZDTyNy0P1noCbfnqrHRn4MU lHx9hdghk7Qn5CZ20k/iyz5HdbWWTdPiK8N1LIkLno0jfz0ERgtEhnAICSR6l2iv6oU/ oSCw== X-Gm-Message-State: ALoCoQlQOTYDIk/OZI6JwCUiZxvSMpkqCK+c8Ziyax7CHZFjx1//6A/3OmtHIGw9nr7F0d1iDRCx X-Received: by 10.180.7.226 with SMTP id m2mr5986471wia.5.1419869362674; Mon, 29 Dec 2014 08:09:22 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.50 with SMTP id u18ls2082352laz.96.gmail; Mon, 29 Dec 2014 08:09:22 -0800 (PST) X-Received: by 10.152.219.3 with SMTP id pk3mr57691486lac.19.1419869362383; Mon, 29 Dec 2014 08:09:22 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id xb8si39982743lbb.109.2014.12.29.08.09.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 29 Dec 2014 08:09:22 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id l4so10993972lbv.26 for ; Mon, 29 Dec 2014 08:09:22 -0800 (PST) X-Received: by 10.152.197.5 with SMTP id iq5mr57283846lac.6.1419869362248; Mon, 29 Dec 2014 08:09:22 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.142.69 with SMTP id ru5csp2824697lbb; Mon, 29 Dec 2014 08:09:21 -0800 (PST) X-Received: by 10.140.94.117 with SMTP id f108mr76012171qge.50.1419869360500; Mon, 29 Dec 2014 08:09:20 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id k95si16084743qgd.72.2014.12.29.08.09.19 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 29 Dec 2014 08:09:20 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y5csd-0001Nb-Pk; Mon, 29 Dec 2014 16:09:15 +0000 Received: from mail-qg0-f47.google.com ([209.85.192.47]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y5csX-0001LS-Uo for lng-odp@lists.linaro.org; Mon, 29 Dec 2014 16:09:09 +0000 Received: by mail-qg0-f47.google.com with SMTP id q108so9486159qgd.34 for ; Mon, 29 Dec 2014 08:09:04 -0800 (PST) X-Received: by 10.140.83.100 with SMTP id i91mr25001581qgd.97.1419869344700; Mon, 29 Dec 2014 08:09:04 -0800 (PST) Received: from localhost.localdomain ([98.221.136.245]) by mx.google.com with ESMTPSA id y20sm3921926qgd.35.2014.12.29.08.09.03 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 29 Dec 2014 08:09:04 -0800 (PST) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Mon, 29 Dec 2014 11:08:58 -0500 Message-Id: <1419869338-7781-1-git-send-email-mike.holmes@linaro.org> X-Mailer: git-send-email 2.1.0 X-Topics: patch Subject: [lng-odp] [PATCH v2] validation: add odp_time test X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: 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-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mike.holmes@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Add odp_time_x API tests Signed-off-by: Mike Holmes --- v2: fix bad auto merge of Makefile.am clean up names test/validation/.gitignore | 1 + test/validation/Makefile.am | 5 ++-- test/validation/odp_time.c | 71 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 test/validation/odp_time.c diff --git a/test/validation/.gitignore b/test/validation/.gitignore index d08db73..40ea12d 100644 --- a/test/validation/.gitignore +++ b/test/validation/.gitignore @@ -8,3 +8,4 @@ odp_shm odp_system odp_pktio odp_buffer +odp_time diff --git a/test/validation/Makefile.am b/test/validation/Makefile.am index c0545b7..692e1a6 100644 --- a/test/validation/Makefile.am +++ b/test/validation/Makefile.am @@ -6,9 +6,9 @@ AM_LDFLAGS += -static TESTS_ENVIRONMENT = ODP_PLATFORM=${with_platform} if ODP_CUNIT_ENABLED -TESTS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_pktio_run odp_buffer odp_system +TESTS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_pktio_run odp_buffer odp_system odp_time check_PROGRAMS = ${bin_PROGRAMS} -bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_pktio odp_buffer odp_system +bin_PROGRAMS = odp_init odp_queue odp_crypto odp_shm odp_schedule odp_pktio odp_buffer odp_system odp_time odp_crypto_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/crypto odp_buffer_CFLAGS = $(AM_CFLAGS) -I$(srcdir)/buffer endif @@ -27,3 +27,4 @@ dist_odp_buffer_SOURCES = buffer/odp_buffer_pool_test.c \ buffer/odp_packet_test.c \ odp_buffer.c common/odp_cunit_common.c dist_odp_system_SOURCES = odp_system.c common/odp_cunit_common.c +dist_odp_time_SOURCES = odp_time.c common/odp_cunit_common.c diff --git a/test/validation/odp_time.c b/test/validation/odp_time.c new file mode 100644 index 0000000..75be1f0 --- /dev/null +++ b/test/validation/odp_time.c @@ -0,0 +1,71 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include "odp_cunit_common.h" + +#define TOLERANCE 1 +#define BUSY_LOOP_CNT 100 + +/* check that a cycles difference gives a reasonable result */ +static void test_odp_cycles_diff(void) +{ + /* volatile to stop optimization of busy loop */ + volatile int count; + uint64_t diff, cycles1, cycles2; + + cycles1 = odp_time_cycles(); + + while (count < BUSY_LOOP_CNT) { + count++; + }; + + cycles2 = odp_time_cycles(); + CU_ASSERT(cycles2 > cycles1); + + diff = odp_time_diff_cycles(cycles1, cycles2); + CU_ASSERT(diff > 0); +} + +/* check that a negative cycles difference gives a reasonable result */ +static void test_odp_cycles_negative_diff(void) +{ + uint64_t diff, cycles1, cycles2; + cycles1 = 10; + cycles2 = 5; + diff = odp_time_diff_cycles(cycles1, cycles2); + CU_ASSERT(diff > 0); +} + +/* check that related conversions come back to the same value */ +static void test_odp_time_conversion(void) +{ + uint64_t ns1, ns2, cycles; + uint64_t upper_limit, lower_limit; + ns1 = 100; + cycles = odp_time_ns_to_cycles(ns1); + CU_ASSERT(cycles > 0); + + ns2 = odp_time_cycles_to_ns(cycles); + + /* 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)); +} + +CU_TestInfo test_odp_time[] = { + {"cycles diff", test_odp_cycles_diff}, + {"negative diff", test_odp_cycles_negative_diff}, + {"conversion", test_odp_time_conversion}, + CU_TEST_INFO_NULL +}; + +CU_SuiteInfo odp_testsuites[] = { + {"Time", NULL, NULL, NULL, NULL, test_odp_time}, + CU_SUITE_INFO_NULL +};