From nobody Sun May 12 04:26:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111916+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111916+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1701384143; cv=none; d=zohomail.com; s=zohoarc; b=nJSmPEpw6IlCqoDMOAxbmkgVz0N9sRql5hRZQXwwrt2ay50+bqGLKD0vySz0jcKCwLbAoNEv0AIZtiasIwaX5odpke/dTF80EbP/DMmjCHdK3tW3l3CuBf1T3TfLShee4cATmV44otbkDwfj3T1mwfq3cOLj5HA7a9NZ+5puuvc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701384143; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=2E7hyVnwPtE9UBWncUtj/iYaX/QORPWpG57ZxRYPifM=; b=RKJENN19dSano6b1Agd3dKhxo2Z60k8wI1CC7DeAiEcF8LRtI83UqTArxNsKwgbftyG+7RtEe4+EQ0oy25juU8ZnGYlWWXmsT5mL13cVDExvrESZ5Z9Ftv3Eh6FGlmRjqn8DaHjJ3joiyAF8I0cQihj2W+g3oPe2PCX+JRVz4IU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111916+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701384143528280.72863713641505; Thu, 30 Nov 2023 14:42:23 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=YyWB7XU4sfNPCeZo0cDbBaVmkMDRrGZUq5iR7za30Rc=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701384143; v=1; b=gKsbOI1wwM3JMLwzd7VFKAWTXX5W4M+GKOze+d3UusEyaGZ+TNbt0e7Ix8iVirkTZVHzOWDD Th+RGWx/8YYvdnWFAWCQ0g/xr0ssX2fjJ1TLHSyk0MD2gH3yzRvwNVWJlIeaKq3IAMHPC0uaWbO RVxXi6s+pTx7oTF1rc4CVf+I= X-Received: by 127.0.0.2 with SMTP id p9GkYY1788612xj81ZdxWZtR; Thu, 30 Nov 2023 14:42:23 -0800 X-Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by mx.groups.io with SMTP id smtpd.web10.9342.1701384142282831258 for ; Thu, 30 Nov 2023 14:42:22 -0800 X-Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-40a4848c6e1so12865645e9.1 for ; Thu, 30 Nov 2023 14:42:22 -0800 (PST) X-Gm-Message-State: q7F7TkKcDTzAz7rPZMbcLwcWx1787277AA= X-Google-Smtp-Source: AGHT+IG8lGqAFPR9g9hEWqg7V07lro8DGa+wZHc+xrGhcn7MQtnhJ0jlnGanrbz+MqjBjYuhW0V4hw== X-Received: by 2002:adf:e981:0:b0:332:f9e8:ce1c with SMTP id h1-20020adfe981000000b00332f9e8ce1cmr174568wrm.12.1701384139945; Thu, 30 Nov 2023 14:42:19 -0800 (PST) X-Received: from PC-PEDRO-ARCH.lan ([2001:8a0:7280:5801:9441:3dce:686c:bfc7]) by smtp.gmail.com with ESMTPSA id k26-20020adfb35a000000b003332faefd86sm547243wrd.0.2023.11.30.14.42.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 14:42:19 -0800 (PST) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Pedro Falcato , Michael D Kinney , Michael Kubacki , Sean Brogan Subject: [edk2-devel] [PATCH 1/2] UnitTestFrameworkPkg: Fix Google Test components with multiple files Date: Thu, 30 Nov 2023 22:42:13 +0000 Message-ID: <20231130224214.86027-2-pedro.falcato@gmail.com> In-Reply-To: <20231130224214.86027-1-pedro.falcato@gmail.com> References: <20231130224214.86027-1-pedro.falcato@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pedro.falcato@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701384145468000010 Content-Type: text/plain; charset="utf-8" Google Test hides test registration in global constructors on global objects. Global constructors are traditionally implemented by placing references to the global constructor's symbol in special sections (traditionally named .ctors or .init_array). These sections are not explicitly referenced by the linker, and libc only looks at special start and end symbols (and calls them). This works fine if you're linking a program manually using gcc a.o b.o c.o -o test_suite but fails miserably when using static libraries (such as what EDK2 does), because traditional static archive symbol resolution rules don't allow for object files to be pulled in to the link if there isn't an undefined symbol reference to that .o elsewhere. Fix it by passing --whole-archive (GCC) and /WHOLEARCHIVE (MSVC). These options force the linker to pull in the entire static library, thus including previously-unreferenced constructors and making sure multi-file gtest EDK2 components work. BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4610 Signed-off-by: Pedro Falcato Cc: Michael D Kinney Cc: Michael Kubacki Cc: Sean Brogan --- Note: /WHOLEARCHIVE should work for VS2015 and newer. I haven't been able = to test it, so if someone could test on msft it would be much appreciat= ed. Testing is as simple as taking this patch set (https://openfw.io/edk2-devel/20231130024611.67135-1-pedro.falcato@gmail.c= om/) and removing the #include "TestCheckSum.cpp" in TestBaseLibMain.cpp. If ev= erything worked correctly, you should have 4 tests and not 0. UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTe= stFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index 5217de31e491..0f11706e7324 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -37,7 +37,7 @@ # MSFT # MSFT:*_*_*_CC_FLAGS =3D /EHsc - MSFT:*_*_*_DLINK_FLAGS =3D=3D /out:"$(BIN_DIR)\$(MODULE_NAME_= GUID).exe" /pdb:"$(BIN_DIR)\$(MODULE_NAME_GUID).pdb" /IGNORE:4001 /NOLOGO /= SUBSYSTEM:CONSOLE /DEBUG /STACK:0x40000,0x40000 /NODEFAULTLIB:libcmt.lib li= bcmtd.lib + MSFT:*_*_*_DLINK_FLAGS =3D=3D /out:"$(BIN_DIR)\$(MODULE_NAME_= GUID).exe" /pdb:"$(BIN_DIR)\$(MODULE_NAME_GUID).pdb" /IGNORE:4001 /NOLOGO /= SUBSYSTEM:CONSOLE /DEBUG /STACK:0x40000,0x40000 /NODEFAULTLIB:libcmt.lib li= bcmtd.lib /WHOLEARCHIVE MSFT:*_*_IA32_DLINK_FLAGS =3D /MACHINE:I386 MSFT:*_*_X64_DLINK_FLAGS =3D /MACHINE:AMD64 =20 @@ -56,7 +56,12 @@ # GCC:*_*_IA32_DLINK_FLAGS =3D=3D -o $(BIN_DIR)/$(MODULE_NAME_GUID) -m32 -= no-pie GCC:*_*_X64_DLINK_FLAGS =3D=3D -o $(BIN_DIR)/$(MODULE_NAME_GUID) -m64 -= no-pie - GCC:*_*_*_DLINK2_FLAGS =3D=3D -lgcov -lpthread -lstdc++ -lm + # + # Surround our static libraries with whole-archive, so constructor-based= test registration works properly. + # Note that we need to --no-whole-archive before linking system librarie= s. + # + GCC:*_*_*_DLINK_FLAGS =3D -Wl,--whole-archive + GCC:*_*_*_DLINK2_FLAGS =3D=3D -Wl,--no-whole-archive -lgcov -lpthread = -lstdc++ -lm =20 # # Need to do this link via gcc and not ld as the pathing to libraries ch= anges from OS version to OS version --=20 2.43.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111916): https://edk2.groups.io/g/devel/message/111916 Mute This Topic: https://groups.io/mt/102904623/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- From nobody Sun May 12 04:26:24 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+111917+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111917+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1701384144; cv=none; d=zohomail.com; s=zohoarc; b=FfOxDlOW5cZhqDy7NXvwhs0GtuyzxmfqVIUc5kMan89LO86CcXNvZeFrbnbCmwqGjSqS27uxzBi8sMsFWos2v3HQGE5drTdWHbflNe7cH2z3d0QCEwZe1rZ69HUJNakpOHWGa9mWPNRhRTuQnUvGU7TgDaBs+vri6MRg42xnH1M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701384144; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Sender:Subject:Subject:To:To:Message-Id; bh=e35ELZsz9h71FYXH/kH2d9jx4aD/AGYyS25W73iROoE=; b=YESYOnhVVqkyE9wodP1R7N4MG7MmyJfnPfWL4Tfk7toXlaKEaMJ4JyK1c0O6m+jvaaZ9G2x3Gpf+SzoKxyCPjSD2yXUdq3JwxOr9f0FU7lAG1vb4FbnmON5O23sN9gSLeF2zT2tSooN1p07eQ3oj7wH9Ie8k2D1iXXmzEv+Vk1Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+111917+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1701384144428207.99631849780064; Thu, 30 Nov 2023 14:42:24 -0800 (PST) Return-Path: DKIM-Signature: a=rsa-sha256; bh=2QIOdROtjJox3xV5QyofGaa3pmaUrbjS2oemFndWXys=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1701384143; v=1; b=a782m76MrEBjoCkAluPtaVLMLJJgyt1GtC+dheX30dRTKtFWl0zTE0WdDr8+XAAGFwXKxYaL Qa+fK2VVpRJhwnzyMpHwpFgzJpcGW7k40mZUwhHi16NJpS0bO4lbWkL7dg1bodZzsuReHWOxzfa YQSfddLyim/n8c27nGzFnex8= X-Received: by 127.0.0.2 with SMTP id DmuRYY1788612xokqkWNHVPT; Thu, 30 Nov 2023 14:42:23 -0800 X-Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) by mx.groups.io with SMTP id smtpd.web11.9238.1701384142840332961 for ; Thu, 30 Nov 2023 14:42:23 -0800 X-Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-40b4744d603so15167295e9.2 for ; Thu, 30 Nov 2023 14:42:22 -0800 (PST) X-Gm-Message-State: PUt387LJPC4C0bNmry4c0gTwx1787277AA= X-Google-Smtp-Source: AGHT+IFBfu1JwOz0cwzWzRrVUzsOXiSSWSklf5ETuKHJ1Hr27NR9aUlj1Lw1JdV0gZuzuU+gK9aQtw== X-Received: by 2002:adf:ee41:0:b0:333:3117:c456 with SMTP id w1-20020adfee41000000b003333117c456mr35503wro.231.1701384140752; Thu, 30 Nov 2023 14:42:20 -0800 (PST) X-Received: from PC-PEDRO-ARCH.lan ([2001:8a0:7280:5801:9441:3dce:686c:bfc7]) by smtp.gmail.com with ESMTPSA id k26-20020adfb35a000000b003332faefd86sm547243wrd.0.2023.11.30.14.42.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Nov 2023 14:42:20 -0800 (PST) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Pedro Falcato , Michael D Kinney , Michael Kubacki , Sean Brogan Subject: [edk2-devel] [PATCH 2/2] UnitTestFrameworkPkg/Readme.md: Remove the mention of the gtest main() limitation Date: Thu, 30 Nov 2023 22:42:14 +0000 Message-ID: <20231130224214.86027-3-pedro.falcato@gmail.com> In-Reply-To: <20231130224214.86027-1-pedro.falcato@gmail.com> References: <20231130224214.86027-1-pedro.falcato@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,pedro.falcato@gmail.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1701384145456000009 Content-Type: text/plain; charset="utf-8" As of the previous commit, this limitation is no longer a thing. You can now write gtest unit tests with multiple files and no need for any hack such as #include. Signed-off-by: Pedro Falcato Cc: Michael D Kinney Cc: Michael Kubacki Cc: Sean Brogan --- UnitTestFrameworkPkg/ReadMe.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/UnitTestFrameworkPkg/ReadMe.md b/UnitTestFrameworkPkg/ReadMe.md index 7da6a320a7f1..d6a3e0c15a2b 100644 --- a/UnitTestFrameworkPkg/ReadMe.md +++ b/UnitTestFrameworkPkg/ReadMe.md @@ -1096,22 +1096,6 @@ int main(int argc, char* argv[]) { } ``` =20 -However, while GoogleTest does not require test suites or test cases to be -registered, there is still one rule within EDK II that currently needs to = be -followed. This rule is that all tests for a given GoogleTest application m= ust -be contained within the same source file that contains the `main()` functi= on -shown above. These tests can be written directly in the file or a `#includ= e` -can be used to add them into the file indirectly. - -The reason for this is due to EDK II taking the host application INF file = and -first compiling all of its source files into a static library. This static -library is then linked into the final host application. The problem with t= his -method is that only the tests in the object file containing the `main()` -function are linked into the final host application. This is because the o= ther -tests are contained in their own object files within the static library and -they have no symbols in them that the final host application depends on, so -those object files are not linked into the final host application. - ### GoogleTest - A Simple Test Case =20 Below is a sample test case from `SampleGoogleTestHost`. --=20 2.43.0 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111917): https://edk2.groups.io/g/devel/message/111917 Mute This Topic: https://groups.io/mt/102904624/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-