From 686cbe4e5176d781a0d00ddaffc19b7a3f0ec309 Mon Sep 17 00:00:00 2001 From: William Yang Date: Wed, 23 Oct 2024 20:10:42 +0200 Subject: [PATCH] refactor: tools/run scripts --- tools/run/bin/debug-check | 36 ++------------------------------- tools/run/bin/lib.sh | 38 +++++++++++++++++++++++++++++++++++ tools/run/bin/sanitizer-check | 34 ++----------------------------- tools/run/bin/valgrind-check | 37 +++------------------------------- 4 files changed, 45 insertions(+), 100 deletions(-) create mode 100644 tools/run/bin/lib.sh diff --git a/tools/run/bin/debug-check b/tools/run/bin/debug-check index 2f1a277a..2c49f3f5 100755 --- a/tools/run/bin/debug-check +++ b/tools/run/bin/debug-check @@ -12,42 +12,10 @@ # # lib_dir=$(dirname "$(realpath "$0")") - -# for compiler flag -#export QUICER_USE_SANITIZERS=1 +source ${lib_dir}/lib.sh # for using asan emulator export ESCRIPT_EMULATOR="${lib_dir}/erl-debug" - -# Since cerl returns different code:root_dir(), we need to override it here -# Erlang_OTP_ROOT_DIR will be picked up by CMakeLists.txt -export Erlang_OTP_ROOT_DIR=$(dirname $(dirname $(which erl))) - -# Set ERL_TOP for Suppressions list -export ERL_TOP=$(cerl -noshell -eval "io:format(\"~s\", [code:root_dir()])" -s erlang halt) - export QUICER_USE_SNK=1 -REBAR3=$(command -v rebar3) - -if [ $# -eq 1 ]; then - case $1 in - all) - escript "$REBAR3" ct - ;; - one_by_one) - AllTCs=$(erl -pa _build/test/lib/quicer/test/ -noshell \ - -eval 'io:format("~p", [lists:flatten( string:join(lists:map(fun erlang:atom_to_list/1, quicer_SUITE:all()), " ") )]), halt()') - for tc in ${AllTCs}; - do - echo "running tc $tc"; - escript "$REBAR3" do ct --suite=test/quicer_SUITE --case="$tc"; - done - ;; - proper) - escript "$REBAR3" as test proper - ;; - esac -else - escript "$REBAR3" $@ -fi +do_run $@ diff --git a/tools/run/bin/lib.sh b/tools/run/bin/lib.sh new file mode 100644 index 00000000..519f6f7c --- /dev/null +++ b/tools/run/bin/lib.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env sh +#export QUICER_USE_SNK=1 +REBAR3=$(command -v rebar3) + +# Since cerl returns different code:root_dir(), we need to override it here +# Erlang_OTP_ROOT_DIR will be picked up by CMakeLists.txt +export Erlang_OTP_ROOT_DIR=$(dirname $(dirname $(which erl))) + +# Set ERL_TOP for Suppressions list +export ERL_TOP=$(cerl -noshell -eval "io:format(\"~s\", [code:root_dir()])" -s erlang halt) + +do_run() { + if [ $# -lt 1 ]; then + echo "Usage: $0 " + exit 1 + fi + + case $1 in + all) + escript "$REBAR3" ct + ;; + one_by_one) + AllTCs=$(erl -pa _build/test/lib/quicer/test/ -noshell \ + -eval 'io:format("~p", [lists:flatten( string:join(lists:map(fun erlang:atom_to_list/1, quicer_SUITE:all()), " ") )]), halt()') + for tc in ${AllTCs}; + do + echo "running tc $tc"; + escript "$REBAR3" do ct --suite=test/quicer_SUITE --case="$tc"; + done + ;; + proper) + escript "$REBAR3" as test proper + ;; + *) + escript "$REBAR3" $@ + ;; + esac +} diff --git a/tools/run/bin/sanitizer-check b/tools/run/bin/sanitizer-check index 58d7d378..3a74e9c1 100755 --- a/tools/run/bin/sanitizer-check +++ b/tools/run/bin/sanitizer-check @@ -12,6 +12,7 @@ # # lib_dir=$(dirname "$(realpath "$0")") +source ${lib_dir}/lib.sh # for compiler flag export QUICER_USE_SANITIZERS=1 @@ -19,15 +20,6 @@ export QUICER_USE_SANITIZERS=1 # for using asan emulator export ESCRIPT_EMULATOR="${lib_dir}/erl-asan" -# Since cerl returns different code:root_dir(), we need to override it here -# Erlang_OTP_ROOT_DIR will be picked up by CMakeLists.txt -export Erlang_OTP_ROOT_DIR=$(dirname $(dirname $(which erl))) - -# Set ERL_TOP for Suppressions list -export ERL_TOP=$(cerl -noshell -eval "io:format(\"~s\", [code:root_dir()])" -s erlang halt) - -export QUICER_USE_SNK=1 - # For asan log output if [ -z "${ASAN_LOG_DIR}" ]; then export ASAN_LOG_DIR=${PWD}/asan_logs @@ -35,26 +27,4 @@ fi mkdir -p "${ASAN_LOG_DIR}" -REBAR3=$(command -v rebar3) - -if [ $# -eq 1 ]; then - case $1 in - all) - escript "$REBAR3" ct - ;; - one_by_one) - AllTCs=$(erl -pa _build/test/lib/quicer/test/ -noshell \ - -eval 'io:format("~p", [lists:flatten( string:join(lists:map(fun erlang:atom_to_list/1, quicer_SUITE:all()), " ") )]), halt()') - for tc in ${AllTCs}; - do - echo "running tc $tc"; - escript "$REBAR3" do ct --suite=test/quicer_SUITE --case="$tc"; - done - ;; - proper) - escript "$REBAR3" as test proper - ;; - esac -else - escript "$REBAR3" $@ -fi +do_run $@ diff --git a/tools/run/bin/valgrind-check b/tools/run/bin/valgrind-check index f9c289d1..c224512d 100755 --- a/tools/run/bin/valgrind-check +++ b/tools/run/bin/valgrind-check @@ -12,21 +12,12 @@ # # lib_dir=$(dirname "$(realpath "$0")") - -# for compiler flag -export QUICER_USE_SANITIZERS=1 +source "${lib_dir}/lib.sh" # for using asan emulator export ESCRIPT_EMULATOR="${lib_dir}/erl-valgrind" -# Since cerl returns different code:root_dir(), we need to override it here -# Erlang_OTP_ROOT_DIR will be picked up by CMakeLists.txt -export Erlang_OTP_ROOT_DIR=$(dirname $(dirname $(which erl))) - -# Set ERL_TOP for Suppressions list -export ERL_TOP=$(cerl -noshell -eval "io:format(\"~s\", [code:root_dir()])" -s erlang halt) - -#export QUICER_USE_SNK=1 +export QUICER_USE_SNK=1 # For log output if [ -z "${VALGRIND_LOG_DIR}" ]; then @@ -35,26 +26,4 @@ fi mkdir -p "${VALGRIND_LOG_DIR}" -REBAR3=$(command -v rebar3) - -if [ $# -eq 1 ]; then - case $1 in - all) - escript "$REBAR3" ct - ;; - one_by_one) - AllTCs=$(erl -pa _build/test/lib/quicer/test/ -noshell \ - -eval 'io:format("~p", [lists:flatten( string:join(lists:map(fun erlang:atom_to_list/1, quicer_SUITE:all()), " ") )]), halt()') - for tc in ${AllTCs}; - do - echo "running tc $tc"; - escript "$REBAR3" do ct --suite=test/quicer_SUITE --case="$tc"; - done - ;; - proper) - escript "$REBAR3" as test proper - ;; - esac -else - escript "$REBAR3" $@ -fi +do_run $@