Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add docker testing #62

Merged
merged 47 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1ad74c7
initial dockerfile
spion Jan 22, 2023
6e4a069
wip
spion Jan 22, 2023
39381d8
Initial successful test for Android 10 and fuse v1
spion Jan 23, 2023
75d3d9a
initial tests working
spion Jan 24, 2023
7c112ba
wip: add two tests
spion Jan 28, 2023
f13aa8f
try to make workflow work
spion Jan 28, 2023
ac967d5
add priviledged and remove sudo
spion Jan 28, 2023
85cc1ec
fix typo
spion Jan 28, 2023
9aae382
apt-get update first
spion Jan 28, 2023
337a8df
auto-yes apt-get install
spion Jan 28, 2023
3849a81
increase wait time
spion Jan 28, 2023
5bd7245
report last output when emulator not available
spion Jan 28, 2023
490f974
add dependency between buid and test
spion Jan 28, 2023
6c84ad0
show stderr for adb shell ls
spion Jan 28, 2023
4f09f5f
verbose errors
spion Jan 28, 2023
8b8e11d
do not run emulator in github actions
spion Jan 28, 2023
4aae834
not sure what is going on, investigating
spion Jan 28, 2023
9c20543
continued
spion Jan 28, 2023
f144e92
more diagnostics
spion Jan 28, 2023
6e72144
run with the right home directory
spion Jan 28, 2023
12b15fc
try macos latest for virtualization
spion Jan 29, 2023
5f709cd
fix: retention days and back to ubuntu runner
spion Aug 11, 2024
be8bcd9
chore: try ubuntu-latest
spion Aug 11, 2024
e30542c
fix: also run build on ubuntu-latest
spion Aug 11, 2024
ef51616
chore: try running without priviledged flag
spion Aug 11, 2024
f9ea09b
chore: try the newer docker-android tag scheme
spion Aug 11, 2024
085a0ae
fix: typo
spion Aug 11, 2024
e89d325
fix: use latest action versions
spion Aug 11, 2024
90aa9dd
fix: use sudo in docker-android image
spion Aug 11, 2024
8bdc243
fix: sudo the tests too
spion Aug 11, 2024
93f67e7
chore: try android-emulator-runner action instead
spion Aug 12, 2024
60da010
fix: kvm not kv
spion Aug 12, 2024
ffd15ec
fix: use actual script
spion Aug 12, 2024
92f5eb5
copy adbfs to right location and run as root
spion Aug 12, 2024
8a8503e
use sudo to copy the binary
spion Aug 12, 2024
128cab5
fix: wait_available /sdcard only
spion Aug 12, 2024
86be4cf
try root dir and list devices
spion Aug 12, 2024
50887a1
chore: add platform-tools to path
spion Aug 12, 2024
84e318a
fix: make it executable
spion Aug 12, 2024
04c458e
chore: cleanup
spion Aug 18, 2024
c9641c3
chore: work around poor multiline script behavior
spion Aug 18, 2024
4bcdec7
use env
spion Aug 18, 2024
c266959
feat: add AVD snapshot generation
spion Aug 18, 2024
21bcdf9
feat: add a decent coverage range
spion Aug 18, 2024
1fc5bc1
chore: do not fail fast
spion Aug 18, 2024
aa6f6a2
fix: reduce range of api-levels
spion Aug 18, 2024
ba3c576
fix: back to a single api-level
spion Aug 19, 2024
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
68 changes: 64 additions & 4 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,72 @@ on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: build-deps
run: sudo apt-get install libfuse-dev
run: sudo apt-get -y install libfuse-dev
- name: make
run: make

- name: copy-binary
uses: actions/upload-artifact@v4
with:
name: adbfs-bin
retention-days: 5
path: |
./adbfs
test:
needs: build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
api-level: [29]

steps:
- uses: actions/checkout@v4
- name: prepare
run: sudo apt-get update && sudo apt-get install -y fuse libfuse-dev
- name: get-adbfs-binary
uses: actions/download-artifact@v4
with:
name: adbfs-bin
- name: copy adbfs binary
run: |
sudo cp ${{ github.workspace }}/adbfs /usr/bin/adbfs
sudo chmod +x /usr/bin/adbfs
- name: Enable KVM
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm

- name: AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}

- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."


- name: run tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
script: sudo env PATH=/usr/local/lib/android/sdk/platform-tools:$PATH ./tests/run.sh
28 changes: 28 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM ubuntu:latest as buildenv
RUN apt update
RUN apt install -y build-essential git pkg-config
RUN apt install -y libfuse-dev fuse
ADD ./* /src/
WORKDIR /src
RUN make


FROM us-docker.pkg.dev/android-emulator-268719/images/30-google-x64:30.1.2
# FROM docker.io/budtmo/docker-android:emulator_12.0
# RUN apt update

# RUN apt install -y fuse libfuse-dev

# ADD ./* /src/
ADD ./tests/* /src/tests/
ADD ./docker/* /src/docker/

RUN chmod +x /src/docker/*.sh

COPY --from=buildenv /src/adbfs /usr/bin/adbfs
RUN chmod +x /usr/bin/adbfs

WORKDIR /src
# CMD /src/docker/run-docker-test.sh
ENTRYPOINT [ "sudo", "bash", "/src/docker/run-test.sh" ]
# ENTRYPOINT [ "bash" ]
12 changes: 12 additions & 0 deletions docker/run-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

export SCRIPT_PATH="docker-android"
export WORK_PATH="/home/androidusr"
export APP_PATH=${WORK_PATH}/${SCRIPT_PATH}
export LOG_PATH=${WORK_PATH}/logs
export SUPERVISORD_CONFIG_PATH="${APP_PATH}/mixins/configs/process"
export DEVICE_TYPE=emulator

/usr/bin/supervisord --configuration ${SUPERVISORD_CONFIG_PATH}/supervisord-port.conf & \
/usr/bin/supervisord --configuration ${SUPERVISORD_CONFIG_PATH}/supervisord-base.conf & \

bash $(dirname $0)/../tests/run.sh
153 changes: 153 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/bin/bash

# echo Running supervisord in the background
# cd /root || exit

# SUPERVISORD_CONFIG_PATH="${APP_PATH}/mixins/configs/process"
# /usr/bin/supervisord --configuration ${SUPERVISORD_CONFIG_PATH}/supervisord-port.conf & \
# /usr/bin/supervisord --configuration ${SUPERVISORD_CONFIG_PATH}/supervisord-base.conf & \

WAIT_TIME=60


wait_available() {

RETRIES=$WAIT_TIME
WAIT_DIR="$1"

while [ $RETRIES -gt 0 ];
do
RETRIES=$((RETRIES - 1))

OUTPUT=$(adb shell ls -d "$WAIT_DIR" 2> /dev/null)

if [ "$OUTPUT" == "$WAIT_DIR" ]
then
break;
fi
sleep 1

done

if [ $RETRIES -le 0 ]
then
echo "Emulator directory $1 was not available for $WAIT_TIME seconds, exiting"
echo "Last output was: $OUTPUT"
echo ""
# echo "Logs for docker-appium were (stdout)"
# echo ""
# cat /var/log/supervisor/docker-android.stdout.log
# echo ""
# echo "stderr"
# echo ""
# cat /var/log/supervisor/docker-android.stderr.log
exit 1
fi

}

echo Checking readiness via adb shell ls -d /sdcard/Android
adb devices
wait_available /


mkdir -p /adbfs
adbfs /adbfs

echo Ready to run adbfs tests

BASE_DIR=/adbfs/sdcard/test

test_mkdir() {

local_timestamp=$(date "+%s")

mkdir "$BASE_DIR/x"
output=$(ls -lad --time-style="+%s" "$BASE_DIR/x")

timestamp=$(echo $output | cut -d' ' -f 6)
path=$(echo $output | cut -d' ' -f 7)

timestamp_diff=$((local_timestamp - timestamp))
abs_diff=${timestamp_diff#-}

if [ "$abs_diff" -gt 120 ];
then
echo "FAIL test_mkdir: file timestamp difference exceeds 120s: $abs_diff"
exit 1
fi

if [ "$path" != "$BASE_DIR/x" ];
then
echo "FAIL test_mkdir: unexpected path"
exit 1
fi

echo "PASS test_mkdir"
}


test_catfile() {

local_timestamp=$(date "+%s")

desired_content="Hello world"

echo "$desired_content" > "$BASE_DIR/file.txt"

output=$(ls -lad --time-style="+%s" "$BASE_DIR/file.txt")

timestamp=$(echo $output | cut -d' ' -f 6)
path=$(echo $output | cut -d' ' -f 7)

timestamp_diff=$((local_timestamp - timestamp))
abs_diff=${timestamp_diff#-}

if [ "$abs_diff" -gt 120 ];
then
echo "FAIL test_catfile: file timestamp difference exceeds 120s: $abs_diff"
exit 1
fi

if [ "$path" != "$BASE_DIR/file.txt" ];
then
echo "FAIL test_catfile: unexpected path"
exit 1
fi

file_contents=$(cat $BASE_DIR/file.txt)

if [ "$file_contents" != "Hello world" ]
then
echo "FAIL test_catfile: unexpected content: $file_contents"
echo "Expected: $desired_content"
exit 1
fi

echo "PASS test_catfile"
}



mkdir "$BASE_DIR"

test_mkdir
test_catfile

# todo

# copy file with cp -a (archive, preserve timestamps)

# read a directory

# touch to update time

# copy preserving timestamps

rm -rf "$BASE_DIR"



# rsync, both directions (compared against rsync of the very same tree on a "pure local" FS).
# ompared to adb push --sync as well maybe