From f663a30c34c516dbc4c1fb6643106464623422bd Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Tue, 22 Oct 2024 20:04:05 +0200 Subject: [PATCH 01/12] test/smoketest: rename signature script to samconf-sign. --- test/smoketest/smoketest.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/smoketest/smoketest.sh b/test/smoketest/smoketest.sh index a62a4eb..d005523 100755 --- a/test/smoketest/smoketest.sh +++ b/test/smoketest/smoketest.sh @@ -54,7 +54,7 @@ function smoketest_signed_config { local CONFIG_FILE="$RESULT_DIR/config.json" echo "Starting smoketest signed config ..." - signature.sh $CONFIG_FILE "$PRIVATE_KEY" + samconf-sign $CONFIG_FILE "$PRIVATE_KEY" samprobe $CONFIG_FILE &> $RESULT_DIR/signed_config_output.txt re=$? if [ $re -ne 0 ]; then @@ -103,7 +103,7 @@ function smoketest_sign_config { echo "Starting smoketest signing config ..." - signature.sh "$RESULT_DIR/config.json" "$PRIVATE_KEY" + samconf-sign "$RESULT_DIR/config.json" "$PRIVATE_KEY" if [ $? -ne 0 ]; then error_exit "signing failed: executable returned error code on exit" fi @@ -130,7 +130,7 @@ function smoketest_genkeys { mkdir -p $RESULT_DIR echo "Starting smoketest signing config ..." - signature.sh create_keys "$RESULT_DIR" "samconf" + samconf-sign create_keys "$RESULT_DIR" "samconf" if [ $? -ne 0 ]; then error_exit "creating a key pair failed" fi From 00a18018bbd6ff2fa481e6b5603a2e94a30d0d17 Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Wed, 23 Oct 2024 17:23:30 +0200 Subject: [PATCH 02/12] cmake: Make sure to install samconf-sign with executable bits. --- src/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c71ab99..a3fa871 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,7 +9,10 @@ add_subdirectory(samconf) if (INSTALL_SAMCONF_TOOLS) install(PROGRAMS ${PROJECT_SOURCE_DIR}/src/signature.sh - PERMISSIONS OWNER_READ OWNER_WRITE + PERMISSIONS + OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_WRITE GROUP_EXECUTE + WORLD_READ WORLD_WRITE WORLD_EXECUTE DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME samconf-sign) endif (INSTALL_SAMCONF_TOOLS) From fef7a8a5e6607587c5576fca96f2f01f5e71068b Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Tue, 22 Oct 2024 20:03:10 +0200 Subject: [PATCH 03/12] smoketest: Refactor environment setup to be independent of the source tree. Now the smoketest script shall not make assumptions about to run inside the source repository and can be installed everywhere. Remove duplication in SMOKETEST_RESULT_DIR. --- ci/run_smoketests.sh | 8 +++++--- test/smoketest/smoketest.sh | 19 ++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/ci/run_smoketests.sh b/ci/run_smoketests.sh index 79a7dd4..b65fcd4 100755 --- a/ci/run_smoketests.sh +++ b/ci/run_smoketests.sh @@ -5,11 +5,13 @@ CMD_PATH=$(cd "$(dirname "$0")" && pwd) BASE_DIR=${CMD_PATH%/*} BUILD_TYPE="${1:-Debug}" -BUILD_DIR="$BASE_DIR/build/$BUILD_TYPE/" - -export SMOKETEST_RESULT_DIR="${SMOKETEST_RESULT_DIR-$BUILD_DIR/result/smoketest_results}" +BUILD_DIR="$BASE_DIR/build/$BUILD_TYPE" SMOKETEST_RUNNER="$BASE_DIR/test/smoketest/smoketest.sh" +export PREFIX_PATH="$BUILD_DIR/dist/usr/local" +export SMOKETEST_RESULT_DIR="${SMOKETEST_RESULT_DIR-$BUILD_DIR/result/smoketest}" +export LD_LIBRARY_PATH="${BASE_DIR}/build/deps/lib" + rm -rf "$SMOKETEST_RESULT_DIR" time "$SMOKETEST_RUNNER" simple_config "$BUILD_TYPE" diff --git a/test/smoketest/smoketest.sh b/test/smoketest/smoketest.sh index d005523..e30a64f 100755 --- a/test/smoketest/smoketest.sh +++ b/test/smoketest/smoketest.sh @@ -1,17 +1,16 @@ #!/bin/bash set -eou pipefail -BASE_DIR=$(realpath $(dirname $0)/../../) +CMDPATH="$(realpath "$(dirname "$0")")" + +export PREFIX_PATH="${PREFIX_PATH-"/usr"}" +export LD_LIBRARY_PATH="${LD_LIBRARY_PATH-""}:${PREFIX_PATH}/lib" +export PATH="${PATH}:${PREFIX_PATH}/bin" -BUILD_TYPE="${2:-Debug}" -BUILD_DIR="$BASE_DIR/build/$BUILD_TYPE" +export SMOKETEST_DIR=${SMOKETEST_DIR-${CMDPATH}} +export SMOKETEST_RESULT_DIR=${SMOKETEST_RESULT_DIR-"./results/smoketest"} +export SMOKETEST_TMP_DIR="${SMOKETEST_TMP_DIR-"$(mktemp -d /tmp/samconf_smoketest_XXXXXX)"}" -DIST_DIR=$(realpath "$BUILD_DIR/dist/") - -export LD_LIBRARY_PATH="$DIST_DIR/usr/local/lib" -export PATH=${PATH}:"$BUILD_DIR/cmake/src/demo:$DIST_DIR/usr/local/bin:$BASE_DIR/src" -export SMOKETEST_DIR=${SMOKETEST_DIR-"$(dirname $0)"} -export SMOKETEST_RESULT_DIR=${SMOKETEST_RESULT_DIR-"$BUILD_DIR/result/smoketest_results"} export PRIVATE_KEY="$SMOKETEST_DIR/samconf.pem" export PUBLIC_KEY="$SMOKETEST_DIR/samconf.pub" export SAMCONF_SIGNATURE_KEY="$PUBLIC_KEY" @@ -152,8 +151,6 @@ smoketest_compile_program_using_libsamconf_test_utils() { rm -rvf $RESULT_DIR mkdir -p $RESULT_DIR - SMOKETEST_TMP_DIR=$(mktemp -d /tmp/samconf_smoketest_XXXXXX) - echo "Try to compile simple program using libsamconf_test_utils" TEST_C_PROG=' #include From f7d59e9fcfab3f88589de7a5c85f552096b8605d Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Wed, 23 Oct 2024 17:27:39 +0200 Subject: [PATCH 04/12] ci: Add summary to run_smoketests.sh and return failure on test fails. Return number of failed test. --- ci/run_smoketests.sh | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/ci/run_smoketests.sh b/ci/run_smoketests.sh index b65fcd4..211adbc 100755 --- a/ci/run_smoketests.sh +++ b/ci/run_smoketests.sh @@ -14,10 +14,30 @@ export LD_LIBRARY_PATH="${BASE_DIR}/build/deps/lib" rm -rf "$SMOKETEST_RESULT_DIR" -time "$SMOKETEST_RUNNER" simple_config "$BUILD_TYPE" -time "$SMOKETEST_RUNNER" signed_config "$BUILD_TYPE" -time "$SMOKETEST_RUNNER" error_signed_config "$BUILD_TYPE" -time "$SMOKETEST_RUNNER" sign_config "$BUILD_TYPE" -time "$SMOKETEST_RUNNER" genkeys "$BUILD_TYPE" -time "$SMOKETEST_RUNNER" compile_program_using_libsamconf_test_utils "$BUILD_TYPE" +FAIL=0 +RESULT="" +function run_test() { + TEST_NAME="${1}" + RESULT="${RESULT}${TEST_NAME} " + if time "${SMOKETEST_RUNNER}" "${TEST_NAME}" "${BUILD_TYPE}"; then + RESULT="${RESULT} OK\n" + else + RESULT="${RESULT} FAILED\n" + FAIL=$((FAIL + 1)) + fi +} + +run_test simple_config +run_test signed_config +run_test error_signed_config +run_test sign_config +run_test genkeys +run_test compile_program_using_libsamconf_test_utils + +echo "################################################################################" +echo "# Summary" +echo "################################################################################" +echo -e "${RESULT}" + +exit "${FAIL}" From 23ee9e890a40ab3e607824f8e4389f335b472299 Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Wed, 23 Oct 2024 17:44:16 +0200 Subject: [PATCH 05/12] ci: Add job for smoketests. --- .gitlab-ci.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7ff8400..4f188e8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -109,6 +109,32 @@ unit-test-debug: reports: junit: build/Debug/result/unit_test/junit.xml +smoketest-test-release: + stage: test + needs: + - build-docker-image + - build-release + - build-dependencies + script: + - ci/run_smoketests.sh Release + artifacts: + when: always + paths: + - build/Release/result/smoketest/ + +smoketest-test-debug: + stage: test + needs: + - build-docker-image + - build-debug + - build-dependencies + script: + - ci/run_smoketests.sh Debug + artifacts: + when: always + paths: + - build/Debug/result/smoketest/ + code-lint: stage: test needs: From 5d4c052969e5235701ddf965a42086d8163a0645 Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Wed, 23 Oct 2024 19:22:52 +0200 Subject: [PATCH 06/12] smoketest: Disable as-needed linker flag for compile checks. For some reason the order of specifying the libraries to link have no effect when compiling from stdin and will be removed by the linker because of `-as-needed`. So ensure the every thing is available by specifying -Wl,--no-as-needed. --- test/smoketest/smoketest.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/smoketest/smoketest.sh b/test/smoketest/smoketest.sh index e30a64f..97f50af 100755 --- a/test/smoketest/smoketest.sh +++ b/test/smoketest/smoketest.sh @@ -176,10 +176,10 @@ int main(int argc, char *argv[]) { echo "$TEST_C_PROG" echo "$TEST_C_PROG" \ - | gcc -v -xc -lsamconf_test_utils -lsamconf -lsafu \ + | gcc -v -Wl,--no-as-needed -xc -lsamconf_test_utils -lsamconf -lsafu \ -I "${DIST_DIR}/usr/local/include/" -L "${DIST_DIR}/usr/local/lib" \ -I "${BASE_DIR}/build/deps/include/" -L "${BASE_DIR}/build/deps/lib" \ - -o "${SMOKETEST_TMP_DIR}/testlibelos" - \ + -o "${SMOKETEST_TMP_DIR}/testlibelos" - \ >> "$RESULT_DIR/libsamconf_test_utils.log" 2>&1 if [ $? -ne 0 ]; then error_exit "failed to compile test program for libsamconf_test_utils" From e047f96b934f29bc6af7f155f2642cda72196669 Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Thu, 24 Oct 2024 11:47:23 +0200 Subject: [PATCH 07/12] smoketest: Add additional CFlags if running in the project directory --- test/smoketest/smoketest.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/smoketest/smoketest.sh b/test/smoketest/smoketest.sh index 97f50af..b79668d 100755 --- a/test/smoketest/smoketest.sh +++ b/test/smoketest/smoketest.sh @@ -146,6 +146,10 @@ function smoketest_genkeys { exit 0 } +run_in_source_tree() { + [ -d "${SMOKETEST_DIR}/../../build/deps" ] +} + smoketest_compile_program_using_libsamconf_test_utils() { RESULT_DIR="$SMOKETEST_RESULT_DIR/compile_program_using_libsamconf_test_utils" rm -rvf $RESULT_DIR @@ -175,10 +179,15 @@ int main(int argc, char *argv[]) { ' echo "$TEST_C_PROG" + if run_in_source_tree; then + BUILD_DEPS_PREFIX="${SMOKETEST_DIR}/../../build/deps" + EXTRA_FLAGS="-I ${BUILD_DEPS_PREFIX}/include/ -L ${BUILD_DEPS_PREFIX}/lib" + fi + echo "$TEST_C_PROG" \ | gcc -v -Wl,--no-as-needed -xc -lsamconf_test_utils -lsamconf -lsafu \ - -I "${DIST_DIR}/usr/local/include/" -L "${DIST_DIR}/usr/local/lib" \ - -I "${BASE_DIR}/build/deps/include/" -L "${BASE_DIR}/build/deps/lib" \ + -I "${PREFIX_PATH}/include/" -L "${PREFIX_PATH}/lib" \ + ${EXTRA_FLAGS} \ -o "${SMOKETEST_TMP_DIR}/testlibelos" - \ >> "$RESULT_DIR/libsamconf_test_utils.log" 2>&1 if [ $? -ne 0 ]; then From 527ae984636371c67f634da34dd1595dbb2a4be7 Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Thu, 24 Oct 2024 11:50:26 +0200 Subject: [PATCH 08/12] smoketest: Do not expect a bash, use `sh` as lowest common denominator. We also need to remove the `-o pipefail` option as not all shell's support it. --- test/smoketest/smoketest.sh | 53 +++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/test/smoketest/smoketest.sh b/test/smoketest/smoketest.sh index b79668d..54fed53 100755 --- a/test/smoketest/smoketest.sh +++ b/test/smoketest/smoketest.sh @@ -1,5 +1,5 @@ -#!/bin/bash -set -eou pipefail +#!/bin/sh +set -eu CMDPATH="$(realpath "$(dirname "$0")")" @@ -7,37 +7,34 @@ export PREFIX_PATH="${PREFIX_PATH-"/usr"}" export LD_LIBRARY_PATH="${LD_LIBRARY_PATH-""}:${PREFIX_PATH}/lib" export PATH="${PATH}:${PREFIX_PATH}/bin" -export SMOKETEST_DIR=${SMOKETEST_DIR-${CMDPATH}} -export SMOKETEST_RESULT_DIR=${SMOKETEST_RESULT_DIR-"./results/smoketest"} +export SMOKETEST_DIR="${SMOKETEST_DIR-${CMDPATH}}" +export SMOKETEST_RESULT_DIR="${SMOKETEST_RESULT_DIR-"./results/smoketest"}" export SMOKETEST_TMP_DIR="${SMOKETEST_TMP_DIR-"$(mktemp -d /tmp/samconf_smoketest_XXXXXX)"}" export PRIVATE_KEY="$SMOKETEST_DIR/samconf.pem" export PUBLIC_KEY="$SMOKETEST_DIR/samconf.pub" export SAMCONF_SIGNATURE_KEY="$PUBLIC_KEY" -function smoketest_simple_config { - set -x +smoketest_simple_config() { RESULT_DIR="$SMOKETEST_RESULT_DIR/simple_config" - rm -rvf $RESULT_DIR - mkdir -p $RESULT_DIR + rm -rvf "${RESULT_DIR}" + mkdir -p "${RESULT_DIR}" echo "Starting smoketest simple config ..." - samprobe "$SMOKETEST_DIR"/config.json &> $RESULT_DIR/simple_config_output.txt - - if [ $? -ne 0 ]; then + if ! samprobe "$SMOKETEST_DIR"/config.json > "${RESULT_DIR}/simple_config_output.txt" 2>&1; then error_exit "samprobe failed" fi - echo -ne "Signature file ${SMOKETEST_DIR}/config.json.sig does not exist.\n\n" \ - > ${RESULT_DIR}/simple_config_nosign_output.txt - cat ${SMOKETEST_DIR}/simple_config_output.txt \ - >> ${RESULT_DIR}/simple_config_nosign_output.txt + printf "Signature file %s/config.json.sig does not exist.\n\n" "${SMOKETEST_DIR}" \ + > "${RESULT_DIR}/simple_config_nosign_output.txt" + cat "${SMOKETEST_DIR}/simple_config_output.txt" \ + >> "${RESULT_DIR}/simple_config_nosign_output.txt" echo "Smoketest comparing output ${RESULT_DIR}/simple_config_output.txt with ${RESULT_DIR}/simple_config_nosign_output.txt" - output_diff=$(diff -w ${RESULT_DIR}/simple_config_output.txt ${RESULT_DIR}/simple_config_nosign_output.txt || echo "diff returned: $?") + output_diff=$(diff -w "${RESULT_DIR}/simple_config_output.txt" "${RESULT_DIR}/simple_config_nosign_output.txt" || echo "diff returned: $?") if [ -n "$output_diff" ]; then echo "Problems occurred while comparing the client output:" - echo -e "$output_diff" + echo "$output_diff" error_exit "Test failed" fi @@ -45,12 +42,12 @@ function smoketest_simple_config { exit 0 } -function smoketest_signed_config { +smoketest_signed_config() { RESULT_DIR="$SMOKETEST_RESULT_DIR/signed_config" rm -rvf $RESULT_DIR mkdir -p $RESULT_DIR cp -a "$SMOKETEST_DIR/config.json" "$RESULT_DIR/config.json" - local CONFIG_FILE="$RESULT_DIR/config.json" + CONFIG_FILE="${RESULT_DIR}/config.json" echo "Starting smoketest signed config ..." samconf-sign $CONFIG_FILE "$PRIVATE_KEY" @@ -64,17 +61,17 @@ function smoketest_signed_config { exit 0 } -function smoketest_error_signed_config { +smoketest_error_signed_config() { RESULT_DIR="$SMOKETEST_RESULT_DIR/error_signed_config" rm -rvf $RESULT_DIR mkdir -p $RESULT_DIR cp -a "$SMOKETEST_DIR/config.json" "$RESULT_DIR/config.json" - local CONFIG_FILE="$RESULT_DIR/config.json" + CONFIG_FILE="${RESULT_DIR}/config.json" echo "Starting smoketest error signed config ..." - echo -n "RSA-SHA2-256:///1234567890123456789012345678901234567890123456789012345678901234" > $CONFIG_FILE.sig + echo "RSA-SHA2-256:///1234567890123456789012345678901234567890123456789012345678901234" > "$CONFIG_FILE.sig" set +e - samprobe $CONFIG_FILE &> $RESULT_DIR/error_signed_config_output.txt + samprobe "$CONFIG_FILE" > "${RESULT_DIR}/error_signed_config_output.txt" 2>&1 re=$? set -e if [ $re -eq 0 ]; then @@ -93,7 +90,7 @@ function smoketest_error_signed_config { exit 0 } -function smoketest_sign_config { +smoketest_sign_config() { RESULT_DIR="$SMOKETEST_RESULT_DIR/sign_config" rm -rvf $RESULT_DIR mkdir -p $RESULT_DIR @@ -123,7 +120,7 @@ function smoketest_sign_config { exit 0 } -function smoketest_genkeys { +smoketest_genkeys() { RESULT_DIR="$SMOKETEST_RESULT_DIR/genkeys" rm -rvf $RESULT_DIR mkdir -p $RESULT_DIR @@ -184,7 +181,7 @@ int main(int argc, char *argv[]) { EXTRA_FLAGS="-I ${BUILD_DEPS_PREFIX}/include/ -L ${BUILD_DEPS_PREFIX}/lib" fi - echo "$TEST_C_PROG" \ + printf '%s' "$TEST_C_PROG" \ | gcc -v -Wl,--no-as-needed -xc -lsamconf_test_utils -lsamconf -lsafu \ -I "${PREFIX_PATH}/include/" -L "${PREFIX_PATH}/lib" \ ${EXTRA_FLAGS} \ @@ -197,13 +194,13 @@ int main(int argc, char *argv[]) { exit 0 } -function print_help { +print_help() { echo echo "Usage: $0 " echo } -function error_exit { +error_exit() { echo "Error : $1, terminating smoketest ..." exit 1 } From 35d7c28a8ec4f0f9939ce4f019dc6c8cbc191d99 Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Wed, 30 Oct 2024 14:23:50 +0100 Subject: [PATCH 09/12] ci: Pass SAMCONF_DEPENDENCY_CONFIG into docker container. --- ci/docker-run.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/docker-run.sh b/ci/docker-run.sh index b88ed65..d5283ea 100755 --- a/ci/docker-run.sh +++ b/ci/docker-run.sh @@ -46,6 +46,7 @@ docker run --rm ${IT} $SSH_AGENT_OPTS \ -w /base \ ${GIT_USER_TOKEN:+-e GIT_USER_TOKEN="${GIT_USER_TOKEN}"} \ ${SOURCES_URI:+-e SOURCES_URI="${SOURCES_URI}"} \ + ${SAMCONF_DEPENDENCY_CONFIG:+-e SAMCONF_DEPENDENCY_CONFIG="${SAMCONF_DEPENDENCY_CONFIG}"} \ --privileged \ --device=/dev/kmsg \ "$IMAGE_NAME" "$@" From a77280bfcccaaf4fe01f28185ac26f16b8588879 Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Wed, 30 Oct 2024 14:43:23 +0100 Subject: [PATCH 10/12] smoketest: Fix remaining shellcheck warnings. --- test/smoketest/smoketest.sh | 62 ++++++++++++++++++++----------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/test/smoketest/smoketest.sh b/test/smoketest/smoketest.sh index 54fed53..e32ca4a 100755 --- a/test/smoketest/smoketest.sh +++ b/test/smoketest/smoketest.sh @@ -44,14 +44,14 @@ smoketest_simple_config() { smoketest_signed_config() { RESULT_DIR="$SMOKETEST_RESULT_DIR/signed_config" - rm -rvf $RESULT_DIR - mkdir -p $RESULT_DIR - cp -a "$SMOKETEST_DIR/config.json" "$RESULT_DIR/config.json" + rm -rvf "${RESULT_DIR}" + mkdir -p "${RESULT_DIR}" + cp -a "$SMOKETEST_DIR/config.json" "${RESULT_DIR}/config.json" CONFIG_FILE="${RESULT_DIR}/config.json" echo "Starting smoketest signed config ..." - samconf-sign $CONFIG_FILE "$PRIVATE_KEY" - samprobe $CONFIG_FILE &> $RESULT_DIR/signed_config_output.txt + samconf-sign "$CONFIG_FILE" "$PRIVATE_KEY" + samprobe "$CONFIG_FILE" > "${RESULT_DIR}/signed_config_output.txt" 2>&1 re=$? if [ $re -ne 0 ]; then error_exit "samprobe with signature failed" @@ -63,9 +63,9 @@ smoketest_signed_config() { smoketest_error_signed_config() { RESULT_DIR="$SMOKETEST_RESULT_DIR/error_signed_config" - rm -rvf $RESULT_DIR - mkdir -p $RESULT_DIR - cp -a "$SMOKETEST_DIR/config.json" "$RESULT_DIR/config.json" + rm -rvf "${RESULT_DIR}" + mkdir -p "${RESULT_DIR}" + cp -a "$SMOKETEST_DIR/config.json" "${RESULT_DIR}/config.json" CONFIG_FILE="${RESULT_DIR}/config.json" echo "Starting smoketest error signed config ..." @@ -79,10 +79,10 @@ smoketest_error_signed_config() { fi echo "Smoketest check output for expected error" - grep -q "ERR: Signature was invalid" $RESULT_DIR/error_signed_config_output.txt - if [ $? -ne 0 ]; then + + if ! grep -q "ERR: Signature was invalid" "${RESULT_DIR}/error_signed_config_output.txt"; then echo "samprobe failed with wrong error:" - cat $RESULT_DIR/error_signed_config_output.txt + cat "${RESULT_DIR}/error_signed_config_output.txt" error_exit "Test failed" fi @@ -92,23 +92,23 @@ smoketest_error_signed_config() { smoketest_sign_config() { RESULT_DIR="$SMOKETEST_RESULT_DIR/sign_config" - rm -rvf $RESULT_DIR - mkdir -p $RESULT_DIR - cp -a "$SMOKETEST_DIR/config.json" "$RESULT_DIR/config.json" + rm -rvf "${RESULT_DIR}" + mkdir -p "${RESULT_DIR}" + cp -a "$SMOKETEST_DIR/config.json" "${RESULT_DIR}/config.json" echo "Starting smoketest signing config ..." - samconf-sign "$RESULT_DIR/config.json" "$PRIVATE_KEY" - if [ $? -ne 0 ]; then + + if ! samconf-sign "${RESULT_DIR}/config.json" "$PRIVATE_KEY"; then error_exit "signing failed: executable returned error code on exit" fi - if [ ! -f "$RESULT_DIR/config.json.sig" ]; then + if [ ! -f "${RESULT_DIR}/config.json.sig" ]; then error_exit "signing failed: signature file doesnt exist" fi - OUTPUT=$(cat $RESULT_DIR/config.json.sig | tr -d "\n") + OUTPUT=$(tr -d "\n" < "${RESULT_DIR}/config.json.sig") EXPECTED_OUTPUT="RSA-SHA2-256:///vc7o5/wo8qPZ9aJiSYuJK/s7Ba4kZQA1luddm+YLozpuD1AT2YtkiasFKITbI3xJnWmeUFfv9k1mgJ0MEXNK/IF8T89lMSxk7eXze4zR32FwjKtjCrs7n4EU27+427QNE6C1tqmmxpwS07PUBA3ngRCa4n1LhrTciZWOEUMLTqAYsE72zd7yV4z0AMR5b1OhUuiKMpw2TLBypMRQZ9bQ63tXG4tBHpdCwq7c4C2OQLbbKB0OyrANg4MCSRYcghnx3Zks1I2NQCGoaK9ir8oYiHHM81UBREvbrT+1ghiu+Xf4O8NNfegSRM79CRsEyf0p23Qvil7+5RrxuspDBzvgnQ==" if [ "$OUTPUT" != "$EXPECTED_OUTPUT" ]; then echo "signing failed:" @@ -122,21 +122,21 @@ smoketest_sign_config() { smoketest_genkeys() { RESULT_DIR="$SMOKETEST_RESULT_DIR/genkeys" - rm -rvf $RESULT_DIR - mkdir -p $RESULT_DIR + rm -rvf "${RESULT_DIR}" + mkdir -p "${RESULT_DIR}" echo "Starting smoketest signing config ..." - samconf-sign create_keys "$RESULT_DIR" "samconf" - if [ $? -ne 0 ]; then + + if ! samconf-sign create_keys "${RESULT_DIR}" "samconf"; then error_exit "creating a key pair failed" fi - if [ ! -f $RESULT_DIR/samconf.pem ] || [ ! -s $RESULT_DIR/samconf.pem ]; then - error_exit "expected private key file does not exist or is empty : $RESULT_DIR/samconf.pem" + if [ ! -f "${RESULT_DIR}/samconf.pem" ] || [ ! -s "${RESULT_DIR}/samconf.pem" ]; then + error_exit "expected private key file does not exist or is empty : ${RESULT_DIR}/samconf.pem" fi - if [ ! -f $RESULT_DIR/samconf.pub ] || [ ! -s $RESULT_DIR/samconf.pub ]; then - error_exit "expected public key file does not exist or is empty : $RESULT_DIR/samconf.pub" + if [ ! -f "${RESULT_DIR}/samconf.pub" ] || [ ! -s "${RESULT_DIR}/samconf.pub" ]; then + error_exit "expected public key file does not exist or is empty : ${RESULT_DIR}/samconf.pub" fi echo "Finished smoketest." @@ -149,8 +149,8 @@ run_in_source_tree() { smoketest_compile_program_using_libsamconf_test_utils() { RESULT_DIR="$SMOKETEST_RESULT_DIR/compile_program_using_libsamconf_test_utils" - rm -rvf $RESULT_DIR - mkdir -p $RESULT_DIR + rm -rvf "${RESULT_DIR}" + mkdir -p "${RESULT_DIR}" echo "Try to compile simple program using libsamconf_test_utils" TEST_C_PROG=' @@ -181,12 +181,16 @@ int main(int argc, char *argv[]) { EXTRA_FLAGS="-I ${BUILD_DEPS_PREFIX}/include/ -L ${BUILD_DEPS_PREFIX}/lib" fi + # shellcheck disable=SC2086 + # reasoning: ${EXTRA_FLAGS} shall expand to " " separated flags printf '%s' "$TEST_C_PROG" \ | gcc -v -Wl,--no-as-needed -xc -lsamconf_test_utils -lsamconf -lsafu \ -I "${PREFIX_PATH}/include/" -L "${PREFIX_PATH}/lib" \ ${EXTRA_FLAGS} \ -o "${SMOKETEST_TMP_DIR}/testlibelos" - \ >> "$RESULT_DIR/libsamconf_test_utils.log" 2>&1 + # shellcheck disable=SC2181 + # reasoning: commandline is to long if [ $? -ne 0 ]; then error_exit "failed to compile test program for libsamconf_test_utils" fi @@ -210,7 +214,7 @@ if [ $# -lt 1 ]; then exit 1 fi -mkdir -p $SMOKETEST_RESULT_DIR +mkdir -p "$SMOKETEST_RESULT_DIR" case $1 in simple_config) From a97da121704a45dadf32e485967bc2d825d462c5 Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Wed, 30 Oct 2024 14:22:52 +0100 Subject: [PATCH 11/12] test/utils: Install pkg-config file for samconf_test_utils. --- test/utest/utils/CMakeLists.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/utest/utils/CMakeLists.txt b/test/utest/utils/CMakeLists.txt index c289880..e0dcdf7 100644 --- a/test/utest/utils/CMakeLists.txt +++ b/test/utest/utils/CMakeLists.txt @@ -55,4 +55,11 @@ if (SAMCONF_TEST_UTILS AND INSTALL_SAMCONF_TEST_UTILS) install(TARGETS samconf_test_utils EXPORT samconfTargets DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(DIRECTORY public/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h") + + include(${PROJECT_SOURCE_DIR}/cmake/pkgconfig/pkgconfig.cmake) + create_pkgconfig( + NAME "samconf_test_utils" + REQUIRES "safu >= ${safu_VERSION}, samconf >= ${samconf_VERSION}" + LIBS "-lsamconf_test_utils" + ) endif (SAMCONF_TEST_UTILS AND INSTALL_SAMCONF_TEST_UTILS) From f6abd6a6f9080272e5d4fb0e83ffb8891d994460 Mon Sep 17 00:00:00 2001 From: Wolfgang Gehrhardt Date: Thu, 31 Oct 2024 14:55:04 +0100 Subject: [PATCH 12/12] elos: Update to 0.60.0 --- cmake/project.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/project.cmake b/cmake/project.cmake index 221bca6..de43eec 100644 --- a/cmake/project.cmake +++ b/cmake/project.cmake @@ -1,5 +1,5 @@ # SPDX-License-Identifier: MIT -set(SAMCONF_VERSION 0.59.0) +set(SAMCONF_VERSION 0.60.0) # Attention: Aside from the version, as many things as possible in this file # should be put into functions, as this solves potential issues with commands