Skip to content

Commit

Permalink
add a runconf-based contrib example
Browse files Browse the repository at this point in the history
Signed-off-by: Jiri Jaburek <[email protected]>
  • Loading branch information
comps committed Feb 1, 2022
1 parent 401f28d commit 7270e41
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/contrib/runconf/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Some test suite use an intermediary layer between tests and the execution logic
to re-use test code by parametrizing the tests.

For example, a test can check ELF binary properties of any passed argument,
reporting PASS/FAIL for that file. An intermediary "runconf" then specifies
several executions of that same test, with different arguments.

These "runconf" files can be a simple static language (like runtest files in the
Linux Test Project), or they can be scripts that dynamically select/parametrize
the tests based on environment.

This example uses bash "runconf", defining a custom function called '+' that
appends user-provided strings into a big array, which simply get passed to
ptef-runner during a default argument-less run.
When arguments are given on CLI, anything from runconf is ignored and the CLI
arguments are used instead, preserving standard PTEF behavior.
9 changes: 9 additions & 0 deletions examples/contrib/runconf/etc-checks/empty
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -x
while [ $# -gt 0 ]; do
if [ -f "/$1" -a ! -s "/$1" ]; then
ptef-report PASS "$1"
else
ptef-report FAIL "$1"
fi
shift
done
9 changes: 9 additions & 0 deletions examples/contrib/runconf/etc-checks/exists
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -x
while [ $# -gt 0 ]; do
if [ -e "/$1" ]; then
ptef-report PASS "$1"
else
ptef-report FAIL "$1"
fi
shift
done
1 change: 1 addition & 0 deletions examples/contrib/runconf/etc-checks/run
17 changes: 17 additions & 0 deletions examples/contrib/runconf/etc-checks/runconf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# this is sourced by bash, so any bash logic is valid here

+ exists/etc/passwd

id=$(. /etc/os-release; echo "$ID")
idlike=$(. /etc/os-release; echo "$ID_LIKE")

if [ "$id" = "fedora" -o "$idlike" = "fedora" ]; then
+ empty/etc/cron.deny
+ empty/etc/motd
fi

if false; then
+ this/is/never/added
fi

# vim: syntax=sh
1 change: 1 addition & 0 deletions examples/contrib/runconf/run
28 changes: 28 additions & 0 deletions examples/contrib/runconf/utils/custom-runner
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

_alltests=()
function + {
_alltests+=("$@")
}

if [ -f runconf ]; then
. runconf
fi

_base=$(basename "$0")

if [ $# -eq 0 ]; then
# no tests configured: behave according to spec, run everything
if [ "${#_alltests[@]}" -eq 0 ]; then
ptef-runner -a "$_base"
else
# since 'alltests' can contain more than ARG_MAX strings,
# use xargs to split them into ARG_MAX-sized runs
printf '%s\0' "${_alltests[@]}" | \
xargs -0 ptef-runner -a "$_base"
fi
else
# running with user arguments, override alltests and just run what
# the user instructed, per the spec
ptef-runner -a "$_base" "$@"
fi

0 comments on commit 7270e41

Please sign in to comment.