-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #913 from atsushieno/android-testing-rebased
Add Android testing setup
- Loading branch information
Showing
46 changed files
with
1,439 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
.idea | ||
|
||
app/src/main/cpp/include/ | ||
app/src/main/cpp/tests/ | ||
app/src/main/jniLibs/ | ||
test-names.txt |
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,41 @@ | ||
# Android test runner | ||
|
||
It is meant to be an Android app that runs those fluidsynth tests under `../test` directory. | ||
|
||
It is not immediately doable because everything is based on ctest where each source has `main()` function that cannot be more than one within a shared library. Therefore, we generate the modified test sources into this standalone Android tester app. | ||
|
||
Also, since those tests have to access to libfluidsynth non-public implementation, we have to build the entire native test libraries (for each ABI), not with `libfluidsynth.so`. | ||
|
||
The application was based on Android Studio 4.2 (when it was created). | ||
|
||
## Building | ||
|
||
Here is a brief task list to generate, build, and run Android tests: | ||
|
||
- run `./convert-tests.sh` to generate runnable tests. | ||
- run `build-scripts/download.sh` to download fluidsynth dependency archives to build from sources as Android dependencies. | ||
- run `build-scripts/build-all-archs.sh` to build fluidsynth native libraries for Android. | ||
- copy `build-scripts/build-artifacts/lib` contents into `app/src/main/jniLibs`. | ||
- run `./gradlew connectedCheck` to build and run Android tests. | ||
|
||
Detailed explanation follows. | ||
|
||
(1) First of all, you have to generate the modified test sources as well as the native test runner from `../test` directory. `./convert-tests.sh` does this work for you. | ||
|
||
It is a simple sed script that expects various preconditions that those existing ctests meet at the moment when this script was created (e.g. test source filename can be used to construct a valid C function name, it must have `int main()` literally, it must be compilable among with other sources, etc.). This also overwrites `app/src/main/cpp/run_all_tests.c` | ||
|
||
You are supposed to run this every time the set of test files get updated. On CI builds it has to be run every time. This also applies when you want to try re-enabling those failing tests, adding exceptional tests that this converter cannot cover, or adding more failing tests. | ||
|
||
(2) Once you are done with generating tests, then the next step is to download all fluidsynth runtime dependencies. This can be done by `./download.sh`. It is based on (but not a complete copy of) [Azure DevOps CI build setup](https://github.com/FluidSynth/fluidsynth/blob/master/.azure/azure-pipelines-android.yml). You have to do once until the list of dependencies changes. On Azure DevOps this step is therefore already handled (when this notes were written). | ||
|
||
(3) Once you are done with downloading all those dependencies, the next step is to build fluidsynth for Android. Locally it can be achieved by `build-scripts/build-all-archs.sh`. It is (again) based on the Azure DevOps setup and therefore it is already handled there (when this notes were written). | ||
|
||
It will end up with `build-scripts/build-artifacts/` that contains a `include` directory and `lib/*` directories for each ABI, on local builds. (Azure DevOps builds it is `$(Build.ArtifactStagingDirectory)/lib/*`.) | ||
|
||
Once you have finished building fluidsynth for Android. there will be `$(topdir)/build_(ABI)` directories. While you want to build the Android tester app, you cannot remove them because those intermediate files (OBJ files) are referenced by this app's `CMakeLists.txt`. | ||
|
||
(4) The `lib` part from the above has to be copied into `app/src/main/jniLibs`. There should be `armeabi-v7a`, `arm64-v8a`, `x86`, and `x86_64` subdirectories. | ||
|
||
(5) After all the steps above are done, the Android tester app is ready to build and run. You can either open this directory as a project on Android Studio, or run `./gradlew build` to build the app, or run `./gradlew connectedCheck` to build and run the tests on a connected Android target (emulator or device). You can also run the tests by simply launching the MainActivity as it run there before showing the UI. | ||
|
||
Note that those tests have to run on an Android target otherwise it does not make sense. `./gradlew build` or `./gradlew check` runs "test" in the project, but it does not mean they run on an Android target. |
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 @@ | ||
/build |
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,63 @@ | ||
plugins { | ||
id 'com.android.application' | ||
id 'kotlin-android' | ||
} | ||
|
||
android { | ||
compileSdkVersion 30 | ||
buildToolsVersion "30.0.3" | ||
|
||
defaultConfig { | ||
applicationId "org.fluidsynth.fluidsynth_tests" | ||
minSdkVersion 24 | ||
targetSdkVersion 30 | ||
versionCode 1 | ||
versionName "1.0" | ||
|
||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
externalNativeBuild { | ||
cmake { | ||
cppFlags '' | ||
arguments '-DANDROID_STL=c++_shared' | ||
} | ||
|
||
if (project.hasProperty('customAbiFilters')) | ||
ndk.abiFilters "$customAbiFilters" | ||
} | ||
} | ||
|
||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = '1.8' | ||
} | ||
externalNativeBuild { | ||
cmake { | ||
path file('src/main/cpp/CMakeLists.txt') | ||
version '3.16.0+' | ||
} | ||
} | ||
buildFeatures { | ||
viewBinding true | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" | ||
implementation 'androidx.core:core-ktx:1.5.0' | ||
implementation 'androidx.appcompat:appcompat:1.3.0' | ||
implementation 'com.google.android.material:material:1.3.0' | ||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4' | ||
testImplementation 'junit:junit:4.13.2' | ||
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||
} |
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,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 |
27 changes: 27 additions & 0 deletions
27
...droid/app/src/androidTest/java/org/fluidsynth/fluidsynth_tests/ExampleInstrumentedTest.kt
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,27 @@ | ||
package org.fluidsynth.fluidsynth_tests | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import org.fluidsynth.fluidsynthtests.TestRunner | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("org.fluidsynth.fluidsynth_tests", appContext.packageName) | ||
|
||
TestRunner.runTests() | ||
} | ||
} |
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,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="org.fluidsynth.fluidsynthtests"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.Fluidsynthtests"> | ||
<activity android:name="org.fluidsynth.fluidsynthtests.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
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,113 @@ | ||
# For more information about using CMake with Android Studio, read the | ||
# documentation: https://d.android.com/studio/projects/add-native-code.html | ||
|
||
# Sets the minimum version of CMake required to build the native library. | ||
|
||
cmake_minimum_required(VERSION 3.10.2) | ||
|
||
# Declares and names the project. | ||
|
||
project("fluidsynth_tests") | ||
|
||
set (TEST_SRC_DIR ../../../../../test) | ||
|
||
# Creates and names a library, sets it as either STATIC | ||
# or SHARED, and provides the relative paths to its source code. | ||
# You can define multiple libraries, and CMake builds them for you. | ||
# Gradle automatically packages shared libraries with your APK. | ||
|
||
AUX_SOURCE_DIRECTORY(tests TEST_SRC_FILES) | ||
FILE(GLOB LINKED_OBJ_FILES ../../../../../build_${CMAKE_ANDROID_ARCH_ABI}/src/CMakeFiles/libfluidsynth-OBJ.dir/**/*.o) | ||
|
||
message("-----------------------TEST_SRC_FILES---------------------------") | ||
message("${TEST_SRC_FILES}") | ||
message("-----------------------LINKED_OBJ_FILES---------------------------") | ||
message("${LINKED_OBJ_FILES}") | ||
|
||
add_library( # Sets the name of the library. | ||
native-lib | ||
|
||
# Sets the library as a shared library. | ||
SHARED | ||
|
||
# Provides a relative path to your source file(s). | ||
${LINKED_OBJ_FILES} | ||
|
||
tests/test_preset_pinning.c | ||
tests/test_seq_event_queue_remove.c | ||
tests/test_seq_scale.c | ||
tests/test_jack_obtaining_synth.c | ||
tests/test_settings_unregister_callback.c | ||
tests/test_pointer_alignment.c | ||
tests/test_sfont_zone.c | ||
tests/test_utf8_open.c | ||
tests/test_seqbind_unregister.c | ||
tests/test_sf3_sfont_loading.c | ||
tests/test_sample_cache.c | ||
tests/test_synth_process.c | ||
tests/test_ct2hz.c | ||
tests/test_seq_evt_order.c | ||
tests/test_snprintf.c | ||
tests/test_seq_event_queue_sort.c | ||
tests/test_sfont_loading.c | ||
tests/test_preset_sample_loading.c | ||
tests/test_sfont_unloading.c | ||
tests/test_sample_rate_change.c | ||
tests/test_sample_validate.c | ||
tests/test_synth_chorus_reverb.c | ||
tests/test_bug_635.c | ||
|
||
run_all_tests.c | ||
native-lib.cpp | ||
) | ||
|
||
target_include_directories(native-lib | ||
PRIVATE | ||
../../../../../build_${CMAKE_ANDROID_ARCH_ABI} | ||
../../../../build-scripts/build-artifacts/include | ||
../../../../build-scripts/android-build-root/${CMAKE_ANDROID_ARCH_ABI}/opt/android/include | ||
../../../../build-scripts/android-build-root/${CMAKE_ANDROID_ARCH_ABI}/opt/android/include/glib-2.0 | ||
../../../../build-scripts/android-build-root/${CMAKE_ANDROID_ARCH_ABI}/opt/android/lib/glib-2.0/include | ||
../../../../../src | ||
../../../../../src/bindings | ||
../../../../../src/drivers | ||
../../../../../src/midi | ||
../../../../../src/rvoice | ||
../../../../../src/sfloader | ||
../../../../../src/synth | ||
../../../../../src/utils | ||
../../../../../test | ||
) | ||
|
||
# Searches for a specified prebuilt library and stores the path as a | ||
# variable. Because CMake includes system libraries in the search path by | ||
# default, you only need to specify the name of the public NDK library | ||
# you want to add. CMake verifies that the library exists before | ||
# completing its build. | ||
|
||
find_library( # Sets the name of the path variable. | ||
log-lib | ||
|
||
# Specifies the name of the NDK library that | ||
# you want CMake to locate. | ||
log ) | ||
|
||
|
||
# Specifies libraries CMake should link to your target library. You | ||
# can link multiple libraries, such as libraries you define in this | ||
# build script, prebuilt third-party libraries, or system libraries. | ||
|
||
target_link_directories(native-lib | ||
PRIVATE | ||
../jniLibs/${CMAKE_ANDROID_ARCH_ABI}) | ||
|
||
target_link_libraries(native-lib | ||
${log-lib} | ||
c++_shared | ||
gobject-2.0 | ||
glib-2.0 | ||
sndfile | ||
instpatch-1.0 | ||
OpenSLES | ||
oboe | ||
) |
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 @@ | ||
#include <jni.h> | ||
#include <string> | ||
#include <jni.h> | ||
|
||
extern "C" int run_all_fluidsynth_tests(); | ||
|
||
extern "C" JNIEXPORT void JNICALL Java_org_fluidsynth_fluidsynthtests_TestRunner_00024Companion_runTests(JNIEnv* env, jobject thiz) { | ||
run_all_fluidsynth_tests(); | ||
} |
22 changes: 22 additions & 0 deletions
22
test-android/app/src/main/java/org/fluidsynth/fluidsynthtests/MainActivity.kt
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,22 @@ | ||
package org.fluidsynth.fluidsynthtests | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import org.fluidsynth.fluidsynthtests.databinding.ActivityMainBinding | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding: ActivityMainBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
binding = ActivityMainBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
|
||
TestRunner.runTests() | ||
|
||
// Example of a call to a native method | ||
binding.sampleText.text = "If this shows up then there was no reported test failure!" | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test-android/app/src/main/java/org/fluidsynth/fluidsynthtests/TestRunner.kt
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 @@ | ||
package org.fluidsynth.fluidsynthtests | ||
|
||
class TestRunner { | ||
companion object { | ||
external fun runTests() | ||
init { | ||
System.loadLibrary("native-lib") | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
test-android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml
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,30 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:aapt="http://schemas.android.com/aapt" | ||
android:width="108dp" | ||
android:height="108dp" | ||
android:viewportWidth="108" | ||
android:viewportHeight="108"> | ||
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> | ||
<aapt:attr name="android:fillColor"> | ||
<gradient | ||
android:endX="85.84757" | ||
android:endY="92.4963" | ||
android:startX="42.9492" | ||
android:startY="49.59793" | ||
android:type="linear"> | ||
<item | ||
android:color="#44000000" | ||
android:offset="0.0" /> | ||
<item | ||
android:color="#00000000" | ||
android:offset="1.0" /> | ||
</gradient> | ||
</aapt:attr> | ||
</path> | ||
<path | ||
android:fillColor="#FFFFFF" | ||
android:fillType="nonZero" | ||
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" | ||
android:strokeWidth="1" | ||
android:strokeColor="#00000000" /> | ||
</vector> |
Oops, something went wrong.