OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.native_test; | |
6 | |
7 import android.app.Activity; | |
8 import android.os.Bundle; | |
9 import android.util.Log; | |
10 | |
11 // 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 // the native activity class loader. | |
14 // 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 // thread. | |
17 public class ChromeNativeTestActivity extends Activity { | |
18 private final String TAG = "ChromeNativeTestActivity"; | |
19 | |
20 // Name of our shlib as obtained from a string resource. | |
21 private String mLibrary; | |
22 | |
23 @Override | |
24 public void onCreate(Bundle savedInstanceState) { | |
25 super.onCreate(savedInstanceState); | |
26 | |
27 mLibrary = getResources().getString(R.string.native_library); | |
28 if ((mLibrary == null) || mLibrary.startsWith("replace")) { | |
29 nativeTestFailed(); | |
30 return; | |
31 } | |
32 | |
33 try { | |
34 loadLibrary(); | |
35 new Thread() { | |
36 @Override | |
37 public void run() { | |
38 Log.d(TAG, ">>nativeRunTests"); | |
39 nativeRunTests(getFilesDir().getAbsolutePath()); | |
40 // TODO(jrg): make sure a crash in native code | |
41 // triggers nativeTestFailed(). | |
bulach
2012/04/12 15:51:42
is it needed? the runner should be smart enough to
John Grabowski
2012/04/13 01:11:37
Yes, it is needed. If we crash we have to wait fo
bulach
2012/04/13 09:42:51
right, sorry, I wasn't clear: rather than add yet-
John Grabowski
2012/04/13 22:51:02
I would prefer to make 'a test failed' distinct fr
| |
42 Log.d(TAG, "<<nativeRunTests"); | |
43 } | |
44 }.start(); | |
45 } catch (UnsatisfiedLinkError e) { | |
bulach
2012/04/12 15:51:42
you probably need to wrap just loadLibrary, not th
John Grabowski
2012/04/13 01:11:37
Not sure I agree; is possible loadLibrary() works
| |
46 Log.e(TAG, "Unable to load lib" + mLibrary + ".so: " + e); | |
47 nativeTestFailed(); | |
48 throw e; | |
49 } | |
50 } | |
51 | |
52 // Signal a failure of the native test loader to python scripts | |
53 // which run tests,. For example, we look for | |
Yaron
2012/04/12 01:29:53
s/,././
John Grabowski
2012/04/13 01:11:37
Done.
| |
54 // NATIVE_LOADER_FAILED build/android/test_package.py. | |
55 private void nativeTestFailed() { | |
56 Log.e(TAG, "[ NATIVE_LOADER_FAILED ]"); | |
bulach
2012/04/13 09:42:51
see above, we could probably reuse the existing me
| |
57 } | |
58 | |
59 private void loadLibrary() throws UnsatisfiedLinkError { | |
60 Log.i(TAG, "loading: " + mLibrary); | |
61 System.loadLibrary(mLibrary); | |
62 Log.i(TAG, "loaded: " + mLibrary); | |
63 } | |
64 | |
65 private native void nativeRunTests(String filesDir); | |
66 } | |
OLD | NEW |