This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android] Implement android test runner for core unit tests
- Loading branch information
1 parent
bd4a059
commit d8cc12b
Showing
8 changed files
with
118 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "runtime.hpp" | ||
#include "../jni.hpp" | ||
|
||
#include <cassert> | ||
#include <dlfcn.h> | ||
#include <jni.h> | ||
#include <signal.h> | ||
#include <string> | ||
|
||
// Required for art / libsigchain | ||
extern "C" JNIEXPORT void EnsureFrontOfChain(int, struct sigaction*) { } | ||
extern "C" JNIEXPORT void AddSpecialSignalHandlerFn(int, void*) { } | ||
extern "C" JNIEXPORT void RemoveSpecialSignalHandlerFn(int, bool (*) (int, siginfo_t*, void*)) { } | ||
|
||
namespace { | ||
const std::string kClassPathCommand{"--class_path="}; | ||
const std::string kClassPath{"-Djava.class.path="}; | ||
const std::string kDefaultDex{"/data/local/tmp/core-tests/classes.dex"}; | ||
} // namespace | ||
|
||
namespace mbgl { | ||
namespace android { | ||
|
||
bool init_runtime(int argc, char *argv[]) { | ||
void* vmHandle = dlopen ("libart.so", RTLD_NOW); | ||
assert(vmHandle != nullptr); | ||
|
||
using CreateJavaVMFn = jint (*) (JavaVM ** vm, JNIEnv ** env, void * vmArgs); | ||
CreateJavaVMFn createJavaVMFn = reinterpret_cast<CreateJavaVMFn>(dlsym(vmHandle, "JNI_CreateJavaVM")); | ||
assert(createJavaVMFn != nullptr); | ||
|
||
std::string classPath = kClassPath + kDefaultDex; | ||
for (int i = 0; i < argc; ++i) { | ||
const std::string arg{argv[i]}; | ||
if (arg.compare(0, kClassPathCommand.length(), kClassPathCommand) == 0) { | ||
classPath = kClassPath + arg.substr(kClassPathCommand.length()); | ||
break; | ||
} | ||
} | ||
|
||
JavaVMOption options[1]; | ||
options[0].optionString = classPath.c_str(); | ||
|
||
JavaVMInitArgs args; | ||
args.version = JNI_VERSION_1_6; | ||
args.nOptions = 1; | ||
args.options = options; | ||
args.ignoreUnrecognized = JNI_TRUE; | ||
|
||
JavaVM * vm; | ||
JNIEnv * env; | ||
|
||
if (createJavaVMFn(&vm, &env, &args) != JNI_OK) { | ||
return false; | ||
} | ||
|
||
void* runtimeHandle = dlopen ("libandroid_runtime.so", RTLD_NOW); | ||
assert(runtimeHandle != nullptr); | ||
|
||
using RegisterNativesFn = jint (*) (JNIEnv * env); | ||
RegisterNativesFn registerNativesFn = reinterpret_cast<RegisterNativesFn>(dlsym(runtimeHandle, "registerFrameworkNatives")); | ||
assert(registerNativesFn != nullptr); | ||
|
||
if (registerNativesFn(env) != JNI_OK) { | ||
return false; | ||
} | ||
|
||
mbgl::android::registerNatives(vm); | ||
return true; | ||
} | ||
|
||
} // namespace android | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#pragma once | ||
|
||
namespace mbgl { | ||
namespace android { | ||
|
||
bool init_runtime(int argc, char *argv[]); | ||
|
||
} // namespace android | ||
} // namespace mbgl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "runtime.hpp" | ||
#include <mbgl/test.hpp> | ||
|
||
int main(int argc, char *argv[]) { | ||
if (!mbgl::android::init_runtime(argc, argv)) { | ||
return 1; | ||
} | ||
|
||
mbgl::runTests(argc, argv); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
global: | ||
EnsureFrontOfChain; | ||
AddSpecialSignalHandlerFn; | ||
RemoveSpecialSignalHandlerFn; | ||
local: | ||
*; | ||
}; |