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 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 27 matching lines...) Expand all Loading... |
38 nativeTestFailed(); | 38 nativeTestFailed(); |
39 return; | 39 return; |
40 } | 40 } |
41 | 41 |
42 // Needed by path_utils_unittest.cc | 42 // Needed by path_utils_unittest.cc |
43 PathUtils.setPrivateDataDirectorySuffix("chrome"); | 43 PathUtils.setPrivateDataDirectorySuffix("chrome"); |
44 | 44 |
45 // Needed by system_monitor_unittest.cc | 45 // Needed by system_monitor_unittest.cc |
46 SystemMonitor.createForTests(this); | 46 SystemMonitor.createForTests(this); |
47 | 47 |
48 try { | 48 |
49 loadLibrary(); | 49 loadLibrary(); |
50 Bundle extras = this.getIntent().getExtras(); | 50 Bundle extras = this.getIntent().getExtras(); |
51 if (extras != null && extras.containsKey(EXTRA_RUN_IN_SUB_THREAD)) { | 51 if (extras != null && extras.containsKey(EXTRA_RUN_IN_SUB_THREAD)) { |
52 // Create a new thread and run tests on it. | 52 // Create a new thread and run tests on it. |
53 new Thread() { | 53 new Thread() { |
54 @Override | 54 @Override |
55 public void run() { | 55 public void run() { |
56 runTests(); | 56 runTests(); |
57 } | 57 } |
58 }.start(); | 58 }.start(); |
59 } else { | 59 } else { |
60 // Post a task to run the tests. This allows us to not block | 60 // Post a task to run the tests. This allows us to not block |
61 // onCreate and still run tests on the main thread. | 61 // onCreate and still run tests on the main thread. |
62 new Handler().postDelayed(new Runnable() { | 62 new Handler().postDelayed(new Runnable() { |
63 @Override | 63 @Override |
64 public void run() { | 64 public void run() { |
65 runTests(); | 65 runTests(); |
66 } | 66 } |
67 }, RUN_TESTS_DELAY_IN_MS); | 67 }, RUN_TESTS_DELAY_IN_MS); |
68 } | |
69 } catch (UnsatisfiedLinkError e) { | |
70 Log.e(TAG, "Unable to load lib" + mLibrary + ".so: " + e); | |
71 nativeTestFailed(); | |
72 throw e; | |
73 } | 68 } |
74 } | 69 } |
75 | 70 |
76 private void runTests() { | 71 private void runTests() { |
77 // This directory is used by build/android/pylib/test_package_apk.py. | 72 // This directory is used by build/android/pylib/test_package_apk.py. |
78 nativeRunTests(getFilesDir().getAbsolutePath(), getApplicationContext())
; | 73 nativeRunTests(getFilesDir().getAbsolutePath(), getApplicationContext())
; |
79 } | 74 } |
80 | 75 |
81 // Signal a failure of the native test loader to python scripts | 76 // Signal a failure of the native test loader to python scripts |
82 // which run tests. For example, we look for | 77 // which run tests. For example, we look for |
83 // RUNNER_FAILED build/android/test_package.py. | 78 // RUNNER_FAILED build/android/test_package.py. |
84 private void nativeTestFailed() { | 79 private void nativeTestFailed() { |
85 Log.e(TAG, "[ RUNNER_FAILED ] could not load native library"); | 80 Log.e(TAG, "[ RUNNER_FAILED ] could not load native library"); |
86 } | 81 } |
87 | 82 |
88 private void loadLibrary() throws UnsatisfiedLinkError { | 83 private void loadLibrary() { |
89 Log.i(TAG, "loading: " + mLibrary); | 84 Log.i(TAG, "loading: " + mLibrary); |
90 System.loadLibrary(mLibrary); | 85 System.loadLibrary(mLibrary); |
91 Log.i(TAG, "loaded: " + mLibrary); | 86 Log.i(TAG, "loaded: " + mLibrary); |
92 } | 87 } |
93 | 88 |
94 private native void nativeRunTests(String filesDir, Context appContext); | 89 private native void nativeRunTests(String filesDir, Context appContext); |
95 } | 90 } |
OLD | NEW |