From patchwork Tue Mar 16 14:32:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Power, Ciara" X-Patchwork-Id: 89238 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 527BCA054F; Tue, 16 Mar 2021 15:33:12 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2C714260075; Tue, 16 Mar 2021 15:33:04 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by mails.dpdk.org (Postfix) with ESMTP id 7391F26005B for ; Tue, 16 Mar 2021 15:33:01 +0100 (CET) IronPort-SDR: w7sdfYjxPsOoEfqadaDN2bGytXaX5l9hyFLnlttfAXuOqMiCIQyPvp3mDOKh7i988xOOH5iMW8 AnkeWprG1kEw== X-IronPort-AV: E=McAfee;i="6000,8403,9924"; a="185906430" X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="185906430" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Mar 2021 07:33:00 -0700 IronPort-SDR: /2K9+247JcgCFocG9FA5iPyZaZRk7A08QKhK0ZU3gfeCvl0WFWnH9/aBODrWmJ16EjgbGauy+I Bp4fRYgfpSGQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.81,251,1610438400"; d="scan'208";a="373805407" Received: from silpixa00400355.ir.intel.com (HELO silpixa00400355.ger.corp.intel.com) ([10.237.223.148]) by orsmga006.jf.intel.com with ESMTP; 16 Mar 2021 07:32:59 -0700 From: Ciara Power To: dev@dpdk.org Cc: declan.doherty@intel.com, Ciara Power Date: Tue, 16 Mar 2021 14:32:48 +0000 Message-Id: <20210316143253.3849182-2-ciara.power@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210316143253.3849182-1-ciara.power@intel.com> References: <20210316143253.3849182-1-ciara.power@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH 1/6] app/test: refactor of unit test suite runner X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Some small changes were made to the unit test suite runner for readability and to enable reuse of some of the function in a later patch. On test suite setup skip/fail, the loop to count testcases as skipped/failed has been moved to another function. This will allow for recursion in a later patch when nested sub-testsuites are used. The unit test suite runner accessed the list of testcases in the suite structure every time the testcase was used. This is now replaced by a testcase variable which improves readability. The summary output now prints the suite name, this will be useful later when multiple nested sub-testsuites are being run. Signed-off-by: Ciara Power --- app/test/test.c | 51 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/app/test/test.c b/app/test/test.c index 624dd48042..72768c8854 100644 --- a/app/test/test.c +++ b/app/test/test.c @@ -207,6 +207,23 @@ main(int argc, char **argv) return ret; } +static void +unit_test_suite_count_tcs_on_setup_fail(struct unit_test_suite *suite, + int test_success, unsigned int *total, unsigned int *skipped, + unsigned int *failed) +{ + struct unit_test_case tc; + + tc = suite->unit_test_cases[*total]; + while (tc.testcase) { + if (!tc.enabled || test_success == TEST_SKIPPED) + (*skipped)++; + else + (*failed)++; + (*total)++; + tc = suite->unit_test_cases[*total]; + } +} int unit_test_suite_runner(struct unit_test_suite *suite) @@ -215,6 +232,7 @@ unit_test_suite_runner(struct unit_test_suite *suite) unsigned int total = 0, executed = 0, skipped = 0; unsigned int succeeded = 0, failed = 0, unsupported = 0; const char *status; + struct unit_test_case tc; if (suite->suite_name) { printf(" + ------------------------------------------------------- +\n"); @@ -228,38 +246,35 @@ unit_test_suite_runner(struct unit_test_suite *suite) * setup did not pass, so count all enabled tests and * mark them as failed/skipped */ - while (suite->unit_test_cases[total].testcase) { - if (!suite->unit_test_cases[total].enabled || - test_success == TEST_SKIPPED) - skipped++; - else - failed++; - total++; - } + unit_test_suite_count_tcs_on_setup_fail(suite, + test_success, &total, + &skipped, &failed); goto suite_summary; } } printf(" + ------------------------------------------------------- +\n"); - while (suite->unit_test_cases[total].testcase) { - if (!suite->unit_test_cases[total].enabled) { + tc = suite->unit_test_cases[total]; + while (tc.testcase) { + if (!tc.enabled) { skipped++; total++; + tc = suite->unit_test_cases[total]; continue; } else { executed++; } /* run test case setup */ - if (suite->unit_test_cases[total].setup) - test_success = suite->unit_test_cases[total].setup(); + if (tc.setup) + test_success = tc.setup(); else test_success = TEST_SUCCESS; if (test_success == TEST_SUCCESS) { /* run the test case */ - test_success = suite->unit_test_cases[total].testcase(); + test_success = tc.testcase(); if (test_success == TEST_SUCCESS) succeeded++; else if (test_success == TEST_SKIPPED) @@ -275,8 +290,8 @@ unit_test_suite_runner(struct unit_test_suite *suite) } /* run the test case teardown */ - if (suite->unit_test_cases[total].teardown) - suite->unit_test_cases[total].teardown(); + if (tc.teardown) + tc.teardown(); if (test_success == TEST_SUCCESS) status = "succeeded"; @@ -287,10 +302,10 @@ unit_test_suite_runner(struct unit_test_suite *suite) else status = "failed"; - printf(" + TestCase [%2d] : %s %s\n", total, - suite->unit_test_cases[total].name, status); + printf(" + TestCase [%2d] : %s %s\n", total, tc.name, status); total++; + tc = suite->unit_test_cases[total]; } /* Run test suite teardown */ @@ -301,7 +316,7 @@ unit_test_suite_runner(struct unit_test_suite *suite) suite_summary: printf(" + ------------------------------------------------------- +\n"); - printf(" + Test Suite Summary \n"); + printf(" + Test Suite Summary : %s\n", suite->suite_name); printf(" + Tests Total : %2d\n", total); printf(" + Tests Skipped : %2d\n", skipped); printf(" + Tests Executed : %2d\n", executed);