| 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.os.Bundle; | 9 import android.os.Bundle; |
| 9 import android.util.Log; | 10 import android.util.Log; |
| 10 | 11 |
| 11 // Android's NativeActivity is mostly useful for pure-native code. | 12 // Android's NativeActivity is mostly useful for pure-native code. |
| 12 // Our tests need to go up to our own java classes, which is not possible using | 13 // Our tests need to go up to our own java classes, which is not possible using |
| 13 // the native activity class loader. | 14 // the native activity class loader. |
| 14 // We start a background thread in here to run the tests and avoid an ANR. | 15 // We start a background thread in here to run the tests and avoid an ANR. |
| 15 // TODO(bulach): watch out for tests that implicitly assume they run on the main | 16 // TODO(bulach): watch out for tests that implicitly assume they run on the main |
| 16 // thread. | 17 // thread. |
| 17 public class ChromeNativeTestActivity extends Activity { | 18 public class ChromeNativeTestActivity extends Activity { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 29 nativeTestFailed(); | 30 nativeTestFailed(); |
| 30 return; | 31 return; |
| 31 } | 32 } |
| 32 | 33 |
| 33 try { | 34 try { |
| 34 loadLibrary(); | 35 loadLibrary(); |
| 35 new Thread() { | 36 new Thread() { |
| 36 @Override | 37 @Override |
| 37 public void run() { | 38 public void run() { |
| 38 Log.d(TAG, ">>nativeRunTests"); | 39 Log.d(TAG, ">>nativeRunTests"); |
| 39 nativeRunTests(getFilesDir().getAbsolutePath()); | 40 nativeRunTests(getFilesDir().getAbsolutePath(), getApplicati
onContext()); |
| 40 // TODO(jrg): make sure a crash in native code | 41 // TODO(jrg): make sure a crash in native code |
| 41 // triggers nativeTestFailed(). | 42 // triggers nativeTestFailed(). |
| 42 Log.d(TAG, "<<nativeRunTests"); | 43 Log.d(TAG, "<<nativeRunTests"); |
| 43 } | 44 } |
| 44 }.start(); | 45 }.start(); |
| 45 } catch (UnsatisfiedLinkError e) { | 46 } catch (UnsatisfiedLinkError e) { |
| 46 Log.e(TAG, "Unable to load lib" + mLibrary + ".so: " + e); | 47 Log.e(TAG, "Unable to load lib" + mLibrary + ".so: " + e); |
| 47 nativeTestFailed(); | 48 nativeTestFailed(); |
| 48 throw e; | 49 throw e; |
| 49 } | 50 } |
| 50 } | 51 } |
| 51 | 52 |
| 52 // Signal a failure of the native test loader to python scripts | 53 // Signal a failure of the native test loader to python scripts |
| 53 // which run tests. For example, we look for | 54 // which run tests. For example, we look for |
| 54 // RUNNER_FAILED build/android/test_package.py. | 55 // RUNNER_FAILED build/android/test_package.py. |
| 55 private void nativeTestFailed() { | 56 private void nativeTestFailed() { |
| 56 Log.e(TAG, "[ RUNNER_FAILED ] could not load native library"); | 57 Log.e(TAG, "[ RUNNER_FAILED ] could not load native library"); |
| 57 } | 58 } |
| 58 | 59 |
| 59 private void loadLibrary() throws UnsatisfiedLinkError { | 60 private void loadLibrary() throws UnsatisfiedLinkError { |
| 60 Log.i(TAG, "loading: " + mLibrary); | 61 Log.i(TAG, "loading: " + mLibrary); |
| 61 System.loadLibrary(mLibrary); | 62 System.loadLibrary(mLibrary); |
| 62 Log.i(TAG, "loaded: " + mLibrary); | 63 Log.i(TAG, "loaded: " + mLibrary); |
| 63 } | 64 } |
| 64 | 65 |
| 65 private native void nativeRunTests(String filesDir); | 66 private native void nativeRunTests(String filesDir, Context appContext); |
| 66 } | 67 } |
| OLD | NEW |