From f318360b3a519f9459863dd642df11069485ec16 Mon Sep 17 00:00:00 2001 From: Patrick Baudin <patrick.baudin@cea.fr> Date: Tue, 28 Jun 2022 15:11:01 +0200 Subject: [PATCH] [Script] bin/tests.sh: Clone/Pull WP-Cache --- bin/test.sh | 162 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 126 insertions(+), 36 deletions(-) diff --git a/bin/test.sh b/bin/test.sh index c14fbdb167a..ebb7658eff3 100755 --- a/bin/test.sh +++ b/bin/test.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash ########################################################################## # # # This file is part of Frama-C. # @@ -25,25 +25,20 @@ CONFIG="<all>" UPDATE= VERBOSE= TESTS= +COUNT= -if [ ! -d "$FRAMAC_WP_QUALIF" ] -then - echo "Warning: FRAMAC_WP_QUALIF not set" - FRAMAC_WP_CACHE=replay -else - FRAMAC_WP_CACHE=offline - FRAMAC_WP_CACHEDIR=$FRAMAC_WP_QUALIF -fi +FRAMAC_WP_CACHE_GIT=git@git.frama-c.com:frama-c/wp-cache.git # -------------------------------------------------------------------------- # --- Help Message # -------------------------------------------------------------------------- +THIS_SCRIPT="$0" function Usage { echo "USAGE" echo "" - echo "./bin/test.sh [OPTIONS|TESTS]..." + echo "${THIS_SCRIPT} [OPTIONS|TESTS]..." echo "" echo "TESTS SPECIFICATION" echo "" @@ -55,7 +50,7 @@ function Usage echo "" echo "OPTIONS" echo "" - echo " -r|--clean clean (remove all) test results" + echo " -r|--clean clean (remove all) test results (includes -p)" echo " -p|--ptests prepare (all) dune files" echo " -v|--verbose display (next) tests output" echo " -u|--update run tests and update wp-cache" @@ -66,12 +61,91 @@ function Usage echo "" echo "VARIABLES" echo "" - echo " FRAMAC_WP_QUALIF" - echo " Clone of git@git.frama-c.com:frama-c/wp-cache.git" - echo " Please, always push updates to #master branch" + echo " FRAMAC_WP_CACHEDIR=$FRAMAC_WP_CACHEDIR" + echo " Git URL: $FRAMAC_WP_CACHE_GIT" + echo " Please, always push updates to #master branch" + echo "" + echo " FRAMAC_WP_CACHE=$FRAMAC_WP_CACHE" + echo " Management mode of wp-cache" echo "" } +# -------------------------------------------------------------------------- +# --- Utilities +# -------------------------------------------------------------------------- + +function Head() +{ + echo "# $@" +} + +function Error () +{ + echo "Error: $@" + exit 1 +} + +function ErrorUsage () +{ + echo "Error: $@" + echo "USAGE: ${THIS_SCRIPT} -h" + exit 1 +} + +function Echo() +{ + [ "$VERBOSE" != "yes" ] || echo $@ +} + +function Run +{ + Echo "> $@" + $@ +} + +function Cmd +{ + Run $@ + [ "$?" = "0" ] || Error "(command exits $?): $@" +} + +# -------------------------------------------------------------------------- +# --- WP Cache Environment +# -------------------------------------------------------------------------- + +function CloneCache +{ + if [ ! -d "$FRAMAC_WP_CACHEDIR" ]; then + Head "Cloning WP cache..." + Cmd git clone $FRAMAC_WP_CACHE_GIT $FRAMAC_WP_CACHEDIR + fi +} + +function PullCache +{ + Head "Pull WP cache..." + Run git -C $FRAMAC_WP_CACHEDIR pull --rebase +} + +function SetEnv +{ + if [ "$FRAMAC_WP_CACHE" = "" ] + then + FRAMAC_WP_CACHE=offline + Echo "Set FRAMAC_WP_CACHE=$FRAMAC_WP_CACHE" + fi + + if [ "$FRAMAC_WP_CACHEDIR" = "" ] + then + FRAMAC_WP_CACHEDIR=.wp-cache + Echo "Set FRAMAC_WP_CACHEDIR=$FRAMAC_WP_CACHEDIR" + fi + + CloneCache + PullCache + +} + # -------------------------------------------------------------------------- # --- Test Dir Processing # -------------------------------------------------------------------------- @@ -89,12 +163,8 @@ function TestDir ALIAS=$1/ptests_config_$CONFIG ;; esac - echo "dune build @$ALIAS" - dune build @$ALIAS - if [ $? != 0 ] - then - exit $? - fi + Head "Running test on directory $1" + Run dune build @$ALIAS } # -------------------------------------------------------------------------- @@ -105,10 +175,9 @@ function TestFile { DIR=$(dirname $1) FILE=$(basename $1) - if [ "$CONFIG" == "<all>" ] - then + [ "$CONFIG" != "<all>" ] || \ echo "Warning: can not run single test in all config" - fi + case "$CONFIG" in "<all>"|"<default>") RESULT=result @@ -123,12 +192,8 @@ function TestFile else ALIAS=$DIR/$RESULT/${FILE%.*}.wtests fi - echo "dune build @$ALIAS" - dune build @$ALIAS - if [ $? != 0 ] - then - exit $? - fi + Head "Running test on file $1" + Cmd build @$ALIAS } # -------------------------------------------------------------------------- @@ -146,9 +211,7 @@ function RunTests then TestFile $1 else - echo "ERROR: don't known what to do with '$1'" - echo "USAGE: bin/test.sh -h" - exit 1 + ErrorUsage "ERROR: don't known what to do with '$1'" fi shift done @@ -166,11 +229,14 @@ do exit 0 ;; "-r"|"--clean") - echo "Cleaning all tests" - make clean-tests + Head "Cleaning all tests..." + Cmd make clean-tests + Head "Generating dune files..." + Cmd make run-ptests ;; "-p"|"--ptests") - make run-ptests + Head "Generating dune files..." + Cmd make run-ptests ;; "-u"|"--update") UPDATE=yes @@ -186,11 +252,35 @@ do CONFIG=$2 shift ;; - *) + "-a"|"--all") + TESTS="tests src/plugins/*/tests" + ;; + "-n"|"--count") + COUNT=yes + ;; + *) TESTS+=" $1" ;; esac shift done +SetEnv RunTests $TESTS + +#-- Count number of .res.log files +if [ "$COUNT" = "yes" ]; then + + BUILD=_build/default + + Head "Number of .res.log files by test directory..." + NB= + for dir in tests src/plugins/*/tests ; do + if [ ! -d "$dir" ] ; then + NB="$((find $BUILD/$dir -name \*.res.log 2> /dev/null) | wc -l)" + [ "$NB" = "0"] || echo "- $dir= $NB" + fi + done + [ "$NB" != "" ] || echo "- <none>" + +fi -- GitLab