EFI_STATUS MainMenuF9Func( IN EFI_MENU_PAGE *Page ) /*++ Routine Description: Handle F9 key in case menu Arguments: Page - A pointer to the menu Returns: EFI_SUCCESS - Handle Space key successfully Other Value - Something failed --*/ { EFI_STATUS Status; EFI_INPUT_KEY Key; EFI_DIALOG_CONTEXT MsgDialogContext; CHAR16 *MsgDialogTitle; // //check parameter. // if (Page == NULL) { return EFI_INVALID_PARAMETER; } MsgDialogTitle = StrDuplicate (L"Prepare running..."); MsgDialogContext.Type = EFI_DIALOG_TYPE_REMINDER; DoDialog (MsgDialogTitle, &MsgDialogContext); ST->ConOut->SetAttribute ( ST->ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK ); ST->ConOut->ClearScreen (ST->ConOut); Status = SctExecute (); if (Status != EFI_SUCCESS) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Execute - %r", Status)); } // //Clear surplus key stroke. // Status = EFI_SUCCESS; while(!EFI_ERROR(Status)) { Status = ST->ConIn->ReadKeyStroke (ST->ConIn, &Key); } MenuPageRefresh (Page); return Status; }
EFI_STATUS CreateSingleSupportFile ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CHAR16 *FileName, IN EFI_HANDLE ImageHandle, IN VOID *Context, OUT EFI_SCT_TEST_FILE **SupportFile ) /*++ Routine Description: Create a test support file data structure. --*/ { EFI_STATUS Status; // // Check parameter // if ((DevicePath == NULL) || (FileName == NULL) || (SupportFile == NULL)) { return EFI_INVALID_PARAMETER; } // // Allocate memory for the support file // Status = BS->AllocatePool ( EfiBootServicesData, sizeof(EFI_SCT_TEST_FILE), SupportFile ); if (EFI_ERROR(Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); return Status; } ZeroMem (*SupportFile, sizeof(EFI_SCT_TEST_FILE)); // // Initialize the items of support file // (*SupportFile)->Signature = EFI_SCT_TEST_FILE_SIGNATURE; (*SupportFile)->Revision = EFI_SCT_TEST_FILE_REVISION; (*SupportFile)->DevicePath = DuplicateDevicePath (DevicePath); (*SupportFile)->FileName = StrDuplicate (FileName); (*SupportFile)->ImageHandle = ImageHandle; (*SupportFile)->Type = EFI_SCT_TEST_FILE_TYPE_SUPPORT; (*SupportFile)->Context = Context; // // Done // return EFI_SUCCESS; }
EFI_STATUS CloseSingleSupportFile ( IN EFI_GUID *Guid ) /*++ Routine Description: Close a test support file to free the public interface. --*/ { EFI_STATUS Status; EFI_LIST_ENTRY *Link; EFI_SCT_TEST_FILE *SupportFile; EFI_TSL_INIT_INTERFACE *TslInit; // // Walk through all support files // for (Link = gFT->SupportFileList.Flink; Link != &gFT->SupportFileList; Link = Link->Flink) { SupportFile = CR (Link, EFI_SCT_TEST_FILE, Link, EFI_SCT_TEST_FILE_SIGNATURE); // // Each support file should provide an EFI_TSL_INIT_INTERFACE instance // TslInit = (EFI_TSL_INIT_INTERFACE *) SupportFile->Context; if (CompareGuid (&TslInit->LibraryGuid, Guid) == 0) { // // Close the support file // Status = TslInit->Close ( TslInit, gFT->SupportHandle ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"TSL close - %r", Status)); return Status; } // // Got it! // return EFI_SUCCESS; } } // // No matched protocol // return EFI_NOT_FOUND; }
EFI_STATUS UnloadSingleSupportFile ( IN EFI_SCT_TEST_FILE *SupportFile ) /*++ Routine Description: Unload a test support file. --*/ { // // Free the items of support file // if (SupportFile->DevicePath != NULL) { BS->FreePool (SupportFile->DevicePath); SupportFile->DevicePath = NULL; } if (SupportFile->FileName != NULL) { BS->FreePool (SupportFile->FileName); SupportFile->FileName = NULL; } switch (SupportFile->Type) { case EFI_SCT_TEST_FILE_TYPE_SUPPORT: // // Test support file // BS->UnloadImage (SupportFile->ImageHandle); break; default: // // Unsupported file // EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Unsupported file")); return EFI_UNSUPPORTED; } // // Free the support file itself // BS->FreePool (SupportFile); // // Done // return EFI_SUCCESS; }
EFI_STATUS UnloadSupportFiles ( IN EFI_LIST_ENTRY *SupportFileList ) /*++ Routine Description: Unload all test support files. Arguments: SupportFileList - Pointer to the support file list. Returns: EFI_SUCCESS - Successfully. Other value - Something failed. --*/ { EFI_SCT_TEST_FILE *SupportFile; // // Check parameters // if (SupportFileList == NULL) { return EFI_INVALID_PARAMETER; } // // Debug information // EFI_SCT_DEBUG ((EFI_SCT_D_TRACE, L"Unload support files")); // // Walk through all test support files // while (!IsListEmpty (SupportFileList)) { SupportFile = CR (SupportFileList->Flink, EFI_SCT_TEST_FILE, Link, EFI_SCT_TEST_FILE_SIGNATURE); RemoveEntryList (&SupportFile->Link); UnloadSingleSupportFile (SupportFile); } // // Done // return EFI_SUCCESS; }
EFI_STATUS CreateSingleCategoryData ( OUT EFI_SCT_CATEGORY_DATA **Category ) /*++ Routine Description: Create a category data. --*/ { EFI_STATUS Status; EFI_SCT_CATEGORY_DATA *TempCategory; // // Check parameters // if (Category == NULL) { return EFI_INVALID_PARAMETER; } // // Allocate memory for the category data // Status = BS->AllocatePool ( EfiBootServicesData, sizeof(EFI_SCT_CATEGORY_DATA), (VOID **)&TempCategory ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); return Status; } ZeroMem (TempCategory, sizeof(EFI_SCT_CATEGORY_DATA)); // // Initialize the items of category data // TempCategory->Signature = EFI_SCT_CATEGORY_DATA_SIGNATURE; TempCategory->Revision = EFI_SCT_CATEGORY_DATA_REVISION; // // Done // *Category = TempCategory; return EFI_SUCCESS; }
EFI_STATUS InsertSingleCategoryData ( IN OUT EFI_LIST_ENTRY *CategoryList, IN EFI_SCT_CATEGORY_DATA *Category ) /*++ Routine Description: Insert a category data into list. --*/ { EFI_LIST_ENTRY *Link; EFI_SCT_CATEGORY_DATA *OldCategory; // // Check whether there are duplicate category data. If yes, remove the old // data // for (Link = CategoryList->Flink; Link != CategoryList; Link = Link->Flink) { OldCategory = CR (Link, EFI_SCT_CATEGORY_DATA, Link, EFI_SCT_CATEGORY_DATA_SIGNATURE); if (CompareGuid (&OldCategory->CategoryGuid, &Category->CategoryGuid) == 0) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Found duplicate category data (GUID = %g)", &Category->CategoryGuid)); RemoveEntryList (&OldCategory->Link); FreeSingleCategoryData (OldCategory); break; } } // // Add this category data into the list // InsertTailList (CategoryList, &Category->Link); // // Done // return EFI_SUCCESS; }
VOID DisplayDeviceConfig ( IN EFI_MENU_PAGE *Page ) { EFI_STATUS Status; // // Check parameters // if (Page == NULL) { return; } // // Clears the screen // ST->ConOut->SetAttribute ( ST->ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK ); ST->ConOut->ClearScreen (ST->ConOut); // // Gather the device configuration data // Status = SctDeviceConfig (); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Device Config - %r", Status)); } // // Refresh the menu page // MenuPageRefresh (Page); // // Done // return; }
EFI_STATUS MainMenuClearFunc ( IN EFI_MENU_PAGE *Page ) { EFI_STATUS Status; EFI_DIALOG_CONTEXT MsgDialogContext; CHAR16 *MsgDialogTitle; MsgDialogTitle = StrDuplicate (L"Deleting files ..."); MsgDialogContext.Type = EFI_DIALOG_TYPE_REMINDER; DoDialog (MsgDialogTitle, &MsgDialogContext); Status = ResetAllTestResults (); MenuPageRefresh (Page); if (EFI_ERROR(Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Reset test results - %r", Status)); return Status; } gContinueExec = FALSE; return EFI_SUCCESS; }
EFI_STATUS GenerateReport ( IN EFI_DEVICE_PATH_PROTOCOL *LogDevicePath, IN CHAR16 *LogFilePath, IN EFI_DEVICE_PATH_PROTOCOL *ReportDevicePath, IN CHAR16 *ReportFileName ) /*++ Routine Description: Generate test report. Arguments: LogDevicePath - Device path of the key files. LogFilePath - Path of the key files. ReportDevicePath - Device path of the report file. ReportFileName - Name of the report file. EFI_SUCCESS - Generate the test report successfully. --*/ { EFI_STATUS Status; UINT32 PassNumber; UINT32 WarnNumber; UINT32 FailNumber; CHAR16 *FileName; CHAR16 *Buffer; UINTN AsciiBufferSize; CHAR8 *AsciiBuffer; UINTN ConfigBufferSize; CHAR8 *ConfigBuffer; EFI_FILE_HANDLE Handle; // // Check parameters // if ((LogDevicePath == NULL) || (LogFilePath == NULL) || (ReportDevicePath == NULL) || (ReportFileName == NULL)) { return EFI_INVALID_PARAMETER; } // // Initialize // PassNumber = 0; WarnNumber = 0; FailNumber = 0; // // Get the configuration data. Start this operation at first since the next // operations will take more time. We could stop the entire process if we // meet any problem in configuration collection. // Status = SctReportConfig ( &ConfigBufferSize, &ConfigBuffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"SctReportConfig: %r", Status)); return Status; } // // Load the GUID database // FileName = PoolPrint (L"%s\\%s", gFT->FilePath, EFI_SCT_FILE_GUID_DATABASE); if (FileName == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); BS->FreePool (ConfigBuffer); return EFI_OUT_OF_RESOURCES; } Status = LoadGuidDatabase (gFT->DevicePath, FileName); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Load GUID database - %r", Status)); BS->FreePool (ConfigBuffer); BS->FreePool (FileName); return Status; } BS->FreePool (FileName); // // Load the assertion information from the log directory // Status = GetProtocolAssertion ( LogDevicePath, LogFilePath, &PassNumber, &WarnNumber, &FailNumber ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Get protocol assertion - %r", Status)); BS->FreePool (ConfigBuffer); UnloadGuidDatabase (); UnloadReportInfor (); return Status; } // // Get the report information to a buffer // Status = GetReportInfor (&Buffer); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Get report infor - %r", Status)); BS->FreePool (ConfigBuffer); UnloadGuidDatabase (); UnloadReportInfor (); return Status; } UnloadGuidDatabase (); UnloadReportInfor (); // // Convert the buffer to ASCII buffer // AsciiBufferSize = StrLen(Buffer) + 1; Status = BS->AllocatePool ( EfiBootServicesData, AsciiBufferSize, &AsciiBuffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); BS->FreePool (ConfigBuffer); BS->FreePool (Buffer); return Status; } Status = UnicodeToAscii (Buffer, AsciiBuffer); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Convert Unicode to ASCII - %r", Status)); BS->FreePool (ConfigBuffer); BS->FreePool (Buffer); BS->FreePool (AsciiBuffer); return Status; } BS->FreePool (Buffer); // // Create the report file // Status = SctCreateFileFromDevicePath ( ReportDevicePath, ReportFileName, &Handle ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Create report file - %r", Status)); BS->FreePool (ConfigBuffer); BS->FreePool (AsciiBuffer); return Status; } // // Write the ASCII buffer to the report file (remove the null-terminator) // AsciiBufferSize --; Status = Handle->Write ( Handle, &AsciiBufferSize, AsciiBuffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Write report file - %r", Status)); BS->FreePool (ConfigBuffer); BS->FreePool (AsciiBuffer); Handle->Close (Handle); return Status; } // // Write the config buffer to the report file // Status = Handle->Write ( Handle, &ConfigBufferSize, ConfigBuffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Write report file - %r", Status)); BS->FreePool (ConfigBuffer); BS->FreePool (AsciiBuffer); Handle->Close (Handle); return Status; } BS->FreePool (ConfigBuffer); BS->FreePool (AsciiBuffer); // // Close the report file // Handle->Close (Handle); // // Done // return EFI_SUCCESS; }
EFI_STATUS SctReportConfig ( OUT UINTN *BufferSize, OUT VOID **Buffer ) /*++ Routine Description: Report the system configuration via shell commands. --*/ { EFI_STATUS Status; UINTN Index; CHAR16 *CmdLine; CHAR16 *FileName; CHAR16 *CmdList[] = { L"map -v", L"memmap", L"pci", L"ver", L"dh -v", L"" }; // // Record an empty line to a file via shell command // CmdLine = PoolPrint ( L"ECHO \" \" >a %s", EFI_SCT_FILE_CFG ); if (CmdLine == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); return EFI_OUT_OF_RESOURCES; } Status = ShellExecute ( gFT->ImageHandle, CmdLine, FALSE ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"ShellExecute: %s - %r", CmdLine, Status)); BS->FreePool (CmdLine); return Status; } BS->FreePool (CmdLine); // // For each shell command // for (Index = 0; CmdList[Index][0] != L'\0'; Index++) { // // Record the command to a file via shell command // CmdLine = PoolPrint ( L"ECHO \"%s\" >>a %s", CmdList[Index], EFI_SCT_FILE_CFG ); if (CmdLine == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); return EFI_OUT_OF_RESOURCES; } Status = ShellExecute ( gFT->ImageHandle, CmdLine, FALSE ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"ShellExecute: %s - %r", CmdLine, Status)); BS->FreePool (CmdLine); return Status; } BS->FreePool (CmdLine); // // Get the system configuration to a file via shell command // CmdLine = PoolPrint ( L"%s >>a %s", CmdList[Index], EFI_SCT_FILE_CFG ); if (CmdLine == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); return EFI_OUT_OF_RESOURCES; } Status = ShellExecute ( gFT->ImageHandle, CmdLine, FALSE ); if (EFI_ERROR (Status)) { // // Just record as a debug info. It is acceptable for this command return // an error status // EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"ShellExecute: %s - %r", CmdLine, Status)); } BS->FreePool (CmdLine); } // // Get the system configuration from the file // FileName = PoolPrint ( L"%s\\%s", gFT->FilePath, EFI_SCT_FILE_CFG ); if (FileName == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); return EFI_OUT_OF_RESOURCES; } Status = ReadFileToBuffer ( gFT->DevicePath, FileName, BufferSize, (VOID **)Buffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"ReadFileToBuffer: %s - %r", FileName, Status)); BS->FreePool (FileName); return Status; } BS->FreePool (FileName); // // Done // return EFI_SUCCESS; }
EFI_STATUS SctMainFunc ( VOID ) /*++ Routine Description: The main routine of SCT. Returns: EFI_SUCCESS - Successfully. OTHERS - Something failed. --*/ { EFI_STATUS Status; // // Check the operations // if (gFT->Operations == EFI_SCT_OPERATIONS_NONE) { // // No operation. Print out the help information // PrintUsage (); return EFI_SUCCESS; } // // Attach the first stage test data (before the test files are loaded) // Status = AttachFirstStageTestData (); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Attach first stage test data - %r", Status)); return Status; } // // Do the first stage operations (before the test files are loaded) // Status = DoFirstStageOperations (); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"First stage operations - %r", Status)); return Status; } // // Attach the second stage test data (after the test files are loaded) // Status = AttachSecondStageTestData (); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Attach second stage test data - %r", Status)); return Status; } // // Do the second stage operations (after the test files are loaded) // Status = DoSecondStageOperations (); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Second stage operations - %r", Status)); return Status; } // // Do the third stage operations (generate report) // Status = DoThirdStageOperations (); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Third stage operations - %r", Status)); return Status; } // // Done // return EFI_SUCCESS; }
EFI_STATUS LoadGuidDatabase ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CHAR16 *FileName ) /*++ Routine Description: Load the GUID database from a file. --*/ { EFI_STATUS Status; UINTN BufferSize; CHAR16 *Buffer; CHAR16 *LineBuffer; CHAR16 *GuidStr; CHAR16 *TitleStr; CHAR16 *IndexStr; // // Check parameters // if ((DevicePath == NULL) || (FileName == NULL)) { return EFI_INVALID_PARAMETER; } // // Read the database file // Status = ReadFileToBuffer ( DevicePath, FileName, &BufferSize, (VOID **)&Buffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Read file to buffer - %r", Status)); return Status; } // // Skip the first unicode char 0xFEFF // if (Buffer[0] != 0xFEFF) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Unsupported GUID database file")); BS->FreePool (Buffer); return EFI_SUCCESS; } LineBuffer = StrTokenLine (Buffer + 1, L"\n\r"); // // Walk through the GUID database file // while (LineBuffer != NULL) { if (LineBuffer[0] == L'#') { LineBuffer = StrTokenLine (NULL, L"\n\r"); continue; } // // Get the GUID string // GuidStr = LineBuffer; // // Get the Title string // TitleStr = StrTokenLine (NULL, L"\n\r"); if (TitleStr == NULL) { LineBuffer = StrTokenLine (NULL, L"\n\r"); continue; } // // Get the Index string // IndexStr = StrTokenLine (NULL, L"\n\r"); if (IndexStr == NULL) { LineBuffer = StrTokenLine (NULL, L"\n\r"); continue; } // // Insert the entry into the GUID database // Status = InsertGuidDatabase (GuidStr, TitleStr, IndexStr); if (EFI_ERROR (Status)) { break; } // // Next line // LineBuffer = StrTokenLine (NULL, L"\n\r"); } BS->FreePool (Buffer); return EFI_SUCCESS; }
EFI_STATUS AutoStrCat ( IN OUT CHAR16 **DstBuffer, IN CHAR16 *SrcBuffer ) /*++ Routine Description: Append one string to an automatically enlarged string. --*/ { EFI_STATUS Status; CHAR16 *TempBuffer; // // Check parameters // if ((DstBuffer == NULL) || (SrcBuffer == NULL)) { return EFI_INVALID_PARAMETER; } if (StrLen(SrcBuffer) >= EFI_SCT_LOG_BUFFER_SIZE) { return EFI_INVALID_PARAMETER; } // // Need to create a new buffer? // if (*DstBuffer == NULL) { // // Allocate buffer for the destination data // mReportBufferMaxSize = EFI_SCT_LOG_BUFFER_SIZE; mReportBufferUsedSize = 0; Status = BS->AllocatePool ( EfiBootServicesData, mReportBufferMaxSize * sizeof(CHAR16), &mReportBuffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); mReportBufferMaxSize = 0; return Status; } ZeroMem (mReportBuffer, mReportBufferMaxSize * sizeof(CHAR16)); } // // Need to enlarge a new buffer // if (mReportBufferUsedSize + StrLen(SrcBuffer) >= mReportBufferMaxSize) { // // Allocate buffer for the destination data // mReportBufferMaxSize = mReportBufferMaxSize * 2; Status = BS->AllocatePool ( EfiBootServicesData, mReportBufferMaxSize * sizeof(CHAR16), &TempBuffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); mReportBufferMaxSize = mReportBufferMaxSize / 2; return Status; } ZeroMem (TempBuffer, mReportBufferMaxSize * sizeof(CHAR16)); // // Copy the original data // CopyMem (TempBuffer, mReportBuffer, mReportBufferUsedSize * sizeof(CHAR16)); // // Free the original buffer // BS->FreePool (mReportBuffer); mReportBuffer = TempBuffer; } // // Append the source data to the destination data // StrCpy (mReportBuffer + mReportBufferUsedSize, SrcBuffer); mReportBufferUsedSize += StrLen(SrcBuffer); // // Done // *DstBuffer = mReportBuffer; return EFI_SUCCESS; }
EFI_STATUS LoadSingleSupportFile ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CHAR16 *FileName, OUT EFI_SCT_TEST_FILE **SupportFile ) /*++ Routine Description: Load a test support file. --*/ { EFI_STATUS Status; EFI_HANDLE ImageHandle; EFI_DEVICE_PATH_PROTOCOL *FileNode; EFI_DEVICE_PATH_PROTOCOL *FilePath; EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; UINTN ExitDataSize; CHAR16 *ExitData; EFI_TSL_INIT_INTERFACE *TslInit; // // Check parameters // if ((DevicePath == NULL) || (FileName == NULL) || (SupportFile == NULL)) { return EFI_INVALID_PARAMETER; } // // Debug information // EFI_SCT_DEBUG ((EFI_SCT_D_TRACE, L"Load support file <%s>", FileName)); // // Add the file path to the device path // FileNode = FileDevicePath (NULL, FileName); if (FileNode == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"FileDevicePath: Out of resources")); return EFI_OUT_OF_RESOURCES; } FilePath = AppendDevicePath (DevicePath, FileNode); if (FilePath == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"AppendDevicePath: Out of resources")); BS->FreePool (FileNode); return EFI_OUT_OF_RESOURCES; } BS->FreePool (FileNode); // // Load the support file // Status = BS->LoadImage ( FALSE, gFT->ImageHandle, FilePath, NULL, 0, &ImageHandle ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Load image - %r", Status)); BS->FreePool (FilePath); return Status; } BS->FreePool (FilePath); // // Verify the image is a driver or not // Status = BS->HandleProtocol ( ImageHandle, &gEfiLoadedImageProtocolGuid, &LoadedImage ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Locate loaded image - %r", Status)); return Status; } if ((LoadedImage->ImageCodeType == EfiBootServicesCode ) || (LoadedImage->ImageCodeType == EfiRuntimeServicesCode)) { // // It is a driver, and then verify it is a TSL (test support library) // Status = BS->StartImage ( ImageHandle, &ExitDataSize, &ExitData ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Start image - %r", Status)); return Status; } // // Is it a test support library? // Status = BS->HandleProtocol ( ImageHandle, &gEfiTslInitInterfaceGuid, &TslInit ); if (!EFI_ERROR (Status)) { Status = CreateSingleSupportFile ( DevicePath, FileName, ImageHandle, TslInit, SupportFile ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Create a support file - %r", Status)); BS->UnloadImage (ImageHandle); return Status; } return EFI_SUCCESS; } BS->UnloadImage (ImageHandle); } // // Unsupported file // EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Unsupported file")); return EFI_UNSUPPORTED; }
EFI_STATUS CloseStandardSupportFiles ( VOID ) /*++ Routine Description: Close the standard support files. Returns: EFI_SUCCESS - Successfully. Other value - Something failed. --*/ { // // Debug information // EFI_SCT_DEBUG ((EFI_SCT_D_TRACE, L"Close standard support files")); // // EFI standard test support file // if ((gFT->StslProtocol != NULL) || (gFT->StslInterface != NULL)) { CloseSingleSupportFile (&gEfiStandardTestLibraryGuid); gFT->StslProtocol = NULL; gFT->StslInterface = NULL; } // // EFI test profile support file // if (gFT->TplProtocol != NULL) { CloseSingleSupportFile (&gEfiTestProfileLibraryGuid); gFT->TplProtocol = NULL; } // // EFI test recovery support file // if ((gFT->TrlProtocol != NULL) || (gFT->TrlInterface != NULL)) { CloseSingleSupportFile (&gEfiTestRecoveryLibraryGuid); gFT->TrlProtocol = NULL; gFT->TrlInterface = NULL; } // // EFI test logging support file // if ((gFT->TllProtocol != NULL) || (gFT->TllInterface != NULL)) { CloseSingleSupportFile (&gEfiTestLoggingLibraryGuid); gFT->TllProtocol = NULL; gFT->TllInterface = NULL; } // // Done // return EFI_SUCCESS; }
EFI_STATUS OpenStandardSupportFiles ( VOID ) /*++ Routine Description: Open the standard support files. Returns: EFI_SUCCESS - Successfully. Other value - Something failed. --*/ { EFI_STATUS Status; CHAR16 *FileName; // // Debug information // EFI_SCT_DEBUG ((EFI_SCT_D_TRACE, L"Open standard support files")); // // EFI standard test support file // Status = OpenSingleSupportFile ( &gEfiStandardTestLibraryGuid, &gFT->StslProtocol, &gFT->StslInterface ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open standard test - %r", Status)); CloseStandardSupportFiles (); return Status; } // // EFI test profile support file // Status = OpenSingleSupportFile ( &gEfiTestProfileLibraryGuid, &gFT->TplProtocol, NULL ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open test profile - %r", Status)); CloseStandardSupportFiles (); return Status; } // // EFI test recovery support file // Status = OpenSingleSupportFile ( &gEfiTestRecoveryLibraryGuid, &gFT->TrlProtocol, &gFT->TrlInterface ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open test recovery - %r", Status)); CloseStandardSupportFiles (); return Status; } // // EFI test logging support file // Status = OpenSingleSupportFile ( &gEfiTestLoggingLibraryGuid, &gFT->TllProtocol, &gFT->TllInterface ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open test logging - %r", Status)); CloseStandardSupportFiles (); return Status; } // // Set the config data of test profile // Status = gFT->TplProtocol->EfiSetSystemDevicePath ( gFT->TplProtocol, gFT->DevicePath, gFT->FilePath ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Set profile config - %r", Status)); CloseStandardSupportFiles (); return Status; } // // Set the config data of test recovery // FileName = PoolPrint (L"%s\\%s", gFT->FilePath, EFI_SCT_FILE_RECOVERY); if (FileName == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); CloseStandardSupportFiles (); return EFI_OUT_OF_RESOURCES; } Status = gFT->TrlInterface->SetConfig ( gFT->TrlInterface, gFT->DevicePath, FileName ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Set recovery config - %r", Status)); CloseStandardSupportFiles (); BS->FreePool (FileName); return Status; } BS->FreePool (FileName); // // Done // return EFI_SUCCESS; }
EFI_STATUS LoadSingleCategoryData ( IN EFI_INI_FILE_HANDLE IniFile, IN UINT32 Order, OUT EFI_SCT_CATEGORY_DATA **Category ) /*++ Routine Description: Load a category data. --*/ { EFI_STATUS Status; CHAR16 Buffer[EFI_SCT_MAX_BUFFER_SIZE]; UINT32 Revision; EFI_SCT_CATEGORY_DATA *TempCategory; // // Check parameters // if (Category == NULL) { return EFI_INVALID_PARAMETER; } // // Create a category data // Status = CreateSingleCategoryData (&TempCategory); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Create a category - %r", Status)); return Status; } // // Initialize the items of category data // TempCategory->Index = Order; // // Check the revision info // Status = CategoryGetString (IniFile, Order, L"Revision", Buffer); if (EFI_ERROR (Status)) { // // Without the revision info, ignore this category data // EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Without revision")); FreeSingleCategoryData (TempCategory); return Status; } Status = SctHexStrToShort (Buffer, &Revision); if (EFI_ERROR (Status) || (Revision != TempCategory->Revision)) { // // With unsupported revision info, ignore this category data // EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Invalid revision")); FreeSingleCategoryData (TempCategory); return EFI_UNSUPPORTED; } // // Load the category GUID // Status = CategoryGetString (IniFile, Order, L"CategoryGuid", Buffer); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Without category GUID")); FreeSingleCategoryData (TempCategory); return Status; } Status = SctStrToGuid (Buffer, &TempCategory->CategoryGuid); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Invalid category GUID")); FreeSingleCategoryData (TempCategory); return Status; } // // Load the interface GUID // Status = CategoryGetString (IniFile, Order, L"InterfaceGuid", Buffer); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Without interface GUID")); FreeSingleCategoryData (TempCategory); return Status; } Status = SctStrToGuid (Buffer, &TempCategory->InterfaceGuid); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Invalid interface GUID")); FreeSingleCategoryData (TempCategory); return Status; } // // Load the name // Status = CategoryGetString (IniFile, Order, L"Name", Buffer); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Without name")); FreeSingleCategoryData (TempCategory); return Status; } TempCategory->Name = StrDuplicate (Buffer); // // Load the description // Status = CategoryGetString (IniFile, Order, L"Description", Buffer); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Without description")); FreeSingleCategoryData (TempCategory); return Status; } TempCategory->Description = StrDuplicate (Buffer); // // Check error // if ((TempCategory->Name == NULL) || (TempCategory->Description == NULL)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Out of resources")); FreeSingleCategoryData (TempCategory); return EFI_OUT_OF_RESOURCES; } // // Done // *Category = TempCategory; return EFI_SUCCESS; }
EFI_STATUS LoadSupportFiles ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CHAR16 *FilePath, IN BOOLEAN Recursive, OUT EFI_LIST_ENTRY *SupportFileList ) /*++ Routine Description: Load all test support files. Arguments: DevicePath - Device path of the files. FilePath - Path of the files. Recursive - Recursively. SupportFileList - Pointer to the support file list. Returns: EFI_SUCCESS - Successfully. Other value - Something failed. --*/ { EFI_STATUS Status; EFI_HANDLE DeviceHandle; EFI_FILE_HANDLE RootDir; EFI_FILE_HANDLE SupportDir; CHAR16 *SubDir; CHAR16 *FileName; UINTN FileInfoSize; EFI_FILE_INFO *FileInfo; EFI_SCT_TEST_FILE *SupportFile; EFI_DEVICE_PATH_PROTOCOL *RemainderPath; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol; // // Check parameters // if ((DevicePath == NULL) || (FilePath == NULL) || (SupportFileList == NULL)) { return EFI_INVALID_PARAMETER; } // // Debug information // EFI_SCT_DEBUG ((EFI_SCT_D_TRACE, L"Load support files from <%s>", FilePath)); // // Locate the device handle from the device path // RemainderPath = DevicePath; Status = BS->LocateDevicePath ( &gEfiSimpleFileSystemProtocolGuid, &RemainderPath, &DeviceHandle ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Locate device handle - %r", Status)); return Status; } // // Locate the volume of the file system // Status = BS->HandleProtocol ( DeviceHandle, &gEfiSimpleFileSystemProtocolGuid, &Vol ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Locate file system - %r", Status)); return Status; } // // Open the root volume // Status = Vol->OpenVolume (Vol, &RootDir); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open root volume - %r", Status)); return Status; } // // Open the support directory // Status = RootDir->Open ( RootDir, &SupportDir, FilePath, EFI_FILE_MODE_READ, EFI_FILE_DIRECTORY ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open support directory - %r", Status)); RootDir->Close (RootDir); return Status; } RootDir->Close (RootDir); // // Allocate memory for the entries in the directory // FileInfoSize = sizeof(EFI_FILE_INFO) + 1024; Status = BS->AllocatePool ( EfiBootServicesData, FileInfoSize, &FileInfo ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); SupportDir->Close (SupportDir); return Status; } // // Walk through each file in the directory // while (TRUE) { // // Read a file entry // FileInfoSize = sizeof(EFI_FILE_INFO) + 1024; Status = SupportDir->Read ( SupportDir, &FileInfoSize, FileInfo ); if (EFI_ERROR (Status) || (FileInfoSize == 0)) { break; } if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == 0) { // // This is a file // if (SctStrEndWith (FileInfo->FileName, L".efi")) { // // Load the support file // FileName = PoolPrint (L"%s\\%s", FilePath, FileInfo->FileName); if (FileName == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); break; } Status = LoadSingleSupportFile ( DevicePath, FileName, &SupportFile ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Load a support file - %r", Status)); BS->FreePool (FileName); continue; } BS->FreePool (FileName); // // Add the support file to the support file list // InsertTailList (SupportFileList, &SupportFile->Link); } } else { // // This is a directory // if (Recursive) { // // Skip the '.' and '..' dir // if ((StrCmp (FileInfo->FileName, L".") == 0) || (StrCmp (FileInfo->FileName, L"..") == 0)) { continue; } // // Load the support files under the sub directory // SubDir = PoolPrint (L"%s\\%s", FilePath, FileInfo->FileName); if (SubDir == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); break; } Status = LoadSupportFiles ( DevicePath, SubDir, Recursive, SupportFileList ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Load support files - %r", Status)); BS->FreePool (SubDir); continue; } BS->FreePool (SubDir); } } } // // Free resources // BS->FreePool (FileInfo); SupportDir->Close (SupportDir); // // Done // return EFI_SUCCESS; }
EFI_STATUS DisplayMainMenu ( VOID ) /*++ Routine Description: Display the main menu Returns: EFI_SUCCESS - Display the menu successfully Other Value - Something failed --*/ { EFI_STATUS Status; EFI_MENU_PAGE *Page; EFI_DIALOG_CONTEXT DialogContext; CHAR16 *DialogTitle; // // Create a standard menu // Status = CreateStandardMenuPage ( L"Main Menu", &Page ); if (EFI_ERROR(Status)) { return Status; } // // Main Menu Items // - Test Case Management // - Test Environment Configuration // - Test Report Generator ... // - Help // Status = AddSimpleMenuItem ( EFI_ITEM_HAVE_SUBITEMS, L"Test Case Management", L"Select and execute test cases", (VOID *)(UINTN)EFI_MENU_ITEM_CASE_MANAGEMENT, Page ); if (EFI_ERROR(Status)) { DestroyMenuPage (Page); return Status; } Status = AddSimpleMenuItem ( EFI_ITEM_HAVE_SUBITEMS, L"Test Environment Configuration", L"Set configuration data for testing", (VOID *)(UINTN)EFI_MENU_ITEM_CONFIG, Page ); if (EFI_ERROR(Status)) { DestroyMenuPage (Page); return Status; } Status = AddSimpleMenuItem ( EFI_ITEM_HAVE_SUBITEMS, L"Test Device Configuration", L"Set device configuration data for IHV's add-in card testing", (VOID *)(UINTN)EFI_MENU_ITEM_DEVICE_CONFIG, Page ); if (EFI_ERROR(Status)) { DestroyMenuPage (Page); return Status; } Status = AddSimpleMenuItem ( EFI_ITEM_HAVE_SUBITEMS, L"View Test Log ...", L"View test log", (VOID *)(UINTN)EFI_MENU_ITEM_VIEW_LOG, Page ); if (EFI_ERROR(Status)) { DestroyMenuPage (Page); return Status; } Status = AddSimpleMenuItem ( EFI_ITEM_HAVE_SUBITEMS, L"Test Report Generator ...", L"Generate test report", (VOID *)(UINTN)EFI_MENU_ITEM_REPORT_GENERATOR, Page ); if (EFI_ERROR(Status)) { DestroyMenuPage (Page); return Status; } #if (EFI_SPECIFICATION_VERSION == 0x0001000A) Status = AddSimpleMenuItem ( EFI_ITEM_HAVE_SUBITEMS, L"Help", L"EFI1.1 Self Certification Test is a toolkit to check an EFI1.1 " L"implementation is EFI1.1 Specification compliant or not.", (VOID *)(UINTN)EFI_MENU_ITEM_UTILITY, Page ); #elif (EFI_SPECIFICATION_VERSION == 0x00020000) Status = AddSimpleMenuItem ( EFI_ITEM_HAVE_SUBITEMS, L"Help", L"UEFI2.0 Self Certification Test is a toolkit to check an UEFI2.0 " L"implementation is UEFI2.0 Specification compliant or not.", (VOID *)(UINTN)EFI_MENU_ITEM_UTILITY, Page ); #elif (EFI_SPECIFICATION_VERSION == 0x0002000A) Status = AddSimpleMenuItem ( EFI_ITEM_HAVE_SUBITEMS, L"Help", L"UEFI2.1 Self Certification Test is a toolkit to check an UEFI2.1 " L"implementation is UEFI2.1 Specification compliant or not.", (VOID *)(UINTN)EFI_MENU_ITEM_UTILITY, Page ); #elif (EFI_SPECIFICATION_VERSION == 0x0002001E) Status = AddSimpleMenuItem ( EFI_ITEM_HAVE_SUBITEMS, L"Help", L"UEFI2.3 Self Certification Test is a toolkit to check an UEFI2.3 " L"implementation is UEFI2.3 Specification compliant or not.", (VOID *)(UINTN)EFI_MENU_ITEM_UTILITY, Page ); #elif (EFI_SPECIFICATION_VERSION == 0x0002001F) Status = AddSimpleMenuItem ( EFI_ITEM_HAVE_SUBITEMS, L"Help", L"UEFI2.3.1C Self Certification Test is a toolkit to check an UEFI2.3.1C " L"implementation is UEFI2.3.1C Specification compliant or not.", (VOID *)(UINTN)EFI_MENU_ITEM_UTILITY, Page ); #endif if (EFI_ERROR(Status)) { DestroyMenuPage (Page); return Status; } // // Main Menu Hot Keys // - Up, Down, Enter, Esc, F5, F6 // Status = AddHotKey ( L"Up/Dn", L"Select Item", SCAN_UP, CHAR_NULL, UpFunc, TRUE, Page ); if (EFI_ERROR(Status)) { DestroyMenuPage (Page); return Status; } Status = AddHotKey ( L"Down", L"Select Item", SCAN_DOWN, CHAR_NULL, DownFunc, FALSE, Page ); if (EFI_ERROR(Status)) { DestroyMenuPage (Page); return Status; } Status = AddHotKey ( L"F4", L"Reset results", SCAN_F4, CHAR_NULL, MainMenuClearFunc, TRUE, Page ); if (EFI_ERROR(Status)) { DestroyMenuPage (Page); return Status; } Status = AddHotKey ( L"F5", L"Load Sequence", SCAN_F5, CHAR_NULL, MainMenuLoadSeqFunc, TRUE, Page ); if (EFI_ERROR (Status)) { DestroyMenuPage (Page); return Status; } Status = AddHotKey ( L"F6", L"Save Sequence", SCAN_F6, CHAR_NULL, MainMenuSaveSeqFunc, TRUE, Page ); if (EFI_ERROR (Status)) { DestroyMenuPage (Page); return Status; } Status = AddHotKey ( L"Enter", L"Select SubMenu", SCAN_NULL, CHAR_CARRIAGE_RETURN, MainMenuEnterFunc, TRUE, Page ); if (EFI_ERROR(Status)) { DestroyMenuPage (Page); return Status; } Status = AddHotKey ( L"ESC", L"Exit", SCAN_ESC, CHAR_NULL, MainMenuEscFunc, TRUE, Page ); if (EFI_ERROR(Status)) { DestroyMenuPage (Page); return Status; } Status = AddHotKey ( L"F9", L"Run", SCAN_F9, CHAR_NULL, MainMenuF9Func, FALSE, Page ); if (EFI_ERROR (Status)) { DestroyMenuPage (Page); return Status; } // // Display the main menu // MenuPageRefresh (Page); // //If start from recovery, remind user to continue running // if (!IsTestFinished () && !gForceExecution) { // //Execution was not finished in last time. Display yes or no dialog // DialogContext.Type = EFI_DIALOG_TYPE_YES_OR_NO; // //Set Yes as default choise // DialogContext.ChooseNumber = EFI_DIALOG_SELECT_YES; DialogTitle = StrDuplicate (L"Continue Run?"); // //Display ask dialog // DoDialog (DialogTitle, &DialogContext); if (DialogContext.ChooseNumber == EFI_DIALOG_SELECT_YES) { // //Change to running background // ST->ConOut->SetAttribute ( ST->ConOut, EFI_LIGHTGRAY | EFI_BACKGROUND_BLACK ); ST->ConOut->ClearScreen (ST->ConOut); Status = SctContinueExecute (); gContinueExec = FALSE; if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Continue execute - %r", Status)); } } else { // //user choose not to continue run immediatly, set global flag, let user to //continue run later // gContinueExec = TRUE; } MenuPageRefresh (Page); } else { // //not start from recovery mode // gContinueExec = FALSE; } // // Start to handle input keys // MenuPageKeyInput (); return EFI_SUCCESS; }
EFI_STATUS LoadReportInfor ( IN CHAR16 *CaseIndexStr, IN CHAR16 *CaseIterationStr, IN CHAR16 *Buffer, IN CHAR16 *FileName ) /*++ Routine Description: Load the report information from a buffer. --*/ { EFI_STATUS Status; CHAR16 *LineBuffer; CHAR16 *GuidStr; CHAR16 *AssertionStr; UINTN AssertionType; CHAR16 *TestNameStr; CHAR16 *TestCategoryStr; CHAR16 *DevicePathStr; CHAR16 *TitleStr; CHAR16 *RuntimeInforStr; CHAR16 *CaseRevisionStr; CHAR16 *CaseGuidStr; CHAR16 *CaseNameStr; CHAR16 GenericGuidStr[EFI_SCT_GUID_LEN]; CHAR16 SystemHangGuidStr[EFI_SCT_GUID_LEN]; // // Check parameters // if ((CaseIndexStr == NULL) || (CaseIterationStr == NULL) || (Buffer == NULL)) { return EFI_INVALID_PARAMETER; } // // Initialize // ZeroMem (GenericGuidStr, EFI_SCT_GUID_LEN * sizeof(CHAR16)); SctGuidToStr (&gTestGenericFailureGuid, GenericGuidStr); ZeroMem (SystemHangGuidStr, EFI_SCT_GUID_LEN * sizeof(CHAR16)); SctGuidToStr (&gEfiSystemHangAssertionGuid, SystemHangGuidStr); CaseGuidStr = NULL; CaseRevisionStr = NULL; CaseNameStr = NULL; TestNameStr = NULL; TestCategoryStr = NULL; DevicePathStr = NULL; // // Start to deal with the ekl file data // if (Buffer[0] != 0xFEFF) { return EFI_SUCCESS; } LineBuffer = StrTokenLine (Buffer + 1, L"\n\r"); while (LineBuffer != NULL) { if (LineBuffer[0] == L'|') { if (LineBuffer[1] == L'H') { // // The head line // StrTokenField (LineBuffer, L"|"); // // Skip the HEAD characters // StrTokenField (NULL, L"|"); // // Skip the first empty string // StrTokenField (NULL, L"|"); // // Skip the second empry string // StrTokenField (NULL, L"|"); // // Skip the configuration number // StrTokenField (NULL, L"|"); // // Skip the scenario string // StrTokenField (NULL, L"|"); // // Skip the execution date // StrTokenField (NULL, L"|"); // // Skip the execution time // StrTokenField (NULL, L"|"); // // Get the case's GUID // CaseGuidStr = StrTokenField (NULL, L"|"); // // Get the case's revision // CaseRevisionStr = StrTokenField (NULL, L"|"); // // Get the case's name // CaseNameStr = StrTokenField (NULL, L"|"); // // Get the test name // TestNameStr = StrTokenField (NULL, L"|"); // // Get the test category // TestCategoryStr = StrTokenField (NULL, L"|"); // // Get the device path // // Note: Don't use "|" to split the device path token, some device path // include that. And from the other way, the device path token should // be the last token in the .ekl header. // DevicePathStr = StrTokenField (NULL, L"\n"); } else if (LineBuffer[1] == L'T') { // // The terminate line, do nothing // } LineBuffer = StrTokenLine (NULL, L"\n\r"); continue; } // // The item line // // // Get the assertion's GUID // GuidStr = StrTokenField (LineBuffer, L":"); if (GuidStr == NULL) { LineBuffer = StrTokenLine (NULL, L"\n\r"); continue; } // // Ignore the generic GUID // if (StrCmp (GuidStr, GenericGuidStr) == 0) { LineBuffer = StrTokenLine (NULL, L"\n\r"); continue; } // // Get the assertion's type // AssertionStr = StrTokenField (NULL, L"|"); if (AssertionStr == NULL) { LineBuffer = StrTokenLine (NULL, L"\n\r"); continue; } if (StrCmp (AssertionStr, L"PASS") == 0) { AssertionType = EFI_SCT_GUID_ASSERTION_TYPE_PASS; } else if (StrCmp (AssertionStr, L"FAILURE") == 0) { AssertionType = EFI_SCT_GUID_ASSERTION_TYPE_FAIL; } else { AssertionType = EFI_SCT_GUID_ASSERTION_TYPE_WARN; } // // Get the Title // TitleStr = StrTokenField (NULL, L":"); if (StrCmp (GuidStr, SystemHangGuidStr) == 0) { TitleStr = StrDuplicate (L"System hangs or stops abnormally."); } // // Get the runtime information // RuntimeInforStr = StrTokenField (NULL, L"\n\r"); if (StrCmp (GuidStr, SystemHangGuidStr) == 0) { RuntimeInforStr = PoolPrint (L"System hang in %s - %s", TestCategoryStr, CaseNameStr); } // // Set the report item // Status = InsertReportInfor ( CaseIndexStr, CaseIterationStr, TestNameStr, TestCategoryStr, GuidStr, AssertionType, TitleStr, RuntimeInforStr, DevicePathStr, CaseRevisionStr, CaseGuidStr, FileName ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Set report item - %r", Status)); if (StrCmp (GuidStr, SystemHangGuidStr) == 0) { BS->FreePool (TitleStr); BS->FreePool (RuntimeInforStr); } return Status; } if (StrCmp (GuidStr, SystemHangGuidStr) == 0) { BS->FreePool (TitleStr); BS->FreePool (RuntimeInforStr); } // // Next line // LineBuffer = StrTokenLine (NULL, L"\n\r"); } return EFI_SUCCESS; }
EFI_STATUS ReadFileToBuffer ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CHAR16 *FileName, OUT UINTN *BufferSize, OUT VOID **Buffer ) /*++ Routine Description: Read a file. --*/ { EFI_STATUS Status; EFI_HANDLE DeviceHandle; EFI_FILE_HANDLE RootDir; EFI_FILE_HANDLE Handle; UINTN FileInfoSize; EFI_FILE_INFO *FileInfo; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol; EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath; UINTN TempBufferSize; VOID *TempBuffer; // // Check parameters // if ((DevicePath == NULL) || (FileName == NULL) || (Buffer == NULL)) { return EFI_INVALID_PARAMETER; } // // Locate the device handle // RemainingDevicePath = DevicePath; Status = BS->LocateDevicePath ( &gEfiSimpleFileSystemProtocolGuid, &RemainingDevicePath, &DeviceHandle ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Locate device path - %r", Status)); return Status; } // // Locate the simple file system // Status = BS->HandleProtocol ( DeviceHandle, &gEfiSimpleFileSystemProtocolGuid, &Vol ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Handle protocol - %r", Status)); return Status; } // // Open the root directory // Status = Vol->OpenVolume (Vol, &RootDir); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open volume - %r", Status)); return Status; } // // Open the file // Status = RootDir->Open ( RootDir, &Handle, FileName, EFI_FILE_MODE_READ, 0 ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open file - %r", Status)); RootDir->Close (RootDir); return Status; } RootDir->Close (RootDir); // // Get the file information // FileInfoSize = sizeof(EFI_FILE_INFO) + 1024; Status = BS->AllocatePool ( EfiBootServicesData, FileInfoSize, &FileInfo ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); Handle->Close (Handle); return Status; } ZeroMem (FileInfo, FileInfoSize); Status = Handle->GetInfo ( Handle, &gEfiFileInfoGuid, &FileInfoSize, FileInfo ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Get file info - %r", Status)); Handle->Close (Handle); BS->FreePool (FileInfo); return Status; } // // Allocate buffer for the file data. The last CHAR16 is for L'\0' // TempBufferSize = (UINTN) FileInfo->FileSize + sizeof(CHAR16); Status = BS->AllocatePool ( EfiBootServicesData, TempBufferSize, &TempBuffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); Handle->Close (Handle); BS->FreePool (FileInfo); return Status; } ZeroMem (TempBuffer, TempBufferSize); BS->FreePool (FileInfo); // // Read the file data to the buffer // Status = Handle->Read ( Handle, &TempBufferSize, TempBuffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Read file - %r", Status)); Handle->Close (Handle); BS->FreePool (TempBuffer); return Status; } Handle->Close (Handle); *BufferSize = TempBufferSize; *Buffer = TempBuffer; return EFI_SUCCESS; }
EFI_STATUS GetInstanceAssertion ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CHAR16 *MetaName, OUT EFI_SCT_LOG_STATE *FileState, OUT UINT32 *Index, OUT UINT32 *Iteration, OUT UINT32 *PassNumber, OUT UINT32 *WarnNumber, OUT UINT32 *FailNumber ) /*++ Routine Description: Get the assertion number of a instance. Arguments: DevicePath - Device path of the key files. MetaName - Meta name of the key files. FileState - The log state. Index - The index of the instance. Interation - The index of the iteration. PassNumber - The number of passed assertions. WarnNumber - The number of warning assertions. FailNumber - The number of failed assertions. Returns: EFI_SUCCESS - Get instance assertion number successfully. --*/ { EFI_STATUS Status; CHAR16 *FileName; UINT32 InstanceIndex; UINT32 IterationIndex; UINTN BufferSize; CHAR16 *Buffer; // // Check parameters // if ((DevicePath == NULL) || (MetaName == NULL) || (FileState == NULL) || (Index == NULL) || (Iteration == NULL) || (PassNumber == NULL) || (WarnNumber == NULL) || (FailNumber == NULL)) { return EFI_INVALID_PARAMETER; } // // Initialize // *FileState = EFI_SCT_LOG_STATE_UNKNOWN; *Index = 0; *Iteration = 0; *PassNumber = 0; *WarnNumber = 0; *FailNumber = 0; InstanceIndex = 0; IterationIndex = 0; // // Found the maximum index of instance and iteration // for (InstanceIndex = 0; TRUE; InstanceIndex ++) { for (IterationIndex = 0; TRUE; IterationIndex ++) { FileName = PoolPrint (MetaName, InstanceIndex, IterationIndex); if (FileName == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); return EFI_OUT_OF_RESOURCES; } if (!FileExist (DevicePath, FileName)) { // // File does not exist // if (IterationIndex != 0) { *Index = InstanceIndex; *Iteration = IterationIndex - 1; } BS->FreePool (FileName); break; } BS->FreePool (FileName); } if (IterationIndex == 0) { break; } } // // No instance file is found // if ((InstanceIndex == 0) && (IterationIndex == 0)) { *FileState = EFI_SCT_LOG_STATE_EMPTY; *Index = 0; *Iteration = 0; return EFI_SUCCESS; } // // The maximum instance index is found // FileName = PoolPrint (MetaName, *Index, *Iteration); if (FileName == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); return EFI_OUT_OF_RESOURCES; } // // Read the file to a buffer // Status = ReadFileToBuffer ( DevicePath, FileName, &BufferSize, &Buffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Read file to buffer - %r", Status)); BS->FreePool (FileName); return Status; } BS->FreePool (FileName); // // Load the buffer to the GUID assertion table with duplicate // Status = LoadGuidAssertion (Buffer, TRUE, FileState); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Load GUID assertion - %r", Status)); BS->FreePool (Buffer); return Status; } BS->FreePool (Buffer); // // Get the assertion number (free the GUID assertion table) // Status = GetAssertionNumber (PassNumber, WarnNumber, FailNumber); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Get assertion number - %r", Status)); return Status; } // // Done // return EFI_SUCCESS; }
EFI_STATUS InsertGuidAssertion ( IN CHAR16 *GuidStr, IN UINTN AssertionType, IN BOOLEAN Duplicate, OUT EFI_SCT_GUID_ASSERTION_STATE *AssertionState ) /*++ Routine Description: Insert a GUID assertion. --*/ { EFI_STATUS Status; INTN Index; UINTN OldAssertionType; CHAR16 SystemHangGuidStr[EFI_SCT_GUID_LEN]; EFI_SCT_GUID_ASSERTION *TempGuidAssertion; // // Check parameters // if ((GuidStr == NULL) || (AssertionState == NULL)) { return EFI_INVALID_PARAMETER; } // // Skip warning assertion in non-duplicate condition // // if (!Duplicate && (AssertionType == EFI_SCT_GUID_ASSERTION_TYPE_WARN)) { // return EFI_SUCCESS; // } // // Initialize // ZeroMem (SystemHangGuidStr, EFI_SCT_GUID_LEN); SctGuidToStr (&gEfiSystemHangAssertionGuid, SystemHangGuidStr); *AssertionState = EFI_SCT_GUID_ASSERTION_STATE_NOT_FOUND; // // Remove the duplicate GUID assertion // if (!Duplicate && (StrCmp (SystemHangGuidStr, GuidStr) != 0)) { // // Seach the GUID assertion, from the last one for performance // for (Index = (INTN)mGuidAssertionUsedSize - 1; Index >= 0; Index --) { if (StrCmp (mGuidAssertion[Index].Guid, GuidStr) != 0) { continue; } // // Find it. // Set the worst assertion type (Pass = 0x01, Warn = 0x03, Fail = 0x07) // OldAssertionType = mGuidAssertion[Index].AssertionType; if ((OldAssertionType | AssertionType) == OldAssertionType) { *AssertionState = EFI_SCT_GUID_ASSERTION_STATE_FOUND; return EFI_SUCCESS; } mGuidAssertion[Index].AssertionType |= AssertionType; *AssertionState = EFI_SCT_GUID_ASSERTION_STATE_OVERRIDE; return EFI_SUCCESS; } } // // Need to create a new buffer? // if (mGuidAssertionMaxSize == 0) { mGuidAssertionMaxSize = EFI_SCT_GUID_ASSERTION_SIZE; mGuidAssertionUsedSize = 0; Status = BS->AllocatePool ( EfiBootServicesData, mGuidAssertionMaxSize * sizeof(EFI_SCT_GUID_ASSERTION), (VOID **)&mGuidAssertion ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); mGuidAssertionMaxSize = 0; return Status; } ZeroMem (mGuidAssertion, mGuidAssertionMaxSize * sizeof(EFI_SCT_GUID_ASSERTION)); } // // Need to enlarge a new buffer? // if (mGuidAssertionUsedSize + 1 >= mGuidAssertionMaxSize) { mGuidAssertionMaxSize = mGuidAssertionMaxSize * 2; Status = BS->AllocatePool ( EfiBootServicesData, mGuidAssertionMaxSize * sizeof(EFI_SCT_GUID_ASSERTION), (VOID **)&TempGuidAssertion ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); mGuidAssertionMaxSize = mGuidAssertionMaxSize / 2; return Status; } ZeroMem (mGuidAssertion, mGuidAssertionMaxSize * sizeof(EFI_SCT_GUID_ASSERTION)); // // Copy the original data // CopyMem (TempGuidAssertion, mGuidAssertion, mGuidAssertionUsedSize * sizeof(EFI_SCT_GUID_ASSERTION)); // // Free the original buffer // BS->FreePool (mGuidAssertion); mGuidAssertion = TempGuidAssertion; } // // Append the GUID entry to the GUID assertion // SctStrnCpy (mGuidAssertion[mGuidAssertionUsedSize].Guid, GuidStr, EFI_SCT_GUID_LEN); mGuidAssertion[mGuidAssertionUsedSize].AssertionType = AssertionType; mGuidAssertionUsedSize ++; return EFI_SUCCESS; }
EFI_STATUS OpenSingleSupportFile ( IN EFI_GUID *Guid, OUT VOID **Protocol, OUT VOID **Interface ) /*++ Routine Description: Open a test support file to get the public interface and private interface. --*/ { EFI_STATUS Status; EFI_LIST_ENTRY *Link; EFI_SCT_TEST_FILE *SupportFile; EFI_TSL_INIT_INTERFACE *TslInit; VOID *TempProtocol; VOID *TempInterface; // // Walk through all support files // for (Link = gFT->SupportFileList.Flink; Link != &gFT->SupportFileList; Link = Link->Flink) { SupportFile = CR (Link, EFI_SCT_TEST_FILE, Link, EFI_SCT_TEST_FILE_SIGNATURE); // // Each support file should provide an EFI_TSL_INIT_INTERFACE instance // TslInit = (EFI_TSL_INIT_INTERFACE *) SupportFile->Context; if (CompareGuid (&TslInit->LibraryGuid, Guid) == 0) { // // Open the support file // Status = TslInit->Open ( TslInit, &gFT->SupportHandle, &TempInterface ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"TSL open - %r", Status)); return Status; } // // Get the public interface // Status = BS->HandleProtocol ( gFT->SupportHandle, Guid, &TempProtocol ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Locate public interface - %r", Status)); return Status; } if (Protocol != NULL) { *Protocol = TempProtocol; } if (Interface != NULL) { *Interface = TempInterface; } // // Got it! // return EFI_SUCCESS; } } // // No matched protocol // return EFI_NOT_FOUND; }
EFI_STATUS LoadGuidAssertion ( IN CHAR16 *Buffer, IN BOOLEAN Duplicate, OUT EFI_SCT_LOG_STATE *FileState ) /*++ Routine Description: Load the GUID assertion from a buffer. --*/ { EFI_STATUS Status; CHAR16 *LineBuffer; CHAR16 *GuidStr; CHAR16 *AssertionStr; UINTN AssertionType; CHAR16 GenericGuidStr[EFI_SCT_GUID_LEN]; EFI_SCT_GUID_ASSERTION_STATE AssertionState; // // Check parameters // if ((Buffer == NULL) || (FileState == NULL)) { return EFI_INVALID_PARAMETER; } // // Initialize // ZeroMem (GenericGuidStr, EFI_SCT_GUID_LEN * sizeof(CHAR16)); SctGuidToStr (&gTestGenericFailureGuid, GenericGuidStr); *FileState = EFI_SCT_LOG_STATE_EMPTY; // // Skip the first unicode char 0xFEFF // if (Buffer[0] != 0xFEFF) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Unsupported GUID assertion buffer")); return EFI_SUCCESS; } LineBuffer = StrTokenLine (Buffer + 1, L"\n\r"); // // Walk through the GUID assertion buffer // while (LineBuffer != NULL) { if (LineBuffer[0] == L'|') { if (LineBuffer[1] == L'H') { // // The head line // *FileState = EFI_SCT_LOG_STATE_RUNNING; } else if (LineBuffer[1] == L'T') { // // The terminate line // *FileState = EFI_SCT_LOG_STATE_FINISHED; } LineBuffer = StrTokenLine (NULL, L"\n\r"); continue; } // // The item line // // // Get the assertion's GUID // GuidStr = StrTokenField (LineBuffer, L":"); if (GuidStr == NULL) { LineBuffer = StrTokenLine (NULL, L"\n\r"); continue; } if (!Duplicate) { // // Ignore the generic GUID // if (StrCmp (GuidStr, GenericGuidStr) == 0) { LineBuffer = StrTokenLine (NULL, L"\n\r"); continue; } } // // Get the assertion's type // AssertionStr = StrTokenField (NULL, L"|"); if (AssertionStr == NULL) { LineBuffer = StrTokenLine (NULL, L"\n\r"); continue; } if (StrCmp (AssertionStr, L"PASS") == 0) { AssertionType = EFI_SCT_GUID_ASSERTION_TYPE_PASS; } else if (StrCmp (AssertionStr, L"FAILURE") == 0) { AssertionType = EFI_SCT_GUID_ASSERTION_TYPE_FAIL; } else { AssertionType = EFI_SCT_GUID_ASSERTION_TYPE_WARN; } // // Skip the reset fields // // // Insert it into GUID assertion // Status = InsertGuidAssertion ( GuidStr, AssertionType, Duplicate, &AssertionState ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Insert GUID assertion - %r", Status)); return Status; } // // Next line // LineBuffer = StrTokenLine (NULL, L"\n\r"); } return EFI_SUCCESS; }
EFI_STATUS LoadCategoryData ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CHAR16 *FileName, OUT EFI_LIST_ENTRY *CategoryList ) /*++ Routine Description: Load the category data list from a file. Arguments: DevicePath - Device path of the file. FileName - Name of the file. CategoryList - Pointer to the category data list. Returns: EFI_SUCCESS - Successfully. Other value - Something failed. --*/ { EFI_STATUS Status; UINT32 Index; UINT32 NumberOfCategories; EFI_INI_FILE_HANDLE IniFile; EFI_SCT_CATEGORY_DATA *Category; // // Check parameters // if ((DevicePath == NULL) || (FileName == NULL) || (CategoryList == NULL)) { return EFI_INVALID_PARAMETER; } // // Debug information // EFI_SCT_DEBUG ((EFI_SCT_D_TRACE, L"Load category data from <%s>", FileName)); // // Open the file // Status = gFT->TplProtocol->EfiIniOpen ( gFT->TplProtocol, DevicePath, FileName, &IniFile ); if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open category file - %r", Status)); return Status; } if (Status == EFI_NOT_FOUND) { // // If the category file does not exist, use the empty setting // EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Category file doesn't exist")); return EFI_SUCCESS; } // // Get the number of categories // Status = CategoryGetOrderNum ( IniFile, &NumberOfCategories ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Get order number - %r", Status)); gFT->TplProtocol->EfiIniClose (gFT->TplProtocol, IniFile); return Status; } // // Walk through all categories // for (Index = 0; Index < NumberOfCategories; Index ++) { // // Load a single category data // Status = LoadSingleCategoryData ( IniFile, Index, &Category ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Load a category (#%d) - %r", Index, Status)); continue; } // // Add this category data into the list // InsertSingleCategoryData (CategoryList, Category); } // // Close the file // gFT->TplProtocol->EfiIniClose ( gFT->TplProtocol, IniFile ); // // Done // return EFI_SUCCESS; }
EFI_STATUS InsertGuidDatabase ( IN CHAR16 *GuidStr, IN CHAR16 *TitleStr, IN CHAR16 *IndexStr ) /*++ Routine Description: Insert a GUID entry. --*/ { EFI_STATUS Status; EFI_SCT_GUID_DATABASE *TempGuidDatabase; // // Check parameters // if ((GuidStr == NULL) || (TitleStr == NULL) || (IndexStr == NULL)) { return EFI_INVALID_PARAMETER; } // // Need to create a new buffer? // if (mGuidDatabaseMaxSize == 0) { mGuidDatabaseMaxSize = EFI_SCT_GUID_DATABASE_SIZE; mGuidDatabaseUsedSize = 0; Status = BS->AllocatePool ( EfiBootServicesData, mGuidDatabaseMaxSize * sizeof(EFI_SCT_GUID_DATABASE), (VOID **)&mGuidDatabase ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); mGuidDatabaseMaxSize = 0; return Status; } ZeroMem (mGuidDatabase, mGuidDatabaseMaxSize * sizeof(EFI_SCT_GUID_DATABASE)); } // // Need to enlarge a new buffer? // if (mGuidDatabaseUsedSize + 1 >= mGuidDatabaseMaxSize) { mGuidDatabaseMaxSize = mGuidDatabaseMaxSize * 2; Status = BS->AllocatePool ( EfiBootServicesData, mGuidDatabaseMaxSize * sizeof(EFI_SCT_GUID_DATABASE), (VOID **)&TempGuidDatabase ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); mGuidDatabaseMaxSize = mGuidDatabaseMaxSize / 2; return Status; } ZeroMem (TempGuidDatabase, mGuidDatabaseMaxSize * sizeof(EFI_SCT_GUID_DATABASE)); // // Copy the original data // CopyMem (TempGuidDatabase, mGuidDatabase, mGuidDatabaseUsedSize * sizeof(EFI_SCT_GUID_DATABASE)); // // Free the original buffer // BS->FreePool (mGuidDatabase); mGuidDatabase = TempGuidDatabase; } // // Append the GUID entry to the GUID database // SctStrnCpy (mGuidDatabase[mGuidDatabaseUsedSize].Guid, GuidStr, EFI_SCT_GUID_LEN); SctStrnCpy (mGuidDatabase[mGuidDatabaseUsedSize].Title, TitleStr, EFI_SCT_TITLE_LEN); SctStrnCpy (mGuidDatabase[mGuidDatabaseUsedSize].Index, IndexStr, EFI_SCT_INDEX_LEN); mGuidDatabaseUsedSize ++; return EFI_SUCCESS; }
EFI_STATUS GetProtocolAssertion ( IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN CHAR16 *FilePath, OUT UINT32 *PassNumber, OUT UINT32 *WarnNumber, OUT UINT32 *FailNumber ) /*++ Routine Description: Get the assertion number of a protocol or service. Arguments: DevicePath - Device path of the key files. FilePath - Path of the key files. PassNumber - The number of passed assertions. WarnNumber - The number of warning assertions. FailNumber - The number of failed assertions. Returns: EFI_SUCCESS - Get instance assertion number successfully. --*/ { EFI_STATUS Status; EFI_HANDLE DeviceHandle; EFI_FILE_HANDLE RootDir; EFI_FILE_HANDLE LogDir; UINTN FileInfoSize; EFI_FILE_INFO *FileInfo; EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Vol; EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath; UINTN BufferSize; CHAR16 *Buffer; CHAR16 *FileName; CHAR16 *LogName; CHAR16 *TempName; CHAR16 *CaseIndexStr; CHAR16 *CaseIterationStr; // // Check parameters // if ((DevicePath == NULL) || (FilePath == NULL) || (PassNumber == NULL) || (WarnNumber == NULL) || (FailNumber == NULL)) { return EFI_INVALID_PARAMETER; } // // Locate the device handle // RemainingDevicePath = DevicePath; Status = BS->LocateDevicePath ( &gEfiSimpleFileSystemProtocolGuid, &RemainingDevicePath, &DeviceHandle ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Locate device path - %r", Status)); return Status; } // // Locate the simple file system // Status = BS->HandleProtocol ( DeviceHandle, &gEfiSimpleFileSystemProtocolGuid, &Vol ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Handle protocol - %r", Status)); return Status; } // // Open the root directory // Status = Vol->OpenVolume (Vol, &RootDir); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open volume - %r", Status)); return Status; } // // Open the log directory // Status = RootDir->Open ( RootDir, &LogDir, FilePath, EFI_FILE_MODE_READ, EFI_FILE_DIRECTORY ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Open directory - %r", Status)); RootDir->Close (RootDir); return Status; } RootDir->Close (RootDir); // // Allocate memory for the entries in the directory // FileInfoSize = sizeof(EFI_FILE_INFO) + 1024; Status = BS->AllocatePool ( EfiBootServicesData, FileInfoSize, &FileInfo ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"Allocate pool - %r", Status)); LogDir->Close (LogDir); return Status; } // // Walk through each file in the directory // while (TRUE) { // // Read a file entry // FileInfoSize = sizeof(EFI_FILE_INFO) + 1024; Status = LogDir->Read ( LogDir, &FileInfoSize, FileInfo ); if (EFI_ERROR (Status) || (FileInfoSize == 0)) { break; } if ((FileInfo->Attribute & EFI_FILE_DIRECTORY) == 0) { // // This is a file // // // Only deal with the EFI key file // if (!SctStrEndWith (FileInfo->FileName, L".ekl")) { continue; } // // Read the file to a buffer // FileName = PoolPrint (L"%s\\%s", FilePath, FileInfo->FileName); if (FileName == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); return EFI_OUT_OF_RESOURCES; } Status = ReadFileToBuffer ( DevicePath, FileName, &BufferSize, &Buffer ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Read file to buffer - %r", Status)); BS->FreePool (FileName); continue; } BS->FreePool (FileName); // // Get the index and iteration from the file name // TempName = StrDuplicate (FileInfo->FileName); // // The following function didn't allocate memory for CaseIndexStr and // CaseIterationStr. So DON'T free the TempName before these two strings // are still used. // Status = GetIndexFromFileName ( TempName, &CaseIndexStr, &CaseIterationStr ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Get index from file name - %r", Status)); BS->FreePool (TempName); continue; } // // Load the buffer to the report information structure // LogName = SctStrEndReplace (FileInfo->FileName, L"log"); Status = LoadReportInfor ( CaseIndexStr, CaseIterationStr, Buffer, LogName ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Load report infor - %r", Status)); BS->FreePool (TempName); BS->FreePool (LogName); BS->FreePool (Buffer); continue; } BS->FreePool (TempName); BS->FreePool (LogName); BS->FreePool (Buffer); // // Get the assertion number (free the GUID assertion table) // Status = GetAssertionNumber (PassNumber, WarnNumber, FailNumber); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Get assertion number - %r", Status)); continue; } } else { // // This is a directory // // // Skip the '.' and '..' dir // if ((StrCmp (FileInfo->FileName, L".") == 0) || (StrCmp (FileInfo->FileName, L"..") == 0)) { continue; } // // Get the report information from the sub directories // FileName = PoolPrint (L"%s\\%s", FilePath, FileInfo->FileName); if (FileName == NULL) { EFI_SCT_DEBUG ((EFI_SCT_D_ERROR, L"PoolPrint: Out of resources")); return EFI_OUT_OF_RESOURCES; } Status = GetProtocolAssertion ( DevicePath, FileName, PassNumber, WarnNumber, FailNumber ); if (EFI_ERROR (Status)) { EFI_SCT_DEBUG ((EFI_SCT_D_DEBUG, L"Get protocol assertion - %r", Status)); BS->FreePool (FileName); continue; } BS->FreePool (FileName); } } // // Free resources // BS->FreePool (FileInfo); LogDir->Close (LogDir); // // Done // return EFI_SUCCESS; }