Something went wrong. Try again.
Reactos
Something went wrong. Try again.
7.2 kB · 221 lines
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222/* * PROJECT: ReactOS Automatic Testing Utility * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) * PURPOSE: Main implementation file * COPYRIGHT: Copyright 2008-2009 Colin Finck (colin@reactos.org) */
#include "precomp.h"#include <cstdio>#include <ndk/setypes.h>#include <ndk/exfuncs.h>
WCHAR TestName[MAX_PATH];
CConfiguration Configuration;
/** * Prints the application usage. */static voidIntPrintUsage(){ cout << "rosautotest - ReactOS Automatic Testing Utility" << endl << "Usage: rosautotest [options] [module] [test]" << endl << " options:" << endl << " /? - Shows this help." << endl << " /c <comment> - Specifies the comment to be submitted to the Web Service." << endl << " Skips the comment set in the configuration file (if any)." << endl << " Only has an effect when /w is also used." << endl << " /n - Do not print test output to console" << endl << " /r - Maintain information to resume from ReactOS crashes" << endl << " Can only be run under ReactOS and relies on sysreg2," << endl << " so incompatible with /w" << endl << " /s - Shut down the system after finishing the tests." << endl << " /t <num> - Repeat the test <num> times (1-10000)" << endl << " /w - Submit the results to the webservice." << endl << " Requires a \"rosautotest.ini\" with valid login data." << endl << " Incompatible with the /r option." << endl << " /l - List all modules that would run." << endl << endl << " module:" << endl << " The module to be tested (i.e. \"advapi32\")" << endl << " If this parameter is specified without any test parameter," << endl << " all tests of the specified module are run." << endl << endl << " test:" << endl << " The test to be run. Needs to be a test of the specified module." << endl;}
staticVOIDSetNtGlobalFlags(){ ULONG NtGlobalFlags = 0; BOOLEAN PrivilegeEnabled; NTSTATUS Status;
/* Enable SeDebugPrivilege */ Status = RtlAdjustPrivilege(SE_DEBUG_PRIVILEGE, TRUE, FALSE, &PrivilegeEnabled); if (!NT_SUCCESS(Status)) { DbgPrint("Failed to enable SeDebugPrivilege: 0x%08lx\n", Status); return; }
/* Get current NtGlobalFlags */ Status = NtQuerySystemInformation(SystemFlagsInformation, &NtGlobalFlags, sizeof(NtGlobalFlags), NULL); if (!NT_SUCCESS(Status)) { DbgPrint("Failed to get NtGlobalFlags: 0x%08lx\n", Status); return; }
/* Disable debug prompts */ NtGlobalFlags |= FLG_DISABLE_DEBUG_PROMPTS;
/* Set new NtGlobalFlags */ Status = NtSetSystemInformation(SystemFlagsInformation, &NtGlobalFlags, sizeof(NtGlobalFlags)); if (!NT_SUCCESS(Status)) { DbgPrint("Failed to set NtGlobalFlags: 0x%08lx\n", Status); }}
/** * Main entry point */extern "C" intwmain(int argc, wchar_t* argv[]){ int ReturnValue = 1; DWORD TestStartTime, TestEndTime;
GetModuleFileNameW(NULL, TestName, _countof(TestName));// printf("Full TestName is '%S'\n", TestName); WCHAR* Name = wcsrchr(TestName, '\\'); if (Name) memmove(TestName, Name + 1, (wcslen(Name + 1) + 1) * sizeof(WCHAR));// printf("Short TestName is '%S'.\n", TestName);
SetNtGlobalFlags();
try { stringstream ss;
/* Set up the configuration */ Configuration.ParseParameters(argc, argv); Configuration.GetSystemInformation(); Configuration.GetConfigurationFromFile();
TestStartTime = GetTickCount(); ss << endl << endl << "[ROSAUTOTEST] System uptime " << setprecision(2) << fixed; ss << (float)TestStartTime / 1000 << " seconds" << endl; StringOut(ss.str());
/* Report tests startup */ InitLogs(); ReportEventW(hLog, EVENTLOG_INFORMATION_TYPE, 0, MSG_TESTS_STARTED, NULL, 0, 0, NULL, NULL);
if (Configuration.GetRepeatCount() > 1) { stringstream ss1;
ss1 << "[ROSAUTOTEST] The test will be repeated " << Configuration.GetRepeatCount() << " times" << endl; StringOut(ss1.str()); }
/* Run the tests */ for (unsigned long i = 0; i < Configuration.GetRepeatCount(); i++) { CWineTest WineTest;
if (Configuration.GetRepeatCount() > 1) { stringstream ss; ss << "[ROSAUTOTEST] Running attempt #" << i+1 << endl; StringOut(ss.str()); } WineTest.Run(); }
/* Clear the stringstream */ ss.str(""); ss.clear();
/* Show the beginning time again */ ss << "[ROSAUTOTEST] System uptime at start was " << setprecision(2) << fixed; ss << (float)TestStartTime / 1000 << " seconds" << endl;
/* Show the time now so that we can see how long the tests took */ TestEndTime = GetTickCount(); ss << endl << "[ROSAUTOTEST] System uptime at end was " << setprecision(2) << fixed; ss << ((float)TestEndTime / 1000) << " seconds" << endl; ss << "[ROSAUTOTEST] Duration was " << (float)(TestEndTime - TestStartTime) / (60 * 1000); ss << " minutes" << endl; StringOut(ss.str());
/* For sysreg2 */ DbgPrint("SYSREG_CHECKPOINT:THIRDBOOT_COMPLETE\n");
ReturnValue = 0; } catch(CInvalidParameterException) { IntPrintUsage(); } catch(CSimpleException& e) { stringstream ss;
// e.GetMessage() must include ending '\n'. ss << "[ROSAUTOTEST] " << e.GetMessage(); StringOut(ss.str()); } catch(CFatalException& e) { stringstream ss;
// e.GetMessage() must include ending '\n'. ss << "An exception occured in rosautotest." << endl << "Message: " << e.GetMessage() << "File: " << e.GetFile() << endl << "Line: " << e.GetLine() << endl << "Last Win32 Error: " << GetLastError() << endl; StringOut(ss.str()); }
/* For sysreg2 to notice if rosautotest itself failed */ if(ReturnValue == 1) DbgPrint("SYSREG_ROSAUTOTEST_FAILURE\n");
/* Report successful end of tests */ ReportEventW(hLog, EVENTLOG_SUCCESS, 0, MSG_TESTS_SUCCESSFUL, NULL, 0, 0, NULL, NULL); FreeLogs();
/* Shut down the system if requested, also in case of an exception above */ if(Configuration.DoShutdown() && !ShutdownSystem()) ReturnValue = 1;
return ReturnValue;}