smoketest: run sibling projects' scenarios with --with
A sibling project is a working copy beside CoreDesktop's with a smoketest/project.conf (NAME, PARENT, URLS), as in miniserver-dev. `run`, `list`, `shell` and `images installed` take --with NAME to add it to the chain; its scenarios are named Project/file, and run along with CoreDesktop's. Images are layered: installed+HamPack is the installed image after `sibling add HamPack`, and rebuilding a layer deletes those on it. The installed image keeps its name, and one built before this (with installed.ref) is still used. A CoreDesktop whose scenario.sh predates sibling projects still builds its installed image. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -60,6 +60,45 @@ coredesktop-dev smoketest run --keep 40 # on failure, leave the VM up to lo
|
|||||||
coredesktop-dev smoketest shell installed # SSH into a throwaway VM
|
coredesktop-dev smoketest shell installed # SSH into a throwaway VM
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Sibling projects
|
||||||
|
|
||||||
|
A sibling project (HamPack, say) can have a smoketest too, run on top of
|
||||||
|
CoreDesktop's. It's a working copy beside CoreDesktop's (in the same folder,
|
||||||
|
or `SMOKETEST_PROJECTS_DIR`) with a `smoketest/project.conf`:
|
||||||
|
|
||||||
|
```
|
||||||
|
NAME=HamPack
|
||||||
|
PARENT=CoreDesktop # or a sibling it's built on, which comes first
|
||||||
|
URLS=(https://gitea.young.computer/david/HamPack.git)
|
||||||
|
```
|
||||||
|
|
||||||
|
beside its scenarios in `smoketest/scenarios/`, which use CoreDesktop's
|
||||||
|
helpers, and, if it likes, `smoketest/health` (checks a machine it's installed
|
||||||
|
on) and `smoketest/setup` (prepares any machine it's tested on; runs before
|
||||||
|
each scenario). See CoreDesktop's `smoketest/README.md`.
|
||||||
|
|
||||||
|
```
|
||||||
|
coredesktop-dev smoketest list --with HamPack # CoreDesktop's scenarios and HamPack's
|
||||||
|
coredesktop-dev smoketest run --with HamPack # the quick ones of both
|
||||||
|
coredesktop-dev smoketest run --with HamPack HamPack/20
|
||||||
|
coredesktop-dev smoketest shell --with HamPack # SSH into CoreDesktop + HamPack
|
||||||
|
```
|
||||||
|
|
||||||
|
A run with `--with` runs every project's scenarios, so it also checks the
|
||||||
|
sibling doesn't break CoreDesktop. A sibling's scenarios are named
|
||||||
|
`HamPack/20-noop-update`, or just `20` if no other project has a 20. Each
|
||||||
|
working copy's `HEAD` is tested, so commit first.
|
||||||
|
|
||||||
|
Siblings get image layers of their own, each built on the one before and kept
|
||||||
|
for later runs: `installed+HamPack` is the installed image after `sibling add
|
||||||
|
HamPack`, at the commit HamPack's branch started from. Rebuilding a layer
|
||||||
|
deletes the layers built on it. To build at other commits, e.g. to test an
|
||||||
|
upgrade from an old release:
|
||||||
|
|
||||||
|
```
|
||||||
|
coredesktop-dev smoketest images installed --with HamPack HamPack=f851678
|
||||||
|
```
|
||||||
|
|
||||||
What it needs: KVM (virtualization turned on in the firmware), about 8 GB of
|
What it needs: KVM (virtualization turned on in the firmware), about 8 GB of
|
||||||
RAM and 4 CPUs per VM (`SMOKETEST_MEMORY`, `SMOKETEST_CPUS`), and about 45 GB
|
RAM and 4 CPUs per VM (`SMOKETEST_MEMORY`, `SMOKETEST_CPUS`), and about 45 GB
|
||||||
in `~/.cache/coredesktop-dev/smoketest`. The images are kept between runs (the
|
in `~/.cache/coredesktop-dev/smoketest`. The images are kept between runs (the
|
||||||
@@ -90,7 +129,8 @@ To watch a VM's screen, set `SMOKETEST_VNC=1` and connect a VNC viewer to
|
|||||||
The terminal can stay quiet for many minutes while a VM boots or installs. To
|
The terminal can stay quiet for many minutes while a VM boots or installs. To
|
||||||
follow along, `tail -f` the logs in `~/.cache/coredesktop-dev/smoketest`:
|
follow along, `tail -f` the logs in `~/.cache/coredesktop-dev/smoketest`:
|
||||||
|
|
||||||
- `build-base/` and `build-installed/`, while an image builds: `build.log` is
|
- `build-base/`, `build-installed/` and `build-installed+HamPack/` (and so
|
||||||
|
on), while an image builds: `build.log` is
|
||||||
what the build printed, and `serial.log` is the VM's console, the place to
|
what the build printed, and `serial.log` is the VM's console, the place to
|
||||||
look when a VM doesn't boot or doesn't answer on SSH.
|
look when a VM doesn't boot or doesn't answer on SSH.
|
||||||
- `runs/<date>-<time>/<scenario>/`: `scenario.log` for each scenario, and
|
- `runs/<date>-<time>/<scenario>/`: `scenario.log` for each scenario, and
|
||||||
|
|||||||
+405
-80
@@ -1,41 +1,81 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# Purpose : coredesktop-dev smoketest: run CoreDesktop's smoketest scenarios
|
# Purpose : coredesktop-dev smoketest: run CoreDesktop's smoketest scenarios
|
||||||
# (smoketest/ in the working copy) on QEMU virtual machines
|
# (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"
|
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}"
|
CLOUD_IMAGE_URL="${SMOKETEST_CLOUD_IMAGE_URL:-https://geo.mirror.pkgbuild.com/images/latest/Arch-Linux-x86_64-cloudimg.qcow2}"
|
||||||
DISK_SIZE=120G
|
DISK_SIZE=120G
|
||||||
RUNS="$SMOKETEST_STATE/runs"
|
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() {
|
smoketest_usage() {
|
||||||
cat << EOF
|
cat << EOF
|
||||||
Usage: coredesktop-dev smoketest <command>
|
Usage: coredesktop-dev smoketest <command>
|
||||||
|
|
||||||
list Show the scenarios
|
list [--with NAME...] Show the scenarios
|
||||||
run [options] [scenario...]
|
run [options] [scenario...]
|
||||||
Run scenarios against the working copy's HEAD
|
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,
|
--tier pr|all pr (the default): the quick ones; all: everything,
|
||||||
including a fresh install and upgrades from older
|
including a fresh install and upgrades from older
|
||||||
commits, which take hours
|
commits, which take hours
|
||||||
--ref REF Test REF instead of HEAD
|
--ref REF Test CoreDesktop's REF instead of its HEAD
|
||||||
--keep After a failure, leave its VM running to look
|
--keep After a failure, leave its VM running to look
|
||||||
around in, and stop
|
around in, and stop
|
||||||
images Show the VM images
|
images Show the VM images
|
||||||
images base (Re)build the base image: Arch + GNOME
|
images base (Re)build the base image: Arch + GNOME
|
||||||
images installed [REF] (Re)build the installed image: base + install.sh at
|
images installed [--with NAME...] [REF | NAME=REF...]
|
||||||
REF (default: where HEAD branched from upstream)
|
(Re)build the installed image (with the siblings
|
||||||
shell [base|installed] Boot a throwaway copy of an image and SSH in
|
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
|
clean [--all] Delete old runs' logs (--all: images and the
|
||||||
package cache too)
|
package cache too)
|
||||||
|
|
||||||
Scenarios are named by file (40-failing-migration) or number (40). Each run
|
Scenarios are named by file (40-failing-migration) or number (40); a
|
||||||
keeps its logs in $RUNS.
|
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.
|
Set SMOKETEST_VNC=1 to watch the VM's screen at VNC display 127.0.0.1:1.
|
||||||
EOF
|
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() {
|
cmd_smoketest() {
|
||||||
local sub="${1:-}"
|
local sub="${1:-}"
|
||||||
shift || true
|
shift || true
|
||||||
@@ -47,6 +87,7 @@ cmd_smoketest() {
|
|||||||
require_working_copy
|
require_working_copy
|
||||||
SCENARIOS="$WORKING_COPY/smoketest/scenarios"
|
SCENARIOS="$WORKING_COPY/smoketest/scenarios"
|
||||||
[ -d "$SCENARIOS" ] || die "$WORKING_COPY has no smoketest/scenarios; is it an older CoreDesktop?"
|
[ -d "$SCENARIOS" ] || die "$WORKING_COPY has no smoketest/scenarios; is it an older CoreDesktop?"
|
||||||
|
PROJECTS_DIR="${SMOKETEST_PROJECTS_DIR:-$(dirname "$WORKING_COPY")}"
|
||||||
"smoketest_$sub" "$@"
|
"smoketest_$sub" "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,6 +101,149 @@ require_vm_tools() {
|
|||||||
|| die "Can't use $KVM_DEVICE. Turn on virtualization (VT-x/AMD-V) in the firmware settings."
|
|| 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
|
# scenario_info FILE: print IMAGE, TIER, DESCRIPTION and the VARIANTS (one per
|
||||||
# line after the first three)
|
# line after the first three)
|
||||||
scenario_info() {
|
scenario_info() {
|
||||||
@@ -71,43 +255,79 @@ scenario_info() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 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() {
|
smoketest_list() {
|
||||||
local file info
|
parse_with "$@"
|
||||||
for file in "$SCENARIOS"/*.sh; do
|
set_chain "${WITH[@]}"
|
||||||
mapfile -t info < <(scenario_info "$file")
|
all_scenarios
|
||||||
printf '%-28s %-8s %-10s %s' "$(basename "$file" .sh)" "${info[1]}" "${info[0]}" "${info[2]}"
|
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 ))
|
(( ${#info[@]} > 3 )) && printf ' (%d variants)' $(( ${#info[@]} - 3 ))
|
||||||
echo
|
echo
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Set SELECTED to the scenario files to run: those named, or those in the tier
|
# select_scenarios TIER [NAME...]: set SELECTED to the indexes, in
|
||||||
|
# SCENARIO_FILES, of the scenarios named, or of those in TIER
|
||||||
select_scenarios() {
|
select_scenarios() {
|
||||||
local tier="$1" name file found info
|
local tier="$1" name i info matches label file
|
||||||
shift
|
shift
|
||||||
SELECTED=()
|
SELECTED=()
|
||||||
if (( $# > 0 )); then
|
if (( $# > 0 )); then
|
||||||
for name in "$@"; do
|
for name in "$@"; do
|
||||||
found=""
|
matches=()
|
||||||
for file in "$SCENARIOS"/*.sh; do
|
for i in "${!SCENARIO_LABELS[@]}"; do
|
||||||
case "$(basename "$file" .sh)" in
|
label="${SCENARIO_LABELS[$i]}"
|
||||||
"$name" | "$name"-*) found="$file"; break ;;
|
[[ "$label" == */* ]] || label="$ROOT_PROJECT/$label"
|
||||||
|
file="${label#*/}"
|
||||||
|
case "$name" in
|
||||||
|
*/*) [[ "${label,,}" == "${name,,}" || "${label,,}" == "${name,,}"-* ]] && matches+=("$i") ;;
|
||||||
|
*) [[ "$file" == "$name" || "$file" == "$name"-* ]] && matches+=("$i") ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
[ -n "$found" ] || die "No scenario called $name (see: coredesktop-dev smoketest list)"
|
(( ${#matches[@]} > 0 )) || die "No scenario called $name (see: coredesktop-dev smoketest list)"
|
||||||
SELECTED+=("$found")
|
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
|
done
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
for file in "$SCENARIOS"/*.sh; do
|
for i in "${!SCENARIO_FILES[@]}"; do
|
||||||
mapfile -t info < <(scenario_info "$file")
|
mapfile -t info < <(scenario_info "${SCENARIO_FILES[$i]}")
|
||||||
[[ "$tier" == all || "${info[1]}" == "$tier" ]] && SELECTED+=("$file")
|
[[ "$tier" == all || "${info[1]}" == "$tier" ]] && SELECTED+=("$i")
|
||||||
done
|
done
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
smoketest_run() {
|
smoketest_run() {
|
||||||
local tier="pr" ref=HEAD keep=0 names=()
|
local tier="pr" ref=HEAD keep=0 names=()
|
||||||
|
parse_with "$@"
|
||||||
|
set -- "${REST[@]}"
|
||||||
while (( $# > 0 )); do
|
while (( $# > 0 )); do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
--tier) tier="${2:-}"; shift 2 || die "--tier needs pr or all" ;;
|
--tier) tier="${2:-}"; shift 2 || die "--tier needs pr or all" ;;
|
||||||
@@ -118,44 +338,53 @@ smoketest_run() {
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
[[ "$tier" == pr || "$tier" == all ]] || die "--tier is pr or all, not $tier"
|
[[ "$tier" == pr || "$tier" == all ]] || die "--tier is pr or all, not $tier"
|
||||||
|
set_chain "${WITH[@]}"
|
||||||
require_vm_tools
|
require_vm_tools
|
||||||
|
|
||||||
local sha
|
local sha i
|
||||||
sha="$(git -C "$WORKING_COPY" rev-parse --verify --quiet "$ref^{commit}")" || die "No such commit: $ref"
|
sha="$(git -C "$WORKING_COPY" rev-parse --verify --quiet "$ref^{commit}")" || die "No such commit: $ref"
|
||||||
if [ "$ref" = HEAD ] && [ -n "$(git -C "$WORKING_COPY" status --porcelain --untracked-files=no)" ]; then
|
for i in "${!CHAIN[@]}"; do
|
||||||
echo "Note: the working copy has uncommitted changes. Only HEAD is installed and"
|
(( 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."
|
echo "updated in the VM; the scenarios themselves are read from the working copy."
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
all_scenarios
|
||||||
select_scenarios "$tier" "${names[@]}"
|
select_scenarios "$tier" "${names[@]}"
|
||||||
local files=("${SELECTED[@]}")
|
(( ${#SELECTED[@]} > 0 )) || die "No scenarios to run."
|
||||||
(( ${#files[@]} > 0 )) || die "No scenarios to run."
|
|
||||||
|
|
||||||
# Build the images the chosen scenarios need, if they aren't there yet
|
# Build the images the chosen scenarios need, if they aren't there yet
|
||||||
local file info need_installed=0
|
local info need_installed=0 top
|
||||||
for file in "${files[@]}"; do
|
top="$(chain_id ${#CHAIN[@]})"
|
||||||
mapfile -t info < <(scenario_info "$file")
|
for i in "${SELECTED[@]}"; do
|
||||||
|
mapfile -t info < <(scenario_info "${SCENARIO_FILES[$i]}")
|
||||||
[ "${info[0]}" = installed ] && need_installed=1
|
[ "${info[0]}" = installed ] && need_installed=1
|
||||||
done
|
done
|
||||||
[ -f "$IMAGES/base.qcow2" ] || build_base_image
|
[ -f "$IMAGES/base.qcow2" ] || build_base_image
|
||||||
if (( need_installed )) && [ ! -f "$IMAGES/installed.qcow2" ]; then
|
if (( need_installed )); then
|
||||||
build_installed_image "$(default_installed_ref)"
|
ensure_chain_image ${#CHAIN[@]}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RUN="$RUNS/$(date +%Y%m%d-%H%M%S)"
|
RUN="$RUNS/$(date +%Y%m%d-%H%M%S)"
|
||||||
mkdir -p "$RUN/shared"
|
mkdir -p "$RUN/shared"
|
||||||
echo "Testing $(git -C "$WORKING_COPY" log -1 --format='%h %s' "$sha"); logs in $RUN"
|
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
|
local results=() failed=0 variants variant status label
|
||||||
for file in "${files[@]}"; do
|
for i in "${SELECTED[@]}"; do
|
||||||
mapfile -t info < <(scenario_info "$file")
|
mapfile -t info < <(scenario_info "${SCENARIO_FILES[$i]}")
|
||||||
variants=("${info[@]:3}")
|
variants=("${info[@]:3}")
|
||||||
(( ${#variants[@]} > 0 )) || variants=("")
|
(( ${#variants[@]} > 0 )) || variants=("")
|
||||||
for variant in "${variants[@]}"; do
|
for variant in "${variants[@]}"; do
|
||||||
run_scenario "$file" "$variant" "$sha" "$keep"
|
run_scenario "${SCENARIO_FILES[$i]}" "${SCENARIO_LABELS[$i]}" "$variant" "$sha" "$top" "$keep"
|
||||||
status=$?
|
status=$?
|
||||||
local label
|
label="${SCENARIO_LABELS[$i]}${variant:+ @ $variant}"
|
||||||
label="$(basename "$file" .sh)${variant:+ @ $variant}"
|
|
||||||
case $status in
|
case $status in
|
||||||
0) results+=("PASS $label") ;;
|
0) results+=("PASS $label") ;;
|
||||||
3) results+=("SKIP $label") ;;
|
3) results+=("SKIP $label") ;;
|
||||||
@@ -173,25 +402,29 @@ smoketest_run() {
|
|||||||
return $failed
|
return $failed
|
||||||
}
|
}
|
||||||
|
|
||||||
# run_scenario FILE VARIANT SHA KEEP: boot a throwaway copy of the scenario's
|
# run_scenario FILE LABEL VARIANT SHA IMAGE_ID KEEP: boot a throwaway copy of
|
||||||
# image and run it. Returns 0 for pass, 3 for skip, anything else for fail.
|
# the scenario's image and run it. Returns 0 for pass, 3 for skip, anything
|
||||||
|
# else for fail.
|
||||||
run_scenario() {
|
run_scenario() {
|
||||||
local file="$1" variant="$2" sha="$3" keep="$4"
|
local file="$1" label="$2" variant="$3" sha="$4" id="$5" keep="$6"
|
||||||
local name dir
|
local name dir
|
||||||
name="$(basename "$file" .sh)${variant:+@$variant}"
|
name="${label//\//_}${variant:+@$variant}"
|
||||||
dir="$RUN/$name"
|
dir="$RUN/$name"
|
||||||
mkdir -p "$dir"
|
mkdir -p "$dir"
|
||||||
echo
|
echo
|
||||||
echo "=== $name"
|
echo "=== $label${variant:+ @ $variant}"
|
||||||
|
|
||||||
(
|
(
|
||||||
export SMOKETEST_RESULTS="$dir" SMOKETEST_SHARED="$RUN/shared" SMOKETEST_REF="$sha" VARIANT="$variant"
|
export SMOKETEST_RESULTS="$dir" SMOKETEST_SHARED="$RUN/shared" SMOKETEST_REF="$sha" VARIANT="$variant"
|
||||||
IMAGE_REF="$(cat "$IMAGES/installed.ref" 2> /dev/null)"
|
export SMOKETEST_CHAIN_FILE="$RUN/chain"
|
||||||
|
IMAGE_REF="$(image_ref "$id" "$ROOT_PROJECT")"
|
||||||
export IMAGE_REF
|
export IMAGE_REF
|
||||||
source "$WORKING_COPY/smoketest/lib/scenario.sh"
|
source "$WORKING_COPY/smoketest/lib/scenario.sh"
|
||||||
source "$file"
|
source "$file"
|
||||||
|
local image="$IMAGE"
|
||||||
|
[ "$IMAGE" = installed ] && image="$id"
|
||||||
|
|
||||||
qemu-img create -q -f qcow2 -b "$IMAGES/$IMAGE.qcow2" -F qcow2 "$dir/disk.qcow2" \
|
qemu-img create -q -f qcow2 -b "$IMAGES/$image.qcow2" -F qcow2 "$dir/disk.qcow2" \
|
||||||
|| die "Couldn't make the VM's disk."
|
|| die "Couldn't make the VM's disk."
|
||||||
vm_start "$dir" "$dir/disk.qcow2"
|
vm_start "$dir" "$dir/disk.qcow2"
|
||||||
trap 'finish_scenario $? '"$keep" EXIT
|
trap 'finish_scenario $? '"$keep" EXIT
|
||||||
@@ -217,13 +450,7 @@ finish_scenario() {
|
|||||||
rm -f "$VM_DIR/disk.qcow2"
|
rm -f "$VM_DIR/disk.qcow2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Where the installed image is built by default: the commit HEAD branched
|
# --- Images ------------------------------------------------------------------
|
||||||
# from upstream, so updating it to HEAD exercises the branch's changes
|
|
||||||
default_installed_ref() {
|
|
||||||
git -C "$WORKING_COPY" merge-base HEAD '@{upstream}' 2> /dev/null \
|
|
||||||
|| git -C "$WORKING_COPY" merge-base HEAD origin/main 2> /dev/null \
|
|
||||||
|| git -C "$WORKING_COPY" rev-parse HEAD
|
|
||||||
}
|
|
||||||
|
|
||||||
download_cloud_image() {
|
download_cloud_image() {
|
||||||
local image="$IMAGES/cloudimg.qcow2" expected actual
|
local image="$IMAGES/cloudimg.qcow2" expected actual
|
||||||
@@ -272,69 +499,167 @@ build_base_image() {
|
|||||||
|
|
||||||
mv "$build/disk.qcow2" "$IMAGES/base.qcow2"
|
mv "$build/disk.qcow2" "$IMAGES/base.qcow2"
|
||||||
# Built on the old base image
|
# Built on the old base image
|
||||||
rm -f "$IMAGES/installed.qcow2" "$IMAGES/installed.ref"
|
rm -f "$IMAGES"/installed*.qcow2 "$IMAGES"/installed*.refs "$IMAGES/installed.ref"
|
||||||
rm -rf "$build"
|
rm -rf "$build"
|
||||||
echo "Built $IMAGES/base.qcow2"
|
echo "Built $IMAGES/base.qcow2"
|
||||||
}
|
}
|
||||||
|
|
||||||
# build_installed_image REF: the base image after install.sh at REF
|
# Delete the images built on image ID, which no longer match it
|
||||||
build_installed_image() {
|
delete_images_on() {
|
||||||
local ref sha build="$SMOKETEST_STATE/build-installed"
|
local file
|
||||||
ref="$1"
|
for file in "$IMAGES/$1+"*.qcow2; do
|
||||||
sha="$(git -C "$WORKING_COPY" rev-parse --verify --quiet "$ref^{commit}")" || die "No such commit: $ref"
|
[ -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
|
require_vm_tools
|
||||||
[ -f "$IMAGES/base.qcow2" ] || build_base_image
|
[ -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"
|
rm -rf "$build"
|
||||||
mkdir -p "$build"
|
mkdir -p "$build"
|
||||||
echo "Building the installed image at $(git -C "$WORKING_COPY" log -1 --format='%h %s' "$sha");" \
|
echo "Building the $id image: $parent + $name at $(git -C "$dir" log -1 --format='%h %s' "$sha")."
|
||||||
"this takes an hour or more. Log: $build/build.log"
|
echo "This takes an hour or more. Log: $build/build.log"
|
||||||
|
|
||||||
qemu-img create -q -f qcow2 -b "$IMAGES/base.qcow2" -F qcow2 "$build/disk.qcow2"
|
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_RESULTS="$build" SMOKETEST_SHARED="$build" SMOKETEST_REF="$sha"
|
||||||
|
export SMOKETEST_CHAIN_FILE="$build/chain"
|
||||||
IMAGE=base
|
IMAGE=base
|
||||||
source "$WORKING_COPY/smoketest/lib/scenario.sh"
|
source "$WORKING_COPY/smoketest/lib/scenario.sh"
|
||||||
vm_start "$build" "$build/disk.qcow2"
|
vm_start "$build" "$build/disk.qcow2"
|
||||||
trap vm_kill EXIT
|
trap vm_kill EXIT
|
||||||
vm_wait_up
|
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"
|
smoketest_install_image "$sha"
|
||||||
# The README says to reboot after installing
|
|
||||||
vm_reboot
|
vm_reboot
|
||||||
|
else
|
||||||
|
die "This CoreDesktop's smoketest/lib/scenario.sh can't add sibling projects; rebase on a newer one."
|
||||||
|
fi
|
||||||
vm_stop
|
vm_stop
|
||||||
) 2>&1 | tee "$build/build.log"
|
) 2>&1 | tee "$build/build.log"
|
||||||
(( PIPESTATUS[0] == 0 )) || die "Building the installed image failed; logs in $build"
|
(( PIPESTATUS[0] == 0 )) || die "Building the $id image failed; logs in $build"
|
||||||
|
|
||||||
mv "$build/disk.qcow2" "$IMAGES/installed.qcow2"
|
delete_images_on "$id"
|
||||||
echo "$sha" > "$IMAGES/installed.ref"
|
mv "$build/disk.qcow2" "$IMAGES/$id.qcow2"
|
||||||
echo "Built $IMAGES/installed.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() {
|
smoketest_images() {
|
||||||
case "${1:-}" in
|
case "${1:-}" in
|
||||||
"")
|
"")
|
||||||
local image
|
local ids=(installed) file id width=10
|
||||||
for image in base installed; do
|
for file in "$IMAGES"/installed+*.refs; do
|
||||||
if [ -f "$IMAGES/$image.qcow2" ]; then
|
[ -f "$file" ] && ids+=("$(basename "$file" .refs)")
|
||||||
printf '%-10s built %s' "$image" "$(date -r "$IMAGES/$image.qcow2" '+%Y-%m-%d %H:%M')"
|
done
|
||||||
[ "$image" = installed ] \
|
for id in "${ids[@]}"; do
|
||||||
&& printf ', at %s' "$(git -C "$WORKING_COPY" log -1 --format='%h %s' "$(cat "$IMAGES/installed.ref")" 2> /dev/null)"
|
(( ${#id} + 1 > width )) && width=$(( ${#id} + 1 ))
|
||||||
echo
|
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
|
else
|
||||||
printf '%-10s not built\n' "$image"
|
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
|
fi
|
||||||
done
|
done
|
||||||
;;
|
;;
|
||||||
base) build_base_image ;;
|
base) build_base_image ;;
|
||||||
installed) build_installed_image "${2:-$(default_installed_ref)}" ;;
|
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 ;;
|
*) smoketest_usage >&2; return 1 ;;
|
||||||
esac
|
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() {
|
smoketest_shell() {
|
||||||
local image="${1:-installed}" dir
|
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" == base || "$image" == installed ]] || die "The image is base or installed, not $image."
|
||||||
|
[ "$image" = installed ] && image="$(chain_id ${#CHAIN[@]})"
|
||||||
require_vm_tools
|
require_vm_tools
|
||||||
[ -f "$IMAGES/$image.qcow2" ] || die "The $image image isn't built: coredesktop-dev smoketest images $image"
|
[ -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"
|
dir="$SMOKETEST_STATE/shell"
|
||||||
rm -rf "$dir"
|
rm -rf "$dir"
|
||||||
mkdir -p "$dir"
|
mkdir -p "$dir"
|
||||||
|
|||||||
+142
-1
@@ -41,7 +41,14 @@ setup() {
|
|||||||
mkdir -p "$SC" "$WC/smoketest/lib"
|
mkdir -p "$SC" "$WC/smoketest/lib"
|
||||||
cat > "$WC/smoketest/lib/scenario.sh" << 'EOF'
|
cat > "$WC/smoketest/lib/scenario.sh" << 'EOF'
|
||||||
SKIP_STATUS=3
|
SKIP_STATUS=3
|
||||||
smoketest_prepare() { echo "prepare $IMAGE $SMOKETEST_REF $IMAGE_REF"; }
|
smoketest_prepare() {
|
||||||
|
echo "prepare $IMAGE $SMOKETEST_REF $IMAGE_REF"
|
||||||
|
[ -z "${SMOKETEST_CHAIN_FILE:-}" ] || cp "$SMOKETEST_CHAIN_FILE" "$HOME/run-chain"
|
||||||
|
}
|
||||||
|
smoketest_build_layer() {
|
||||||
|
echo "build_layer $1 $2" >> "$HOME/layers"
|
||||||
|
cp "$SMOKETEST_CHAIN_FILE" "$HOME/layer-chain-$1"
|
||||||
|
}
|
||||||
fail() { echo "FAIL: $*"; exit 1; }
|
fail() { echo "FAIL: $*"; exit 1; }
|
||||||
skip() { echo "SKIP: $*"; exit 3; }
|
skip() { echo "SKIP: $*"; exit 3; }
|
||||||
EOF
|
EOF
|
||||||
@@ -181,3 +188,137 @@ last_run() {
|
|||||||
[[ "${lines[3]}" == " done after "*s ]]
|
[[ "${lines[3]}" == " done after "*s ]]
|
||||||
[ "${#lines[@]}" -eq 4 ]
|
[ "${#lines[@]}" -eq 4 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# --- Sibling projects ---
|
||||||
|
|
||||||
|
# A sibling project, HamPack, beside the working copy, with scenarios 10 and 20
|
||||||
|
make_sibling() {
|
||||||
|
SIB="$HOME/Projects/HamPack"
|
||||||
|
mkdir -p "$SIB/smoketest/scenarios"
|
||||||
|
printf '%s\n' NAME=HamPack PARENT=CoreDesktop 'URLS=(https://example.com/HamPack.git)' \
|
||||||
|
> "$SIB/smoketest/project.conf"
|
||||||
|
printf '%s\n' 'DESCRIPTION="HamPack updates"' TIER=pr IMAGE=installed 'scenario() {' 'echo hampack scenario' '}' \
|
||||||
|
> "$SIB/smoketest/scenarios/20-update.sh"
|
||||||
|
printf '%s\n' 'DESCRIPTION="HamPack installs"' TIER=nightly IMAGE=base 'scenario() {' 'true' '}' \
|
||||||
|
> "$SIB/smoketest/scenarios/15-install.sh"
|
||||||
|
git -C "$SIB" init -q
|
||||||
|
git -C "$SIB" add -A
|
||||||
|
git -C "$SIB" commit -qm HamPack
|
||||||
|
SIB_SHA="$(git -C "$SIB" rev-parse HEAD)"
|
||||||
|
# Building an image shuts its VM down with sudo systemctl poweroff
|
||||||
|
stub sudo '[ "$*" = "systemctl poweroff" ] || exit 0
|
||||||
|
for f in "$HOME"/.cache/coredesktop-dev/smoketest/build-*/qemu.pid; do kill "$(cat "$f")"; done'
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "list --with adds a sibling's scenarios, as Project/file" {
|
||||||
|
make_sibling
|
||||||
|
run cdd smoketest list
|
||||||
|
[[ "$output" != *HamPack* ]]
|
||||||
|
run cdd smoketest list --with hampack
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"10-passes"* ]]
|
||||||
|
[[ "$output" == *"HamPack/20-update"*"pr"*"installed"*"HamPack updates"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "run --with builds the sibling's image on the installed one, and runs every project's scenarios in it" {
|
||||||
|
make_sibling
|
||||||
|
root="$(cat "$STATE/images/installed.ref")"
|
||||||
|
run cdd smoketest run --with HamPack 10 HamPack/20
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$(cat "$HOME/layers")" = "build_layer HamPack $SIB_SHA" ]
|
||||||
|
# The layer is built with CoreDesktop as it is in the installed image
|
||||||
|
[ "$(cat "$HOME/layer-chain-HamPack")" = "$(printf 'CoreDesktop\t%s\t%s\t%s\t\nHamPack\t%s\t%s\t\t%s' \
|
||||||
|
"$WC" "$root" "$root" "$SIB" "$SIB_SHA" https://example.com/HamPack.git)" ]
|
||||||
|
[ "$(cat "$STATE/images/installed+HamPack.refs")" = "$(printf 'CoreDesktop %s\nHamPack %s' "$root" "$SIB_SHA")" ]
|
||||||
|
[[ "$output" == *"PASS 10-passes"* ]]
|
||||||
|
[[ "$output" == *"PASS HamPack/20-update"* ]]
|
||||||
|
[[ "$output" == *"hampack scenario"* ]]
|
||||||
|
[ "$(grep -c "^qemu-img create -q -f qcow2 -b $STATE/images/installed+HamPack.qcow2 " "$STUB_LOG")" -eq 2 ]
|
||||||
|
# Scenarios get the chain, with each project's commit under test and in the image
|
||||||
|
[ "$(cat "$HOME/run-chain")" = "$(printf 'CoreDesktop\t%s\t%s\t%s\t\nHamPack\t%s\t%s\t%s\t%s' \
|
||||||
|
"$WC" "$(git -C "$WC" rev-parse HEAD)" "$root" "$SIB" "$SIB_SHA" "$SIB_SHA" https://example.com/HamPack.git)" ]
|
||||||
|
|
||||||
|
# The next run uses it
|
||||||
|
: > "$HOME/layers"
|
||||||
|
run cdd smoketest run --with HamPack HamPack/20
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ ! -s "$HOME/layers" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "a scenario number two projects share must be named with its project" {
|
||||||
|
make_sibling
|
||||||
|
scenario_file 20-update pr installed true
|
||||||
|
run cdd smoketest run --with HamPack 20
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "$output" == *"20 could be any of:"*"20-update"*"HamPack/20-update"* ]]
|
||||||
|
[[ "$output" == *"Name it as Project/file, e.g. CoreDesktop/20."* ]]
|
||||||
|
not_called qemu-system-x86_64
|
||||||
|
|
||||||
|
run cdd smoketest run --with HamPack CoreDesktop/20
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "$output" == *"Name it by its whole file name."* ]]
|
||||||
|
|
||||||
|
run cdd smoketest run --with HamPack CoreDesktop/20-update hampack/20
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[[ "$output" == *"PASS 20-update"*"PASS HamPack/20-update"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "--with needs a sibling of a project already in the chain" {
|
||||||
|
make_sibling
|
||||||
|
run cdd smoketest list --with Nope
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "$output" == *"No sibling project called Nope"* ]]
|
||||||
|
|
||||||
|
sed -i 's/PARENT=CoreDesktop/PARENT=MiniServer/' "$SIB/smoketest/project.conf"
|
||||||
|
run cdd smoketest list --with HamPack
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "$output" == *"HamPack is a sibling of MiniServer: add --with MiniServer before it."* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "rebuilding the installed image deletes the images built on it" {
|
||||||
|
make_sibling
|
||||||
|
cdd smoketest run --with HamPack HamPack/20
|
||||||
|
[ -f "$STATE/images/installed+HamPack.qcow2" ]
|
||||||
|
run cdd smoketest images installed
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$(cat "$HOME/layers" | tail -n 1)" = "build_layer CoreDesktop $(git -C "$WC" rev-parse HEAD)" ]
|
||||||
|
[ ! -e "$STATE/images/installed+HamPack.qcow2" ]
|
||||||
|
[ ! -e "$STATE/images/installed.ref" ]
|
||||||
|
[ "$(cat "$STATE/images/installed.refs")" = "CoreDesktop $(git -C "$WC" rev-parse HEAD)" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "images installed builds siblings at the commits given" {
|
||||||
|
make_sibling
|
||||||
|
first="$SIB_SHA"
|
||||||
|
git -C "$SIB" commit -q --allow-empty -m second
|
||||||
|
run cdd smoketest images installed --with HamPack "HamPack=$first"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$(cat "$HOME/layers")" = "build_layer HamPack $first" ]
|
||||||
|
|
||||||
|
run cdd smoketest images
|
||||||
|
[[ "$output" == *"installed+HamPack built"*"HamPack ${first:0:7} HamPack"* ]]
|
||||||
|
|
||||||
|
run cdd smoketest images installed --with HamPack "CoreDesktop=nosuch"
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "$output" == *"CoreDesktop has no commit nosuch"* ]]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "a CoreDesktop from before sibling projects still builds its installed image, but not a sibling's" {
|
||||||
|
make_sibling
|
||||||
|
sed -i '/^smoketest_build_layer() {/,/^}/d' "$WC/smoketest/lib/scenario.sh"
|
||||||
|
printf '%s\n' 'smoketest_install_image() { echo "install_image $1" >> "$HOME/layers"; }' \
|
||||||
|
>> "$WC/smoketest/lib/scenario.sh"
|
||||||
|
stub ssh 'echo "ssh $*" >> "$HOME/ssh.log"; while [ $# -gt 0 ]; do
|
||||||
|
case "$1" in -i | -o | -p) shift 2 ;; *@*) shift; break ;; *) shift ;; esac
|
||||||
|
done
|
||||||
|
[ $# -gt 0 ] || exit 0
|
||||||
|
case "$*" in *boot_id*) echo "boot-$RANDOM" ; exit 0 ;; esac
|
||||||
|
cd "$HOME" && exec setsid -w bash -c "$*"'
|
||||||
|
run cdd smoketest images installed
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$(cat "$HOME/layers")" = "install_image $(git -C "$WC" rev-parse HEAD)" ]
|
||||||
|
|
||||||
|
run cdd smoketest images installed --with HamPack
|
||||||
|
[ "$status" -eq 1 ]
|
||||||
|
[[ "$output" == *"can't add sibling projects"* ]]
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user