1+ # Save as .github/workflows/tests.yml
12name : Unit Tests
23
34on :
@@ -14,49 +15,76 @@ concurrency:
1415 group : unit-tests-${{ github.ref }}
1516 cancel-in-progress : true
1617
18+ env :
19+ # Tag produced by docker/build-trt.bash
20+ IMAGE : sam3-tensorrt:infer
21+
1722jobs :
23+ # This job name is what you select in the branch protection rule.
1824 unit-tests :
19- runs-on : [self-hosted, linux, gpu]
20- timeout-minutes : 60
25+ runs-on : [self-hosted, linux, gpu] # must match --labels used in config.sh
26+ timeout-minutes : 90
2127
28+ # Don't run fork PRs on your own hardware.
2229 if : >-
2330 github.event_name != 'pull_request' ||
2431 github.event.pull_request.head.repo.full_name == github.repository
2532
2633 steps :
2734 - uses : actions/checkout@v4
2835 with :
36+ # Keep sam3trt/build between runs for incremental C++ builds.
2937 clean : false
3038
31- - name : Check GPU and engines
32- run : |
33- nvidia-smi
34- echo "HOME=$HOME"
35- ls -lh "$HOME/models"
36- if ! ls "$HOME"/models/*.engine >/dev/null 2>&1; then
37- echo "::error::No .engine files found in $HOME/models on this runner"
38- exit 1
39- fi
40-
41- # Cpp tests
42- - name : Configure (C++)
43- working-directory : sam3trt
44- run : cmake -S . -B build -DSAM3TRT_BUILD_TESTS=ON -DSAM3TRT_BUILD_ROS=OFF
45-
46- - name : Build (C++)
47- working-directory : sam3trt
48- run : cmake --build build -j"$(nproc)"
49-
50- - name : Run C++ tests
51- working-directory : sam3trt
52- run : ctest --test-dir build --output-on-failure -E Timing
53-
54- # Python tests
55- - name : Install and run Python tests
56- if : ${{ !cancelled() }}
39+ # Same script you use by hand. It must run from inside docker/ (it uses
40+ # `-f Dockerfile.trt .`). Layers are cached, so only the first run is slow.
41+ - name : Build docker image
42+ working-directory : docker
43+ run : ./build-trt.bash
44+
45+ - name : Run unit tests in container
46+ env :
47+ # Engines live on the runner machine (they are not in git).
48+ # Must contain image_encoder_fp16.engine, text_encoder_fp16.engine,
49+ # mask_decoder_fp16.engine.
50+ MODELS_DIR : /home/jason/models
51+ TEST_SCRIPT : |
52+ set -uo pipefail
53+ rc=0
54+
55+ if ! ls "$HOME"/models/*.engine >/dev/null 2>&1; then
56+ echo "::error::No .engine files found in the mounted models dir"
57+ exit 1
58+ fi
59+ nvidia-smi || true
60+
61+ echo "::group::C++ build and tests"
62+ ( cd "$HOME/sam3trt" \
63+ && cmake -S . -B build -DSAM3TRT_BUILD_TESTS=ON -DSAM3TRT_BUILD_ROS=OFF \
64+ && cmake --build build -j"$(nproc)" \
65+ && ctest --test-dir build --output-on-failure -E Timing ) || rc=1
66+ echo "::endgroup::"
67+
68+ echo "::group::Python tests"
69+ ( cd "$HOME" \
70+ && pip install --user --break-system-packages --no-cache-dir ./sam3trtpy \
71+ && cd sam3trtpy \
72+ && python3 -m unittest discover -s tests -v ) || rc=1
73+ echo "::endgroup::"
74+
75+ exit $rc
5776 run : |
58- python3 -m venv --system-site-packages .venv
59- . .venv/bin/activate
60- pip install ./sam3trtpy
61- cd sam3trtpy
62- python3 -m unittest discover -s tests -v
77+ U="$(whoami)"
78+ # Same mounts as docker/run-trt.bash, minus the interactive/X11 parts.
79+ docker run --rm \
80+ --gpus all \
81+ --ipc=host \
82+ --user "$(id -u):$(id -g)" \
83+ -e HOME="/home/$U" \
84+ -e TEST_SCRIPT \
85+ -v "$MODELS_DIR:/home/$U/models" \
86+ -v "$GITHUB_WORKSPACE/sam3trt:/home/$U/sam3trt" \
87+ -v "$GITHUB_WORKSPACE/sam3trtpy:/home/$U/sam3trtpy" \
88+ -w "/home/$U" \
89+ "$IMAGE" \
90+ bash -c "$TEST_SCRIPT"
0 commit comments