From nobody Sat Feb 7 09:10:58 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+62318+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+62318+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1594325248; cv=none; d=zohomail.com; s=zohoarc; b=LZgdQS0y/gsrQqWmIJSu0DvX4uuw70zORBN6uzMBbVuNKqG9yPV0xlf4ColIUYwLkeeFncVNQXr5oQKhr1w8ou3EBuFcbkGrC7O2xA0roQ1lb9+am/ZaXKK40HvIoWtjWgIY2PPBKEChb/b15Rltc0wfZUhlDJqrN5MbY90FJWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594325248; 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=rh6MVEAYwvZoP5Cm/0nvHpZ9hsNXB2aUV5pjhSbhO/g=; b=bRnXTtn8hpE+9uo4DSMaExsTsuZyBvh6Wmz0Z5kECu0j36ueO/idSIxvr3Si6CLVyQ3eqTVlswti2Nst07w/ZQ5KFzj/NVGYeZ9z47atq24MCN+aycZV6CPlPaRjAtZFfGw5eaViLDyoL6WPq/f+n0Xfp70DOrod96+3qBXcDbY= 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+62318+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 1594325248943175.47744346625677; Thu, 9 Jul 2020 13:07:28 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id tpiKYY1788612xUrD8TFRb7i; Thu, 09 Jul 2020 13:07:28 -0700 X-Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by mx.groups.io with SMTP id smtpd.web10.2279.1594320443104781899 for ; Thu, 09 Jul 2020 11:47:23 -0700 X-Received: by mail-pf1-f194.google.com with SMTP id s26so1395825pfm.4 for ; Thu, 09 Jul 2020 11:47:23 -0700 (PDT) X-Gm-Message-State: vTFOvjxQW1Ip53KCPjCeEFXJx1787277AA= X-Google-Smtp-Source: ABdhPJzRBsNwMs//sLFcasec87M+0bZRSst2GgSCOBmz9Mu8q2iFx2V73PUzQZS53HVMEj6rSeNQyg== X-Received: by 2002:aa7:860f:: with SMTP id p15mr23391011pfn.59.1594320442406; Thu, 09 Jul 2020 11:47:22 -0700 (PDT) X-Received: from tvis-name-05.localdomain ([50.34.40.129]) by smtp.gmail.com with ESMTPSA id b11sm3581140pfr.179.2020.07.09.11.47.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Jul 2020 11:47:22 -0700 (PDT) From: matthewfcarlson@gmail.com To: devel@edk2.groups.io Cc: Michael D Kinney , Sean Brogan , Bret Barkelew , Matthew Carlson Subject: [edk2-devel] [PATCH v2 1/3] UnitTestFrameworkPkg : BaseTimerLibPosix: Adds a host-based timer Lib Date: Thu, 9 Jul 2020 11:47:18 -0700 Message-Id: <20200709184720.1746-2-matthewfcarlson@gmail.com> In-Reply-To: <20200709184720.1746-1-matthewfcarlson@gmail.com> References: <20200709184720.1746-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=1594325248; bh=d2Sd+sC4rCkcdwP38bOdwCGL79NlcGugEbYuiGmXonI=; h=Cc:Date:From:Reply-To:Subject:To; b=MauZ6hrreusUIhdffn2t5j5KouHvGknG25gCSsvycz+Na6i6sSejUSxGwfNTtc0SyK9 Xp4gSYCaAVxcVdGoHee0YLgGgOnArE4n0s/u9Mp/GX4fzBoQ1TmvaHBJmJOFG5aI2kzkV yP2OcyAYQKfocCJVw8Nj4FpV5oawJlAzAGU= 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 Signed-off-by: Matthew Carlson --- UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibPosix.c = | 125 ++++++++++++++++++++ UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.inf= | 38 ++++++ UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.uni= | 15 +++ UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc = | 1 + UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc = | 4 +- 5 files changed, 180 insertions(+), 3 deletions(-) diff --git a/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibP= osix.c b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibPosix= .c new file mode 100644 index 000000000000..cd12dde7bd81 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/TimerLibPosix.c @@ -0,0 +1,125 @@ +/** @file + A semi-functional instance of the Timer Library. + + Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.
+ 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 + ) +{ + return NanoSecondDelay(MicroSeconds * 1000000) / 1000000; +} + +/** + 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 0; +} + +/** + 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 + ) +{ + // Return the current number of nanoseconds on the clock + struct timespec ts; + timespec_get(&ts, TIME_UTC); + 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 + ) +{ + return (UINT64)(-1); +} + +/** + 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..aed6f15e1828 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosi= x.inf @@ -0,0 +1,38 @@ +## @file +# An instance of Timer Library for posix compliant hosts. +# +# A semi-functional instance of the Timer Library that can be used for ho= st based testing +# as a functional timer library instance. + +# +# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
+# 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 + +# +# 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..21cae0e7c7aa --- /dev/null +++ b/UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosi= x.uni @@ -0,0 +1,15 @@ +// @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) 2007 - 2014, Intel Corporation. All rights reserved.
+// 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..70d9f954d3ca 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -13,9 +13,7 @@ UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.i= nf DebugLib|UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.= inf MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocationL= ibPosix/MemoryAllocationLibPosix.inf - -[BuildOptions] - GCC:*_*_*_CC_FLAGS =3D -fno-pie + TimerLib|UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerL= ibPosix.inf =20 [BuildOptions.common.EDKII.HOST_APPLICATION] # --=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 (#62318): https://edk2.groups.io/g/devel/message/62318 Mute This Topic: https://groups.io/mt/75405698/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-