github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/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] [FILENAME-PATTERN[:TEST-PATTERN]] 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 FILENAME-PATTERN Run only test files that match 'test/system/*name*', 17 e.g. '500' or 'net' will match 500-networking.bats. 18 19 TEST-PATTERN When appended to a filename-pattern, and you have a 20 modern-enough version of bats installed (i.e. Fedora 21 but not RHEL), runs with '--filter TEST-PATTERN' which 22 runs only subtests within FILENAME-PATTERH whose names 23 match that string. 24 25 -T Passed on to bats, which will then show timing data 26 27 --help display usage message 28 29 By default, tests ./bin/podman. To test a different podman, do: 30 31 \$ PODMAN=/abs/path/to/podman $0 .... 32 33 To test podman-remote, start your own servers (root and rootless) via: 34 35 /path/to/podman system service --timeout=0 36 37 ...then invoke this script with PODMAN=\$(pwd)/bin/podman-remote 38 39 (You'd think Ed could be bothered to do all that in this script; but then 40 the flow would be 'sudo start-service; sudo run-bats; sudo stop-service' 41 and by the time we get to stop-service, the sudo timeout will have lapsed, 42 and the script will be hanging at the password prompt, and you, who left 43 your desk for coffee or a walk and expected to come back to completed 44 root and rootless tests, will be irked because only root tests ran and 45 now you have to wait for rootless). 46 47 $0 also passes through \$OCI_RUNTIME, should you need to test that. 48 " 49 50 # END usage message 51 ############################################################################### 52 # BEGIN initialization and command-line arg checking 53 54 # By default, test the podman in our working directory. 55 # Some tests cd out of our workdir, so abs path is important 56 export PODMAN=${PODMAN:-$(pwd)/bin/podman} 57 58 # Because 'make' doesn't do this by default 59 chcon -t container_runtime_exec_t $PODMAN 60 61 # Directory in which 62 TESTS=test/system 63 64 REMOTE= 65 ROOT_ONLY= 66 ROOTLESS_ONLY= 67 68 declare -a bats_opts=() 69 70 declare -a bats_filter=() 71 72 for i;do 73 value=`expr "$i" : '[^=]*=\(.*\)'` 74 case "$i" in 75 -h|--help) echo "$usage"; exit 0;; 76 --root) ROOT_ONLY=1 ;; 77 --rootless) ROOTLESS_ONLY=1 ;; 78 --remote) REMOTE=remote; echo "--remote is TBI"; exit 1;; 79 --ts|-T) bats_opts+=("-T") ;; 80 */*.bats) TESTS=$i ;; 81 *) 82 if [[ $i =~ : ]]; then 83 tname=${i%:*} # network:localhost -> network 84 filt=${i#*:} # network:localhost -> localhost 85 TESTS=$(echo $TESTS/*$tname*.bats) 86 bats_filter=("--filter" "$filt") 87 else 88 TESTS=$(echo $TESTS/*$i*.bats) 89 fi 90 ;; 91 esac 92 done 93 94 # END initialization and command-line arg checking 95 ############################################################################### 96 97 rc=0 98 99 # As of 2021-11 podman has a bunch of external helper binaries 100 if [[ -z "$CONTAINERS_HELPER_BINARY_DIR" ]]; then 101 export CONTAINERS_HELPER_BINARY_DIR=$(pwd)/bin 102 fi 103 104 # Used in 120-load test to identify rootless destination for podman image scp 105 export PODMAN_ROOTLESS_USER=$(id -un) 106 107 # Root 108 if [ -z "$ROOTLESS_ONLY" ]; then 109 echo "# bats ${bats_filter[@]} $TESTS" 110 sudo --preserve-env=PODMAN \ 111 --preserve-env=PODMAN_TEST_DEBUG \ 112 --preserve-env=OCI_RUNTIME \ 113 --preserve-env=CONTAINERS_HELPER_BINARY_DIR \ 114 --preserve-env=PODMAN_ROOTLESS_USER \ 115 bats "${bats_opts[@]}" "${bats_filter[@]}" $TESTS 116 rc=$? 117 fi 118 119 # Rootless. (Only if we're not already root) 120 if [[ -z "$ROOT_ONLY" && "$(id -u)" != 0 ]]; then 121 echo "--------------------------------------------------" 122 echo "\$ bats ${bats_filter[@]} $TESTS" 123 bats "${bats_opts[@]}" "${bats_filter[@]}" $TESTS 124 rc=$((rc | $?)) 125 fi 126 127 exit $rc