[ROSAUTOTEST] Add /t parameter for repeating tests
[reactos.git] / modules / rostests / rosautotest / main.cpp
1 /*
2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Main implementation file
5 * COPYRIGHT: Copyright 2008-2009 Colin Finck (colin@reactos.org)
6 */
7
8 #include "precomp.h"
9 #include <cstdio>
10
11 CConfiguration Configuration;
12
13 /**
14 * Prints the application usage.
15 */
16 static void
17 IntPrintUsage()
18 {
19 cout << "rosautotest - ReactOS Automatic Testing Utility" << endl
20 << "Usage: rosautotest [options] [module] [test]" << endl
21 << " options:" << endl
22 << " /? - Shows this help." << endl
23 << " /c <comment> - Specifies the comment to be submitted to the Web Service." << endl
24 << " Skips the comment set in the configuration file (if any)." << endl
25 << " Only has an effect when /w is also used." << endl
26 << " /n - Do not print test output to console" << endl
27 << " /r - Maintain information to resume from ReactOS crashes" << endl
28 << " Can only be run under ReactOS and relies on sysreg2," << endl
29 << " so incompatible with /w" << endl
30 << " /s - Shut down the system after finishing the tests." << endl
31 << " /t <num> - Repeat the test <num> times (1-10000)" << endl
32 << " /w - Submit the results to the webservice." << endl
33 << " Requires a \"rosautotest.ini\" with valid login data." << endl
34 << " Incompatible with the /r option." << endl
35 << endl
36 << " module:" << endl
37 << " The module to be tested (i.e. \"advapi32\")" << endl
38 << " If this parameter is specified without any test parameter," << endl
39 << " all tests of the specified module are run." << endl
40 << endl
41 << " test:" << endl
42 << " The test to be run. Needs to be a test of the specified module." << endl;
43 }
44
45 /**
46 * Main entry point
47 */
48 extern "C" int
49 wmain(int argc, wchar_t* argv[])
50 {
51 int ReturnValue = 1;
52
53 try
54 {
55 stringstream ss;
56
57 /* Set up the configuration */
58 Configuration.ParseParameters(argc, argv);
59 Configuration.GetSystemInformation();
60 Configuration.GetConfigurationFromFile();
61
62 ss << endl
63 << endl
64 << "[ROSAUTOTEST] System uptime " << setprecision(2) << fixed;
65 ss << ((float)GetTickCount()/1000) << " seconds" << endl;
66 StringOut(ss.str());
67
68 /* Report tests startup */
69 InitLogs();
70 ReportEventW(hLog,
71 EVENTLOG_INFORMATION_TYPE,
72 0,
73 MSG_TESTS_STARTED,
74 NULL,
75 0,
76 0,
77 NULL,
78 NULL);
79
80 if (Configuration.GetRepeatCount() > 1)
81 {
82 stringstream ss1;
83
84 ss1 << "[ROSAUTOTEST] The test will be repeated " << Configuration.GetRepeatCount() << " times" << endl;
85 StringOut(ss1.str());
86 }
87
88 /* Run the tests */
89 for (unsigned long i = 0; i < Configuration.GetRepeatCount(); i++)
90 {
91 CWineTest WineTest;
92
93 if (Configuration.GetRepeatCount() > 1)
94 {
95 stringstream ss;
96 ss << "[ROSAUTOTEST] Running attempt #" << i+1 << endl;
97 StringOut(ss.str());
98 }
99 WineTest.Run();
100 }
101
102 /* For sysreg2 */
103 DbgPrint("SYSREG_CHECKPOINT:THIRDBOOT_COMPLETE\n");
104
105 ReturnValue = 0;
106 }
107 catch(CInvalidParameterException)
108 {
109 IntPrintUsage();
110 }
111 catch(CSimpleException& e)
112 {
113 stringstream ss;
114
115 // e.GetMessage() must include ending '\n'.
116 ss << "[ROSAUTOTEST] " << e.GetMessage();
117 StringOut(ss.str());
118 }
119 catch(CFatalException& e)
120 {
121 stringstream ss;
122
123 // e.GetMessage() must include ending '\n'.
124 ss << "An exception occured in rosautotest." << endl
125 << "Message: " << e.GetMessage()
126 << "File: " << e.GetFile() << endl
127 << "Line: " << e.GetLine() << endl
128 << "Last Win32 Error: " << GetLastError() << endl;
129 StringOut(ss.str());
130 }
131
132 /* For sysreg2 to notice if rosautotest itself failed */
133 if(ReturnValue == 1)
134 DbgPrint("SYSREG_ROSAUTOTEST_FAILURE\n");
135
136 /* Report successful end of tests */
137 ReportEventW(hLog,
138 EVENTLOG_SUCCESS,
139 0,
140 MSG_TESTS_SUCCESSFUL,
141 NULL,
142 0,
143 0,
144 NULL,
145 NULL);
146 FreeLogs();
147
148 /* Shut down the system if requested, also in case of an exception above */
149 if(Configuration.DoShutdown() && !ShutdownSystem())
150 ReturnValue = 1;
151
152 return ReturnValue;
153 }