[ROSAUTOTEST]
[reactos.git] / rostests / rosautotest / main.cpp
1 /*
2 * PROJECT: ReactOS Automatic Testing Utility
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
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 << " /r - Maintain information to resume from ReactOS crashes" << endl
27 << " Can only be run under ReactOS and relies on sysreg2," << endl
28 << " so incompatible with /w" << endl
29 << " /s - Shut down the system after finishing the tests." << endl
30 << " /w - Submit the results to the webservice." << endl
31 << " Requires a \"rosautotest.ini\" with valid login data." << endl
32 << " Incompatible with the /r option." << endl
33 << endl
34 << " module:" << endl
35 << " The module to be tested (i.e. \"advapi32\")" << endl
36 << " If this parameter is specified without any test parameter," << endl
37 << " all tests of the specified module are run." << endl
38 << endl
39 << " test:" << endl
40 << " The test to be run. Needs to be a test of the specified module." << endl;
41 }
42
43 /**
44 * Main entry point
45 */
46 extern "C" int
47 wmain(int argc, wchar_t* argv[])
48 {
49 CWineTest WineTest;
50 int ReturnValue = 1;
51
52 try
53 {
54 stringstream ss;
55
56 /* Set up the configuration */
57 Configuration.ParseParameters(argc, argv);
58 Configuration.GetSystemInformation();
59 Configuration.GetConfigurationFromFile();
60
61 ss << "\n\nSystem uptime " << setprecision(2) << fixed ;
62 ss << ((float)GetTickCount()/1000) << " seconds\n";
63 StringOut(ss.str());
64
65 /* Report tests startup */
66 InitLogs();
67 ReportEventW(hLog,
68 EVENTLOG_INFORMATION_TYPE,
69 0,
70 MSG_TESTS_STARTED,
71 NULL,
72 0,
73 0,
74 NULL,
75 NULL);
76
77 /* Run the tests */
78 WineTest.Run();
79
80 /* For sysreg2 */
81 DbgPrint("SYSREG_CHECKPOINT:THIRDBOOT_COMPLETE\n");
82
83 ReturnValue = 0;
84 }
85 catch(CInvalidParameterException)
86 {
87 IntPrintUsage();
88 }
89 catch(CSimpleException& e)
90 {
91 StringOut(e.GetMessage());
92 }
93 catch(CFatalException& e)
94 {
95 stringstream ss;
96
97 ss << "An exception occured in rosautotest." << endl
98 << "Message: " << e.GetMessage() << endl
99 << "File: " << e.GetFile() << endl
100 << "Line: " << e.GetLine() << endl
101 << "Last Win32 Error: " << GetLastError() << endl;
102 StringOut(ss.str());
103 }
104
105 /* For sysreg2 to notice if rosautotest itself failed */
106 if(ReturnValue == 1)
107 DbgPrint("SYSREG_ROSAUTOTEST_FAILURE\n");
108
109 /* Report successful end of tests */
110 ReportEventW(hLog,
111 EVENTLOG_SUCCESS,
112 0,
113 MSG_TESTS_SUCCESSFUL,
114 NULL,
115 0,
116 0,
117 NULL,
118 NULL);
119 FreeLogs();
120
121 /* Shut down the system if requested, also in case of an exception above */
122 if(Configuration.DoShutdown() && !ShutdownSystem())
123 ReturnValue = 1;
124
125 return ReturnValue;
126 }