Skip to content

Commit 936303b

Browse files
committed
PeiMp2UnitTest: Refine test code.
Add sample code about how to add this test driver. Signed-off-by: Eric Dong <[email protected]>
1 parent 47e868e commit 936303b

File tree

2 files changed

+84
-12
lines changed

2 files changed

+84
-12
lines changed

PeiMp2UnitTest/PeiMp2UnitTest.c

+30-12
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
**/
1010

1111
#include <PiPei.h>
12-
#include <Ppi/EdkiiMpServices2.h>
12+
#include <Ppi/MpServices2.h>
1313
#include <Library/PeiServicesLib.h>
1414
#include <Library/DebugLib.h>
1515
#include <Library/TimerLib.h>
1616
#include <Library/SynchronizationLib.h>
1717

18+
EDKII_PEI_MP_SERVICES2_PPI *mCpuMp2Ppi;
19+
1820
typedef struct {
1921
UINT32 MagicNum;
2022
UINT32 SleepTime;
@@ -177,13 +179,23 @@ Procedure (
177179
)
178180
{
179181
PEI_MP2_PROCEDURE_PARAM *Argument;
182+
UINTN ApIndex;
183+
184+
ApIndex = 0;
185+
186+
EFI_STATUS Status;
187+
188+
if (mCpuMp2Ppi != NULL) {
189+
Status = mCpuMp2Ppi->WhoAmI (mCpuMp2Ppi, &ApIndex);
190+
ASSERT_EFI_ERROR (Status);
191+
}
180192

181193
Argument = (PEI_MP2_PROCEDURE_PARAM *)ProcedureArgument;
182194
while (!AcquireSpinLockOrFail (&mConsoleLock)) {
183195
CpuPause ();
184196
}
185197

186-
DEBUG((DEBUG_INFO, " Procedure function done, SleepTime = 0x%x.\n", Argument->SleepTime));
198+
DEBUG((DEBUG_INFO, "Ap 0x%x Procedure function done, SleepTime = 0x%x.\n", ApIndex, Argument->SleepTime));
187199
ReleaseSpinLock (&mConsoleLock);
188200

189201
if (Argument->SleepTime != 0) {
@@ -208,7 +220,7 @@ PeiMp2UnitTest (
208220
)
209221
{
210222
EFI_STATUS Status;
211-
EDKII_PEI_MP_SERVICES2_PPI *CpuMp2Ppi;
223+
212224
PEI_MP2_PROCEDURE_PARAM ProcParam;
213225

214226
InitializeSpinLock((SPIN_LOCK*) &mConsoleLock);
@@ -220,7 +232,7 @@ PeiMp2UnitTest (
220232
&gEdkiiPeiMpServices2PpiGuid,
221233
0,
222234
NULL,
223-
(VOID **)&CpuMp2Ppi
235+
(VOID **)&mCpuMp2Ppi
224236
);
225237
ASSERT_EFI_ERROR (Status);
226238

@@ -230,30 +242,36 @@ PeiMp2UnitTest (
230242

231243
ProcParam.SleepTime = 0;
232244
DEBUG((DEBUG_INFO, "1.Test StartupAllCPUs begin, SleepTime = 0x%x\n", ProcParam.SleepTime));
233-
Status = CpuMp2Ppi->StartupAllCPUs (
234-
CpuMp2Ppi,
245+
Status = mCpuMp2Ppi->StartupAllCPUs (
246+
mCpuMp2Ppi,
235247
Procedure,
236248
0,
237249
&ProcParam
238250
);
239251
if (EFI_ERROR (Status)) {
240-
DEBUG((DEBUG_INFO, "Test StartupAllCPUs End ==== Fail !\n"));
252+
DEBUG((DEBUG_INFO, "1. Test StartupAllCPUs End ==== Fail !\n"));
241253
} else {
242-
DEBUG((DEBUG_INFO, "Test StartupAllCPUs End ==== Pass !\n"));
254+
DEBUG((DEBUG_INFO, "1. Test StartupAllCPUs End ==== Pass !\n"));
243255
}
244256

245257
ProcParam.SleepTime = 0x30;
246258
DEBUG((DEBUG_INFO, "2.Test StartupAllCPUs with SleepTime = 0x%x\n", ProcParam.SleepTime));
247-
Status = CpuMp2Ppi->StartupAllCPUs (
248-
CpuMp2Ppi,
259+
Status = mCpuMp2Ppi->StartupAllCPUs (
260+
mCpuMp2Ppi,
249261
Procedure,
250262
0x20,
251263
&ProcParam
252264
);
253265
if (EFI_ERROR (Status)) {
254-
DEBUG((DEBUG_INFO, "Test StartupAllCPUs End ==== Fail !\n"));
266+
//
267+
// StartAllCPUs will let APs to run the procedure first, then BSP
268+
// itself will run the procedure, at last BSP will check the APs
269+
// result. So the timeout value not works here because Bsp run
270+
// procedure also needs time.
271+
//
272+
DEBUG((DEBUG_INFO, "2. Test StartupAllCPUs End ==== Fail !\n"));
255273
} else {
256-
DEBUG((DEBUG_INFO, "Test StartupAllCPUs End ==== Pass !\n"));
274+
DEBUG((DEBUG_INFO, "2. Test StartupAllCPUs End ==== Pass !\n"));
257275
}
258276

259277
DEBUG((DEBUG_INFO, "Edkii Pei Mp Services2 Ppi test End!\n"));

UnitTestPkg.dsc

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## @file
2+
# This package provides the modules that build for a full feature platform.
3+
# This BoardModulePkg should only depend on EDKII Core packages and MinPlatformPkg.
4+
#
5+
# The DEC files are used by the utilities that parse DSC and
6+
# INF files to generate AutoGen.c and AutoGen.h files
7+
# for the build infrastructure.
8+
#
9+
# Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
10+
#
11+
# SPDX-License-Identifier: BSD-2-Clause-Patent
12+
#
13+
##
14+
15+
[Defines]
16+
PLATFORM_NAME = UnitTestPkg
17+
PLATFORM_GUID = D36FD4CC-6CD1-4CE6-AA0B-EDB469DAE48B
18+
PLATFORM_VERSION = 0.1
19+
DSC_SPECIFICATION = 0x00010005
20+
OUTPUT_DIRECTORY = Build/BoardModulePkg
21+
SUPPORTED_ARCHITECTURES = IA32|X64
22+
BUILD_TARGETS = DEBUG|RELEASE|NOOPT
23+
SKUID_IDENTIFIER = DEFAULT
24+
25+
[LibraryClasses]
26+
BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
27+
BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
28+
29+
###################################################################################################
30+
#
31+
# Components Section - list of the modules and components that will be processed by compilation
32+
# tools and the EDK II tools to generate PE32/PE32+/Coff image files.
33+
#
34+
# Note: The EDK II DSC file is not used to specify how compiled binary images get placed
35+
# into firmware volume images. This section is just a list of modules to compile from
36+
# source into UEFI-compliant binaries.
37+
# It is the FDF file that contains information on combining binary files into firmware
38+
# volume images, whose concept is beyond UEFI and is described in PI specification.
39+
# Binary modules do not need to be listed in this section, as they should be
40+
# specified in the FDF file. For example: Shell binary (Shell_Full.efi), FAT binary (Fat.efi),
41+
# Logo (Logo.bmp), and etc.
42+
# There may also be modules listed in this section that are not required in the FDF file,
43+
# When a module listed here is excluded from FDF file, then UEFI-compliant binary will be
44+
# generated for it, but the binary will not be put into any firmware volume.
45+
#
46+
###################################################################################################
47+
48+
[Components]
49+
UnitTestPkg/PeiMp2UnitTest/PeiMp2UnitTest.inf {
50+
<LibraryClasses>
51+
DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
52+
SerialPortLib|MdeModulePkg/Library/BaseSerialPortLib16550/BaseSerialPortLib16550.inf
53+
TimerLib|MdePkg/Library/SecPeiDxeTimerLibCpu/SecPeiDxeTimerLibCpu.inf
54+
}

0 commit comments

Comments
 (0)