Skip to content

Commit 297a7b3

Browse files
authored
Merge pull request #62 from spion/feat/add-docker-testing
feat: add docker testing
2 parents fd56381 + ba3c576 commit 297a7b3

File tree

4 files changed

+257
-4
lines changed

4 files changed

+257
-4
lines changed

.github/workflows/ccpp.yml

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,72 @@ on: [push]
44

55
jobs:
66
build:
7-
87
runs-on: ubuntu-latest
9-
108
steps:
11-
- uses: actions/checkout@v2
9+
- uses: actions/checkout@v4
1210
- name: build-deps
13-
run: sudo apt-get install libfuse-dev
11+
run: sudo apt-get -y install libfuse-dev
1412
- name: make
1513
run: make
14+
15+
- name: copy-binary
16+
uses: actions/upload-artifact@v4
17+
with:
18+
name: adbfs-bin
19+
retention-days: 5
20+
path: |
21+
./adbfs
22+
test:
23+
needs: build
24+
runs-on: ubuntu-latest
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
api-level: [29]
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
- name: prepare
33+
run: sudo apt-get update && sudo apt-get install -y fuse libfuse-dev
34+
- name: get-adbfs-binary
35+
uses: actions/download-artifact@v4
36+
with:
37+
name: adbfs-bin
38+
- name: copy adbfs binary
39+
run: |
40+
sudo cp ${{ github.workspace }}/adbfs /usr/bin/adbfs
41+
sudo chmod +x /usr/bin/adbfs
42+
- name: Enable KVM
43+
run: |
44+
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
45+
sudo udevadm control --reload-rules
46+
sudo udevadm trigger --name-match=kvm
47+
48+
- name: AVD cache
49+
uses: actions/cache@v4
50+
id: avd-cache
51+
with:
52+
path: |
53+
~/.android/avd/*
54+
~/.android/adb*
55+
key: avd-${{ matrix.api-level }}
56+
57+
- name: create AVD and generate snapshot for caching
58+
if: steps.avd-cache.outputs.cache-hit != 'true'
59+
uses: reactivecircus/android-emulator-runner@v2
60+
with:
61+
api-level: ${{ matrix.api-level }}
62+
force-avd-creation: false
63+
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
64+
disable-animations: false
65+
script: echo "Generated AVD snapshot for caching."
66+
67+
68+
- name: run tests
69+
uses: reactivecircus/android-emulator-runner@v2
70+
with:
71+
api-level: ${{ matrix.api-level }}
72+
force-avd-creation: false
73+
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
74+
disable-animations: true
75+
script: sudo env PATH=/usr/local/lib/android/sdk/platform-tools:$PATH ./tests/run.sh

docker/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM ubuntu:latest as buildenv
2+
RUN apt update
3+
RUN apt install -y build-essential git pkg-config
4+
RUN apt install -y libfuse-dev fuse
5+
ADD ./* /src/
6+
WORKDIR /src
7+
RUN make
8+
9+
10+
FROM us-docker.pkg.dev/android-emulator-268719/images/30-google-x64:30.1.2
11+
# FROM docker.io/budtmo/docker-android:emulator_12.0
12+
# RUN apt update
13+
14+
# RUN apt install -y fuse libfuse-dev
15+
16+
# ADD ./* /src/
17+
ADD ./tests/* /src/tests/
18+
ADD ./docker/* /src/docker/
19+
20+
RUN chmod +x /src/docker/*.sh
21+
22+
COPY --from=buildenv /src/adbfs /usr/bin/adbfs
23+
RUN chmod +x /usr/bin/adbfs
24+
25+
WORKDIR /src
26+
# CMD /src/docker/run-docker-test.sh
27+
ENTRYPOINT [ "sudo", "bash", "/src/docker/run-test.sh" ]
28+
# ENTRYPOINT [ "bash" ]

docker/run-test.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
export SCRIPT_PATH="docker-android"
3+
export WORK_PATH="/home/androidusr"
4+
export APP_PATH=${WORK_PATH}/${SCRIPT_PATH}
5+
export LOG_PATH=${WORK_PATH}/logs
6+
export SUPERVISORD_CONFIG_PATH="${APP_PATH}/mixins/configs/process"
7+
export DEVICE_TYPE=emulator
8+
9+
/usr/bin/supervisord --configuration ${SUPERVISORD_CONFIG_PATH}/supervisord-port.conf & \
10+
/usr/bin/supervisord --configuration ${SUPERVISORD_CONFIG_PATH}/supervisord-base.conf & \
11+
12+
bash $(dirname $0)/../tests/run.sh

tests/run.sh

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/bin/bash
2+
3+
# echo Running supervisord in the background
4+
# cd /root || exit
5+
6+
# SUPERVISORD_CONFIG_PATH="${APP_PATH}/mixins/configs/process"
7+
# /usr/bin/supervisord --configuration ${SUPERVISORD_CONFIG_PATH}/supervisord-port.conf & \
8+
# /usr/bin/supervisord --configuration ${SUPERVISORD_CONFIG_PATH}/supervisord-base.conf & \
9+
10+
WAIT_TIME=60
11+
12+
13+
wait_available() {
14+
15+
RETRIES=$WAIT_TIME
16+
WAIT_DIR="$1"
17+
18+
while [ $RETRIES -gt 0 ];
19+
do
20+
RETRIES=$((RETRIES - 1))
21+
22+
OUTPUT=$(adb shell ls -d "$WAIT_DIR" 2> /dev/null)
23+
24+
if [ "$OUTPUT" == "$WAIT_DIR" ]
25+
then
26+
break;
27+
fi
28+
sleep 1
29+
30+
done
31+
32+
if [ $RETRIES -le 0 ]
33+
then
34+
echo "Emulator directory $1 was not available for $WAIT_TIME seconds, exiting"
35+
echo "Last output was: $OUTPUT"
36+
echo ""
37+
# echo "Logs for docker-appium were (stdout)"
38+
# echo ""
39+
# cat /var/log/supervisor/docker-android.stdout.log
40+
# echo ""
41+
# echo "stderr"
42+
# echo ""
43+
# cat /var/log/supervisor/docker-android.stderr.log
44+
exit 1
45+
fi
46+
47+
}
48+
49+
echo Checking readiness via adb shell ls -d /sdcard/Android
50+
adb devices
51+
wait_available /
52+
53+
54+
mkdir -p /adbfs
55+
adbfs /adbfs
56+
57+
echo Ready to run adbfs tests
58+
59+
BASE_DIR=/adbfs/sdcard/test
60+
61+
test_mkdir() {
62+
63+
local_timestamp=$(date "+%s")
64+
65+
mkdir "$BASE_DIR/x"
66+
output=$(ls -lad --time-style="+%s" "$BASE_DIR/x")
67+
68+
timestamp=$(echo $output | cut -d' ' -f 6)
69+
path=$(echo $output | cut -d' ' -f 7)
70+
71+
timestamp_diff=$((local_timestamp - timestamp))
72+
abs_diff=${timestamp_diff#-}
73+
74+
if [ "$abs_diff" -gt 120 ];
75+
then
76+
echo "FAIL test_mkdir: file timestamp difference exceeds 120s: $abs_diff"
77+
exit 1
78+
fi
79+
80+
if [ "$path" != "$BASE_DIR/x" ];
81+
then
82+
echo "FAIL test_mkdir: unexpected path"
83+
exit 1
84+
fi
85+
86+
echo "PASS test_mkdir"
87+
}
88+
89+
90+
test_catfile() {
91+
92+
local_timestamp=$(date "+%s")
93+
94+
desired_content="Hello world"
95+
96+
echo "$desired_content" > "$BASE_DIR/file.txt"
97+
98+
output=$(ls -lad --time-style="+%s" "$BASE_DIR/file.txt")
99+
100+
timestamp=$(echo $output | cut -d' ' -f 6)
101+
path=$(echo $output | cut -d' ' -f 7)
102+
103+
timestamp_diff=$((local_timestamp - timestamp))
104+
abs_diff=${timestamp_diff#-}
105+
106+
if [ "$abs_diff" -gt 120 ];
107+
then
108+
echo "FAIL test_catfile: file timestamp difference exceeds 120s: $abs_diff"
109+
exit 1
110+
fi
111+
112+
if [ "$path" != "$BASE_DIR/file.txt" ];
113+
then
114+
echo "FAIL test_catfile: unexpected path"
115+
exit 1
116+
fi
117+
118+
file_contents=$(cat $BASE_DIR/file.txt)
119+
120+
if [ "$file_contents" != "Hello world" ]
121+
then
122+
echo "FAIL test_catfile: unexpected content: $file_contents"
123+
echo "Expected: $desired_content"
124+
exit 1
125+
fi
126+
127+
echo "PASS test_catfile"
128+
}
129+
130+
131+
132+
mkdir "$BASE_DIR"
133+
134+
test_mkdir
135+
test_catfile
136+
137+
# todo
138+
139+
# copy file with cp -a (archive, preserve timestamps)
140+
141+
# read a directory
142+
143+
# touch to update time
144+
145+
# copy preserving timestamps
146+
147+
rm -rf "$BASE_DIR"
148+
149+
150+
151+
# rsync, both directions (compared against rsync of the very same tree on a "pure local" FS).
152+
# ompared to adb push --sync as well maybe
153+

0 commit comments

Comments
 (0)