#!/bin/bash # # Purpose : coredesktop-dev smoketest: run CoreDesktop's smoketest scenarios # (smoketest/ in the working copy), and those of the sibling projects # asked for, on QEMU virtual machines # # A sibling project is a working copy beside CoreDesktop's (in PROJECTS_DIR) # with a smoketest/project.conf: # # NAME=HamPack # PARENT=CoreDesktop # or another sibling it's built on # URLS=(https://gitea.young.computer/david/HamPack.git) # # and its scenarios in smoketest/scenarios/, plus, if it likes, a # smoketest/health script that checks a machine it's installed on and a # smoketest/setup script that prepares any machine it's tested on. Its # scenarios use CoreDesktop's smoketest/lib/scenario.sh. # # Runs test a chain: CoreDesktop, then each sibling asked for with --with, in # that order. Its images are layered, each on the one before: # # base Arch with GNOME # installed base + CoreDesktop's install.sh # installed+HamPack + sibling add HamPack source "$(dirname "${BASH_SOURCE[0]}")/vm.sh" CLOUD_IMAGE_URL="${SMOKETEST_CLOUD_IMAGE_URL:-https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2}" DISK_SIZE=120G RUNS="$SMOKETEST_STATE/runs" ROOT_PROJECT=CoreDesktop # Commits to build image layers at, by project name (images installed NAME=REF) declare -gA REFS=() smoketest_usage() { cat << EOF Usage: coredesktop-dev smoketest list [--with NAME...] Show the scenarios run [options] [scenario...] Run scenarios against each working copy's HEAD --with NAME Add sibling project NAME to the chain (repeatable; a sibling of a sibling comes after its parent) --tier pr|all pr (the default): the quick ones; all: everything, including a fresh install and upgrades from older commits, which take hours --ref REF Test CoreDesktop's REF instead of its HEAD --keep After a failure, leave its VM running to look around in, and stop images Show the VM images images base (Re)build the base image: Arch + GNOME images installed [--with NAME...] [REF | NAME=REF...] (Re)build the installed image (with the siblings named): CoreDesktop's install.sh at REF, then sibling add for each, at the commits given (default: where each branch started from upstream) shell [base|installed] [--with NAME...] Boot a throwaway copy of an image and SSH in clean [--all] Delete old runs' logs (--all: images and the package cache too) Scenarios are named by file (40-failing-migration) or number (40); a sibling's as HamPack/20-noop-update, or just 20 if no other has a 20. Sibling projects are working copies in $(projects_dir_hint) with a smoketest/project.conf. Each run keeps its logs in $RUNS. Set SMOKETEST_VNC=1 to watch the VM's screen at VNC display 127.0.0.1:1. EOF } projects_dir_hint() { load_config if [ -n "$WORKING_COPY" ]; then echo "${SMOKETEST_PROJECTS_DIR:-$(dirname "$WORKING_COPY")}" else echo "the folder holding CoreDesktop's working copy" fi } cmd_smoketest() { local sub="${1:-}" shift || true case "$sub" in -h | --help | "") smoketest_usage; [ -n "$sub" ]; return ;; list | run | images | shell | clean) ;; *) smoketest_usage >&2; return 1 ;; esac require_working_copy SCENARIOS="$WORKING_COPY/smoketest/scenarios" [ -d "$SCENARIOS" ] || die "$WORKING_COPY has no smoketest/scenarios; is it an older CoreDesktop?" PROJECTS_DIR="${SMOKETEST_PROJECTS_DIR:-$(dirname "$WORKING_COPY")}" "smoketest_$sub" "$@" } require_vm_tools() { local tool for tool in qemu-system-x86_64 qemu-img xorriso curl ssh scp ssh-keygen; do command -v "$tool" &> /dev/null \ || die "$tool isn't installed. Install coredesktop-dev's packages: bash $(sibling_dir)/update.sh" done [ -r "$KVM_DEVICE" ] && [ -w "$KVM_DEVICE" ] \ || die "Can't use $KVM_DEVICE. Turn on virtualization (VT-x/AMD-V) in the firmware settings." } # --- Projects and chains ----------------------------------------------------- # Working copies that are sibling projects, one per line project_dirs() { local conf dir for conf in "$PROJECTS_DIR"/*/smoketest/project.conf; do [ -f "$conf" ] || continue dir="$(dirname "$(dirname "$conf")")" [ "$(realpath "$dir")" = "$(realpath "$WORKING_COPY")" ] || echo "$dir" done return 0 } # project_conf DIR: print the project's NAME, PARENT, then its URLS, one a line project_conf() { ( NAME="" PARENT="" URLS=() # shellcheck source=/dev/null source "$1/smoketest/project.conf" > /dev/null || exit 1 printf '%s\n' "$NAME" "$PARENT" (( ${#URLS[@]} == 0 )) || printf '%s\n' "${URLS[@]}" ) } # find_project NAME: print the working copy of sibling project NAME (any case) find_project() { local dir info while read -r dir; do mapfile -t info < <(project_conf "$dir") if [ "${info[0],,}" = "${1,,}" ]; then echo "$dir" return 0 fi done < <(project_dirs) die "No sibling project called $1 in $PROJECTS_DIR (a working copy with a smoketest/project.conf)." } # set_chain [NAME...]: set CHAIN (project names) and CHAIN_DIRS (their working # copies) to CoreDesktop then each sibling named, checking each comes after # its parent set_chain() { local dir info name CHAIN=("$ROOT_PROJECT") CHAIN_DIRS=("$WORKING_COPY") for name in "$@"; do dir="$(find_project "$name")" || exit 1 mapfile -t info < <(project_conf "$dir") in_chain "${info[0]}" && die "${info[0]} is in the chain twice." [ -n "${info[1]}" ] || die "${info[0]} has no PARENT in its smoketest/project.conf." in_chain "${info[1]}" || die "${info[0]} is a sibling of ${info[1]}: add --with ${info[1]} before it." (( ${#info[@]} > 2 )) || die "${info[0]} has no URLS in its smoketest/project.conf." CHAIN+=("${info[0]}") CHAIN_DIRS+=("$dir") done } in_chain() { local name for name in "${CHAIN[@]}"; do [ "$name" = "$1" ] && return 0 done return 1 } # chain_id N: the image of the first N projects in the chain: installed, then # installed+HamPack and so on chain_id() { local IFS=+ if (( $1 == 1 )); then echo installed else echo "installed+${CHAIN[*]:1:$(($1 - 1))}" fi } # Parse --with options out of the arguments: set WITH, and REST to the others parse_with() { WITH=() REST=() while (( $# > 0 )); do case "$1" in --with) [ -n "${2:-}" ] || die "--with needs a project name"; WITH+=("$2"); shift 2 ;; --with=*) WITH+=("${1#--with=}"); shift ;; *) REST+=("$1"); shift ;; esac done } # with_args N: the --with options for the first N projects of the chain, each # with a space before it with_args() { local i for (( i = 1; i < $1; i++ )); do printf ' --with %s' "${CHAIN[$i]}" done } # The commit project DIR's branch started from, so building an image there and # updating it to HEAD exercises the branch's changes default_ref() { git -C "$1" merge-base HEAD '@{upstream}' 2> /dev/null \ || git -C "$1" merge-base HEAD origin/main 2> /dev/null \ || git -C "$1" rev-parse HEAD } # image_refs ID: print the image's projects and their commits, one "NAME SHA" # a line. An installed image from before sibling projects has installed.ref. image_refs() { if [ -f "$IMAGES/$1.refs" ]; then cat "$IMAGES/$1.refs" elif [ "$1" = installed ] && [ -f "$IMAGES/installed.ref" ]; then echo "$ROOT_PROJECT $(cat "$IMAGES/installed.ref")" fi } # image_ref ID NAME: the commit project NAME is at in image ID image_ref() { image_refs "$1" | awk -v n="$2" '$1 == n { print $2 }' } # write_chain_file FILE IMAGE_ID ROOT_SHA [N]: for smoketest/lib/scenario.sh, # one line per project in the chain (the first N, default all): name, working # copy, commit under test (CoreDesktop's ROOT_SHA, the others' HEAD), the # commit it's at in image IMAGE_ID (empty if none), and its URLs # (CoreDesktop's are in scenario.sh), tab-separated write_chain_file() { local file="$1" id="$2" root_sha="$3" n="${4:-${#CHAIN[@]}}" i info sha urls : > "$file" for (( i = 0; i < n; i++ )); do if (( i == 0 )); then sha="$root_sha" urls="" else sha="$(git -C "${CHAIN_DIRS[$i]}" rev-parse HEAD)" || die "${CHAIN_DIRS[$i]} has no commits." mapfile -t info < <(project_conf "${CHAIN_DIRS[$i]}") urls="${info[*]:2}" fi printf '%s\t%s\t%s\t%s\t%s\n' "${CHAIN[$i]}" "${CHAIN_DIRS[$i]}" "$sha" \ "$(image_ref "$id" "${CHAIN[$i]}")" "$urls" >> "$file" done } # --- Scenarios --------------------------------------------------------------- # scenario_info FILE: print IMAGE, TIER, DESCRIPTION and the VARIANTS (one per # line after the first three) scenario_info() { ( source "$WORKING_COPY/smoketest/lib/scenario.sh" source "$1" printf '%s\n' "$IMAGE" "$TIER" "$DESCRIPTION" (( ${#VARIANTS[@]} == 0 )) || printf '%s\n' "${VARIANTS[@]}" ) } # Set SCENARIO_FILES and SCENARIO_LABELS to every scenario of every project in # the chain, in chain order. CoreDesktop's are labelled by file, a sibling's # as Project/file. all_scenarios() { local i file SCENARIO_FILES=() SCENARIO_LABELS=() for i in "${!CHAIN[@]}"; do for file in "${CHAIN_DIRS[$i]}"/smoketest/scenarios/*.sh; do [ -f "$file" ] || continue SCENARIO_FILES+=("$file") if (( i == 0 )); then SCENARIO_LABELS+=("$(basename "$file" .sh)") else SCENARIO_LABELS+=("${CHAIN[$i]}/$(basename "$file" .sh)") fi done done } smoketest_list() { parse_with "$@" set_chain "${WITH[@]}" all_scenarios local i info for i in "${!SCENARIO_FILES[@]}"; do mapfile -t info < <(scenario_info "${SCENARIO_FILES[$i]}") printf '%-28s %-8s %-10s %s' "${SCENARIO_LABELS[$i]}" "${info[1]}" "${info[0]}" "${info[2]}" (( ${#info[@]} > 3 )) && printf ' (%d variants)' $(( ${#info[@]} - 3 )) echo done } # select_scenarios TIER [NAME...]: set SELECTED to the indexes, in # SCENARIO_FILES, of the scenarios named, or of those in TIER select_scenarios() { local tier="$1" name i info matches label file shift SELECTED=() if (( $# > 0 )); then for name in "$@"; do matches=() for i in "${!SCENARIO_LABELS[@]}"; do label="${SCENARIO_LABELS[$i]}" [[ "$label" == */* ]] || label="$ROOT_PROJECT/$label" file="${label#*/}" case "$name" in */*) [[ "${label,,}" == "${name,,}" || "${label,,}" == "${name,,}"-* ]] && matches+=("$i") ;; *) [[ "$file" == "$name" || "$file" == "$name"-* ]] && matches+=("$i") ;; esac done (( ${#matches[@]} > 0 )) || die "No scenario called $name (see: coredesktop-dev smoketest list)" if (( ${#matches[@]} > 1 )); then echo "$name could be any of:" >&2 for i in "${matches[@]}"; do echo " ${SCENARIO_LABELS[$i]}" >&2; done [[ "$name" == */* ]] && die "Name it by its whole file name." die "Name it as Project/file, e.g. $ROOT_PROJECT/$name." fi SELECTED+=("${matches[0]}") done return fi for i in "${!SCENARIO_FILES[@]}"; do mapfile -t info < <(scenario_info "${SCENARIO_FILES[$i]}") [[ "$tier" == all || "${info[1]}" == "$tier" ]] && SELECTED+=("$i") done return 0 } smoketest_run() { local tier="pr" ref=HEAD keep=0 names=() parse_with "$@" set -- "${REST[@]}" while (( $# > 0 )); do case "$1" in --tier) tier="${2:-}"; shift 2 || die "--tier needs pr or all" ;; --ref) ref="${2:-}"; shift 2 || die "--ref needs a commit" ;; --keep) keep=1; shift ;; -*) die "Unknown option: $1" ;; *) names+=("$1"); shift ;; esac done [[ "$tier" == pr || "$tier" == all ]] || die "--tier is pr or all, not $tier" set_chain "${WITH[@]}" require_vm_tools local sha i sha="$(git -C "$WORKING_COPY" rev-parse --verify --quiet "$ref^{commit}")" || die "No such commit: $ref" for i in "${!CHAIN[@]}"; do (( i == 0 )) && [ "$ref" != HEAD ] && continue if [ -n "$(git -C "${CHAIN_DIRS[$i]}" status --porcelain --untracked-files=no)" ]; then echo "Note: ${CHAIN_DIRS[$i]} has uncommitted changes. Only HEAD is installed and" echo "updated in the VM; the scenarios themselves are read from the working copy." fi done all_scenarios select_scenarios "$tier" "${names[@]}" (( ${#SELECTED[@]} > 0 )) || die "No scenarios to run." # Build the images the chosen scenarios need, if they aren't there yet local info need_installed=0 top top="$(chain_id ${#CHAIN[@]})" for i in "${SELECTED[@]}"; do mapfile -t info < <(scenario_info "${SCENARIO_FILES[$i]}") [ "${info[0]}" = installed ] && need_installed=1 done [ -f "$IMAGES/base.qcow2" ] || build_base_image if (( need_installed )); then ensure_chain_image ${#CHAIN[@]} fi RUN="$RUNS/$(date +%Y%m%d-%H%M%S)" mkdir -p "$RUN/shared" write_chain_file "$RUN/chain" "$top" "$sha" echo "Testing, logs in $RUN:" echo " $ROOT_PROJECT: $(git -C "$WORKING_COPY" log -1 --format='%h %s' "$sha")" for (( i = 1; i < ${#CHAIN[@]}; i++ )); do echo " ${CHAIN[$i]}: $(git -C "${CHAIN_DIRS[$i]}" log -1 --format='%h %s')" done local results=() failed=0 variants variant status label for i in "${SELECTED[@]}"; do mapfile -t info < <(scenario_info "${SCENARIO_FILES[$i]}") variants=("${info[@]:3}") (( ${#variants[@]} > 0 )) || variants=("") for variant in "${variants[@]}"; do run_scenario "${SCENARIO_FILES[$i]}" "${SCENARIO_LABELS[$i]}" "$variant" "$sha" "$top" "$keep" status=$? label="${SCENARIO_LABELS[$i]}${variant:+ @ $variant}" case $status in 0) results+=("PASS $label") ;; 3) results+=("SKIP $label") ;; *) results+=("FAIL $label"); failed=1 ;; esac if (( failed && keep )); then break 2 fi done done echo printf '%s\n' "${results[@]}" | tee "$RUN/summary" echo "Logs: $RUN" return $failed } # run_scenario FILE LABEL VARIANT SHA IMAGE_ID KEEP: boot a throwaway copy of # the scenario's image and run it. Returns 0 for pass, 3 for skip, anything # else for fail. run_scenario() { local file="$1" label="$2" variant="$3" sha="$4" id="$5" keep="$6" local name dir name="${label//\//_}${variant:+@$variant}" dir="$RUN/$name" mkdir -p "$dir" echo echo "=== $label${variant:+ @ $variant}" ( export SMOKETEST_RESULTS="$dir" SMOKETEST_SHARED="$RUN/shared" SMOKETEST_REF="$sha" VARIANT="$variant" export SMOKETEST_CHAIN_FILE="$RUN/chain" IMAGE_REF="$(image_ref "$id" "$ROOT_PROJECT")" export IMAGE_REF source "$WORKING_COPY/smoketest/lib/scenario.sh" source "$file" local image="$IMAGE" [ "$IMAGE" = installed ] && image="$id" qemu-img create -q -f qcow2 -b "$IMAGES/$image.qcow2" -F qcow2 "$dir/disk.qcow2" \ || die "Couldn't make the VM's disk." vm_start "$dir" "$dir/disk.qcow2" trap 'finish_scenario $? '"$keep" EXIT vm_wait_up smoketest_prepare set -e scenario ) 2>&1 | tee "$dir/scenario.log" return "${PIPESTATUS[0]}" } # Runs as the scenario's subshell exits: stop the VM and delete its disk, # unless it failed and --keep was given finish_scenario() { local status="$1" keep="$2" if (( status != 0 && status != SKIP_STATUS && keep )); then echo echo "The VM is still running. To look around: $(vm_ssh_command)" echo "To stop it: kill $(vm_pid) Its disk: $VM_DIR/disk.qcow2" return fi vm_kill rm -f "$VM_DIR/disk.qcow2" } # --- Images ------------------------------------------------------------------ download_cloud_image() { local image="$IMAGES/cloudimg.qcow2" expected actual [ -f "$image" ] && return 0 mkdir -p "$IMAGES" echo "Downloading Arch's cloud image..." curl -fL --progress-bar -o "$image.part" "$CLOUD_IMAGE_URL" || die "Couldn't download $CLOUD_IMAGE_URL" expected="$(curl -fsSL "$CLOUD_IMAGE_URL.SHA256" | awk '{print $1}')" \ || die "Couldn't download $CLOUD_IMAGE_URL.SHA256" actual="$(sha256sum "$image.part" | awk '{print $1}')" [ -n "$expected" ] && [ "$expected" = "$actual" ] \ || die "The cloud image's checksum doesn't match; try again." mv "$image.part" "$image" } build_base_image() { require_vm_tools download_cloud_image local build="$SMOKETEST_STATE/build-base" rm -rf "$build" mkdir -p "$build/seed" echo "Building the base image (Arch + GNOME); log: $build/build.log" cp --reflink=auto "$IMAGES/cloudimg.qcow2" "$build/disk.qcow2" qemu-img resize -q "$build/disk.qcow2" "$DISK_SIZE" ensure_ssh_key sed "s|@SSH_KEY@|$(cat "$SSH_KEY.pub")|" "$(sibling_dir)/vm/user-data" > "$build/seed/user-data" printf 'instance-id: coredesktop-smoketest\nlocal-hostname: coredesktop-smoketest\n' \ > "$build/seed/meta-data" xorriso -as mkisofs -quiet -output "$build/seed.iso" -volid cidata -joliet -rock \ "$build/seed/user-data" "$build/seed/meta-data" || die "Couldn't make the cloud-init disk." ( vm_start "$build" "$build/disk.qcow2" -cdrom "$build/seed.iso" trap vm_kill EXIT wait_for_ssh echo "Waiting for cloud-init to set up the VM's user..." vm_ssh 'cloud-init status --wait' < /dev/null > /dev/null || true echo "Installing GNOME (vm/provision.sh)..." vm_put "$(sibling_dir)/vm/provision.sh" /tmp/provision.sh || die "Couldn't copy provision.sh to the VM." vm_exec 'sudo bash /tmp/provision.sh' || die "Provisioning failed; see $build/build.log" vm_stop ) 2>&1 | tee "$build/build.log" (( PIPESTATUS[0] == 0 )) || die "Building the base image failed; see $build/build.log" mv "$build/disk.qcow2" "$IMAGES/base.qcow2" # Built on the old base image rm -f "$IMAGES"/installed*.qcow2 "$IMAGES"/installed*.refs "$IMAGES/installed.ref" rm -rf "$build" echo "Built $IMAGES/base.qcow2" } # Delete the images built on image ID, which no longer match it delete_images_on() { local file for file in "$IMAGES/$1+"*.qcow2; do [ -f "$file" ] || continue echo "Deleting $(basename "$file" .qcow2), which was built on the old $1 image." rm -f "$file" "${file%.qcow2}.refs" done } # ensure_chain_image N: build the image of the first N projects in the chain # (and the images under it) if it isn't there ensure_chain_image() { [ -f "$IMAGES/$(chain_id "$1").qcow2" ] || build_chain_image "$1" } # build_chain_image N: (re)build the image of the first N projects of the # chain: the image of the first N-1 (or base), plus the Nth project installed # at REFS[name], or the commit its branch started from. The projects under it # must be at REFS[name] already, if given. build_chain_image() { local n="$1" id parent name dir ref sha i id="$(chain_id "$n")" name="${CHAIN[$((n - 1))]}" dir="${CHAIN_DIRS[$((n - 1))]}" require_vm_tools [ -f "$IMAGES/base.qcow2" ] || build_base_image if (( n == 1 )); then parent=base else parent="$(chain_id $((n - 1)))" ensure_chain_image $((n - 1)) for (( i = 0; i < n - 1; i++ )); do ref="${REFS[${CHAIN[$i]}]:-}" [ -n "$ref" ] || continue sha="$(git -C "${CHAIN_DIRS[$i]}" rev-parse --verify --quiet "$ref^{commit}")" \ || die "${CHAIN[$i]} has no commit $ref." [ "$sha" = "$(image_ref "$parent" "${CHAIN[$i]}")" ] \ || die "The $parent image has ${CHAIN[$i]} at another commit. Build it at $ref first:" \ "coredesktop-dev smoketest images installed$(with_args $((n - 1))) ${CHAIN[$i]}=$ref" done fi ref="${REFS[$name]:-$(default_ref "$dir")}" sha="$(git -C "$dir" rev-parse --verify --quiet "$ref^{commit}")" || die "$name has no commit $ref." local build="$SMOKETEST_STATE/build-$id" rm -rf "$build" mkdir -p "$build" echo "Building the $id image: $parent + $name at $(git -C "$dir" log -1 --format='%h %s' "$sha")." echo "This takes an hour or more. Log: $build/build.log" qemu-img create -q -f qcow2 -b "$IMAGES/$parent.qcow2" -F qcow2 "$build/disk.qcow2" # The projects under this one, at the commits they're at in the parent image write_chain_file "$build/chain" "$parent" "$(image_ref "$parent" "$ROOT_PROJECT")" "$n" ( export SMOKETEST_RESULTS="$build" SMOKETEST_SHARED="$build" SMOKETEST_REF="$sha" export SMOKETEST_CHAIN_FILE="$build/chain" IMAGE=base source "$WORKING_COPY/smoketest/lib/scenario.sh" vm_start "$build" "$build/disk.qcow2" trap vm_kill EXIT vm_wait_up if declare -F smoketest_build_layer > /dev/null; then smoketest_build_layer "$name" "$sha" elif (( n == 1 )); then # A CoreDesktop from before sibling projects smoketest_install_image "$sha" vm_reboot else die "This CoreDesktop's smoketest/lib/scenario.sh can't add sibling projects; rebase on a newer one." fi vm_stop ) 2>&1 | tee "$build/build.log" (( PIPESTATUS[0] == 0 )) || die "Building the $id image failed; logs in $build" delete_images_on "$id" mv "$build/disk.qcow2" "$IMAGES/$id.qcow2" { [ "$parent" = base ] || image_refs "$parent" echo "$name $sha" } > "$IMAGES/$id.refs" [ "$id" = installed ] && rm -f "$IMAGES/installed.ref" rm -rf "$build" echo "Built $IMAGES/$id.qcow2" } smoketest_images() { case "${1:-}" in "") local ids=(installed) file id width=10 for file in "$IMAGES"/installed+*.refs; do [ -f "$file" ] && ids+=("$(basename "$file" .refs)") done for id in "${ids[@]}"; do (( ${#id} + 1 > width )) && width=$(( ${#id} + 1 )) done if [ -f "$IMAGES/base.qcow2" ]; then printf '%-*s built %s\n' "$width" base "$(date -r "$IMAGES/base.qcow2" '+%Y-%m-%d %H:%M')" else printf '%-*s not built\n' "$width" base fi for id in "${ids[@]}"; do if [ -f "$IMAGES/$id.qcow2" ]; then printf '%-*s built %s, at %s\n' "$width" "$id" "$(date -r "$IMAGES/$id.qcow2" '+%Y-%m-%d %H:%M')" \ "$(image_refs "$id" | while read -r name sha; do printf '%s%s %s' "${sep:-}" "$name" "$(git -C "$(image_project_dir "$name")" log -1 \ --format='%h %s' "$sha" 2> /dev/null || echo "${sha:0:9}")" sep=", " done)" else printf '%-*s not built\n' "$width" "$id" fi done ;; base) build_base_image ;; installed) shift parse_with "$@" set_chain "${WITH[@]}" declare -gA REFS=() local arg for arg in "${REST[@]}"; do if [[ "$arg" == *=* ]]; then in_chain "${arg%%=*}" || die "${arg%%=*} isn't in the chain; add it with --with." REFS["${arg%%=*}"]="${arg#*=}" else REFS["$ROOT_PROJECT"]="$arg" fi done build_chain_image ${#CHAIN[@]} ;; *) smoketest_usage >&2; return 1 ;; esac } # image_project_dir NAME: the working copy of project NAME, for describing an # image's commits (CoreDesktop's, or a sibling's if it's found) image_project_dir() { if [ "$1" = "$ROOT_PROJECT" ]; then echo "$WORKING_COPY" else (find_project "$1" 2> /dev/null) || echo /nonexistent fi } smoketest_shell() { parse_with "$@" set_chain "${WITH[@]}" local image="${REST[0]:-installed}" dir [[ "$image" == base || "$image" == installed ]] || die "The image is base or installed, not $image." [ "$image" = installed ] && image="$(chain_id ${#CHAIN[@]})" require_vm_tools [ -f "$IMAGES/$image.qcow2" ] \ || die "The $image image isn't built: coredesktop-dev smoketest images ${REST[0]:-installed}$(with_args ${#CHAIN[@]})" dir="$SMOKETEST_STATE/shell" rm -rf "$dir" mkdir -p "$dir" qemu-img create -q -f qcow2 -b "$IMAGES/$image.qcow2" -F qcow2 "$dir/disk.qcow2" vm_start "$dir" "$dir/disk.qcow2" # Expanded now: $dir is local, and gone by the time the script exits # shellcheck disable=SC2064 trap "vm_kill; rm -rf $(printf '%q' "$dir")" EXIT echo "Starting a throwaway copy of the $image image..." vm_wait_up vm_ssh -t } smoketest_clean() { case "${1:-}" in "") rm -rf "$RUNS" && echo "Deleted $RUNS" ;; --all) rm -rf "$SMOKETEST_STATE" && echo "Deleted $SMOKETEST_STATE" ;; *) smoketest_usage >&2; return 1 ;; esac }