Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Igr-tests: Minor fixes and improvements #207

Merged
merged 3 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,8 @@

# Integration test output:
/src/igr-tests/*/output/**
/src/igr-tests/basic/basic-ran
/src/igr-tests/environ/env-record
/src/igr-tests/environ2/env-record
/src/igr-tests/ps-environ/env-record
/src/igr-tests/chain-to/recorded-output
/src/igr-tests/restart/basic-ran
/src/igr-tests/check-basic/output.txt
/src/igr-tests/check-cycle/output.txt
/src/igr-tests/check-cycle2/output.txt
/src/igr-tests/check-lint/output.txt
/src/igr-tests/reload1/sd
/src/igr-tests/reload2/sd
/src/igr-tests/no-command-error/dinit-run.log
/src/igr-tests/var-subst/args-record

# Generated man pages:
/doc/manpages/*.5
Expand Down
27 changes: 11 additions & 16 deletions src/igr-tests/igr_functions.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Included from run-test.sh files. Do not run independently.
# Included from run-test.sh files. DO NOT run independently.

### This file contain basic variables for running Integration tests of
### This file contain basic variables & functions for running Integration tests of
### Dinit.

# Input variables:
Expand Down Expand Up @@ -33,7 +33,7 @@ error() {
>&2 echo " ... $2"
fi
if [ -n "${STAGE:-}" ]; then
echo "${TEST_NAME:-}: Failed at stage $STAGE."
>&2 echo "${TEST_NAME:-}: Failed at stage $STAGE."
fi
if [ -e "${SOCKET:-}" ]; then
stop_dinit # A dinit instance is running, stopping...
Expand All @@ -57,31 +57,26 @@ find_executable() {
varname=$2
if [ -z "$(eval "echo \${${varname}:-}")" ]; then
if [ -x "$DINIT_BINDIR/$exename" ]; then
export $varname="$DINIT_BINDIR/$exename"
export "$varname"="$DINIT_BINDIR/$exename"
else
return 1
fi
fi
}

find_dinit() { find_executable dinit DINIT; }
find_dinitctl() { find_executable dinitctl DINITCTL; }
find_dinitcheck() { find_executable dinitcheck DINITCHECK; }
find_dinitmonitor() { find_executable dinit-monitor DINITMONITOR; }


## Change directory to run-test.sh location
cd "$(dirname "$0")" || error "Can't change directory to script location."

## Prepare $IGR_OUTPUT
TEST_NAME="${PWD##*/}"
if [ -z "$TEST_NAME" ]; then error "Failed to guess test name."; fi
[ -n "$TEST_NAME" ] || error "Failed to guess test name."
if [ -z "${IGR_OUTPUT:-}" ]; then
IGR_OUTPUT="$PWD"
if [ -z "$IGR_OUTPUT" ]; then error "Failed to guess igr output files location."; fi
[ -n "$IGR_OUTPUT" ] || error "Failed to guess igr output files location."
export IGR_OUTPUT
else
# Igr tests are used by meson.
# Igr test is probably used by Meson.
mkdir -p "$IGR_OUTPUT/$TEST_NAME/"
IGR_OUTPUT="$IGR_OUTPUT/$TEST_NAME/"
export IGR_OUTPUT
Expand All @@ -101,7 +96,7 @@ fi
# throw an error on failure.
spawn_dinit() {
find_dinit || error "Cannot find dinit exec path." "Specify 'DINIT_BINDIR' and/or ensure dinit is compiled."
"$DINIT" $QUIET -u -d sd -p "$SOCKET" "$@" &
"$DINIT" $QUIET -u -d sd -p "$SOCKET" -l /dev/null "$@" &
DINITPID=$!
# Wait for Dinit socket shows up.
TIMEOUT=0
Expand Down Expand Up @@ -132,7 +127,7 @@ stop_dinit() {
return 0
else
warning "Cannot stopping dinit via dinitctl." "Fallback to killing DINITPID."
kill "$DINITPID" || ( echo "${TEST_NAME:-}: Cannot stop Dinit instance!" && exit 1 )
kill "$DINITPID" || ( echo "${TEST_NAME:-}: Cannot stop Dinit instance!" && exit 1 ) >&2
wait "$DINITPID"
fi
}
Expand All @@ -143,7 +138,7 @@ stop_dinit() {
# throw an error on failure.
spawn_dinit_oneshot() {
find_dinit || error "Cannot find dinit exec path." "Specify 'DINIT_BINDIR' and/or ensure dinit is compiled."
"$DINIT" $QUIET -u -d sd -p "$SOCKET" "$@"
"$DINIT" $QUIET -u -d sd -p "$SOCKET" -l /dev/null "$@"
}

# This function find dinitctl and allow access to dinit daemon via dinitctl.
Expand Down Expand Up @@ -209,7 +204,7 @@ compare_file() {
# throw an error on any other failure.
compare_cmd() {
if [ ! -e "$2" ]; then
error "$2 file isn't exist!"
error "$2 file doesn't exist!"
fi
if [ "${3:-}" = "err" ]; then
CMD_OUT="$($1 2>&1 || true)"
Expand Down