| OLD | NEW |
| 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. |
| 11 | 11 |
| 12 #include <android/log.h> | 12 #include <android/log.h> |
| 13 #include <signal.h> | 13 #include <signal.h> |
| 14 | 14 |
| 15 #include "base/android/base_jni_registrar.h" | 15 #include "base/android/base_jni_registrar.h" |
| 16 #include "base/android/context_utils.h" | 16 #include "base/android/context_utils.h" |
| 17 #include "base/android/fifo_utils.h" | |
| 18 #include "base/android/jni_string.h" | 17 #include "base/android/jni_string.h" |
| 19 #include "base/android/scoped_java_ref.h" | 18 #include "base/android/scoped_java_ref.h" |
| 20 #include "base/at_exit.h" | 19 #include "base/at_exit.h" |
| 21 #include "base/base_switches.h" | 20 #include "base/base_switches.h" |
| 22 #include "base/command_line.h" | 21 #include "base/command_line.h" |
| 23 #include "base/files/file_path.h" | 22 #include "base/files/file_path.h" |
| 24 #include "base/files/file_util.h" | 23 #include "base/files/file_util.h" |
| 25 #include "base/logging.h" | 24 #include "base/logging.h" |
| 26 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 27 #include "base/test/test_support_android.h" | 26 #include "base/test/test_support_android.h" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 base::CommandLine::ForCurrentProcess()->AppendArguments( | 97 base::CommandLine::ForCurrentProcess()->AppendArguments( |
| 99 base::CommandLine(argc, &argv[0]), false); | 98 base::CommandLine(argc, &argv[0]), false); |
| 100 const base::CommandLine& command_line = | 99 const base::CommandLine& command_line = |
| 101 *base::CommandLine::ForCurrentProcess(); | 100 *base::CommandLine::ForCurrentProcess(); |
| 102 | 101 |
| 103 base::FilePath stdout_file_path( | 102 base::FilePath stdout_file_path( |
| 104 base::android::ConvertJavaStringToUTF8(env, jstdout_file_path)); | 103 base::android::ConvertJavaStringToUTF8(env, jstdout_file_path)); |
| 105 | 104 |
| 106 // A few options, such "--gtest_list_tests", will just use printf directly | 105 // A few options, such "--gtest_list_tests", will just use printf directly |
| 107 // Always redirect stdout to a known file. | 106 // Always redirect stdout to a known file. |
| 108 if (!base::android::RedirectStream(stdout, stdout_file_path, "a+")) { | 107 if (freopen(stdout_file_path.value().c_str(), "a+", stdout) == NULL) { |
| 109 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n", | 108 AndroidLog(ANDROID_LOG_ERROR, "Failed to redirect stream to file: %s: %s\n", |
| 110 stdout_file_path.value().c_str(), strerror(errno)); | 109 stdout_file_path.value().c_str(), strerror(errno)); |
| 111 exit(EXIT_FAILURE); | 110 exit(EXIT_FAILURE); |
| 112 } | 111 } |
| 113 dup2(STDOUT_FILENO, STDERR_FILENO); | 112 dup2(STDOUT_FILENO, STDERR_FILENO); |
| 114 | 113 |
| 115 if (command_line.HasSwitch(switches::kWaitForDebugger)) { | 114 if (command_line.HasSwitch(switches::kWaitForDebugger)) { |
| 116 AndroidLog(ANDROID_LOG_VERBOSE, | 115 AndroidLog(ANDROID_LOG_VERBOSE, |
| 117 "Native test waiting for GDB because flag %s was supplied", | 116 "Native test waiting for GDB because flag %s was supplied", |
| 118 switches::kWaitForDebugger); | 117 switches::kWaitForDebugger); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 143 sa.sa_sigaction = SignalHandler; | 142 sa.sa_sigaction = SignalHandler; |
| 144 sa.sa_flags = SA_SIGINFO; | 143 sa.sa_flags = SA_SIGINFO; |
| 145 | 144 |
| 146 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { | 145 for (unsigned int i = 0; kExceptionSignals[i] != -1; ++i) { |
| 147 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); | 146 sigaction(kExceptionSignals[i], &sa, &g_old_sa[kExceptionSignals[i]]); |
| 148 } | 147 } |
| 149 } | 148 } |
| 150 | 149 |
| 151 } // namespace android | 150 } // namespace android |
| 152 } // namespace testing | 151 } // namespace testing |
| OLD | NEW |