From patchwork Mon Jan 18 13:16:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 59924 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp1991253lbb; Mon, 18 Jan 2016 05:16:37 -0800 (PST) X-Received: by 10.140.230.68 with SMTP id a65mr20058496qhc.31.1453122997861; Mon, 18 Jan 2016 05:16:37 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id j203si30854009qhc.107.2016.01.18.05.16.37; Mon, 18 Jan 2016 05:16:37 -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 1FDD961717; Mon, 18 Jan 2016 13:16:37 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=RrtM92fT; 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 BB1F96162A; Mon, 18 Jan 2016 13:16:26 +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 39D8A6162C; Mon, 18 Jan 2016 13:16:25 +0000 (UTC) Received: from mail-lf0-f48.google.com (mail-lf0-f48.google.com [209.85.215.48]) by lists.linaro.org (Postfix) with ESMTPS id D704F61611 for ; Mon, 18 Jan 2016 13:16:23 +0000 (UTC) Received: by mail-lf0-f48.google.com with SMTP id m198so171833566lfm.0 for ; Mon, 18 Jan 2016 05:16:23 -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=PBe59igzCXCAbqYQsStOiI9Ocun4RI+YRiSxsc1N0TU=; b=RrtM92fTcx3XAD3tWQG17eodqwatPBA+XZ4wjJ6Hx2rEA29Dr85pVBTfIbYtRJ74eg wyJzd4ekgB6PAZuLO9wbVDPMipxXpb7uB9e77x5ZlnKFptEtcVj2HZWycebkWdrs/oP9 BH59Ee42lVA+AwsJ69kqKangShZ7WPHx/nn8w= 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=PBe59igzCXCAbqYQsStOiI9Ocun4RI+YRiSxsc1N0TU=; b=Pb9ORQsDIRj9d25eZo/03rmJ7dFBtz9Cqpp/uPagmAvAlETwJcWCRN+WDlBv3cBJjA 2Bii40KagMlDjodzJNEvtEPPaVh37ZgSKoNVKeXWCPFmwiWwLykn50InfzxigI4fWgLi LmpRC38EXTR6Lw67Cs/VljEgMs7d7e+le215JHSakgDlCgFK7Z0YeTgvRpNJn1qPWFEf e3XhqcKMDbFkLCiPRdfR1tZqblgkLUd+uB3iVUYIc0MNqCIfh3KxtJ/VCSRNbpzKl0M2 +SZEat618nOlx1YAohzDxa+1NtSgwgqb8IQ4x6JIfoaYcqDlB7T4/xgGwZWszisCz/Fj o/sg== X-Gm-Message-State: ALoCoQnsbS+l2BIzDNQo6ub6V1/Nd55f0b6HrKTgNXY7li2re7VC+OvIqRGAhEoOeir+2UuYM59hCqGZPtHo0j26WjFHZXES6w== X-Received: by 10.25.212.199 with SMTP id l190mr8589616lfg.163.1453122982502; Mon, 18 Jan 2016 05:16:22 -0800 (PST) Received: from localhost.localdomain ([195.238.92.128]) by smtp.gmail.com with ESMTPSA id rg10sm3177697lbb.11.2016.01.18.05.16.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Jan 2016 05:16:21 -0800 (PST) From: Ivan Khoronzhuk To: lng-odp@lists.linaro.org Date: Mon, 18 Jan 2016 15:16:14 +0200 Message-Id: <1453122974-8664-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 v6] 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 v5: - add res instead of "1" while wrap - get cycle stamps a multiple of res instead direct valuues. - move resolution test before diff test Since v3: - modified log "wrap is not detected" - increased try num for diff to match 16 seconds - decreased try num for resolution to match 1 second - allow resolution to be up to max / 1024 - correct wrap detection for resolution Since v2: - added c <= max - replaced etalon on tmp - added msg about skip - handled resolution wrap # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # On branch validation_tests_corrections # Changes to be committed: # modified: platform/linux-keystone2/odp_crypto.c # modified: test/validation/system/system.c # # Changes not staged for commit: # modified: platform/linux-keystone2/odp_schedule.c # # Untracked files: # .checkpatch-camelcase.git.81a3df4 # example/traffic_mgmt/ # test/validation/system/system.c | 125 ++++++++++++++++++++++++++++++++++++++++ test/validation/system/system.h | 4 ++ 2 files changed, 129 insertions(+) diff --git a/test/validation/system/system.c b/test/validation/system/system.c index 7dc2cc0..7f54338 100644 --- a/test/validation/system/system.c +++ b/test/validation/system/system.c @@ -10,6 +10,9 @@ #include "test_debug.h" #include "system.h" +#define DIFF_TRY_NUM 160 +#define RES_TRY_NUM 10 + void system_test_odp_version_numbers(void) { int char_ok = 0; @@ -40,6 +43,124 @@ 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_resolution(void) +{ + int i; + uint64_t res; + uint64_t c2, c1, max; + + max = odp_cpu_cycles_max(); + + res = odp_cpu_cycles_resolution(); + CU_ASSERT(res != 0); + CU_ASSERT(res < max / 1024); + + for (i = 0; i < RES_TRY_NUM; i++) { + c1 = odp_cpu_cycles(); + odp_time_wait_ns(100 * ODP_TIME_MSEC_IN_NS + i); + c2 = odp_cpu_cycles(); + + CU_ASSERT(c1 % res == 0); + CU_ASSERT(c2 % res == 0); + } +} + +void system_test_odp_cpu_cycles_diff(void) +{ + int i; + uint64_t c2, c1, c3, max; + uint64_t tmp, diff, res; + + res = odp_cpu_cycles_resolution(); + max = odp_cpu_cycles_max(); + + /* check resolution for wrap */ + c1 = max - 2 * res; + do + c2 = odp_cpu_cycles(); + while (c1 < c2); + + diff = odp_cpu_cycles_diff(c1, c1); + CU_ASSERT(diff == 0); + + /* wrap */ + tmp = c2 + (max - c1) + res; + diff = odp_cpu_cycles_diff(c2, c1); + CU_ASSERT(diff == tmp); + CU_ASSERT(diff % res == 0); + + /* no wrap, revert args */ + tmp = c1 - c2; + diff = odp_cpu_cycles_diff(c1, c2); + CU_ASSERT(diff == tmp); + CU_ASSERT(diff % res == 0); + + c3 = odp_cpu_cycles(); + for (i = 0; i < DIFF_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); + CU_ASSERT(c1 % res == 0); + CU_ASSERT(c2 % res == 0); + CU_ASSERT(c1 <= max && c2 <= max); + + if (c2 > c1) + tmp = c2 - c1; + else + tmp = c2 + (max - c1) + res; + + diff = odp_cpu_cycles_diff(c2, c1); + CU_ASSERT(diff == tmp); + CU_ASSERT(diff % res == 0); + + /* wrap is detected and verified */ + if (c2 < c1) + break; + } + + /* wrap was detected, no need to continue */ + if (i < DIFF_TRY_NUM) + return; + + /* wrap has to be detected if possible */ + CU_ASSERT(max > UINT32_MAX); + CU_ASSERT((max - c3) > UINT32_MAX); + + printf("wrap was not detected..."); +} + void system_test_odp_sys_cache_line_size(void) { uint64_t cache_size; @@ -91,6 +212,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_resolution), + ODP_TEST_INFO(system_test_odp_cpu_cycles_diff), 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[];