/** * assistant function to auto judge the user's choice, correct or uncorrect? * @param Seconds time inteval * @return TRUE/FALSE standing for correct/uncorrect choice respectively */ BOOLEAN AutoJudge( IN UINTN Seconds, IN BOOLEAN Default, IN CHAR16 *Message ) { EFI_STATUS Status; EFI_EVENT WaitList[2]; UINTN NoWait, WaitIndex; EFI_INPUT_KEY Key; BOOLEAN PressYes; // // Set 1 second periodic timer // Status = gtBS->SetTimer(TimerEvent, TimerPeriodic, 10000000); // // Set up a wait list for a key and the timer // NoWait = 0; WaitList[NoWait++] = TimerEvent; WaitList[NoWait++] = gtST->ConIn->WaitForKey; PressYes = Default; // // Wait for either // Print (Message); while (NoWait) { if (Default == TRUE) { Print(L"\rYes/No?(Auto judge as Yes in %d seconds)",Seconds); } else { Print(L"\rYes/No?(Auto judge as No in %d seconds)",Seconds); } Status = gtBS->WaitForEvent (NoWait, WaitList, &WaitIndex); switch (WaitIndex) { case 0: Seconds -= 1; if (Seconds <= 0) { // // To stop loop // NoWait = 0; } break; case 1: // // Read the key // Status = gtST->ConIn->ReadKeyStroke (gtST->ConIn, &Key); APrint ((char*)(&Key.UnicodeChar)); switch( Key.UnicodeChar ) { case 'Y': case 'y': NoWait = 0; PressYes = TRUE; break; case 'N': case 'n': NoWait = 0; PressYes = FALSE; break; default : Print(L"\n"); break; } break; default: break; // // bad WaitIndex response // } } Print (L"\r\n"); // // Done, cancle periodic timer // Status = gtBS->SetTimer (TimerEvent, TimerCancel, 0); return PressYes; }
BOOLEAN AutoJudgeGop ( IN UINTN X, IN UINTN Y, IN UINTN Seconds, IN BOOLEAN Default, IN CHAR16 *Message ) /*++ Routine Description: Assistant function to auto judge the user's choice, correct or uncorrect? Arguments: X - The coordination of X Y - The coordination of Y Seconds - The time to wait the user for judging Default - Default value(True/False) for auto judge(Yes/No) Message - The message printed to the serial port to remind the user Returns: TRUE/FALSE standing for correct/uncorrect choice respectively --*/ { EFI_STATUS Status; EFI_EVENT WaitList[2]; UINTN NoWait; UINTN WaitIndex; EFI_INPUT_KEY Key; BOOLEAN PressYes; CHAR16 *Msg; UINTN AutoJudge; Msg = NULL; AutoJudge = 1; Status = gtBS->CreateEvent ( EFI_EVENT_TIMER, 0, NULL, NULL, &TimerEvent ); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "Create event. %a:%d:%r\n", __FILE__, (UINTN)__LINE__, Status)); return FALSE; } // // Set 1 second periodic timer // Status = gtBS->SetTimer (TimerEvent, TimerPeriodic, 10000000); // // Set up a wait list for a key and the timer // NoWait = 0; WaitList[NoWait++] = TimerEvent; WaitList[NoWait++] = gtST->ConIn->WaitForKey; PressYes = Default; // // Wait for either // PrintAt (Y, X, Message); while (AutoJudge && (Seconds > 0)) { if (Default == TRUE) { Msg = PoolPrint (L"Yes/No?(Auto judge as Yes in %d seconds ", Seconds); } else { Msg = PoolPrint (L"Yes/No?(Auto judge as No in %d seconds ", Seconds); } if (Msg == NULL) { return FALSE; } else { PrintAt (Y + 40, X, Msg); FreePool (Msg); } Status = gtBS->WaitForEvent (NoWait, WaitList, &WaitIndex); switch (WaitIndex) { case 0: Seconds--; if (Seconds <= 0) { // // To stop loop // AutoJudge = 0; } break; case 1: // // Read the key // Status = gtST->ConIn->ReadKeyStroke (gtST->ConIn, &Key); APrint ((char *) (&Key.UnicodeChar)); switch (Key.UnicodeChar) { case 'Y': case 'y': AutoJudge = 0; PressYes = TRUE; break; case 'N': case 'n': AutoJudge = 0; PressYes = FALSE; break; default: break; } break; default: break; // // bad WaitIndex response // } } // // Print (L"\r\n"); // // Done, cancle periodic timer event // gtBS->CloseEvent (TimerEvent); return PressYes; }
BOOLEAN WaitForUserCheck () { UINTN NoWait = 1, WaitIndex; EFI_EVENT WaitList[1]; EFI_STATUS Status; EFI_INPUT_KEY Key; BOOLEAN PressYes=FALSE; Print (L"\r\nPress \"Y\" or \"N\"..."); // // Set 1 second periodic timer // Status = gtBS->SetTimer (TimerEvent, TimerPeriodic, 10000000); // // Set up a wait list for a key and the timer // NoWait = 0; WaitList[NoWait++] = gtST->ConIn->WaitForKey; // // Wait for either // while (NoWait) { Status = gtBS->WaitForEvent (NoWait, WaitList, &WaitIndex); switch (WaitIndex) { case 0: // // Read the key // Status = gtST->ConIn->ReadKeyStroke (gtST->ConIn, &Key); APrint ((char *)(&Key.UnicodeChar)); switch (Key.UnicodeChar) { case 'Y': case 'y': NoWait = 0; PressYes = TRUE; break; case 'N': case 'n': NoWait = 0; PressYes = FALSE; break; default : Print (L"\n"); break; } break; default: break; } } Print (L"\r\n"); // // Done, cancle periodic timer // Status = gtBS->SetTimer (TimerEvent, TimerCancel, 0); return PressYes; }
static void grub_xputs_dumb(const char *str) { APrint((CHAR8 *)str); }
BOOLEAN AutoJudge ( IN UINTN Seconds, IN BOOLEAN Default, IN CHAR16 *Message ) /*++ Routine Description: Assistant function to auto judge the user's choice, correct or uncorrect. Arguments: Seconds - Time inteval Default - Default value to judge Message - String to desplay on screen Returns: TRUE - correct choice respectively FALSE - uncorrect choice respectively --*/ { EFI_STATUS Status; EFI_EVENT WaitList[2]; UINTN NoWait; UINTN WaitIndex; EFI_INPUT_KEY Key; BOOLEAN PressYes; // // Set 1 second periodic timer // Status = gtBS->SetTimer (TimerEvent, TimerPeriodic, 10000000); // // Set up a wait list for a key and the timer // NoWait = 0; WaitList[NoWait++] = TimerEvent; WaitList[NoWait++] = gtST->ConIn->WaitForKey; PressYes = Default; // // Wait for either // Print (Message); while (NoWait) { if (Default == TRUE) { Print (L"\rYes/No?(Auto judge as Yes in %d seconds)", Seconds); } else { Print (L"\rYes/No?(Auto judge as No in %d seconds)", Seconds); } Status = gtBS->WaitForEvent (NoWait, WaitList, &WaitIndex); switch (WaitIndex) { case 0: Seconds -= 1; if (Seconds <= 0) { // // To stop loop // NoWait = 0; } break; case 1: // // Read the key // Status = gtST->ConIn->ReadKeyStroke (gtST->ConIn, &Key); APrint ((char *) (&Key.UnicodeChar)); switch (Key.UnicodeChar) { case 'Y': case 'y': NoWait = 0; PressYes = TRUE; break; case 'N': case 'n': NoWait = 0; PressYes = FALSE; break; default: Print (L"\n"); break; } break; default: break; // // bad WaitIndex response // } } Print (L"\r\n"); // // Done, cancle periodic timer // Status = gtBS->SetTimer (TimerEvent, TimerCancel, 0); return PressYes; }
// // TDS 4.1.3 // EFI_STATUS BBTestReadKeyStrokeFunctionManualTest ( IN EFI_BB_TEST_PROTOCOL *This, IN VOID *ClientInterface, IN EFI_TEST_LEVEL TestLevel, IN EFI_HANDLE SupportHandle ) { EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib; EFI_STATUS Status; EFI_SIMPLE_TEXT_IN_PROTOCOL *SimpleIn; EFI_TEST_ASSERTION AssertionType; EFI_INPUT_KEY Key; EFI_DEVICE_PATH_PROTOCOL *DevicePath; CHAR16 *DevicePathStr; BOOLEAN KeyPressed=FALSE, EscPressed=FALSE; // // Verify whether it is one of IHV interfaces // if (! IsIhvInterface (ClientInterface, SupportHandle)) { return EFI_UNSUPPORTED; } // // Get the Standard Library Interface // Status = gtBS->HandleProtocol ( SupportHandle, &gEfiStandardTestLibraryGuid, &StandardLib ); if (EFI_ERROR(Status)) { StandardLib->RecordAssertion ( StandardLib, EFI_TEST_ASSERTION_FAILED, gTestGenericFailureGuid, L"BS.HandleProtocol - Handle standard test library", L"%a:%d:Status - %r", __FILE__, __LINE__, Status ); return Status; } SimpleIn = (EFI_SIMPLE_TEXT_IN_PROTOCOL *)ClientInterface; // // Get Device Path of current Simple_Text_In_Protocol // And out put device path or device name // Status = LocateDevicePathFromSimpleTextIn (SimpleIn, &DevicePath, StandardLib); if (Status == EFI_SUCCESS) { DevicePathStr = DevicePathToStr (DevicePath); if (DevicePathStr != NULL) { StandardLib->RecordMessage ( StandardLib, EFI_VERBOSE_LEVEL_DEFAULT, L"\r\nCurrent Device: %s", DevicePathStr ); Status = gtBS->FreePool (DevicePathStr); if (EFI_ERROR(Status)) { StandardLib->RecordAssertion ( StandardLib, EFI_TEST_ASSERTION_FAILED, gTestGenericFailureGuid, L"BS.FreePool - Free pool", L"%a:%d:Status - %r", __FILE__, __LINE__, Status ); return Status; } DevicePathStr=NULL; } } else { // // Console Splitter/StdErr // StandardLib->RecordMessage ( StandardLib, EFI_VERBOSE_LEVEL_DEFAULT, L"\r\nCurrent Device: ConsoleSplitter/TxtIn" ); } // // wait for times // Print (L"\r\nReadKeyStroke Function Test Start!\r\n"); WaitTimeOrKey (5); // // Assertion Point 4.1.3.2.1 // ReadKeyStroke() // Print (L"\r\nPress any key and wait for echo. Two ESC keys to quit"); while (TRUE) { KeyPressed = WaitTimeOrKeySimpleIn (SimpleIn, 1); if (KeyPressed==TRUE) { Print (L"\r\nKey Pressed--"); // // Key Pressed! // // // Call ReadKeyStroke to retrieve the key // Status = SimpleIn->ReadKeyStroke (SimpleIn, &Key); if (EFI_ERROR(Status)) { AssertionType = EFI_TEST_ASSERTION_FAILED; StandardLib->RecordAssertion ( StandardLib, AssertionType, gSimpleTextInInterfaceTestAssertionGuid009, L"EFI_SIMPLE_TEXT_IN_PROTOCOL.ReadKeyStroke - ReadKeyStroke() with key input", L"%a:%d, Status = %r", __FILE__, __LINE__, Status ); } // // Output what user input // if (Key.ScanCode==0) { // // Unicode character // APrint ((char*)(&Key.UnicodeChar)); } else { // // Scan code character // Print (ScanCodeDesc (Key.ScanCode)); } if (Key.ScanCode==SCAN_ESC) { if (EscPressed==TRUE) { break; } EscPressed = TRUE; } else { EscPressed=FALSE; } } } if (AutoJudge (5, TRUE, L"\r\nEcho correct?\r\n")==TRUE) { AssertionType = EFI_TEST_ASSERTION_PASSED; } else { AssertionType = EFI_TEST_ASSERTION_FAILED; } StandardLib->RecordAssertion ( StandardLib, AssertionType, gSimpleTextInInterfaceTestAssertionGuid010, L"EFI_SIMPLE_TEXT_IN_PROTOCOL.ReadKeyStroke - ReadKeyStroke() with key input, user's view", L"%a:%d", __FILE__, __LINE__ ); return EFI_SUCCESS; }
// // TDS 4.2.2 // EFI_STATUS BBTestWaitForKeyConformanceManualTest ( IN EFI_BB_TEST_PROTOCOL *This, IN VOID *ClientInterface, IN EFI_TEST_LEVEL TestLevel, IN EFI_HANDLE SupportHandle ) { EFI_STANDARD_TEST_LIBRARY_PROTOCOL *StandardLib; EFI_STATUS Status; EFI_SIMPLE_TEXT_IN_PROTOCOL *SimpleIn; EFI_TEST_ASSERTION AssertionType; EFI_INPUT_KEY Key; EFI_DEVICE_PATH_PROTOCOL *DevicePath; CHAR16 *DevicePathStr; UINTN WaitIndex; // // Get the Standard Library Interface // Status = gtBS->HandleProtocol ( SupportHandle, &gEfiStandardTestLibraryGuid, &StandardLib ); if (EFI_ERROR(Status)) { StandardLib->RecordAssertion ( StandardLib, EFI_TEST_ASSERTION_FAILED, gTestGenericFailureGuid, L"BS.HandleProtocol - Handle standard test library", L"%a:%d:Status - %r", __FILE__, __LINE__, Status ); return Status; } SimpleIn = (EFI_SIMPLE_TEXT_IN_PROTOCOL *)ClientInterface; // // Get Device Path of current Simple_Text_In_Protocol // And out put device path or device name // Status = LocateDevicePathFromSimpleTextIn (SimpleIn, &DevicePath, StandardLib); if (Status == EFI_SUCCESS) { DevicePathStr = DevicePathToStr (DevicePath); if (DevicePathStr != NULL) { StandardLib->RecordMessage ( StandardLib, EFI_VERBOSE_LEVEL_DEFAULT, L"\r\nCurrent Device: %s", DevicePathStr ); Status = gtBS->FreePool (DevicePathStr); if (EFI_ERROR(Status)) { StandardLib->RecordAssertion ( StandardLib, EFI_TEST_ASSERTION_FAILED, gTestGenericFailureGuid, L"BS.FreePool - Free pool", L"%a:%d:Status - %r", __FILE__, __LINE__, Status ); return Status; } DevicePathStr=NULL; } } else { // // Console Splitter/StdErr // StandardLib->RecordMessage ( StandardLib, EFI_VERBOSE_LEVEL_DEFAULT, L"\r\nCurrent Device: ConsoleSplitter/TxtIn" ); } // // wait for times // Print (L"\r\nWaitForKey Conformance Test Start!\r\n"); WaitTimeOrKey (5); // // Assertion Point 4.2.2.2.1 // ReadKeyStroke() // // // Call Reset with ExtendedVerification as TRUE // Status = SimpleIn->Reset (SimpleIn, TRUE); if (EFI_ERROR(Status)) { AssertionType = EFI_TEST_ASSERTION_FAILED; StandardLib->RecordAssertion ( StandardLib, AssertionType, gTestGenericFailureGuid, L"EFI_SIMPLE_TEXT_IN_PROTOCOL.Reset - Reset with ExtendedVeirification as TRUE", L"%a:%d, Status = %r", __FILE__, __LINE__, Status ); } // // Call CheckEvent() on the WaitForKey event // Status = gtBS->CheckEvent (SimpleIn->WaitForKey); if (Status!=EFI_NOT_READY) { AssertionType = EFI_TEST_ASSERTION_FAILED; } else { AssertionType = EFI_TEST_ASSERTION_PASSED; } StandardLib->RecordAssertion ( StandardLib, AssertionType, gSimpleTextInConformanceTestAssertionGuid007, L"EFI_SIMPLE_TEXT_IN_PROTOCOL.WaitForKey - Event check before key input", L"%a:%d, Status = %r, Expected = %r", __FILE__, __LINE__, Status, EFI_NOT_READY ); // // Prompt tester to input some character // Print (L"Press ONE displayable key! and NO More!"); // // WaitForKey event // Status = gtBS->WaitForEvent (1, &(SimpleIn->WaitForKey), &WaitIndex); if (EFI_ERROR(Status)) { AssertionType = EFI_TEST_ASSERTION_FAILED; } else { AssertionType = EFI_TEST_ASSERTION_PASSED; } StandardLib->RecordAssertion ( StandardLib, AssertionType, gSimpleTextInConformanceTestAssertionGuid008, L"EFI_SIMPLE_TEXT_IN_PROTOCOL.WaitForKey - Wait for event with key input", L"%a:%d, Status = %r, Expected = %r", __FILE__, __LINE__, Status, EFI_SUCCESS ); Print (L"\r\nThe key(s) input:"); // // Call ReadKeyStroke repeatedly to receive the character. // while (TRUE) { // // Call ReadKeyStroke to retrieve the key // Status = SimpleIn->ReadKeyStroke (SimpleIn, &Key); if (EFI_ERROR(Status)) { break; } // // Output what user input // if (Key.ScanCode==0) { // // Unicode character // APrint ((char*)(&Key.UnicodeChar)); } else { // // Scan code character // Print (ScanCodeDesc (Key.ScanCode)); } } // // Wait 2 second for user to check the key echoed. // gtBS->Stall (2000000); // // Call CheckEvent() on the WaitForKey event // Status = gtBS->CheckEvent (SimpleIn->WaitForKey); if (Status!=EFI_NOT_READY) { AssertionType = EFI_TEST_ASSERTION_FAILED; } else { AssertionType = EFI_TEST_ASSERTION_PASSED; } StandardLib->RecordAssertion ( StandardLib, AssertionType, gSimpleTextInConformanceTestAssertionGuid010, L"EFI_SIMPLE_TEXT_IN_PROTOCOL.WaitForKey - Event check after key read stroken", L"%a:%d, Status = %r, Expected = %r", __FILE__, __LINE__, Status, EFI_NOT_READY ); return EFI_SUCCESS; }