Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
PR #1733: ch-test: make force-auto its own phase
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaudill authored Oct 24, 2023
1 parent 88a47f8 commit d11e859
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 9 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,20 +393,39 @@ jobs:
- name: run test suite (Git WD, standard)
run: |
bin/ch-test all
# Validate that “rootemu” test phase didn’t run (skipped by default
# on standard scope).
[[ $(cat /tmp/ch-test.tmp.$USER/rootemu) = no ]]
- name: run root emulation phase
if: ${{ matrix.builder == 'ch-image'
&& matrix.pack_fmt == 'squash-mount'
&& matrix.cache == 'enabled' }}
run: |
# We only really need to run the root emulation tests once in CI.
# ch-image with an enabled cache is required for these unit tests.
# Since all CI tests that use ch-image with an enabled cache take
# roughly the same amount of time, we arbitrarily chose squash-mount
# as the pack format.
bin/ch-test rootemu
# Validate that “rootemu” test phase ran.
[[ $(cat /tmp/ch-test.tmp.$USER/rootemu) = yes ]]
- name: run test suite (installed from Git WD, standard)
if: ${{ matrix.builder == 'ch-image'
&& matrix.pack_fmt == 'squash-mount'
&& matrix.cache == 'enabled' }}
run: |
$ch_prefix/from-git/bin/ch-test all
[[ $(cat /tmp/ch-test.tmp.$USER/rootemu) = no ]]
- name: run test suite (installed from tarball, standard)
if: ${{ matrix.builder == 'ch-image'
&& matrix.pack_fmt == 'squash-mount'
&& matrix.cache == 'enabled' }}
run: |
$ch_prefix/from-tarball/bin/ch-test all
[[ $(cat /tmp/ch-test.tmp.$USER/rootemu) = no ]]
- name: uninstall from tarball
if: ${{ matrix.keep_sudo }}
Expand Down Expand Up @@ -448,6 +467,7 @@ jobs:
if: ${{ matrix.builder == 'docker' }}
run: |
bin/ch-test all
[[ $(cat /tmp/ch-test.tmp.$USER/rootemu) = no ]]
- name: remove non-essential dependencies
if: ${{ matrix.builder == 'docker' }}
Expand Down Expand Up @@ -486,6 +506,7 @@ jobs:
if: ${{ matrix.builder == 'docker' }}
run: |
bin/ch-test all
[[ $(cat /tmp/ch-test.tmp.$USER/rootemu) = no ]]
- name: print ending environment
if: ${{ always() }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ a.out
/lib/version.py
/lib/version.sh
/lib/version.txt
/test/build/61_force-auto.bats
/test/force-auto.bats
/test/docs-sane
/test/fixtures/symlink-to-tmp
/test/force-auto
Expand Down
28 changes: 26 additions & 2 deletions bin/ch-test
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Usage:
$ $(basename "$0") [PHASE] [--scope SCOPE] [--pack-fmt FMT] [OPTIONS]
Valid phases: build, build-images, run, examples, all, mk-perm-dirs, clean,
Valid phases: build-images, build, rootemu, run, examples, all, most, mk-perm-dirs, clean,
rm-perm-dirs
Valid scopes: quick, standard, full
Valid pack formats: squash-mount, tar-unpack, squash-unpack
Expand Down Expand Up @@ -662,6 +662,16 @@ test_one_file () {
bats "$one_file"
}

test_rootemu () {
if command -v ch-image > /dev/null 2>&1; then
bats force-auto.bats
echo yes > "$TMP_/rootemu"
elif [[ -n "$1" ]]; then
printf "error: ch-image required, not found\n"
exit 1
fi
}

test_run () {
echo 'executing run phase tests ...'
if [[ ! -f ${TMP_}/run_auto.bats ]]; then
Expand Down Expand Up @@ -761,6 +771,9 @@ if [[ ! -d $TMP_ ]]; then
chmod 700 "$TMP_"
fi

# Record that we haven’t (yet) run the “rootemu” tests
echo no > "$TMP_/rootemu"

# Find test directories. Note some of this gets rewritten at install time.
CHTEST_DIR=${ch_base}/test
CHTEST_EXAMPLES_DIR=${ch_base}/examples
Expand Down Expand Up @@ -799,7 +812,7 @@ fi
while [[ $# -gt 0 ]]; do
opt=$1; shift
case $opt in
all|build|build-images|clean|examples|mk-perm-dirs|rm-perm-dirs|run)
all|build|build-images|clean|examples|mk-perm-dirs|rm-perm-dirs|rootemu|run)
require_unset phase
phase=$opt
;;
Expand Down Expand Up @@ -1118,6 +1131,14 @@ case $phase in
test_build_images
test_build

phase=rootemu
if [[ "$scope" != "full" ]]; then
echo "skipping root emulation tests (full scope only)"
else
echo 'executing root emulation tests...'
test_rootemu
fi

phase=run
dir_img_mk
dir_tar_check
Expand Down Expand Up @@ -1180,6 +1201,9 @@ case $phase in
dir_perm_rm "$d"
done
;;
rootemu)
test_rootemu optional # ch-image optional
;;
run)
dir_img_mk
test_make
Expand Down
8 changes: 6 additions & 2 deletions doc/ch-test.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,17 @@ allows trading off thoroughness versus time.
images directory produced by a successful :code:`build` phase, which can
be copied from the build system if it’s not also the run system.

:code:`rootemu`
Test the root emulation modes (:code:`seccomp`, :code:`fakeroot`, and
:code:`none`) on various linux distributions.

:code:`examples`
Example applications. Requires an unpacked images directory produced by a
successful :code:`run` phase.

:code:`all`
Execute phases :code:`build`, :code:`run`, and :code:`examples`, in that
order.
Execute phases :code:`build`, :code:`rootemu`, :code:`run`, and
:code:`examples`, in that order.

:code:`mk-perm-dirs`
Create the filesystem permissions directories. Requires
Expand Down
6 changes: 3 additions & 3 deletions test/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ sotest/sotest

CLEANFILES = $(sobuilts) \
docs-sane force-auto make-perms-test \
build/61_force-auto.bats
force-auto.bats

if ENABLE_TEST
nobase_test_DATA = $(testfiles)
nobase_test_SCRIPTS = $(testfiles_exec)
nobase_nodist_test_SCRIPTS = $(sobuilts)
if ENABLE_CH_IMAGE # this means we have Python
nobase_test_DATA += build/61_force-auto.bats
build/61_force-auto.bats: force-auto
nobase_test_DATA += force-auto.bats
force-auto.bats: force-auto
./$< > $@
endif
# See comment about symlinks in examples/Makefile.am.
Expand Down
1 change: 1 addition & 0 deletions test/build/55_cache.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ EOF


@test "${tag}: ignore patterns" {
# fails unless “__ch-test_ignore__” is included in the global gitignore file.
git check-ignore -q __ch-test_ignore__ \
|| pedantic_fail 'global ignore not configured'

Expand Down
2 changes: 1 addition & 1 deletion test/force-auto.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class T_Alpine_Latest(Alpine):
print("""\
# NOTE: This file is auto-generated. Do not modify.
load ../common
load common
setup () {
[[ $CH_TEST_BUILDER = ch-image ]] || skip 'ch-image only'
Expand Down

0 comments on commit d11e859

Please sign in to comment.