From e1e60cb07a3279ecc9b22edaca2b1b4428013ed8 Mon Sep 17 00:00:00 2001 From: Alexander Sosedkin Date: Thu, 13 Jun 2024 20:54:52 +0200 Subject: [PATCH] fixup emulator-based tests --- .github/workflows/emulator.yml | 29 +++++---------- ...tstrap-channel.py => bootstrap_channel.py} | 6 +-- ...ootstrap-flakes.py => bootstrap_flakes.py} | 11 +++--- tests/emulator/common.py | 2 +- ...{on-device-tests.py => on_device_tests.py} | 0 tests/emulator/test_channel_shell.py | 37 +++++++++++++++++++ tests/emulator/test_channel_uiautomator.py | 7 ++++ 7 files changed, 63 insertions(+), 29 deletions(-) rename tests/emulator/{bootstrap-channel.py => bootstrap_channel.py} (89%) rename tests/emulator/{bootstrap-flakes.py => bootstrap_flakes.py} (76%) rename tests/emulator/{on-device-tests.py => on_device_tests.py} (100%) create mode 100644 tests/emulator/test_channel_shell.py create mode 100644 tests/emulator/test_channel_uiautomator.py diff --git a/.github/workflows/emulator.yml b/.github/workflows/emulator.yml index 2c1ee516..621b533a 100644 --- a/.github/workflows/emulator.yml +++ b/.github/workflows/emulator.yml @@ -6,13 +6,13 @@ on: - cron: 0 0 * * 1 jobs: - emulator: + emulate: runs-on: ubuntu-latest strategy: matrix: api-level: [29] - way: [flakes, channel] + way: [bootstrap_flakes, test_channel_uiautomator, test_channel_shell] steps: - name: Checkout repository @@ -27,6 +27,9 @@ jobs: name: nix-on-droid signingKey: "${{ secrets.CACHIX_SIGNING_KEY }}" + - name: Build droidctl + run: nix build 'github:t184256/droidctl' + - name: Configure AVD cache uses: actions/cache@v4 id: avd-cache @@ -46,29 +49,15 @@ jobs: disable-animations: false script: echo "Generated AVD snapshot for caching." - - name: Test using channels api-level=${{ matrix.api-level }} - if: ${{ matrix.way == 'channel' }} - uses: reactivecircus/android-emulator-runner@v2 - with: - target: default - api-level: ${{ matrix.api-level }} - arch: x86_64 - script: | - pushd tests/emulator - nix run . -- run bootstrap-channel.py - nix run . -- run on-device-tests.py - popd - - - name: Bootstrap using flakes api-level=${{ matrix.api-level }} - if: ${{ matrix.way == 'flakes' }} + - name: Test way=${{ matrix.way}} api-level=${{ matrix.api-level }} uses: reactivecircus/android-emulator-runner@v2 with: target: default api-level: ${{ matrix.api-level }} arch: x86_64 - script: | - pushd tests/emulator - nix run . -- run bootstrap-flakes.py + script: > + pushd tests/emulator && + nix run 'github:t184256/droidctl' -- run ${{ matrix.way }}.py && popd # TODO: push to cachix from device diff --git a/tests/emulator/bootstrap-channel.py b/tests/emulator/bootstrap_channel.py similarity index 89% rename from tests/emulator/bootstrap-channel.py rename to tests/emulator/bootstrap_channel.py index 91502e02..bbead4d2 100644 --- a/tests/emulator/bootstrap-channel.py +++ b/tests/emulator/bootstrap_channel.py @@ -17,11 +17,11 @@ def run(d): wait_for(d, 'Installing and updating nix-channels...') wait_for(d, 'unpacking channels...') - wait_for(d, 'Installing first Nix-on-Droid generation...', timeout=180) + wait_for(d, 'Installing first Nix-on-Droid generation...', timeout=600) wait_for(d, 'Copying default Nix-on-Droid config...', timeout=180) wait_for(d, 'Congratulations!') - wait_for(d, 'See config file for further information!') - wait_for(d, 'bash-5.25$') + wait_for(d, 'See config file for further information.') + wait_for(d, 'bash-5.2$') d('input text "echo smoke-test | base64"') # remove d.ui.press('enter') diff --git a/tests/emulator/bootstrap-flakes.py b/tests/emulator/bootstrap_flakes.py similarity index 76% rename from tests/emulator/bootstrap-flakes.py rename to tests/emulator/bootstrap_flakes.py index 24336f85..68663d4b 100644 --- a/tests/emulator/bootstrap-flakes.py +++ b/tests/emulator/bootstrap_flakes.py @@ -12,16 +12,17 @@ def run(d): wait_for(d, 'Welcome to Nix-on-Droid!') wait_for(d, 'Do you want to set it up with flakes? (y/N)') - d('input text y') # remove + d('input text y') d.ui.press('enter') wait_for(d, 'Setting up Nix-on-Droid with flakes...') - ... - wait_for(d, 'Installing first Nix-on-Droid generation...', timeout=180) + wait_for(d, 'Installing flake from default template...') + wait_for(d, 'Overriding input urls / arch in flake...') + wait_for(d, 'Installing first Nix-on-Droid generation...', timeout=600) wait_for(d, 'Copying default Nix-on-Droid config...', timeout=180) wait_for(d, 'Congratulations!') - wait_for(d, 'See config file for further information!') - wait_for(d, 'bash-5.25$') + wait_for(d, 'See config file for further information.') + wait_for(d, 'bash-5.2$') d('input text "echo smoke-test | base64"') # remove d.ui.press('enter') diff --git a/tests/emulator/common.py b/tests/emulator/common.py index 749ae972..daa433f3 100644 --- a/tests/emulator/common.py +++ b/tests/emulator/common.py @@ -3,7 +3,7 @@ SERVER = 'https://nix-on-droid.unboiled.info' APK = f'{SERVER}/com.termux.nix_188035-x86_64.apk' -BOOTSTRAP_URL = f'{SERVER}/testing' +BOOTSTRAP_URL = f'{SERVER}/bootstrap-testing' def wait_for(d, on_screen_text, timeout=30, critical=True): diff --git a/tests/emulator/on-device-tests.py b/tests/emulator/on_device_tests.py similarity index 100% rename from tests/emulator/on-device-tests.py rename to tests/emulator/on_device_tests.py diff --git a/tests/emulator/test_channel_shell.py b/tests/emulator/test_channel_shell.py new file mode 100644 index 00000000..86b83e29 --- /dev/null +++ b/tests/emulator/test_channel_shell.py @@ -0,0 +1,37 @@ +import bootstrap_channel +import subprocess + +from common import wait_for + +TD = '/data/data/com.termux.nix/files/usr/home/.cache/nix-on-droid-self-test' + + +def run(d): + #bootstrap_channel.run(d) + + d('input text "exit"') # remove + d.ui.press('enter') + + nod = d.app('com.termux.nix') + nod.launch() + + wait_for(d, 'bash-5.2$') + + # run tests in a way that'd display progress in CI + user = d.su('stat -c %U /data/data/com.termux.nix').output.strip() + # WARNING: assumes `su 0` style `su` that doesn't support -c from now on + print(f'{user=}') + for cmd in [ + 'id', + f'mkdir -p {TD}', + f'touch {TD}/confirmation-granted', + ('/data/data/com.termux.nix/files/usr/bin/login echo test'), + ('/data/data/com.termux.nix/files/usr/bin/login id'), + ('cd /data/data/com.termux.nix/files/home; ' + 'pwd; ' + 'id; ' + '/data/data/com.termux.nix/files/usr/bin/login ' + ' nix-on-droid on-device-test') + ]: + subprocess.run(['adb', 'shell', 'su', '0', 'su', user, + 'sh', '-c', cmd]) diff --git a/tests/emulator/test_channel_uiautomator.py b/tests/emulator/test_channel_uiautomator.py new file mode 100644 index 00000000..d76cee0a --- /dev/null +++ b/tests/emulator/test_channel_uiautomator.py @@ -0,0 +1,7 @@ +import bootstrap_channel +import on_device_tests + + +def run(d): + bootstrap_channel.run(d) + on_device_tests.run(d)