b5fb2174b73133edbf16bfe771102b1cf3620c7a
[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(), TRUE);
64
65 /* Run the tests */
66 WineTest.Run();
67
68 /* For sysreg2 */
69 DbgPrint("SYSREG_CHECKPOINT:THIRDBOOT_COMPLETE\n");
70
71 ReturnValue = 0;
72 }
73 catch(CInvalidParameterException)
74 {
75 IntPrintUsage();
76 }
77 catch(CSimpleException& e)
78 {
79 StringOut(e.GetMessage(), TRUE);
80 }
81 catch(CFatalException& e)
82 {
83 stringstream ss;
84
85 ss << "An exception occured in rosautotest." << endl
86 << "Message: " << e.GetMessage() << endl
87 << "File: " << e.GetFile() << endl
88 << "Line: " << e.GetLine() << endl
89 << "Last Win32 Error: " << GetLastError() << endl;
90 StringOut(ss.str(), TRUE);
91 }
92
93 /* For sysreg2 to notice if rosautotest itself failed */
94 if(ReturnValue == 1)
95 DbgPrint("SYSREG_ROSAUTOTEST_FAILURE\n");
96
97 /* Shut down the system if requested, also in case of an exception above */
98 if(Configuration.DoShutdown() && !ShutdownSystem())
99 ReturnValue = 1;
100
101 return ReturnValue;
102 }