github.com/AbhinandanKurakure/podman/v3@v3.4.10/hack/bats (about) 1 #!/bin/bash 2 # 3 # bats wrapper - invokes bats, root & rootless, on podman system tests 4 # 5 6 ############################################################################### 7 # BEGIN usage message 8 9 usage="Usage: $0 [--root] [--rootless] [--filter=filename[:testname]] 10 11 $0 is a wrapper for invoking podman system tests. 12 13 --root Run only as root 14 --rootless Run only as user (i.e. you) 15 16 --filter=name Run only test files that match 'test/system/*name*', 17 e.g. '500' or 'net' will match 500-networking.bats. 18 If ':pattern' is appended, and you have a modern-enough 19 version of bats installed, runs with '--filter pattern' 20 which runs only subtests that match 'pattern' 21 22 --help display usage message 23 24 By default, tests ./bin/podman. To test a different podman, do: 25 26 \$ PODMAN=/abs/path/to/podman $0 .... 27 28 To test podman-remote, start your own servers (root and rootless) via: 29 30 /path/to/podman system service --timeout=0 31 32 ...then invoke this script with PODMAN=\$(pwd)/bin/podman-remote 33 34 (You'd think Ed could be bothered to do all that in this script; but then 35 the flow would be 'sudo start-service; sudo run-bats; sudo stop-service' 36 and by the time we get to stop-service, the sudo timeout will have lapsed, 37 and the script will be hanging at the password prompt, and you, who left 38 your desk for coffee or a walk and expected to come back to completed 39 root and rootless tests, will be irked because only root tests ran and 40 now you have to wait for rootless). 41 42 $0 also passes through \$OCI_RUNTIME, should you need to test that. 43 " 44 45 # END usage message 46 ############################################################################### 47 # BEGIN initialization and command-line arg checking 48 49 # By default, test the podman in our working directory. 50 # Some tests cd out of our workdir, so abs path is important 51 export PODMAN=${PODMAN:-$(pwd)/bin/podman} 52 53 # Because 'make' doesn't do this by default 54 chcon -t container_runtime_exec_t $PODMAN 55 56 # Directory in which 57 TESTS=test/system 58 59 REMOTE= 60 ROOT_ONLY= 61 ROOTLESS_ONLY= 62 63 declare -a bats_filter=() 64 65 for i;do 66 value=`expr "$i" : '[^=]*=\(.*\)'` 67 case "$i" in 68 -h|--help) echo "$usage"; exit 0;; 69 --root) ROOT_ONLY=1 ;; 70 --rootless) ROOTLESS_ONLY=1 ;; 71 --remote) REMOTE=remote; echo "--remote is TBI"; exit 1;; 72 */*.bats) TESTS=$i ;; 73 *) 74 if [[ $i =~ : ]]; then 75 tname=${i%:*} # network:localhost -> network 76 filt=${i#*:} # network:localhost -> localhost 77 TESTS=$(echo $TESTS/*$tname*.bats) 78 bats_filter=("--filter" "$filt") 79 else 80 TESTS=$(echo $TESTS/*$i*.bats) 81 fi 82 ;; 83 esac 84 done 85 86 # END initialization and command-line arg checking 87 ############################################################################### 88 89 rc=0 90 91 # Root 92 if [ -z "$ROOTLESS_ONLY" ]; then 93 echo "# bats ${bats_filter[@]} $TESTS" 94 sudo --preserve-env=PODMAN \ 95 --preserve-env=PODMAN_TEST_DEBUG \ 96 --preserve-env=OCI_RUNTIME \ 97 bats "${bats_filter[@]}" $TESTS 98 rc=$? 99 fi 100 101 # Rootless 102 echo "--------------------------------------------------" 103 if [ -z "$ROOT_ONLY" ]; then 104 echo "\$ bats ${bats_filter[@]} $TESTS" 105 bats "${bats_filter[@]}" $TESTS 106 rc=$((rc | $?)) 107 fi 108 109 exit $rc