From patchwork Mon Jan 5 22:27:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Holmes X-Patchwork-Id: 42761 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f71.google.com (mail-ee0-f71.google.com [74.125.83.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id F017725B5B for ; Mon, 5 Jan 2015 22:28:12 +0000 (UTC) Received: by mail-ee0-f71.google.com with SMTP id c13sf12604078eek.2 for ; Mon, 05 Jan 2015 14:28:11 -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=1i0z7FzoPI/FnwHHx9R/i3GTfd5nsctd11V/I3FfY1Y=; b=SxghMV5XW7ltA9l3nrEloZum5v2/w6+Mext2hHZn1AZ8OoBheC58hBSpj0mw/CRk+3 AeKR4NbsoSRNio0xHLN5uFRPi+O1HhIy/+wmmioS0CxAapvB/pWRJHb5Yq7GGHRoyryK giXRGFNiIjWdOtxDv9GQ5uHWNmkaqtz6Yy4rbOTpgTjhTUeae99GrxKdnPiS0vkO3uKs 8pbToUvi6thik106AdZLrrwia02RkSDBkn9I9nvqlkhNh1Y827idm47dfUPlKkOvH811 xtyFjbBvYGCa4SNmm/yNhUiKHikVsVBt+BQUInygjmJaYs1ogwYTCp0BUCM8ibBgZG0J zEqQ== X-Gm-Message-State: ALoCoQlPsl+5KaW1W7uEcdwVKKF1J49cS2A4qtj3wylFTjK3gvtUnnT8uiURNBJi6APhmFyYcMhb X-Received: by 10.112.13.161 with SMTP id i1mr6675lbc.20.1420496891897; Mon, 05 Jan 2015 14:28:11 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.203.162 with SMTP id kr2ls2566184lac.36.gmail; Mon, 05 Jan 2015 14:28:11 -0800 (PST) X-Received: by 10.152.19.71 with SMTP id c7mr95964805lae.79.1420496891735; Mon, 05 Jan 2015 14:28:11 -0800 (PST) Received: from mail-lb0-f180.google.com (mail-lb0-f180.google.com. [209.85.217.180]) by mx.google.com with ESMTPS id gl8si63769382lbc.60.2015.01.05.14.28.11 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 05 Jan 2015 14:28:11 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.180 as permitted sender) client-ip=209.85.217.180; Received: by mail-lb0-f180.google.com with SMTP id l4so18218775lbv.39 for ; Mon, 05 Jan 2015 14:28:11 -0800 (PST) X-Received: by 10.152.43.103 with SMTP id v7mr96258650lal.29.1420496891600; Mon, 05 Jan 2015 14:28:11 -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.9.200 with SMTP id c8csp1007058lbb; Mon, 5 Jan 2015 14:28:10 -0800 (PST) X-Received: by 10.140.41.113 with SMTP id y104mr139346526qgy.51.1420496889831; Mon, 05 Jan 2015 14:28:09 -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 c3si35460834qaj.77.2015.01.05.14.28.08 (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 05 Jan 2015 14:28:09 -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 1Y8G85-0006Wb-6z; Mon, 05 Jan 2015 22:28:05 +0000 Received: from mail-qg0-f43.google.com ([209.85.192.43]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Y8G7y-0006WW-QP for lng-odp@lists.linaro.org; Mon, 05 Jan 2015 22:27:58 +0000 Received: by mail-qg0-f43.google.com with SMTP id z107so16282046qgd.30 for ; Mon, 05 Jan 2015 14:27:53 -0800 (PST) X-Received: by 10.224.120.8 with SMTP id b8mr138261609qar.36.1420496873637; Mon, 05 Jan 2015 14:27:53 -0800 (PST) Received: from localhost.localdomain ([98.221.136.245]) by mx.google.com with ESMTPSA id y2sm30740232qaj.3.2015.01.05.14.27.52 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Jan 2015 14:27:52 -0800 (PST) From: Mike Holmes To: lng-odp@lists.linaro.org Date: Mon, 5 Jan 2015 17:27:39 -0500 Message-Id: <1420496859-15812-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.180 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 Reviewed-by: Bill Fischofer --- 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..b0f29cf --- /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 = 0; + 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 +};