Skip to content

Commit

Permalink
Merge pull request #62 from spion/feat/add-docker-testing
Browse files Browse the repository at this point in the history
feat: add docker testing
  • Loading branch information
spion authored Aug 27, 2024
2 parents fd56381 + ba3c576 commit 297a7b3
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 4 deletions.
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

0 comments on commit 297a7b3

Please sign in to comment.