Index: remoting/test/app_remoting_test_driver.cc |
diff --git a/remoting/test/app_remoting_test_driver.cc b/remoting/test/app_remoting_test_driver.cc |
index 07bbde72b90ad7eec5e3e1a4da0bac3fd03e3b20..3fc7fa8013bc116ac93d9ab55e9fc8413837d779 100644 |
--- a/remoting/test/app_remoting_test_driver.cc |
+++ b/remoting/test/app_remoting_test_driver.cc |
@@ -11,14 +11,16 @@ |
#include "base/test/test_switches.h" |
#include "google_apis/google_api_keys.h" |
#include "net/base/escape.h" |
+#include "remoting/test/app_remoting_test_driver_environment.h" |
#include "testing/gtest/include/gtest/gtest.h" |
namespace switches { |
- const char kUserNameSwitchName[] = "username"; |
const char kAuthCodeSwitchName[] = "authcode"; |
- const char kServiceEnvironmentSwitchName[] = "environment"; |
const char kHelpSwitchName[] = "help"; |
+ const char kLoggingLevelSwitchName[] = "verbosity"; |
Wez
2015/02/13 03:01:52
Is this the name that other Chromium code uses for
joedow
2015/02/14 02:31:27
I wanted a separate switch which only turned on lo
Wez
2015/02/19 22:00:22
Is --vmodule format really that complex?
|
+ const char kServiceEnvironmentSwitchName[] = "environment"; |
const char kSingleProcessTestsSwitchName[] = "single-process-tests"; |
+ const char kUserNameSwitchName[] = "username"; |
Wez
2015/02/13 03:01:52
Indentation
joedow
2015/02/14 02:31:27
Done.
|
} |
namespace { |
@@ -66,6 +68,9 @@ void PrintUsage() { |
switches::kHelpSwitchName); |
printf(" %s: Specifies the service api to use (dev|test) [default: dev]\n", |
switches::kServiceEnvironmentSwitchName); |
+ printf(" %s: Specifies the optional logging level of the tool (0-3)." |
+ " [default: off]\n", |
+ switches::kLoggingLevelSwitchName); |
} |
void PrintAuthCodeInfo() { |
@@ -105,10 +110,21 @@ void PrintAuthCodeInfo() { |
} // namespace |
+using remoting::test::AppRemotingSharedData; |
Wez
2015/02/13 03:01:52
nit: You only refer to this a few times; suggest n
joedow
2015/02/14 02:31:27
Done.
|
+ |
int main(int argc, char** argv) { |
testing::InitGoogleTest(&argc, argv); |
TestSuite test_suite(argc, argv); |
+ // In some configurations, GTest will run main twice. This should not happen |
+ // since we inject the single-process flag, but this is a safeguard in case |
Wez
2015/02/13 03:01:52
Why would the single-process flag have any effect
joedow
2015/02/14 02:31:27
It seemed like main was run twice when GTest was i
|
+ // the flag is changed later. If main is run twice, we don't want to double |
+ // initialize the global data as that will result in a leak or crash. If we |
Wez
2015/02/13 03:01:52
Why do we not tear down the global data when main
joedow
2015/02/14 02:31:27
The GTest framework handles it, there is a comment
|
+ // decide to run in multiple processes, we will want to move the global init |
+ // code into a base::TestSuite derivation and use it instead of the base |
+ // class we use now. |
+ DCHECK(!AppRemotingSharedData); |
+ |
// The pointer returned here refers to a singleton, since we don't own the |
// lifetime of the object, don't wrap in a scoped_ptr construct or release it. |
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
@@ -145,6 +161,71 @@ int main(int argc, char** argv) { |
return -1; |
} |
+ std::string user_name; |
+ user_name = command_line->GetSwitchValueASCII(switches::kUserNameSwitchName); |
+ DVLOG(1) << "Running tests as: " << user_name; |
+ |
+ std::string auth_code; |
+ // Check to see if the user passed in a one time use auth_code for |
+ // refreshing their credentials. |
+ if (command_line->HasSwitch(switches::kAuthCodeSwitchName)) { |
+ auth_code = command_line->GetSwitchValueASCII( |
+ switches::kAuthCodeSwitchName); |
Wez
2015/02/13 03:01:52
Note that you can just call GetSwitchValueASCII an
joedow
2015/02/14 02:31:27
Done.
|
+ } |
+ |
+ std::string service_environment; |
+ // If the user passed in a service environment, use it, otherwise set a |
+ // default value. |
+ if (command_line->HasSwitch(switches::kServiceEnvironmentSwitchName)) { |
+ service_environment = command_line->GetSwitchValueASCII( |
+ switches::kServiceEnvironmentSwitchName); |
+ } else { |
+ // Default to the development service environment. |
+ service_environment = "dev"; |
+ } |
+ // Only two values are allowed, so validate them before proceeding. |
+ if (service_environment != "test" && service_environment != "dev") { |
+ LOG(ERROR) << "Invalid " << switches::kServiceEnvironmentSwitchName |
+ << " argument passed in."; |
+ PrintUsage(); |
+ return -1; |
+ } |
+ |
+ // Update the logging verbosity level is user specified one. |
+ std::string verbosity_level; |
+ if (command_line->HasSwitch(switches::kLoggingLevelSwitchName)) { |
+ verbosity_level = command_line->GetSwitchValueASCII( |
+ switches::kLoggingLevelSwitchName); |
+ |
+ // Turn on logging for the test_driver and remoting components. |
+ // This switch is parsed during logging::InitLogging. |
+ command_line->AppendSwitchASCII("vmodule", |
+ "*/remoting/*=" + verbosity_level); |
+ logging::LoggingSettings logging_settings; |
+ logging::InitLogging(logging_settings); |
+ } |
+ |
+ // Create and register our global test data object. It will handle |
+ // retrieving an access token for the user and spinning up VMs. |
+ // The GTest framework will own the lifetime of this object once |
+ // it is registered below. |
+ scoped_ptr<remoting::test::AppRemotingTestDriverEnvironment> shared_data; |
+ |
+ shared_data.reset( |
+ new remoting::test::AppRemotingTestDriverEnvironment( |
+ user_name, |
+ service_environment)); |
+ |
+ if (!shared_data->Initialize(auth_code)) { |
+ // If we failed to initialize our shared data object, then bail. |
+ return -1; |
+ } |
+ |
+ // Since we've successfully set up our shared_data object, we'll assign the |
+ // value to our global* and transfer ownership to the framework. |
+ AppRemotingSharedData = shared_data.release(); |
+ testing::AddGlobalTestEnvironment(AppRemotingSharedData); |
+ |
// Because many tests may access the same remoting host(s), we need to run |
// the tests sequentially so they do not interfere with each other. |
return base::LaunchUnitTestsSerially( |