Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/public_github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,53 @@ jobs:
cmake .. ${{ matrix.cmake_arguments }}
cmake --build . --config ${{ matrix.Build_type }}
ctest --verbose -C ${{ matrix.Build_type }}

aarch64_android_cmake_build_test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Install dependencies
run: |
export HOMEBREW_NO_AUTO_UPDATE=1
brew install cmake wabt

- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "17"

- name: Setup Android SDK
run: |
set -ex
brew install --cask android-commandlinetools
echo "ANDROID_SDK_ROOT=$(brew --prefix)/share/android-commandlinetools" >> $GITHUB_ENV
echo "ANDROID_HOME=$(brew --prefix)/share/android-commandlinetools" >> $GITHUB_ENV

- name: Accept Android SDK licenses
run: |
yes | $ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --licenses

- name: Install Android NDK and emulator
run: |
$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/sdkmanager --install "ndk;27.2.12479018" "emulator" "platform-tools" "system-images;android-35;google_apis;arm64-v8a"
echo "ANDROID_NDK_HOME=$ANDROID_SDK_ROOT/ndk/27.2.12479018" >> $GITHUB_ENV

- name: Create Android virtual device
run: |
$ANDROID_SDK_ROOT/cmdline-tools/latest/bin/avdmanager create avd -n arm64_emulator -k "system-images;android-35;google_apis;arm64-v8a" -d "pixel_6"

- name: gen testcase
run: python3 tests/spectest.py

- name: Build for Android
run: |
cmake -DVB_ENABLE_DEV_FEATURE=OFF -DENABLE_SPECTEST=1 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_PLATFORM=android-35 -B build_android
cmake --build build_android --parallel

- name: Run Android tests
run: |
python3 ./scripts/android/android_test.py --avd arm64_emulator
45 changes: 35 additions & 10 deletions scripts/android/android_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,32 @@ def setup_logging(debug=False):
)


def get_android_sdk_root():
"""Get the Android SDK root path from environment variables."""
sdk_root = os.environ.get(
"ANDROID_SDK_ROOT") or os.environ.get("ANDROID_HOME")
if not sdk_root:
sdk_root = "/opt/android-sdk"
logging.info(
f"ANDROID_SDK_ROOT/ANDROID_HOME not set, using default path: {sdk_root}")
return sdk_root


def get_emulator_path():
"""Get the path to the Android emulator executable."""
return os.path.join(get_android_sdk_root(), "emulator", "emulator")


def get_adb_path():
"""Get the path to the adb executable."""
return os.path.join(get_android_sdk_root(), "platform-tools", "adb")


def launch_emulator(avd_name="x86_64_emulator"):
"""Launch the Android emulator"""
logging.info("Starting Android emulator...")
emulator_cmd = [
"/opt/android-sdk/emulator/emulator",
get_emulator_path(),
"-avd",
avd_name,
"-no-audio",
Expand All @@ -58,11 +79,12 @@ def launch_emulator(avd_name="x86_64_emulator"):
def is_emulator_ready(timeout=180, check_interval=5):
"""Check if the emulator is running and ready."""
logging.info("Checking if emulator is ready...")
adb = get_adb_path()

# First wait for device to be detected
try:
subprocess.run(
["/opt/android-sdk/platform-tools/adb", "wait-for-device"],
[adb, "wait-for-device"],
check=True,
timeout=timeout,
)
Expand All @@ -76,7 +98,7 @@ def is_emulator_ready(timeout=180, check_interval=5):
try:
result = subprocess.run(
[
"/opt/android-sdk/platform-tools/adb",
adb,
"shell",
"getprop",
"sys.boot_completed",
Expand All @@ -103,11 +125,12 @@ def is_emulator_ready(timeout=180, check_interval=5):

def run_tests():
"""Run the spectest on the emulator."""
adb = get_adb_path()
try:
logging.info("Pushing test binary to the emulator...")
subprocess.run(
[
"/opt/android-sdk/platform-tools/adb",
adb,
"push",
"./build_android/bin/vb_spectest_json",
"/tmp",
Expand All @@ -118,7 +141,7 @@ def run_tests():
logging.info("Pushing test cases to the emulator...")
subprocess.run(
[
"/opt/android-sdk/platform-tools/adb",
adb,
"push",
"./tests/testcases.json",
"/tmp",
Expand All @@ -129,7 +152,7 @@ def run_tests():
# Make the binary executable
subprocess.run(
[
"/opt/android-sdk/platform-tools/adb",
adb,
"shell",
"chmod +x /tmp/vb_spectest_json",
],
Expand All @@ -139,7 +162,7 @@ def run_tests():
logging.info("Running tests on the emulator...")
process = subprocess.Popen(
[
"/opt/android-sdk/platform-tools/adb",
adb,
"shell",
"/tmp/vb_spectest_json",
"/tmp/testcases.json",
Expand All @@ -157,14 +180,16 @@ def run_tests():


def parse_args():
parser = argparse.ArgumentParser(description="Run Android tests in emulator")
parser = argparse.ArgumentParser(
description="Run Android tests in emulator")
parser.add_argument(
"--avd", default="x86_64_emulator", help="Name of the AVD to use"
)
parser.add_argument(
"--timeout", type=int, default=180, help="Timeout for emulator boot in seconds"
)
parser.add_argument("--debug", action="store_true", help="Enable debug logging")
parser.add_argument("--debug", action="store_true",
help="Enable debug logging")
return parser.parse_args()


Expand All @@ -187,7 +212,7 @@ def main():
# Kill the emulator before exiting
logging.info("Shutting down the emulator...")
subprocess.run(
["/opt/android-sdk/platform-tools/adb", "emu", "kill"], check=False
[get_adb_path(), "emu", "kill"], check=False
)

# Return test result
Expand Down
Loading