From 64ef7074dbc2509da7d7a08db28832228ea0318b Mon Sep 17 00:00:00 2001 From: JeremyTubongbanua Date: Fri, 3 Jan 2025 21:48:15 +0000 Subject: [PATCH] refactor: tests/functional_tests/tools --- tests/functional_tests/tools/build.sh | 49 +++++++++++++++++++ .../tools/{run_test.sh => clean.sh} | 10 +--- tests/functional_tests/tools/ctest.sh | 20 ++++++++ tests/functional_tests/tools/run_ctest.sh | 13 ----- 4 files changed, 70 insertions(+), 22 deletions(-) create mode 100755 tests/functional_tests/tools/build.sh rename tests/functional_tests/tools/{run_test.sh => clean.sh} (52%) create mode 100755 tests/functional_tests/tools/ctest.sh delete mode 100755 tests/functional_tests/tools/run_ctest.sh diff --git a/tests/functional_tests/tools/build.sh b/tests/functional_tests/tools/build.sh new file mode 100755 index 00000000..71610817 --- /dev/null +++ b/tests/functional_tests/tools/build.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# ########## +# This script CMake configures and builds the project for functional tests assuming virtual environment is already setup. +# ########## + +FULL_PATH_TO_SCRIPT="$(realpath "${BASH_SOURCE[0]}")" +SCRIPT_DIRECTORY="$(dirname "$FULL_PATH_TO_SCRIPT")" +cd "$SCRIPT_DIRECTORY" + +# 1. Go to the root of the project +cd ../../.. + +# 2. Variables + +# 2.1 Default values +ATSIGN_FIRST="@alice🛠" +ATSIGN_SECOND="@bob🛠" +ATDIRECTORY_HOST="vip.ve.atsign.zone" +ATDIRECTORY_PORT=64 + +# 2.2 Parse command line arguments +while getopts f:s:h:p: flag +do + case "${flag}" in + f) ATSIGN_FIRST=${OPTARG};; + s) ATSIGN_SECOND=${OPTARG};; + h) ATDIRECTORY_HOST=${OPTARG};; + p) ATDIRECTORY_PORT=${OPTARG};; + esac +done + +# 2.3 Print variables +echo "ATSIGN_FIRST (-f): $ATSIGN_FIRST" +echo "ATSIGN_SECOND (-s): $ATSIGN_SECOND" +echo "ATDIRECTORY_HOST (-h): $ATDIRECTORY_HOST" +echo "ATDIRECTORY_PORT (-p): $ATDIRECTORY_PORT" + +# 3. CMake configure +cmake -S . -B build \ + -DATSDK_BUILD_TESTS="func" \ + -DCMAKE_BUILD_TYPE=Debug \ + -DFIRST_ATSIGN="\"$ATSIGN_FIRST\"" \ + -DSECOND_ATSIGN="\"$ATSIGN_SECOND\"" \ + -DATDIRECTORY_HOST="\"$ATDIRECTORY_HOST\"" \ + -DATDIRECTORY_PORT=$ATDIRECTORY_PORT + +# 4. CMake build (this step will build atsdk and link the atsdk to the functional +cmake --build build diff --git a/tests/functional_tests/tools/run_test.sh b/tests/functional_tests/tools/clean.sh similarity index 52% rename from tests/functional_tests/tools/run_test.sh rename to tests/functional_tests/tools/clean.sh index ef3f91ee..425ef4c1 100755 --- a/tests/functional_tests/tools/run_test.sh +++ b/tests/functional_tests/tools/clean.sh @@ -1,13 +1,5 @@ #!/bin/bash -set -eu FULL_PATH_TO_SCRIPT="$(realpath "${BASH_SOURCE[0]}")" SCRIPT_DIRECTORY="$(dirname "$FULL_PATH_TO_SCRIPT")" cd "$SCRIPT_DIRECTORY" -cd .. - -"../../tools/install.sh" - -cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -cmake --build build --target $1 - -./build/$1 +rm -rf build \ No newline at end of file diff --git a/tests/functional_tests/tools/ctest.sh b/tests/functional_tests/tools/ctest.sh new file mode 100755 index 00000000..df994326 --- /dev/null +++ b/tests/functional_tests/tools/ctest.sh @@ -0,0 +1,20 @@ +#!/bin/bash +FULL_PATH_TO_SCRIPT="$(realpath "${BASH_SOURCE[0]}")" +SCRIPT_DIRECTORY="$(dirname "$FULL_PATH_TO_SCRIPT")" +cd "$SCRIPT_DIRECTORY" + +# 1. Go to root of the project + +cd ../../.. + +# 2. Check if build directory exists + +if [ ! -d "build" ]; then + echo "Build directory does not exist. Run build.sh first." + exit 1 +fi + +# 3. Run ctest + +ctest --test-dir build/tests/functional_tests --output-on-failure -VV --timeout 90 + diff --git a/tests/functional_tests/tools/run_ctest.sh b/tests/functional_tests/tools/run_ctest.sh deleted file mode 100755 index 0432fee5..00000000 --- a/tests/functional_tests/tools/run_ctest.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash -set -eu -FULL_PATH_TO_SCRIPT="$(realpath "${BASH_SOURCE[0]}")" -SCRIPT_DIRECTORY="$(dirname "$FULL_PATH_TO_SCRIPT")" -cd "$SCRIPT_DIRECTORY/.." - -# 1. Install atSDK -../../tools/install.sh - -# 2. Run tests -cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -cmake --build build -ctest --test-dir build -VV --timeout 60