Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: testing/android/native_test/native_test_launcher.cc

Issue 1138993009: Revert of [Android] Refactor the native test wrappers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This class sets up the environment for running the native tests inside an 5 // This class sets up the environment for running the native tests inside an
6 // android application. It outputs (to a fifo) markers identifying the 6 // android application. It outputs (to a fifo) markers identifying the
7 // START/PASSED/CRASH of the test suite, FAILURE/SUCCESS of individual tests, 7 // START/PASSED/CRASH of the test suite, FAILURE/SUCCESS of individual tests,
8 // etc. 8 // etc.
9 // These markers are read by the test runner script to generate test results. 9 // These markers are read by the test runner script to generate test results.
10 // It installs signal handlers to detect crashes. 10 // It installs signal handlers to detect crashes.
(...skipping 10 matching lines...) Expand all
21 #include "base/base_switches.h" 21 #include "base/base_switches.h"
22 #include "base/command_line.h" 22 #include "base/command_line.h"
23 #include "base/files/file_path.h" 23 #include "base/files/file_path.h"
24 #include "base/files/file_util.h" 24 #include "base/files/file_util.h"
25 #include "base/logging.h" 25 #include "base/logging.h"
26 #include "base/strings/stringprintf.h" 26 #include "base/strings/stringprintf.h"
27 #include "gtest/gtest.h" 27 #include "gtest/gtest.h"
28 #include "jni/NativeTestActivity_jni.h" 28 #include "jni/NativeTestActivity_jni.h"
29 #include "testing/android/native_test/native_test_util.h" 29 #include "testing/android/native_test/native_test_util.h"
30 30
31 using testing::native_test_util::ArgsToArgv;
32 using testing::native_test_util::ParseArgsFromCommandLineFile;
33 using testing::native_test_util::ParseArgsFromString;
34 using testing::native_test_util::ScopedMainEntryLogger;
35
31 // The main function of the program to be wrapped as a test apk. 36 // The main function of the program to be wrapped as a test apk.
32 extern int main(int argc, char** argv); 37 extern int main(int argc, char** argv);
33 38
34 namespace testing {
35 namespace android {
36
37 namespace { 39 namespace {
38 40
39 // The test runner script writes the command line file in 41 // The test runner script writes the command line file in
40 // "/data/local/tmp". 42 // "/data/local/tmp".
41 static const char kCommandLineFilePath[] = 43 static const char kCommandLineFilePath[] =
42 "/data/local/tmp/chrome-native-tests-command-line"; 44 "/data/local/tmp/chrome-native-tests-command-line";
43 45
44 const char kLogTag[] = "chromium"; 46 const char kLogTag[] = "chromium";
45 const char kCrashedMarker[] = "[ CRASHED ]\n"; 47 const char kCrashedMarker[] = "[ CRASHED ]\n";
46 48
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 // A few options, such "--gtest_list_tests", will just use printf directly 116 // A few options, such "--gtest_list_tests", will just use printf directly
115 // Always redirect stdout to a known file. 117 // Always redirect stdout to a known file.
116 unlink(stdout_file_path.value().c_str()); 118 unlink(stdout_file_path.value().c_str());
117 if (jstdout_fifo) { 119 if (jstdout_fifo) {
118 if (!base::android::CreateFIFO(stdout_file_path, 0666)) { 120 if (!base::android::CreateFIFO(stdout_file_path, 0666)) {
119 AndroidLog(ANDROID_LOG_ERROR, "Failed to create fifo %s: %s\n", 121 AndroidLog(ANDROID_LOG_ERROR, "Failed to create fifo %s: %s\n",
120 stdout_file_path.value().c_str(), strerror(errno)); 122 stdout_file_path.value().c_str(), strerror(errno));
121 exit(EXIT_FAILURE); 123 exit(EXIT_FAILURE);
122 } 124 }
123 } 125 }
124 if (!base::android::RedirectStream(stdout, stdout_file_path, "w+")) { 126 if (!base::android::RedirectStream(stdout, stdout_file_path, "w")) {
125 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n", 127 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n",
126 stdout_file_path.value().c_str(), strerror(errno)); 128 stdout_file_path.value().c_str(), strerror(errno));
127 exit(EXIT_FAILURE); 129 exit(EXIT_FAILURE);
128 } 130 }
129 dup2(STDOUT_FILENO, STDERR_FILENO); 131 dup2(STDOUT_FILENO, STDERR_FILENO);
130 132
131 if (command_line.HasSwitch(switches::kWaitForDebugger)) { 133 if (command_line.HasSwitch(switches::kWaitForDebugger)) {
132 AndroidLog(ANDROID_LOG_VERBOSE, 134 AndroidLog(ANDROID_LOG_VERBOSE,
133 "Native test waiting for GDB because flag %s was supplied", 135 "Native test waiting for GDB because flag %s was supplied",
134 switches::kWaitForDebugger); 136 switches::kWaitForDebugger);
135 base::debug::WaitForDebugger(24 * 60 * 60, false); 137 base::debug::WaitForDebugger(24 * 60 * 60, false);
136 } 138 }
137 139
138 ScopedMainEntryLogger scoped_main_entry_logger; 140 ScopedMainEntryLogger scoped_main_entry_logger;
139 main(argc, &argv[0]); 141 main(argc, &argv[0]);
140 } 142 }
141 143
142 bool RegisterNativeTestJNI(JNIEnv* env) { 144 bool RegisterNativeTestJNI(JNIEnv* env) {
143 return RegisterNativesImpl(env); 145 return RegisterNativesImpl(env);
144 } 146 }
145 147
148
146 // TODO(nileshagrawal): now that we're using FIFO, test scripts can detect EOF. 149 // TODO(nileshagrawal): now that we're using FIFO, test scripts can detect EOF.
147 // Remove the signal handlers. 150 // Remove the signal handlers.
148 void InstallHandlers() { 151 void InstallHandlers() {
149 struct sigaction sa; 152 struct sigaction sa;
150 memset(&sa, 0, sizeof(sa)); 153 memset(&sa, 0, sizeof(sa));
151 154
152 sa.sa_sigaction = SignalHandler; 155 sa.sa_sigaction = SignalHandler;
153 sa.sa_flags = SA_SIGINFO; 156 sa.sa_flags = SA_SIGINFO;
154 157
155 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { 158 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) {
156 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); 159 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]);
157 } 160 }
158 } 161 }
159
160 } // namespace android
161 } // namespace testing
OLDNEW
« no previous file with comments | « testing/android/native_test/native_test_launcher.h ('k') | testing/android/native_test/native_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698