8d6d342da97cf31d69ceecf0b2b2ccd835c212e2
[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 << " /w - Submit the results to the webservice." << endl
32 << " Requires a \"rosautotest.ini\" with valid login data." << endl
33 << " Incompatible with the /r option." << endl
34 << endl
35 << " module:" << endl
36 << " The module to be tested (i.e. \"advapi32\")" << endl
37 << " If this parameter is specified without any test parameter," << endl
38 << " all tests of the specified module are run." << endl
39 << endl
40 << " test:" << endl
41 << " The test to be run. Needs to be a test of the specified module." << endl;
42 }
43
44 /**
45 * Main entry point
46 */
47 extern "C" int
48 wmain(int argc, wchar_t* argv[])
49 {
50 CWineTest WineTest;
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 << "\n\nSystem uptime " << setprecision(2) << fixed ;
63 ss << ((float)GetTickCount()/1000) << " seconds\n";
64 StringOut(ss.str());
65
66 /* Report tests startup */
67 InitLogs();
68 ReportEventW(hLog,
69 EVENTLOG_INFORMATION_TYPE,
70 0,
71 MSG_TESTS_STARTED,
72 NULL,
73 0,
74 0,
75 NULL,
76 NULL);
77
78 /* Run the tests */
79 WineTest.Run();
80
81 /* For sysreg2 */
82 DbgPrint("SYSREG_CHECKPOINT:THIRDBOOT_COMPLETE\n");
83
84 ReturnValue = 0;
85 }
86 catch(CInvalidParameterException)
87 {
88 IntPrintUsage();
89 }
90 catch(CSimpleException& e)
91 {
92 // e.GetMessage() must include ending '\n'.
93 StringOut(e.GetMessage());
94 }
95 catch(CFatalException& e)
96 {
97 stringstream ss;
98
99 // e.GetMessage() must include ending '\n'.
100 ss << "An exception occured in rosautotest." << endl
101 << "Message: " << e.GetMessage()
102 << "File: " << e.GetFile() << endl
103 << "Line: " << e.GetLine() << endl
104 << "Last Win32 Error: " << GetLastError() << endl;
105 StringOut(ss.str());
106 }
107
108 /* For sysreg2 to notice if rosautotest itself failed */
109 if(ReturnValue == 1)
110 DbgPrint("SYSREG_ROSAUTOTEST_FAILURE\n");
111
112 /* Report successful end of tests */
113 ReportEventW(hLog,
114 EVENTLOG_SUCCESS,
115 0,
116 MSG_TESTS_SUCCESSFUL,
117 NULL,
118 0,
119 0,
120 NULL,
121 NULL);
122 FreeLogs();
123
124 /* Shut down the system if requested, also in case of an exception above */
125 if(Configuration.DoShutdown() && !ShutdownSystem())
126 ReturnValue = 1;
127
128 return ReturnValue;
129 }