From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com []) by mx.groups.io with SMTP id smtpd.web12.7397.1592180374394024448 for ; Sun, 14 Jun 2020 17:19:35 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=fail (domain: intel.com, ip: , mailfrom: michael.d.kinney@intel.com) IronPort-SDR: 4MJpXWIJCsym+F3GEk3QtWjIBR045IJtC2xhcggabP0md2GECox2V9wKwdWjruzJEDVGVEnaew JA1ysZRi56ZA== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2020 17:19:25 -0700 IronPort-SDR: w9AfY2rSxz4IDYa6h3IHtEeuu+7vJRdsvOSCX8RJ/uHR8DXFz3MWiyiApf4wsZordtmOKpDSEN jqiHfRfFET4Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,513,1583222400"; d="scan'208";a="276370278" Received: from mdkinney-mobl2.amr.corp.intel.com ([10.252.142.246]) by orsmga006.jf.intel.com with ESMTP; 14 Jun 2020 17:19:25 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Sean Brogan , Bret Barkelew , Jiewen Yao Subject: [Patch 10/15] UnitTestFrameworkPkg/UnitTestLib: Move print log into cleanup Date: Sun, 14 Jun 2020 17:19:13 -0700 Message-Id: <20200615001918.22164-11-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20200615001918.22164-1-michael.d.kinney@intel.com> References: <20200615001918.22164-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit https://bugzilla.tianocore.org/show_bug.cgi?id=2805 If a unit test fails with an exception or an assert, then the CmockaUnitTestFunctionRunner() is terminated and the logic that follows the invocation of the unit test is skipped. This currently skips the logic that prints log messages. Move the print of log messages to the beginning of CmockaUnitTestTeardownFunctionRunner() that is guaranteed to be executed when a unit test completes normally or is terminated with an exception or an assert. Cc: Sean Brogan Cc: Bret Barkelew Cc: Jiewen Yao Signed-off-by: Michael D Kinney --- .../Library/UnitTestLib/RunTestsCmocka.c | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c index fb81cc9658..29f4752d59 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c +++ b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c @@ -53,21 +53,9 @@ CmockaUnitTestFunctionRunner ( UnitTest->Result = UNIT_TEST_SKIPPED; } else { UnitTest->Result = UNIT_TEST_RUNNING; - Framework->CurrentTest = UnitTest; UnitTest->Result = UnitTest->RunTest (UnitTest->Context); Framework->CurrentTest = NULL; - - // Print out the log messages - This is a partial solution as it - // does not get the log into the XML. Need cmocka changes to support - // stdout and stderr in their xml format - // - if (UnitTest->Log != NULL) { - print_message("UnitTest: %s - %s\n", UnitTest->Name, UnitTest->Description); - print_message("Log Output Start\n"); - print_message("%s", UnitTest->Log); - print_message("Log Output End\n"); - } } } @@ -112,6 +100,18 @@ CmockaUnitTestTeardownFunctionRunner ( Suite = (UNIT_TEST_SUITE *)(UnitTest->ParentSuite); Framework = (UNIT_TEST_FRAMEWORK *)(Suite->ParentFramework); + // + // Print out the log messages - This is a partial solution as it + // does not get the log into the XML. Need cmocka changes to support + // stdout and stderr in their xml format + // + if (UnitTest->Log != NULL) { + print_message("UnitTest: %s - %s\n", UnitTest->Name, UnitTest->Description); + print_message("Log Output Start\n"); + print_message("%s", UnitTest->Log); + print_message("Log Output End\n"); + } + if (UnitTest->CleanUp == NULL) { return 0; } @@ -119,6 +119,7 @@ CmockaUnitTestTeardownFunctionRunner ( Framework->CurrentTest = UnitTest; UnitTest->CleanUp (UnitTest->Context); Framework->CurrentTest = NULL; + // // Return 0 for success. Non-zero for error. // -- 2.21.0.windows.1