From nobody Mon Feb 9 15:08:56 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+62558+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+62558+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1594751002; cv=none; d=zohomail.com; s=zohoarc; b=WottCxVaOc0mmWVMFH+padn/IFn5Ter/ueDm3OqdFSD2NTwAK2VW3REvQk7OlW6N7Lrj35hsO/9ndYqVRBmwVqsq/TXyLiRdxsUGPUyIfiXwM+9hp40auWwJB+oyBD11TrpF2aR9ZkMVXv0Gl4gt8/NbdRo8f4ekdykyDLOre8M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594751002; 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=eKybtLTiMH2lljDQZmT5A2ryjMsd+EC9KyzsCNkJRmI=; b=GEZqPaXglgnroyk3RcMxONk93b5z0L2kAPf/w4Tc/nZVb6idy9bMPnc5my4GaAE4/IVCnkCKFhWfLcpprvnIPafdJWMrnRG1e0CdAqleeD8n8IkBM+Akm7qp8Qa9QQvGkDYX1aaIF2kmeDbx3kyr4d1+kdT0rMQrvTg9obE6VvI= 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+62558+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 1594751002403990.1693073283046; Tue, 14 Jul 2020 11:23:22 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id s1ocYY1788612xK1kYurW7Jb; Tue, 14 Jul 2020 11:23:22 -0700 X-Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by mx.groups.io with SMTP id smtpd.web11.2794.1594751001497034223 for ; Tue, 14 Jul 2020 11:23:21 -0700 X-Received: by mail-pj1-f67.google.com with SMTP id gc15so1186505pjb.0 for ; Tue, 14 Jul 2020 11:23:21 -0700 (PDT) X-Gm-Message-State: msBQ93FYCu2YGBbYXzGwNy4yx1787277AA= X-Google-Smtp-Source: ABdhPJxzLnUSNRwAWc4K71nHk3VAmhKhhcIvYKiiRaATd/KEnDsmWYpx6oMfrg+mIRo5N/VUHFkyVQ== X-Received: by 2002:a17:90b:4d08:: with SMTP id mw8mr5958422pjb.119.1594751000792; Tue, 14 Jul 2020 11:23:20 -0700 (PDT) X-Received: from tvis-name-05.localdomain ([50.34.40.129]) by smtp.gmail.com with ESMTPSA id s194sm16615540pgs.24.2020.07.14.11.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2020 11:23:20 -0700 (PDT) From: matthewfcarlson@gmail.com To: devel@edk2.groups.io Cc: Michael D Kinney , Sean Brogan , Bret Barkelew Subject: [edk2-devel] [PATCH v3 1/3] UnitTestFrameworkPkg : BaseTimerLibPosix: Adds a host-based timer Lib Date: Tue, 14 Jul 2020 11:23:15 -0700 Message-Id: <20200714182317.1605-2-matthewfcarlson@gmail.com> In-Reply-To: <20200714182317.1605-1-matthewfcarlson@gmail.com> References: <20200714182317.1605-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=1594751002; bh=DfYmPBDdSYuOVWO1lSqovhitHvOJ920amikDEQMXXOo=; h=Cc:Date:From:Reply-To:Subject:To; b=gnv04udA0JtHXGB0WHM0uvDu0/byhirkrPeOzxIi9OrDsyPBOAo5sOqrgyLIwMCGwwc FpRmZe9FamWRBGhdOUAYwUyUV2CT+jEVi5Mz2XiK5cz8R5oOW2OlMJAuD4RVmmCeC678Y SORLcQRt/ITFLQFsEobPUMXEV+ZMFupUUkI= 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 Reviewed-by: Michael D Kinney =20 --- 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 (#62558): https://edk2.groups.io/g/devel/message/62558 Mute This Topic: https://groups.io/mt/75504998/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-