From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iLvI6br8; spf=pass (domain: gmail.com, ip: 209.85.210.194, mailfrom: matthewfcarlson@gmail.com) Received: by mail-pf1-f194.google.com with SMTP id s26so1395825pfm.4 for ; Thu, 09 Jul 2020 11:47:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GjD9TawcArbYbDjLRLyPPCQ0mEwx1I3EQ0DzajOhTG8=; b=iLvI6br8bij0c4VchVFN7z3/Cg3gJHsJtbBGaSlJHwqGpMtQnzl6492bnSgTIKGfUR /6lT43E/wk7bV0YCCx2pFnKu9QF8jISF3iI/CiuyqdQ1n6yPJMdlHalbmPtkGJZ0kaA7 pTLXsGLXIuh2cLTPQZbl25gIrymf71CKi9jJQieVAQEW3akpG+I8LUaiBP3Yo32ILcqu 3tdtw9CbZrGPxvCp+3UP6S3CgL0suZXuDC+Io915i72F7GqGBQGy6EylPHw7x83qXirt u1xo8LmM+I18voqLpqGNKIDpktCUJQ3LEkOzMxkrp1+y5BRF3hN2+Xl3fQPEgc5q8gxy L6FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=GjD9TawcArbYbDjLRLyPPCQ0mEwx1I3EQ0DzajOhTG8=; b=YUgFvsSkjPWxqVlUZx9yp/p6HBaF4aXKiVL/aNQCTMgBgcP9yGNsLCMoD/bKWloJom A9R5P8lp7rpoK92ZKUEXWPkVANsyqflk17a9mODooydmt3mhTNm8hbAcSj4WMNq9EtoD RVeg32hJgv6h+bYk/omNHMOFJymq8YhDkX9WminevuGVf8ZruUWRDdYnP4rE7qkdsYG4 Ixrgjbgei+M2k/kZJ1B4v5/I5Mel660miF+r1b6A6VDM26MyaBpp72vacmFbUe0hTrFz CDyZyZMX39ZJDl0SbLSQDiBiNV13dscQTW8l+yUZFiRN1P4WkmPCdFBI7QiBAgzMiKL0 xTmQ== X-Gm-Message-State: AOAM533TityA9qdCbsvSt3rDDWbaMueHf2Xx1dfgwZmITbPojKiDc84j 9Ft5k9A4GnZRFTuj5t05+pTtlnkO8cs= 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) Return-Path: 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: [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> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20200709184720.1746-1-matthewfcarlson@gmail.com> References: <20200709184720.1746-1-matthewfcarlson@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=0D + A semi-functional instance of the Timer Library.=0D +=0D + Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.
=0D + Copyright (c) Microsoft Corporation.=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +=0D +**/=0D +=0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +#include =0D +=0D +/**=0D + Stalls the CPU for at least the given number of microseconds.=0D +=0D + @param MicroSeconds The minimum number of microseconds to delay.=0D + @return The value of MicroSeconds inputted.=0D +=0D +**/=0D +UINTN=0D +EFIAPI=0D +MicroSecondDelay (=0D + IN UINTN MicroSeconds=0D + )=0D +{=0D + return NanoSecondDelay(MicroSeconds * 1000000) / 1000000;=0D +}=0D +=0D +/**=0D + Stalls the CPU for at least the given number of nanoseconds.=0D +=0D + @param NanoSeconds The minimum number of nanoseconds to delay.=0D + @return The value of NanoSeconds inputted.=0D +=0D +**/=0D +UINTN=0D +EFIAPI=0D +NanoSecondDelay (=0D + IN UINTN NanoSeconds=0D + )=0D +{=0D + // Since this is a host based test, we don't actually want to stall=0D + return 0;=0D +}=0D +=0D +/**=0D + Retrieves the current value of a 64-bit free running performance counter= .=0D +=0D + The counter can either count up by 1 or count down by 1. If the physical= =0D + performance counter counts by a larger increment, then the counter value= s=0D + must be translated. The properties of the counter can be retrieved from= =0D + GetPerformanceCounterProperties().=0D +=0D + @return The current value of the free running performance counter.=0D +=0D +**/=0D +UINT64=0D +EFIAPI=0D +GetPerformanceCounter (=0D + VOID=0D + )=0D +{=0D + // Return the current number of nanoseconds on the clock=0D + struct timespec ts;=0D + timespec_get(&ts, TIME_UTC);=0D + return ts.tv_nsec;=0D +}=0D +=0D +/**=0D + Retrieves the 64-bit frequency in Hz and the range of performance counte= r=0D + values.=0D +=0D + If StartValue is not NULL, then the value that the performance counter s= tarts=0D + with immediately after is it rolls over is returned in StartValue. If=0D + EndValue is not NULL, then the value that the performance counter end wi= th=0D + immediately before it rolls over is returned in EndValue. The 64-bit=0D + frequency of the performance counter in Hz is always returned. If StartV= alue=0D + is less than EndValue, then the performance counter counts up. If StartV= alue=0D + is greater than EndValue, then the performance counter counts down. For= =0D + example, a 64-bit free running counter that counts up would have a Start= Value=0D + of 0 and an EndValue of 0xFFFFFFFFFFFFFFFF. A 24-bit free running counte= r=0D + that counts down would have a StartValue of 0xFFFFFF and an EndValue of = 0.=0D +=0D + @param StartValue The value the performance counter starts with when i= t=0D + rolls over.=0D + @param EndValue The value that the performance counter ends with bef= ore=0D + it rolls over.=0D +=0D + @return The frequency in Hz.=0D +=0D +**/=0D +UINT64=0D +EFIAPI=0D +GetPerformanceCounterProperties (=0D + OUT UINT64 *StartValue, OPTIONAL=0D + OUT UINT64 *EndValue OPTIONAL=0D + )=0D +{=0D + return (UINT64)(-1);=0D +}=0D +=0D +/**=0D + Converts elapsed ticks of performance counter to time in nanoseconds.=0D +=0D + This function converts the elapsed ticks of running performance counter = to=0D + time value in unit of nanoseconds.=0D +=0D + @param Ticks The number of elapsed ticks of running performance cou= nter.=0D +=0D + @return The elapsed time in nanoseconds.=0D +=0D +**/=0D +UINT64=0D +EFIAPI=0D +GetTimeInNanoSecond (=0D + IN UINT64 Ticks=0D + )=0D +{=0D + return Ticks;=0D +}=0D 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=0D +# An instance of Timer Library for posix compliant hosts.=0D +#=0D +# A semi-functional instance of the Timer Library that can be used for ho= st based testing=0D +# as a functional timer library instance.=0D +=0D +#=0D +# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
= =0D +# Copyright (c) Microsoft Corporation.=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D BaseTimerLibPosix=0D + MODULE_UNI_FILE =3D BaseTimerLibPosix.uni=0D + FILE_GUID =3D a2a413b8-43c3-40cc-a298-be7a214d3564= =0D + MODULE_TYPE =3D BASE=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D TimerLib=0D +=0D +#=0D +# VALID_ARCHITECTURES =3D HOST=0D +#=0D +=0D +[Sources]=0D + TimerLibPosix.c=0D +=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D +=0D +=0D +[LibraryClasses]=0D + DebugLib=0D 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=0D +// An instance of Timer Library for posix compliant hosts.=0D +//=0D +// A semi-functional instance of the Timer Library that can be used=0D +// for host based unit tests on posix compliant machines.=0D +//=0D +// Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
= =0D +// Copyright (c) Microsoft Corporation.=0D +//=0D +// SPDX-License-Identifier: BSD-2-Clause-Patent=0D +//=0D +=0D +#string STR_MODULE_ABSTRACT #language en-US "Host instance of = Timer Library"=0D +=0D +#string STR_MODULE_DESCRIPTION #language en-US "An instance of th= e Timer Library that can be used for host based unit tests."=0D 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=0D UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf=0D UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAlloca= tionLibPosix.inf=0D + UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerLibPosix.i= nf=0D UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf=0D 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=0D DebugLib|UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.= inf=0D MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocationL= ibPosix/MemoryAllocationLibPosix.inf=0D -=0D -[BuildOptions]=0D - GCC:*_*_*_CC_FLAGS =3D -fno-pie=0D + TimerLib|UnitTestFrameworkPkg/Library/Posix/BaseTimerLibPosix/BaseTimerL= ibPosix.inf=0D =0D [BuildOptions.common.EDKII.HOST_APPLICATION]=0D #=0D --=20 2.27.0.windows.1