OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 package org.chromium.native_test; | 5 package org.chromium.native_test; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.os.Bundle; | 9 import android.os.Bundle; |
10 import android.os.Environment; | 10 import android.os.Environment; |
(...skipping 11 matching lines...) Expand all Loading... |
22 /** | 22 /** |
23 * Android's NativeActivity is mostly useful for pure-native code. | 23 * Android's NativeActivity is mostly useful for pure-native code. |
24 * Our tests need to go up to our own java classes, which is not possible using | 24 * Our tests need to go up to our own java classes, which is not possible using |
25 * the native activity class loader. | 25 * the native activity class loader. |
26 */ | 26 */ |
27 public class ChromeNativeTestActivity extends Activity { | 27 public class ChromeNativeTestActivity extends Activity { |
28 public static final String EXTRA_COMMAND_LINE_FILE = | 28 public static final String EXTRA_COMMAND_LINE_FILE = |
29 "org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile"; | 29 "org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile"; |
30 public static final String EXTRA_COMMAND_LINE_FLAGS = | 30 public static final String EXTRA_COMMAND_LINE_FLAGS = |
31 "org.chromium.native_test.ChromeNativeTestActivity.CommandLineFlags"
; | 31 "org.chromium.native_test.ChromeNativeTestActivity.CommandLineFlags"
; |
| 32 public static final String EXTRA_STDOUT_FILE = |
| 33 "org.chromium.native_test.ChromeNativeTestActivity.StdoutFile"; |
32 | 34 |
33 private static final String TAG = "ChromeNativeTestActivity"; | 35 private static final String TAG = "ChromeNativeTestActivity"; |
34 private static final String EXTRA_RUN_IN_SUB_THREAD = "RunInSubThread"; | 36 private static final String EXTRA_RUN_IN_SUB_THREAD = "RunInSubThread"; |
35 // We post a delayed task to run tests so that we do not block onCreate(). | 37 // We post a delayed task to run tests so that we do not block onCreate(). |
36 private static final long RUN_TESTS_DELAY_IN_MS = 300; | 38 private static final long RUN_TESTS_DELAY_IN_MS = 300; |
37 | 39 |
38 @Override | 40 @Override |
39 public void onCreate(Bundle savedInstanceState) { | 41 public void onCreate(Bundle savedInstanceState) { |
40 super.onCreate(savedInstanceState); | 42 super.onCreate(savedInstanceState); |
41 CommandLine.init(new String[]{}); | 43 CommandLine.init(new String[]{}); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 commandLineFilePath = ""; | 84 commandLineFilePath = ""; |
83 } else { | 85 } else { |
84 File commandLineFile = new File(commandLineFilePath); | 86 File commandLineFile = new File(commandLineFilePath); |
85 if (!commandLineFile.isAbsolute()) { | 87 if (!commandLineFile.isAbsolute()) { |
86 commandLineFilePath = Environment.getExternalStorageDirectory()
+ "/" | 88 commandLineFilePath = Environment.getExternalStorageDirectory()
+ "/" |
87 + commandLineFilePath; | 89 + commandLineFilePath; |
88 } | 90 } |
89 Log.i(TAG, "command line file path: " + commandLineFilePath); | 91 Log.i(TAG, "command line file path: " + commandLineFilePath); |
90 } | 92 } |
91 | 93 |
| 94 String stdoutFilePath = getIntent().getStringExtra(EXTRA_STDOUT_FILE); |
| 95 boolean stdoutFifo = false; |
| 96 if (stdoutFilePath == null) { |
| 97 stdoutFilePath = new File(getFilesDir(), "test.fifo").getAbsolutePat
h(); |
| 98 stdoutFifo = true; |
| 99 } |
| 100 |
92 // This directory is used by build/android/pylib/test_package_apk.py. | 101 // This directory is used by build/android/pylib/test_package_apk.py. |
93 nativeRunTests(commandLineFlags, commandLineFilePath, getFilesDir().getA
bsolutePath(), | 102 nativeRunTests(commandLineFlags, commandLineFilePath, stdoutFilePath, st
doutFifo, |
94 getApplicationContext()); | 103 getApplicationContext()); |
| 104 finish(); |
95 } | 105 } |
96 | 106 |
97 // Signal a failure of the native test loader to python scripts | 107 // Signal a failure of the native test loader to python scripts |
98 // which run tests. For example, we look for | 108 // which run tests. For example, we look for |
99 // RUNNER_FAILED build/android/test_package.py. | 109 // RUNNER_FAILED build/android/test_package.py. |
100 private void nativeTestFailed() { | 110 private void nativeTestFailed() { |
101 Log.e(TAG, "[ RUNNER_FAILED ] could not load native library"); | 111 Log.e(TAG, "[ RUNNER_FAILED ] could not load native library"); |
102 } | 112 } |
103 | 113 |
104 private void loadLibraries() { | 114 private void loadLibraries() { |
105 for (String library : NativeLibraries.LIBRARIES) { | 115 for (String library : NativeLibraries.LIBRARIES) { |
106 Log.i(TAG, "loading: " + library); | 116 Log.i(TAG, "loading: " + library); |
107 System.loadLibrary(library); | 117 System.loadLibrary(library); |
108 Log.i(TAG, "loaded: " + library); | 118 Log.i(TAG, "loaded: " + library); |
109 } | 119 } |
110 } | 120 } |
111 | 121 |
112 private native void nativeRunTests(String commandLineFlags, String commandLi
neFilePath, | 122 private native void nativeRunTests(String commandLineFlags, String commandLi
neFilePath, |
113 String filesDir, Context appContext); | 123 String stdoutFilePath, boolean stdoutFifo, Context appContext); |
114 } | 124 } |
OLD | NEW |