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

[RFC] check: Add option for report generation #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion check
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,10 @@ _call_test() {
_write_test_run
_output_test_run

if [[ $GENERATE_REPORT -eq 1 ]]; then
_generate_test_report
fi

if [[ ${TEST_RUN["status"]} = fail ]]; then
case "${TEST_RUN["reason"]}" in
output)
Expand Down Expand Up @@ -585,6 +589,15 @@ _check() {
# shellcheck disable=SC2034
SRCDIR="$(realpath src)"

if [[ $GENERATE_REPORT -eq 1 && $REPORT_FORMAT != 'text' ]]; then
_error "Supported report formats: text"
else
# shellcheck disable=SC1091
. "common/reports"
_report_main
fi


local test_dev
for test_dev in "${TEST_DEVS[@]}"; do
if [[ ! -e $test_dev ]]; then
Expand Down Expand Up @@ -644,6 +657,9 @@ Test runs:
-x, --exclude=TEST exclude a test (or test group) from the list of
tests to run

-R, --report=format generate report in specified format for each TEST_DEVS
Supported formats: text

Miscellaneous:
-c, --config=FILE load configuration from FILE instead of the default
(\"./config\"); if this option is used multiple times,
Expand All @@ -663,7 +679,7 @@ Miscellaneous:
esac
}

if ! TEMP=$(getopt -o 'do:q::x:c:h' --long 'device-only,quick::,exclude:,output:,config:,help' -n "$0" -- "$@"); then
if ! TEMP=$(getopt -o 'do:q::x:R:c:h' --long 'device-only,quick::,exclude:,output:,report:,config:,help' -n "$0" -- "$@"); then
exit 1
fi

Expand All @@ -672,6 +688,7 @@ unset TEMP

LOADED_CONFIG=0
OPTION_EXCLUDE=()
GENERATE_REPORT=0
while true; do
case "$1" in
'-d'|'--device-only')
Expand All @@ -692,6 +709,11 @@ while true; do
OPTION_EXCLUDE+=("$2")
shift 2
;;
'-R'|'--report')
GENERATE_REPORT=1
REPORT_FORMAT="$2"
shift 2
;;
'-c'|'--config')
# shellcheck source=/dev/null
. "$2"
Expand Down
30 changes: 30 additions & 0 deletions common/reports
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

_generate_test_report() {
local device
device="$(basename "$RESULTS_DIR")"

#xunit to follow
if [[ $REPORT_FORMAT == 'text' ]]; then
printf '\n%s\n' "$device" >> "$AGGRES"
printf '%s\n' "$TEST_NAME" >> "$AGGRES"

local key value
for key in "${!TEST_RUN[@]}"; do
value="${TEST_RUN["$key"]}"
printf '%s\t%s\n' "$key" "$value" >> "$AGGRES"
done
fi
}

_report_main() {
AGGRES="${OUTPUT}/report_${REPORT_FORMAT}"

echo "genereting report ... ${REPORT_FORMAT} (in ${AGGRES})"

#xunit to follow
if [[ $REPORT_FORMAT == 'text' ]]; then
echo "$REPORT_FORMAT report generated on $(date)" > "$AGGRES"
fi
}