From patchwork Fri Jan 15 12:32:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 59856 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp511669lbb; Fri, 15 Jan 2016 04:33:19 -0800 (PST) X-Received: by 10.140.106.228 with SMTP id e91mr12631397qgf.59.1452861199782; Fri, 15 Jan 2016 04:33:19 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id c108si13128114qgf.117.2016.01.15.04.33.19; Fri, 15 Jan 2016 04:33:19 -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 Received: by lists.linaro.org (Postfix, from userid 109) id 3403561902; Fri, 15 Jan 2016 12:33:19 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=A58ahqUV; dkim-adsp=none (unprotected policy); dkim-atps=neutral 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 A1739618C9; Fri, 15 Jan 2016 12:33:13 +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 8248C6177F; Fri, 15 Jan 2016 12:33:11 +0000 (UTC) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) by lists.linaro.org (Postfix) with ESMTPS id 30DFD6177F for ; Fri, 15 Jan 2016 12:33:06 +0000 (UTC) Received: by mail-lb0-f181.google.com with SMTP id bc4so313082793lbc.2 for ; Fri, 15 Jan 2016 04:33:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=PAXQ3nBc4eCp9q3+WVY2v0iKC/TkJqILTUKpPd9J7Oc=; b=A58ahqUVd5Pi18EE0IMJfkgDQmJW+FKEImZCfTzUW19ri+/UvFDFlPYmNveI4cc/d4 ib+kSyjHmC2scc4NLxGCllkcIqUAr11H0NwLj3tnHSiZP0Yt+H9aYOxtWh7a9Pe1umlK NoQlKLI5viQ2Xp7Kyz5fGhZoVlimCZg1lOnhw= 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; bh=PAXQ3nBc4eCp9q3+WVY2v0iKC/TkJqILTUKpPd9J7Oc=; b=TciYpBkREE1zaDNuVudr9jUSPhwkVHeQyEv9ZANBe+0TtECoJDIH+NsFbpztGhyRKu Q/ToenhyA3TcDfrX66e+KYxyjbH+5OiKoWcNEs059Z3J7z2LjRfCuf/2vn08K/W2xs3B 7Wkha/dukiCxrl7KpR5ycSaAHvT4MmEhY40e/rSJGNkRITD0dKPyoePjpukZsnyqNnZ3 c8ZlFc5ACXEgWSgOHTysuew8UWKL9Ew0Fh7LQddogzib153cmgGZ8VexNY6y51mNAvPi iY2f2qxsKdcsPgoCsxPRRcCWTo6CLP1gpcugYGv7IwL3ozvguBoZRFgMDfFtttUtAanQ HDhw== X-Gm-Message-State: ALoCoQmWNps4aDqFOtuJ7HxEC4M2nSfCDXcyJxeORzi2dZeRnRI7UcaiyowFw7nbwMZFmNkvHqgqW5Ig2mANG2tj5+BfKUs7Dw== X-Received: by 10.112.149.202 with SMTP id uc10mr3114172lbb.57.1452861184428; Fri, 15 Jan 2016 04:33:04 -0800 (PST) Received: from localhost.localdomain ([195.238.92.128]) by smtp.gmail.com with ESMTPSA id l129sm1356258lfl.37.2016.01.15.04.33.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Jan 2016 04:33:03 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Fri, 15 Jan 2016 14:32:55 +0200 Message-Id: <1452861175-25908-1-git-send-email-ivan.khoronzhuk@linaro.org> X-Mailer: git-send-email 1.9.1 X-Topics: patch Cc: petri.savolainen@nokia.com Subject: [lng-odp] [PATCH v3] validation: system: add validation tests for odp_cpu_cycles_* calls 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" https://bugs.linaro.org/show_bug.cgi?id=1906 Signed-off-by: Ivan Khoronzhuk --- Since v2: - added c <= max - replaced etalon on tmp - added msg about skip - handled resolution wrap test/validation/system/system.c | 133 ++++++++++++++++++++++++++++++++++++++++ test/validation/system/system.h | 4 ++ 2 files changed, 137 insertions(+) diff --git a/test/validation/system/system.c b/test/validation/system/system.c index 7dc2cc0..2cf5d29 100644 --- a/test/validation/system/system.c +++ b/test/validation/system/system.c @@ -10,6 +10,8 @@ #include "test_debug.h" #include "system.h" +#define TRY_NUM 80 + void system_test_odp_version_numbers(void) { int char_ok = 0; @@ -40,6 +42,133 @@ void system_test_odp_cpu_count(void) CU_ASSERT(0 < cpus); } +void system_test_odp_cpu_cycles(void) +{ + uint64_t c2, c1; + + c1 = odp_cpu_cycles(); + odp_time_wait_ns(100); + c2 = odp_cpu_cycles(); + + CU_ASSERT(c2 != c1); +} + +void system_test_odp_cpu_cycles_max(void) +{ + uint64_t c2, c1; + uint64_t max1, max2; + + max1 = odp_cpu_cycles_max(); + odp_time_wait_ns(100); + max2 = odp_cpu_cycles_max(); + + CU_ASSERT(max1 >= UINT32_MAX / 2); + CU_ASSERT(max1 == max2); + + c1 = odp_cpu_cycles(); + odp_time_wait_ns(1000); + c2 = odp_cpu_cycles(); + + CU_ASSERT(c1 <= max1 && c2 <= max1); +} + +void system_test_odp_cpu_cycles_diff(void) +{ + int i; + uint64_t c2, c1; + uint64_t tmp, diff; + + c2 = 100; + c1 = 39; + + diff = odp_cpu_cycles_diff(c2, c2); + CU_ASSERT(diff == 0); + + tmp = c2 - c1; + diff = odp_cpu_cycles_diff(c2, c1); + CU_ASSERT(diff == tmp); + + tmp = c1 + (odp_cpu_cycles_max() - c2) + 1; + diff = odp_cpu_cycles_diff(c1, c2); + CU_ASSERT(diff == tmp); + + c1 = odp_cpu_cycles(); + if (!(odp_cpu_cycles_max() <= UINT32_MAX || + (odp_cpu_cycles_max() - c1) <= UINT32_MAX)) { + printf("wrap detection is skipped..."); + return; + } + + /* must handle one wrap */ + for (i = 0; i < TRY_NUM; i++) { + c1 = odp_cpu_cycles(); + odp_time_wait_ns(100 * ODP_TIME_MSEC_IN_NS + i); + c2 = odp_cpu_cycles(); + + CU_ASSERT(c2 != c1); + + if (c2 > c1) + tmp = c2 - c1; + else + tmp = c2 + (odp_cpu_cycles_max() - c1) + 1; + + diff = odp_cpu_cycles_diff(c2, c1); + CU_ASSERT(diff == tmp); + + /* wrap is detected and verified */ + if (c2 < c1) + break; + } + + /* wrap has to be detected */ + CU_ASSERT(i < TRY_NUM); +} + +void system_test_odp_cpu_cycles_resolution(void) +{ + int i; + uint64_t rest; + uint64_t res, diff; + uint64_t c2, c1, max; + + res = odp_cpu_cycles_resolution(); + CU_ASSERT(res != 0); + CU_ASSERT(res < 500); + + /* check resolution for wrap */ + max = odp_cpu_cycles_max(); + c1 = max - 2 * res; + c2 = odp_cpu_cycles(); + diff = odp_cpu_cycles_diff(c2, c1); + rest = diff % res; + CU_ASSERT(rest == 0); + + /* + * must be a multiple of resolution in + * whole interval till wrap, in another + * case resolution is set incorrectly + */ + for (i = 0; i < TRY_NUM; i++) { + c1 = odp_cpu_cycles(); + odp_time_wait_ns(100 * ODP_TIME_MSEC_IN_NS + i); + c2 = odp_cpu_cycles(); + + diff = odp_cpu_cycles_diff(c2, c1); + rest = diff % res; + CU_ASSERT(rest == 0); + + rest = c1 % res; + CU_ASSERT(rest == 0); + + rest = c2 % res; + CU_ASSERT(rest == 0); + + /* wrap is detected and verified */ + if (c2 < c1) + break; + } +} + void system_test_odp_sys_cache_line_size(void) { uint64_t cache_size; @@ -91,6 +220,10 @@ odp_testinfo_t system_suite[] = { ODP_TEST_INFO(system_test_odp_sys_page_size), ODP_TEST_INFO(system_test_odp_sys_huge_page_size), ODP_TEST_INFO(system_test_odp_sys_cpu_hz), + ODP_TEST_INFO(system_test_odp_cpu_cycles), + ODP_TEST_INFO(system_test_odp_cpu_cycles_max), + ODP_TEST_INFO(system_test_odp_cpu_cycles_diff), + ODP_TEST_INFO(system_test_odp_cpu_cycles_resolution), ODP_TEST_INFO_NULL, }; diff --git a/test/validation/system/system.h b/test/validation/system/system.h index 869aaff..0c263f2 100644 --- a/test/validation/system/system.h +++ b/test/validation/system/system.h @@ -17,6 +17,10 @@ void system_test_odp_sys_cpu_model_str(void); void system_test_odp_sys_page_size(void); void system_test_odp_sys_huge_page_size(void); void system_test_odp_sys_cpu_hz(void); +void system_test_odp_cpu_cycles_max(void); +void system_test_odp_cpu_cycles(void); +void system_test_odp_cpu_cycles_diff(void); +void system_test_odp_cpu_cycles_resolution(void); /* test arrays: */ extern odp_testinfo_t system_suite[];