diff --git a/NeoML/test/android/.gitignore b/NeoML/test/android/.gitignore new file mode 100644 index 000000000..09b993d06 --- /dev/null +++ b/NeoML/test/android/.gitignore @@ -0,0 +1,8 @@ +*.iml +.gradle +/local.properties +/.idea +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/NeoML/test/android/app/.gitignore b/NeoML/test/android/app/.gitignore new file mode 100644 index 000000000..796b96d1c --- /dev/null +++ b/NeoML/test/android/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/NeoML/test/android/app/build.gradle b/NeoML/test/android/app/build.gradle new file mode 100644 index 000000000..ca161617f --- /dev/null +++ b/NeoML/test/android/app/build.gradle @@ -0,0 +1,55 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + buildToolsVersion '29.0.3' + + defaultConfig { + ndk { + abiFilters 'arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64' + } + applicationId "com.neoml.test" + minSdkVersion 21 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + } + + buildTypes { + debug { + jniDebuggable = true + debuggable = true + + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + externalNativeBuild { + cmake { + path "src/main/jni/CMakeLists.txt" + version "3.11.0+" + } + } +} + +task copyTestData(type: Copy) { + from('../../data') + into('src/main/assets/data') +} + +afterEvaluate { + android.applicationVariants.all { variant -> + variant.javaCompiler.dependsOn(copyTestData) + } +} + +dependencies { + implementation fileTree(include: ['*.jar'], dir: 'libs') + implementation 'com.android.support:appcompat-v7:26.1.0' + implementation 'com.android.support.constraint:constraint-layout:1.0.2' + implementation 'com.android.support:design:26.1.0' +} diff --git a/NeoML/test/android/app/proguard-rules.pro b/NeoML/test/android/app/proguard-rules.pro new file mode 100644 index 000000000..f1b424510 --- /dev/null +++ b/NeoML/test/android/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/NeoML/test/android/app/src/main/AndroidManifest.xml b/NeoML/test/android/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..66c38dc1d --- /dev/null +++ b/NeoML/test/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/NeoML/test/android/app/src/main/java/com/neoml/test/MainActivity.java b/NeoML/test/android/app/src/main/java/com/neoml/test/MainActivity.java new file mode 100644 index 000000000..ad35cf0b3 --- /dev/null +++ b/NeoML/test/android/app/src/main/java/com/neoml/test/MainActivity.java @@ -0,0 +1,105 @@ +package com.neoml.test; + +import android.content.Context; +import android.content.res.AssetManager; +import android.os.Bundle; +import android.widget.TextView; +import android.support.v7.app.AppCompatActivity; +import android.view.Menu; +import android.view.MenuItem; + +import android.os.AsyncTask; +import android.os.ParcelFileDescriptor; + +import android.system.Os; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class MainActivity extends AppCompatActivity { + class LogTask extends AsyncTask { + @Override + protected Void doInBackground(ParcelFileDescriptor... fds) { + try { + ParcelFileDescriptor.AutoCloseInputStream stream = + new ParcelFileDescriptor.AutoCloseInputStream(fds[0]); + BufferedReader buffReader = new BufferedReader(new InputStreamReader(stream)); + String line; + while ((line = buffReader.readLine()) != null) { + android.util.Log.d(Tag, line); + publishProgress(line); // pass the data to onProgressUpdate + } + } catch (Exception exception) { + android.util.Log.e(Tag, "Except in log thread", exception); + } + return null; + } + + @Override + protected void onProgressUpdate(String... log) { + TextView tv = (TextView) findViewById(R.id.logView); + for (String line: log) { + tv.append(line); + tv.append("\n"); + } + } + } + public native void RunTests( Object assetManager ); + + static AssetManager assetManager; + static Context context; + static String Tag = "NeoMLTest"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + assetManager = getAssets(); + context = getApplicationContext(); + + setContentView(R.layout.activity_main); + // Example of a call to a native method + System.loadLibrary("NeoMLTestJni"); + + try { + ParcelFileDescriptor pipe[] = ParcelFileDescriptor.createPipe(); + Os.dup2(pipe[1].getFileDescriptor(), 1); // stdout + Os.dup2(pipe[1].getFileDescriptor(), 2); // stderr + pipe[1].close(); + + new LogTask().execute(pipe[0]); + + new Thread(new Runnable() { + public void run() { + RunTests(assetManager); + } + }).start(); + + } catch (Exception exception) { + android.util.Log.e(Tag, "Except", exception); + } + } + + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + // Inflate the menu; this adds items to the action bar if it is present. + getMenuInflater().inflate(R.menu.menu_main, menu); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + + //noinspection SimplifiableIfStatement + if (id == R.id.action_settings) { + return true; + } + + return super.onOptionsItemSelected(item); + } +} diff --git a/NeoML/test/android/app/src/main/jni/CMakeLists.txt b/NeoML/test/android/app/src/main/jni/CMakeLists.txt new file mode 100644 index 000000000..ce571ccf4 --- /dev/null +++ b/NeoML/test/android/app/src/main/jni/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.11 FATAL_ERROR) + +project(NeoMLTestJni) + +set(NeoML_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../../../..) + +list(APPEND CMAKE_MODULE_PATH ${NeoML_DIR}/cmake) + +include(Utils) + +set(NeoMathEngine_BUILD_SHARED OFF CACHE BOOL "" FORCE) +set(NeoML_BUILD_SHARED OFF CACHE BOOL "" FORCE) +set(NeoOnnx_BUILD OFF CACHE BOOL "" FORCE) +add_subdirectory(${NeoML_DIR}/NeoML ${CMAKE_BINARY_DIR}/NeoML) + +add_subdirectory(${NeoML_DIR}/NeoML/test/src ${CMAKE_BINARY_DIR}/NeoML/test/src) + +add_library(${PROJECT_NAME} SHARED + NeoMLTestJni.cpp +) + +add_gtest_target() + +target_link_libraries(${PROJECT_NAME} PRIVATE NeoMLTestSrc NeoML gtest) + +configure_target(${PROJECT_NAME}) diff --git a/NeoML/test/android/app/src/main/jni/NeoMLTestJni.cpp b/NeoML/test/android/app/src/main/jni/NeoMLTestJni.cpp new file mode 100644 index 000000000..4fc824dc3 --- /dev/null +++ b/NeoML/test/android/app/src/main/jni/NeoMLTestJni.cpp @@ -0,0 +1,10 @@ +#include +#include + +extern "C" +JNIEXPORT void JNICALL Java_com_neoml_test_MainActivity_RunTests( JNIEnv *, jobject, jobject assetManager ) +{ + int argc = 2; + char* argv[2] = {"--MathEngine=cpu", "--gtest_filter=*"}; + NeoMLTest::RunTests( argc, argv, assetManager ); +} diff --git a/NeoML/test/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/NeoML/test/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 000000000..c7bd21dbd --- /dev/null +++ b/NeoML/test/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + diff --git a/NeoML/test/android/app/src/main/res/drawable/ic_launcher_background.xml b/NeoML/test/android/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 000000000..d5fccc538 --- /dev/null +++ b/NeoML/test/android/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/NeoML/test/android/app/src/main/res/layout/activity_main.xml b/NeoML/test/android/app/src/main/res/layout/activity_main.xml new file mode 100644 index 000000000..d04b3d9f7 --- /dev/null +++ b/NeoML/test/android/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,19 @@ + + + + + + + + diff --git a/NeoML/test/android/app/src/main/res/layout/content_main.xml b/NeoML/test/android/app/src/main/res/layout/content_main.xml new file mode 100644 index 000000000..fe4385b53 --- /dev/null +++ b/NeoML/test/android/app/src/main/res/layout/content_main.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + diff --git a/NeoML/test/android/app/src/main/res/menu/menu_main.xml b/NeoML/test/android/app/src/main/res/menu/menu_main.xml new file mode 100644 index 000000000..3e7ea6d76 --- /dev/null +++ b/NeoML/test/android/app/src/main/res/menu/menu_main.xml @@ -0,0 +1,10 @@ + + + diff --git a/NeoML/test/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/NeoML/test/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 000000000..eca70cfe5 --- /dev/null +++ b/NeoML/test/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/NeoML/test/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/NeoML/test/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 000000000..eca70cfe5 --- /dev/null +++ b/NeoML/test/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/NeoML/test/android/app/src/main/res/mipmap-hdpi/ic_launcher.png b/NeoML/test/android/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 000000000..a2f590828 Binary files /dev/null and b/NeoML/test/android/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/NeoML/test/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/NeoML/test/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 000000000..1b5239980 Binary files /dev/null and b/NeoML/test/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/NeoML/test/android/app/src/main/res/mipmap-mdpi/ic_launcher.png b/NeoML/test/android/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 000000000..ff10afd6e Binary files /dev/null and b/NeoML/test/android/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/NeoML/test/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/NeoML/test/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 000000000..115a4c768 Binary files /dev/null and b/NeoML/test/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/NeoML/test/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/NeoML/test/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 000000000..dcd3cd808 Binary files /dev/null and b/NeoML/test/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/NeoML/test/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/NeoML/test/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 000000000..459ca609d Binary files /dev/null and b/NeoML/test/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/NeoML/test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/NeoML/test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 000000000..8ca12fe02 Binary files /dev/null and b/NeoML/test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/NeoML/test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/NeoML/test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 000000000..8e19b410a Binary files /dev/null and b/NeoML/test/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/NeoML/test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/NeoML/test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 000000000..b824ebdd4 Binary files /dev/null and b/NeoML/test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/NeoML/test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/NeoML/test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 000000000..4c19a13c2 Binary files /dev/null and b/NeoML/test/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/NeoML/test/android/app/src/main/res/values/colors.xml b/NeoML/test/android/app/src/main/res/values/colors.xml new file mode 100644 index 000000000..3ab3e9cbc --- /dev/null +++ b/NeoML/test/android/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #3F51B5 + #303F9F + #FF4081 + diff --git a/NeoML/test/android/app/src/main/res/values/dimens.xml b/NeoML/test/android/app/src/main/res/values/dimens.xml new file mode 100644 index 000000000..59a0b0c4f --- /dev/null +++ b/NeoML/test/android/app/src/main/res/values/dimens.xml @@ -0,0 +1,3 @@ + + 16dp + diff --git a/NeoML/test/android/app/src/main/res/values/strings.xml b/NeoML/test/android/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..1d981c3a7 --- /dev/null +++ b/NeoML/test/android/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + NeoMLTestAndroid + Settings + diff --git a/NeoML/test/android/app/src/main/res/values/styles.xml b/NeoML/test/android/app/src/main/res/values/styles.xml new file mode 100644 index 000000000..545b9c6d2 --- /dev/null +++ b/NeoML/test/android/app/src/main/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + +