From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by mx.groups.io with SMTP id smtpd.web12.2040.1594171887145755342 for ; Tue, 07 Jul 2020 18:31:27 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20161025 header.b=WhokDF00; spf=pass (domain: gmail.com, ip: 209.85.215.173, mailfrom: matthewfcarlson@gmail.com) Received: by mail-pg1-f173.google.com with SMTP id t6so20884811pgq.1 for ; Tue, 07 Jul 2020 18:31:27 -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=9BtZsuygB2VYeROoljyXZQNtQu+SZHOX9R2f6pTWfCg=; b=WhokDF002Wx5R3HmXAZ8V9AYER2WKUBmxSOo7nh2OHguCsdVx1gaGQPQF7QyCbeY24 Lxbn4WE6pHtnmvXjiptKrL5jz1BypZu2lkGJFtoqhfid3NUDIYjmYCjX6UisfHzWeS60 oQN4j2BRY4IcMehPPgljNRCKWbuFMWBd7qNTmNysFX1Tfc04QU6PP9DTp3JHJGsCfJcH fM8V6qTGah4dTfz8DozzZf9l8PvhmuTmyeyVPrpEVukCJf/5YULEty3SmBz5Ngx56toR Tkkac4H6kt0o7on5RWEvUz9WtTm0E+VBmZ8IBxhX84tvlkIqVrSDzYSfN44J9f45h2ez 8QAQ== 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=9BtZsuygB2VYeROoljyXZQNtQu+SZHOX9R2f6pTWfCg=; b=QG47K6EW3Tcq4t/tKEK/M99v/VJUtkkLH1SXT8nlymTdYupbpLOWr1bY66Nn1LjAtb Ya3tsdQ8VFG4+fRPTm88p/2npEXk90DeEC6e280q2+QzihKJ8pdsCbr3U5W3E6GGv1+y eG5KpCk8H5J9kZnSw9P/QmhMbakZLg7gC34VyKjkmlPMdcSbcV6ayn2FGJBCbEe7UFsr VefLQJAfUucLosCOpxSfOVHTItRrZ26f609RHQlYsHhxpVLH47ihRAt/S90GBCY+M2f/ L/P9YGjjbP14wFP4FLDdcIMcJzw1VYYjl/7dQ0roQ33fIoUSGhqItvPawQY3ST44M7dq MXGg== X-Gm-Message-State: AOAM532iqU/4+Uq1yTc56Gl9eeoKdyd66a3hbEfl3a32VuoAhTF99Q8N 91hF24JhusowZBw4vg2rqJtyvYCLD1g= X-Google-Smtp-Source: ABdhPJxqqVgB2vAv+Is9k/zeeUH+NRAY19Gcf6Y122WOnKU/SjeNK8EUkM5ThTXNFnLpXIUrHjuePw== X-Received: by 2002:a62:7653:: with SMTP id r80mr29066326pfc.236.1594171886306; Tue, 07 Jul 2020 18:31:26 -0700 (PDT) Return-Path: Received: from tvis-name-05.localdomain ([50.34.40.129]) by smtp.gmail.com with ESMTPSA id b191sm2036055pga.13.2020.07.07.18.31.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 18:31:25 -0700 (PDT) From: matthewfcarlson@gmail.com To: devel@edk2.groups.io Cc: Matthew Carlson Subject: [PATCH v1 1/3] UnitTestFrameworkPkg : BaseTimerLib: Adds a host-based timer Lib Date: Tue, 7 Jul 2020 18:31:20 -0700 Message-Id: <20200708013122.1301-2-matthewfcarlson@gmail.com> X-Mailer: git-send-email 2.27.0.windows.1 In-Reply-To: <20200708013122.1301-1-matthewfcarlson@gmail.com> References: <20200708013122.1301-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. Signed-off-by: Matthew Carlson --- UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/TimerLibHost.c | = 137 ++++++++++++++++++++ UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/BaseTimerLibHost.inf | = 40 ++++++ UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/BaseTimerLibHost.uni | = 19 +++ UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc | = 1 + 4 files changed, 197 insertions(+) diff --git a/UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/TimerLibHos= t.c b/UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/TimerLibHost.c new file mode 100644 index 000000000000..61304e66f54f --- /dev/null +++ b/UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/TimerLibHost.c @@ -0,0 +1,137 @@ +/** @file=0D + A non-functional instance of the Timer Library.=0D +=0D + Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.
=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 + Stalls the CPU for the number of microseconds specified by MicroSeconds.= =0D +=0D + @param MicroSeconds The minimum number of microseconds to delay.=0D +=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 + Stalls the CPU for the number of nanoseconds specified by NanoSeconds.=0D +=0D + @param NanoSeconds The minimum number of nanoseconds to delay.=0D +=0D + @return The value of NanoSeconds inputted.=0D +=0D +**/=0D +UINTN=0D +EFIAPI=0D +NanoSecondDelay (=0D + IN UINTN NanoSeconds=0D + )=0D +{=0D + /*UINT64 start =3D GetPerformanceCounter();=0D + UINT64 goal =3D start + NanoSeconds;=0D + DEBUG(( DEBUG_ERROR, "Delaying for %d ns. Start: %d to %d\n", NanoSecond= s, start, goal));=0D + // check if we need to wait for the counter to roll over=0D + if (start > goal) {=0D + DEBUG(( DEBUG_ERROR, "Start is more than goal\n"));=0D + while (GetPerformanceCounter() > goal);=0D + }=0D + while (GetPerformanceCounter() < goal);=0D + return NanoSeconds;*/=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 + 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/Host/BaseTimerLibHost/BaseTimerLi= bHost.inf b/UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/BaseTimerLib= Host.inf new file mode 100644 index 000000000000..ac091cd10af1 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/BaseTimerLibHost.i= nf @@ -0,0 +1,40 @@ +## @file=0D +# NULL instance of Timer Library as a template.=0D +#=0D +# A non-functional instance of the Timer Library that can be used as a te= mplate=0D +# for the implementation of a functional timer library instance. This lib= rary instance can=0D +# also be used to test build DXE, Runtime, DXE SAL, and DXE SMM modules t= hat require timer=0D +# services as well as EBC modules that require timer services.=0D +#=0D +# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.
= =0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +#=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D BaseTimerLibHost=0D + MODULE_UNI_FILE =3D BaseTimerLibHost.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 +#=0D +# VALID_ARCHITECTURES =3D IA32 X64 EBC AARCH=0D +#=0D +=0D +[Sources]=0D + TimerLibHost.c=0D +=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D +=0D +=0D +[LibraryClasses]=0D + DebugLib=0D +=0D diff --git a/UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/BaseTimerLi= bHost.uni b/UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/BaseTimerLib= Host.uni new file mode 100644 index 000000000000..6e100bd383d2 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/BaseTimerLibHost.u= ni @@ -0,0 +1,19 @@ +// /** @file=0D +// NULL instance of Timer Library as a template.=0D +//=0D +// A non-functional instance of the Timer Library that can be used as a te= mplate=0D +// for the implementation of a functional timer library instance. This lib= rary instance can=0D +// also be used to test build DXE, Runtime, DXE SAL, and DXE SMM modules t= hat require timer=0D +// services as well as EBC modules that require timer services.=0D +//=0D +// Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
= =0D +//=0D +// SPDX-License-Identifier: BSD-2-Clause-Patent=0D +//=0D +// **/=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 +=0D diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTe= stFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index e954968efc52..bc7b7afa1729 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -13,6 +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 + TimerLib|UnitTestFrameworkPkg/Library/Host/BaseTimerLibHost/BaseTimerLib= Host.inf=0D =0D [BuildOptions]=0D GCC:*_*_*_CC_FLAGS =3D -fno-pie=0D --=20 2.25.1.vfs.1.1