From e724dd7f40240188b292a6b7e5101847798025b8 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Thu, 21 Jul 2022 08:26:49 +0200 Subject: [PATCH] Test: Added detail env var to sum.sh, Changed make test to include detailed test --- apps/snmp/snmp_handler.c | 6 +++--- docker/main/Makefile.in | 2 +- example/main/example_backend_nacm.c | 2 +- test/lib.sh | 1 + test/sum.sh | 30 +++++++++++++++++++++++++++-- 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/apps/snmp/snmp_handler.c b/apps/snmp/snmp_handler.c index 69f950e5..9854790d 100644 --- a/apps/snmp/snmp_handler.c +++ b/apps/snmp/snmp_handler.c @@ -83,7 +83,7 @@ snmp_common_handler(netsnmp_mib_handler *handler, { int retval = -1; netsnmp_variable_list *requestvb; /* sub of request */ - cbuf *cb; + cbuf *cb = NULL; if (request == NULL || shp == NULL){ clicon_err(OE_XML, EINVAL, "request or shp is null"); @@ -832,7 +832,7 @@ snmp_table_get(clicon_handle h, yang_stmt *yk; char *xpath = NULL; cvec *cvk_orig; - cvec *cvk_val; + cvec *cvk_val = NULL; int i; cg_var *cv; char *defaultval = NULL; @@ -951,7 +951,7 @@ snmp_table_set(clicon_handle h, yang_stmt *yrestype = NULL; char *xpath = NULL; cvec *cvk_orig; - cvec *cvk_val; + cvec *cvk_val = NULL; int i; cg_var *cv; int ret; diff --git a/docker/main/Makefile.in b/docker/main/Makefile.in index fdc61f00..038331e4 100644 --- a/docker/main/Makefile.in +++ b/docker/main/Makefile.in @@ -83,7 +83,7 @@ push: # therefore the sleep 1 before tests start test: docker ./cleanup.sh ; ./start.sh # kill (ignore error) and the start it - sudo docker exec -t clixon-system bash -c 'sleep 2 && cd /usr/local/bin/test && ./sum.sh' + sudo docker exec -t clixon-system bash -c 'sleep 2 && cd /usr/local/bin/test && detail=true ./sum.sh' depend: diff --git a/example/main/example_backend_nacm.c b/example/main/example_backend_nacm.c index 9001474a..9ee872c2 100644 --- a/example/main/example_backend_nacm.c +++ b/example/main/example_backend_nacm.c @@ -75,7 +75,7 @@ static int _transaction_log = 0; */ static char *_validate_fail_xpath = NULL; -/*! Sub state variable to fail on validate/commit, +/*! Sub state variable to fail on validate/commit (not configured) * Obscure, but a way to first trigger a validation error, next time to trigger a commit error */ static int _validate_fail_toggle = 0; /* fail at validate and commit */ diff --git a/test/lib.sh b/test/lib.sh index 0218fd4b..932b6c1f 100755 --- a/test/lib.sh +++ b/test/lib.sh @@ -312,6 +312,7 @@ if $NGINXCHECK; then fi # systemctl fi +# Temp directory where all tests write their data to dir=/var/tmp/$0 if [ ! -d $dir ]; then mkdir $dir diff --git a/test/sum.sh b/test/sum.sh index d94371fe..4d84c11e 100755 --- a/test/sum.sh +++ b/test/sum.sh @@ -8,6 +8,17 @@ : ${pattern:=test_*.sh} +# If set, show details of (first) failing test after all tests completed +: ${detail:=false} + +# temp directory, now used only by detail +dir=/var/tmp/$0 +if $detail; then + if [ ! -d $dir ]; then + mkdir $dir + fi +fi + # You can specify tests files to exclude using the 'SKIPLIST' variable in a # site.sh file. See example in README.md. Files excluded by the 'SKIPLIST' # variable have precedence over files included by the 'pattern' variable. @@ -28,20 +39,35 @@ fi let sumerr=0 # error counter for testfile in $pattern; do # For lib.sh the variable must be called testfile echo "Running $testfile" - ./$testfile > /dev/null 2>&1 + if $detail; then + ./$testfile > $dir/err.log 2>&1 + else + ./$testfile > /dev/null 2>&1 + fi errcode=$? if [ $errcode -ne 0 ]; then let sumerr++ echo -e "\e[31mError in $testfile errcode=$errcode" echo -ne "\e[0m" + if $detail; then + detail=false; # Just once for now, print at end + fi fi done if [ $sumerr -eq 0 ]; then echo "OK" else + echo -e "\e[31m" + if [ -f $dir/err.log ]; then + echo "Detailed output of first error:" + echo -ne "\e[0m" + cat $dir/err.log + echo + fi echo -e "\e[31m${sumerr} Errors" echo -ne "\e[0m" + rm -rf $dir exit -1 fi - +rm -rf $dir