From 587d59e82e2a004c6cb57b600d34c85c78c70d9d Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 20 May 2024 14:06:27 -0700 Subject: [PATCH 1/8] Add basic tests using Bash scripts --- CMakeLists.txt | 1 + test/CMakeLists.txt | 1 + test/bash/CMakeLists.txt | 30 ++++++++++++ test/bash/ssmc_tools.sh | 95 ++++++++++++++++++++++++++++++++++++ test/bash/test.sh | 103 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 230 insertions(+) create mode 100644 test/CMakeLists.txt create mode 100644 test/bash/CMakeLists.txt create mode 100644 test/bash/ssmc_tools.sh create mode 100644 test/bash/test.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index f0c953a..a215b43 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,4 +25,5 @@ target_link_libraries(${PROJECT_NAME} INTERFACE cjson) if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) add_subdirectory(examples) + add_subdirectory(test) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..e8882f0 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(bash) diff --git a/test/bash/CMakeLists.txt b/test/bash/CMakeLists.txt new file mode 100644 index 0000000..9df2e3f --- /dev/null +++ b/test/bash/CMakeLists.txt @@ -0,0 +1,30 @@ +function(download_data url file_name) + set(DATASET_ARCHIVE ${CMAKE_BINARY_DIR}/data/${file_name}) + + file(DOWNLOAD + ${url} + ${DATASET_ARCHIVE}) +endfunction() + +download_data(https://suitesparse-collection-website.herokuapp.com/MM/DIMACS10/chesapeake.tar.gz + chesapeake.tar.gz) + +download_data(https://suitesparse-collection-website.herokuapp.com/MM/HB/1138_bus.tar.gz + 1138_bus.tar.gz) + +download_data(https://suitesparse-collection-website.herokuapp.com/MM/Belcastro/mouse_gene.tar.gz + mouse_gene.tar.gz) + +download_data(https://suitesparse-collection-website.herokuapp.com/MM/Pajek/IMDB.tar.gz + IMDB.tar.gz) + +find_program(BASH_PROGRAM bash) + +enable_testing() + +if(BASH_PROGRAM) + add_test(NAME integration.chesapeake COMMAND ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/test.sh ${CMAKE_BINARY_DIR}/data/chesapeake.tar.gz) + add_test(NAME integration.1138_bus COMMAND ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/test.sh ${CMAKE_BINARY_DIR}/data/1138_bus.tar.gz) + add_test(NAME integration.mouse_gene COMMAND ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/test.sh ${CMAKE_BINARY_DIR}/data/mouse_gene.tar.gz) + add_test(NAME integration.IMDB COMMAND ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/test.sh ${CMAKE_BINARY_DIR}/data/IMDB.tar.gz) +endif() diff --git a/test/bash/ssmc_tools.sh b/test/bash/ssmc_tools.sh new file mode 100644 index 0000000..5b46802 --- /dev/null +++ b/test/bash/ssmc_tools.sh @@ -0,0 +1,95 @@ +convert_ssmc() { + echo "unpacking $1" + fpath=$1 + + format=$2 + + if [ -z "$format" ] + then + format=COO + else + format=$2 + fi + + format_string=`echo ${format} | tr '[:upper:]' '[:lower:]'` + + echo "Writing in format ${format}." + + fname=`basename ${fpath}` + directory=`dirname ${fpath}` + tar -xf $fpath -C $directory + + matrix_name=${fname/.tar.gz/} + + main_matrix=$directory/$matrix_name/$matrix_name.mtx + + dest_file=$directory/$matrix_name.${format_string}.bsp.h5 + + # echo "dest file ${dest_file}" + + # echo "Primary matrix is \"${main_matrix}\" -> ${dest_file}/root" + echo "mtx2bsp ${main_matrix} ${dest_file} ${format}" + mtx2bsp ${main_matrix} ${dest_file} ${format} + + # Set "null option" to return an empty list if no files match glob. + shopt -s nullglob + + for secondary_matrix in ${directory}/${matrix_name}/${matrix_name}_*.mtx + do + # echo "Secondary matrix \"${secondary_matrix}\"" + secondary_name=`basename ${secondary_matrix}` + secondary_name=${secondary_name/.mtx/} + secondary_name=${secondary_name/${matrix_name}_/} + echo "mtx2bsp ${secondary_matrix} ${dest_file}:${secondary_name}" + mtx2bsp ${secondary_matrix} ${dest_file}:${secondary_name} + done + + rm -r ${directory}/${matrix_name} +} + +check_ssmc() { + echo "unpacking $1" + fpath=$1 + + format=$2 + + if [ -z "$format" ] + then + format=COO + else + format=$2 + fi + + format_string=`echo ${format} | tr '[:upper:]' '[:lower:]'` + + fname=`basename ${fpath}` + directory=`dirname ${fpath}` + tar -xf $fpath -C $directory + + matrix_name=${fname/.tar.gz/} + + main_matrix=$directory/$matrix_name/$matrix_name.mtx + + dest_file=$directory/$matrix_name.${format_string}.bsp.h5 + + # echo "dest file ${dest_file}" + + # echo "Primary matrix is \"${main_matrix}\" -> ${dest_file}/root" + echo "check_equivalence ${main_matrix} ${dest_file}" + check_equivalence ${main_matrix} ${dest_file} + + # Set "null option" to return an empty list if no files match glob. + shopt -s nullglob + + for secondary_matrix in ${directory}/${matrix_name}/${matrix_name}_*.mtx + do + # echo "Secondary matrix \"${secondary_matrix}\"" + secondary_name=`basename ${secondary_matrix}` + secondary_name=${secondary_name/.mtx/} + secondary_name=${secondary_name/${matrix_name}_/} + echo "check_equivalence ${secondary_matrix} ${dest_file}:${secondary_name}" + check_equivalence ${secondary_matrix} ${dest_file}:${secondary_name} + done + + rm -r ${directory}/${matrix_name} +} diff --git a/test/bash/test.sh b/test/bash/test.sh new file mode 100644 index 0000000..6a10607 --- /dev/null +++ b/test/bash/test.sh @@ -0,0 +1,103 @@ +#!/usr/bin/env bash +set -e + +convert_ssmc() { + echo "unpacking $1" + fpath=$1 + + format=$2 + + if [ -z "$format" ] + then + format=COO + else + format=$2 + fi + + format_string=`echo ${format} | tr '[:upper:]' '[:lower:]'` + + echo "Writing in format ${format}." + + fname=`basename ${fpath}` + directory=`dirname ${fpath}` + tar -xf $fpath -C $directory + + matrix_name=${fname/.tar.gz/} + + main_matrix=$directory/$matrix_name/$matrix_name.mtx + + dest_file=$directory/$matrix_name.${format_string}.bsp.h5 + + # echo "dest file ${dest_file}" + + # echo "Primary matrix is \"${main_matrix}\" -> ${dest_file}/root" + echo "mtx2bsp ${main_matrix} ${dest_file} ${format}" + mtx2bsp ${main_matrix} ${dest_file} ${format} + + # Set "null option" to return an empty list if no files match glob. + shopt -s nullglob + + for secondary_matrix in ${directory}/${matrix_name}/${matrix_name}_*.mtx + do + # echo "Secondary matrix \"${secondary_matrix}\"" + secondary_name=`basename ${secondary_matrix}` + secondary_name=${secondary_name/.mtx/} + secondary_name=${secondary_name/${matrix_name}_/} + echo "mtx2bsp ${secondary_matrix} ${dest_file}:${secondary_name}" + mtx2bsp ${secondary_matrix} ${dest_file}:${secondary_name} + done + + rm -r ${directory}/${matrix_name} +} + +check_ssmc() { + echo "unpacking $1" + fpath=$1 + + format=$2 + + if [ -z "$format" ] + then + format=COO + else + format=$2 + fi + + format_string=`echo ${format} | tr '[:upper:]' '[:lower:]'` + + fname=`basename ${fpath}` + directory=`dirname ${fpath}` + tar -xf $fpath -C $directory + + matrix_name=${fname/.tar.gz/} + + main_matrix=$directory/$matrix_name/$matrix_name.mtx + + dest_file=$directory/$matrix_name.${format_string}.bsp.h5 + + # echo "dest file ${dest_file}" + + # echo "Primary matrix is \"${main_matrix}\" -> ${dest_file}/root" + echo "check_equivalence ${main_matrix} ${dest_file}" + check_equivalence ${main_matrix} ${dest_file} + + # Set "null option" to return an empty list if no files match glob. + shopt -s nullglob + + for secondary_matrix in ${directory}/${matrix_name}/${matrix_name}_*.mtx + do + # echo "Secondary matrix \"${secondary_matrix}\"" + secondary_name=`basename ${secondary_matrix}` + secondary_name=${secondary_name/.mtx/} + secondary_name=${secondary_name/${matrix_name}_/} + echo "check_equivalence ${secondary_matrix} ${dest_file}:${secondary_name}" + check_equivalence ${secondary_matrix} ${dest_file}:${secondary_name} + done + + rm -r ${directory}/${matrix_name} +} + +export PATH=$PATH:$PWD/../../examples + +convert_ssmc $1 COO +check_ssmc $1 COO From 6b79b3e5b78435510a9f2d6cc72251266eecf9a8 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 20 May 2024 14:10:17 -0700 Subject: [PATCH 2/8] Add basic GitHub Actions CI --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f6aecee --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,38 @@ +name: "CI" + +on: + push: + branches: + - main + + pull_request: + +jobs: + checks: + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.12' + cache: 'pip' + - run: pip install -r requirements.txt + - name: Checks + uses: pre-commit/action@v3.0.0 + + gcc: + runs-on: 'ubuntu-latest' + strategy: + matrix: + cxx: [gcc, clang] + name: ${{ matrix.cxx }} + env: + CXX: ${{ matrix.cxx }} + steps: + - uses: actions/checkout@v4 + - name: CMake + run: cmake -B build + - name: Build + run: make -C build -j `nproc` + - name: Test + run: ctest build/test/bash From a4452b1cfbf32a90e3a1085549e1045b48eab042 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 20 May 2024 14:13:56 -0700 Subject: [PATCH 3/8] Update CI to install HDF5 --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6aecee..2d32e68 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,10 @@ jobs: steps: - uses: actions/checkout@v4 - name: CMake - run: cmake -B build + run: | + sudo apt-get update + sudo apt-get install libhdf5-dev + cmake -B build - name: Build run: make -C build -j `nproc` - name: Test From e1a0160a8afed453a179cb3e57e9a9f1c5c0127b Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 20 May 2024 14:15:17 -0700 Subject: [PATCH 4/8] Troubleshoot failing to run tests --- .github/workflows/ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2d32e68..4f770dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,4 +38,6 @@ jobs: - name: Build run: make -C build -j `nproc` - name: Test - run: ctest build/test/bash + run: | + pwd + ctest ./build/test/bash From 76d247e403ac56ac5c7ae4d2477bad70643450c6 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 20 May 2024 14:18:07 -0700 Subject: [PATCH 5/8] Fix to select correct test dir --- .github/workflows/ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4f770dc..b6af5ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,4 @@ jobs: - name: Build run: make -C build -j `nproc` - name: Test - run: | - pwd - ctest ./build/test/bash + run: ctest --test-dir ./build/test/bash From c44399aff4dfda97e64fe8f99c1a7a9129603af6 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 20 May 2024 14:20:18 -0700 Subject: [PATCH 6/8] Testing if CI fails with a breaking change. --- examples/mtx2bsp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/mtx2bsp.c b/examples/mtx2bsp.c index 6b18639..48945ce 100644 --- a/examples/mtx2bsp.c +++ b/examples/mtx2bsp.c @@ -114,6 +114,8 @@ int main(int argc, char** argv) { bsp_print_matrix_info(matrix); + bsp_array_write(matrix.values, 0, -12); + printf(" === Writing to %s... ===\n", output_fname); bsp_write_matrix(output_fname, matrix, group_name, user_json); printf(" === Done writing. ===\n"); From 9e06aaa8e8e41b5d6948eaaf03ea0d6a604456b7 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 20 May 2024 14:22:26 -0700 Subject: [PATCH 7/8] Undoing breaking change - CI should now pass. --- examples/mtx2bsp.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/mtx2bsp.c b/examples/mtx2bsp.c index 48945ce..6b18639 100644 --- a/examples/mtx2bsp.c +++ b/examples/mtx2bsp.c @@ -114,8 +114,6 @@ int main(int argc, char** argv) { bsp_print_matrix_info(matrix); - bsp_array_write(matrix.values, 0, -12); - printf(" === Writing to %s... ===\n", output_fname); bsp_write_matrix(output_fname, matrix, group_name, user_json); printf(" === Done writing. ===\n"); From 77e77c264aead54ffb2531a1b7310a3d09fc7804 Mon Sep 17 00:00:00 2001 From: Benjamin Brock Date: Mon, 20 May 2024 14:23:25 -0700 Subject: [PATCH 8/8] Removing unused file `ssmc_tools.sh` --- test/bash/ssmc_tools.sh | 95 ----------------------------------------- 1 file changed, 95 deletions(-) delete mode 100644 test/bash/ssmc_tools.sh diff --git a/test/bash/ssmc_tools.sh b/test/bash/ssmc_tools.sh deleted file mode 100644 index 5b46802..0000000 --- a/test/bash/ssmc_tools.sh +++ /dev/null @@ -1,95 +0,0 @@ -convert_ssmc() { - echo "unpacking $1" - fpath=$1 - - format=$2 - - if [ -z "$format" ] - then - format=COO - else - format=$2 - fi - - format_string=`echo ${format} | tr '[:upper:]' '[:lower:]'` - - echo "Writing in format ${format}." - - fname=`basename ${fpath}` - directory=`dirname ${fpath}` - tar -xf $fpath -C $directory - - matrix_name=${fname/.tar.gz/} - - main_matrix=$directory/$matrix_name/$matrix_name.mtx - - dest_file=$directory/$matrix_name.${format_string}.bsp.h5 - - # echo "dest file ${dest_file}" - - # echo "Primary matrix is \"${main_matrix}\" -> ${dest_file}/root" - echo "mtx2bsp ${main_matrix} ${dest_file} ${format}" - mtx2bsp ${main_matrix} ${dest_file} ${format} - - # Set "null option" to return an empty list if no files match glob. - shopt -s nullglob - - for secondary_matrix in ${directory}/${matrix_name}/${matrix_name}_*.mtx - do - # echo "Secondary matrix \"${secondary_matrix}\"" - secondary_name=`basename ${secondary_matrix}` - secondary_name=${secondary_name/.mtx/} - secondary_name=${secondary_name/${matrix_name}_/} - echo "mtx2bsp ${secondary_matrix} ${dest_file}:${secondary_name}" - mtx2bsp ${secondary_matrix} ${dest_file}:${secondary_name} - done - - rm -r ${directory}/${matrix_name} -} - -check_ssmc() { - echo "unpacking $1" - fpath=$1 - - format=$2 - - if [ -z "$format" ] - then - format=COO - else - format=$2 - fi - - format_string=`echo ${format} | tr '[:upper:]' '[:lower:]'` - - fname=`basename ${fpath}` - directory=`dirname ${fpath}` - tar -xf $fpath -C $directory - - matrix_name=${fname/.tar.gz/} - - main_matrix=$directory/$matrix_name/$matrix_name.mtx - - dest_file=$directory/$matrix_name.${format_string}.bsp.h5 - - # echo "dest file ${dest_file}" - - # echo "Primary matrix is \"${main_matrix}\" -> ${dest_file}/root" - echo "check_equivalence ${main_matrix} ${dest_file}" - check_equivalence ${main_matrix} ${dest_file} - - # Set "null option" to return an empty list if no files match glob. - shopt -s nullglob - - for secondary_matrix in ${directory}/${matrix_name}/${matrix_name}_*.mtx - do - # echo "Secondary matrix \"${secondary_matrix}\"" - secondary_name=`basename ${secondary_matrix}` - secondary_name=${secondary_name/.mtx/} - secondary_name=${secondary_name/${matrix_name}_/} - echo "check_equivalence ${secondary_matrix} ${dest_file}:${secondary_name}" - check_equivalence ${secondary_matrix} ${dest_file}:${secondary_name} - done - - rm -r ${directory}/${matrix_name} -}