diff --git a/.github/workflows/compilation.yaml b/.github/workflows/compilation.yaml index 1442389..5d16e5a 100644 --- a/.github/workflows/compilation.yaml +++ b/.github/workflows/compilation.yaml @@ -9,6 +9,8 @@ on: jobs: build: runs-on: ubuntu-latest + permissions: + contents: read steps: - name: Checkout code diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..30f6089 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,60 @@ +name: Run Tests + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + test: + runs-on: ubuntu-latest + permissions: + contents: read + checks: write + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Install Conan + uses: conan-io/setup-conan@v1 + + - name: Create default Conan profile + run: conan profile detect --force + + - name: Create build directory + run: mkdir -p src/build + + - name: Install dependencies + run: conan install src --output-folder=src/build --build=missing + + - name: Configure CMake + working-directory: src + run: cmake --preset conan-release + + - name: Build + working-directory: src + run: cmake --build --preset conan-release + + - name: Run unit tests + working-directory: src + run: | + echo "Running SHA implementation tests..." + ./run_all_ut.sh Release + # Also generate XML output for test reporting + ./build/Release/ut_sha_functions --gtest_output=xml:test-results.xml + continue-on-error: false + + - name: Publish test results + uses: EnricoMi/publish-unit-test-result-action@v2 + if: always() + with: + files: | + src/test-results.xml + check_name: "Unit Test Results" + comment_mode: "off" + + - name: Test Summary + if: always() + run: echo "✅ All tests completed successfully" diff --git a/README.md b/README.md index 2739ec5..ddcbce5 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Italian: Implementazione Secure Hash Algorithm (SHA) [![Cmake compilation Conan](https://github.com/AndreaCicca/SHA-implementation/actions/workflows/compilation.yaml/badge.svg)](https://github.com/AndreaCicca/SHA-implementation/actions/workflows/compilation.yaml) +[![Run Tests](https://github.com/AndreaCicca/SHA-implementation/actions/workflows/test.yaml/badge.svg)](https://github.com/AndreaCicca/SHA-implementation/actions/workflows/test.yaml) Corso di Crittografia presso Unipr. @@ -42,3 +43,32 @@ cmake --build build > [!NOTE] > Per non copia e incollare i singoli comandi si può usare lo script src/compile.sh + +## Esecuzione dei test + +Dopo aver compilato il progetto, è possibile eseguire i test unitari: + +### Eseguire tutti i test + +```bash +cd src && ./run_all_ut.sh +``` + +### Eseguire i test manualmente + +```bash +cd src && ./build/Release/ut_sha_functions +``` + +### Eseguire i test con output XML (per CI/CD) + +```bash +cd src && ./build/Release/ut_sha_functions --gtest_output=xml:test-results.xml +``` + +I test verificano la correttezza dell'implementazione SHA-1 e SHA-256 confrontandola con la libreria OpenSSL, includendo: +- Test con stringhe vuote, corte, lunghe e molto lunghe +- Test con caratteri speciali e non-ASCII +- Test di determinismo +- Test dell'effetto valanga (avalanche effect) +- Test di performance diff --git a/src/run_all_ut.sh b/src/run_all_ut.sh index 475b253..eda997d 100755 --- a/src/run_all_ut.sh +++ b/src/run_all_ut.sh @@ -5,9 +5,32 @@ set -e # Nella cartella ./build avviare tutti gli eseguibili che iniziano con ut_ BUILD_DIR="build" +BUILD_TYPE="${1:-Release}" # Default to Release if not specified -if [ -d "$BUILD_DIR" ]; then - for file in "$BUILD_DIR"/ut_*; do - ./"$file" - done -fi \ No newline at end of file +# Cerca gli eseguibili di test nelle diverse possibili locazioni +TEST_LOCATIONS=( + "$BUILD_DIR/$BUILD_TYPE" + "$BUILD_DIR" +) + +echo "Searching for test executables (build type: $BUILD_TYPE)..." + +TESTS_FOUND=0 +for location in "${TEST_LOCATIONS[@]}"; do + if [ -d "$location" ]; then + for file in "$location"/ut_*; do + if [ -x "$file" ]; then + echo "Running test: $file" + "$file" + TESTS_FOUND=$((TESTS_FOUND + 1)) + fi + done + fi +done + +if [ $TESTS_FOUND -eq 0 ]; then + echo "No test executables found. Please build the project first." + exit 1 +fi + +echo "All tests completed successfully! ($TESTS_FOUND test suite(s) executed)" \ No newline at end of file