From nobody Sun Feb 8 06:21:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+62641+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62641+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1594847476; cv=none; d=zohomail.com; s=zohoarc; b=DqFDJIdW0QsVQV4Y2jbM4/6YnKzpIrG1GSWHhonUPIAtpdJwYowOFlHmjFR+QbMsAu6lmYaTiZq+pisGpwPuMXHDoN+gCCyNGyaTR1RWHXpip89L3FEE5gUEAPe3dSCXU9QLr3G2/vOESK39obmqJtc32Ipc9WqUqb6scw4DF4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594847476; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=bNlv386AL6121WC3buXCVDHug4GRWXg5lA8qtmR+Ep8=; b=dwL4a3CYFzIbRd7isZ/MWLBqI8wvglkL9/SRaD3aD0SnCtEwOTQu+cVkbRlizYz8XeRR/dMXaLgkVijMGwEUZk8SAuy5U4U7GiZzXlw+QtojYr0OvAgMMo+EOGM1CljNZmQERtP6Xy8L6CocoJ6dhAw5RvidHA7cWksiISSehss= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+62641+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159484747677553.26102894653991; Wed, 15 Jul 2020 14:11:16 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id Ng6mYY1788612x13NkmcVaWx; Wed, 15 Jul 2020 14:11:16 -0700 X-Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by mx.groups.io with SMTP id smtpd.web12.1802.1594847475701787544 for ; Wed, 15 Jul 2020 14:11:15 -0700 X-Received: by mail-pf1-f196.google.com with SMTP id z3so2637460pfn.12 for ; Wed, 15 Jul 2020 14:11:15 -0700 (PDT) X-Gm-Message-State: RB67GJUepc0o7zC3M9PlZmp6x1787277AA= X-Google-Smtp-Source: ABdhPJykzB7eg/d5lXTtrl9Fz3eHwyfN4nmNqAEZ4XMzJVrlTzewKavNIZF7TzcXBRjaV3hnamoPyA== X-Received: by 2002:a62:1b4a:: with SMTP id b71mr1038737pfb.9.1594847475014; Wed, 15 Jul 2020 14:11:15 -0700 (PDT) X-Received: from tvis-name-05.localdomain ([50.34.40.129]) by smtp.gmail.com with ESMTPSA id 204sm2842159pfx.3.2020.07.15.14.11.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jul 2020 14:11:14 -0700 (PDT) From: "Matthew Carlson" To: devel@edk2.groups.io Cc: Michael D Kinney , Sean Brogan , Bret Barkelew , Matthew Carlson Subject: [edk2-devel] [PATCH v4 1/3] UnitTestFrameworkPkg : BaseTimerLibPosix: Adds a host-based timer Lib Date: Wed, 15 Jul 2020 14:11:10 -0700 Message-Id: <20200715211112.778-2-matthewfcarlson@gmail.com> In-Reply-To: <20200715211112.778-1-matthewfcarlson@gmail.com> References: <20200715211112.778-1-matthewfcarlson@gmail.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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,matthewfcarlson@gmail.com Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1594847476; bh=dwUxZfD0vIUyMyLdV9RfuO5KuKXLfvGzQEodFSX3Dag=; h=Cc:Date:From:Reply-To:Subject:To; b=KWOvTHClwRLPhEXMfRS4yOr8YX5r+rBAOOBX+rVE3TQ/aRRUeaf+1PVhIzC5S+xGVPi F9jS35nSMTBs07f9l2HcuYX/TQlpaFe2TsJGiBvh8PY3EQAcQfsVkQksi57dqI9nCOXI2 FJ/IXufwGtIO2QqanvKV3JEQfqzmRqvyzJQ= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" From: Matthew Carlson This adds a host based BaseTimerLib that won't assert. Cc: Michael D Kinney Cc: Sean Brogan Cc: Bret Barkelew Reviewed-by: Michael D Kinney Signed-off-by: Matthew Carlson --- UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibPosix.c = | 132 ++++++++++++++++++++ UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.inf= | 33 +++++ UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.uni= | 14 +++ UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc = | 1 + UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc = | 1 + 5 files changed, 181 insertions(+) diff --git a/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibP= osix.c b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibPosix= .c new file mode 100644 index 000000000000..3c1394e3b21b --- /dev/null +++ b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibPosix.c @@ -0,0 +1,132 @@ +/** @file + A semi-functional instance of the Timer Library. + + Copyright (c) Microsoft Corporation. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +/** + Stalls the CPU for at least the given number of microseconds. + + @param MicroSeconds The minimum number of microseconds to delay. + @return The value of MicroSeconds inputted. + +**/ +UINTN +EFIAPI +MicroSecondDelay ( + IN UINTN MicroSeconds + ) +{ + // Since this is a host based test, we don't actually want to stall + return MicroSeconds; +} + +/** + Stalls the CPU for at least the given number of nanoseconds. + + @param NanoSeconds The minimum number of nanoseconds to delay. + @return The value of NanoSeconds inputted. + +**/ +UINTN +EFIAPI +NanoSecondDelay ( + IN UINTN NanoSeconds + ) +{ + // Since this is a host based test, we don't actually want to stall + return NanoSeconds; +} + +/** + Retrieves the current value of a 64-bit free running performance counter. + + The counter can either count up by 1 or count down by 1. If the physical + performance counter counts by a larger increment, then the counter values + must be translated. The properties of the counter can be retrieved from + GetPerformanceCounterProperties(). + + @return The current value of the free running performance counter. + +**/ +UINT64 +EFIAPI +GetPerformanceCounter ( + VOID + ) +{ + struct timespec ts; + timespec_get(&ts, TIME_UTC); + // Return the current number of nanoseconds on the clock + return ts.tv_nsec; +} + +/** + Retrieves the 64-bit frequency in Hz and the range of performance counter + values. + + If StartValue is not NULL, then the value that the performance counter s= tarts + with immediately after is it rolls over is returned in StartValue. If + EndValue is not NULL, then the value that the performance counter end wi= th + immediately before it rolls over is returned in EndValue. The 64-bit + frequency of the performance counter in Hz is always returned. If StartV= alue + is less than EndValue, then the performance counter counts up. If StartV= alue + is greater than EndValue, then the performance counter counts down. For + example, a 64-bit free running counter that counts up would have a Start= Value + of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counter + that counts down would have a StartValue of 0xFFFFFF and an EndValue of = 0. + + @param StartValue The value the performance counter starts with when it + rolls over. + @param EndValue The value that the performance counter ends with bef= ore + it rolls over. + + @return The frequency in Hz. + +**/ +UINT64 +EFIAPI +GetPerformanceCounterProperties ( + OUT UINT64 *StartValue, OPTIONAL + OUT UINT64 *EndValue OPTIONAL + ) +{ + if ( EndValue !=3D NULL ) { + *EndValue =3D MAX_UINT64; + } + if ( StartValue !=3D NULL ) { + *StartValue =3D 0; + } + // Return the number of nanoseconds in a second + return 1000000000; +} + +/** + Converts elapsed ticks of performance counter to time in nanoseconds. + + This function converts the elapsed ticks of running performance counter = to + time value in unit of nanoseconds. + + @param Ticks The number of elapsed ticks of running performance cou= nter. + + @return The elapsed time in nanoseconds. + +**/ +UINT64 +EFIAPI +GetTimeInNanoSecond ( + IN UINT64 Ticks + ) +{ + return Ticks; +} diff --git a/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimer= LibPosix.inf b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTim= erLibPosix.inf new file mode 100644 index 000000000000..797f04bb125b --- /dev/null +++ b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosi= x.inf @@ -0,0 +1,33 @@ +## @file +# An instance of Timer Library for posix compliant hosts. +# +# A semi-functional instance of the Timer Library that can be used for +# host based testing as a functional timer library instance. +# +# Copyright (c) Microsoft Corporation. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D BaseTimerLibPosix + MODULE_UNI_FILE =3D BaseTimerLibPosix.uni + FILE_GUID =3D a2a413b8-43c3-40cc-a298-be7a214d3564 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D TimerLib|HOST_APPLICATION +# +# VALID_ARCHITECTURES =3D HOST +# + +[Sources] + TimerLibPosix.c + +[Packages] + MdePkg/MdePkg.dec + +[LibraryClasses] + DebugLib diff --git a/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimer= LibPosix.uni b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTim= erLibPosix.uni new file mode 100644 index 000000000000..a6859a0fc88a --- /dev/null +++ b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosi= x.uni @@ -0,0 +1,14 @@ +// @file +// An instance of Timer Library for posix compliant hosts. +// +// A semi-functional instance of the Timer Library that can be used +// for host based unit tests on posix compliant machines. +// +// Copyright (c) Microsoft Corporation. +// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// + +#string STR_MODULE_ABSTRACT #language en-US "Host instance of = Timer Library" + +#string STR_MODULE_DESCRIPTION #language en-US "An instance of th= e Timer Library that can be used for host based unit tests." diff --git a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc b/U= nitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc index 701e7299d767..f82b3b7a323e 100644 --- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc +++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc @@ -30,4 +30,5 @@ UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAlloca= tionLibPosix.inf + UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.i= nf UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTe= stFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index e954968efc52..76f0a719ded3 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -13,6 +13,7 @@ UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.i= nf DebugLib|UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.= inf MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocationL= ibPosix/MemoryAllocationLibPosix.inf + TimerLib|UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerL= ibPosix.inf =20 [BuildOptions] GCC:*_*_*_CC_FLAGS =3D -fno-pie --=20 2.27.0.windows.1 -=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 (#62641): https://edk2.groups.io/g/devel/message/62641 Mute This Topic: https://groups.io/mt/75529777/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-