Skip to content

Commit 293228b

Browse files
authored
Merge pull request #5 from GraphBLAS/add-tests
Add basic tests using Bash scripts
2 parents 68c0d2b + 77e77c2 commit 293228b

File tree

5 files changed

+176
-0
lines changed

5 files changed

+176
-0
lines changed

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: "CI"
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
10+
jobs:
11+
checks:
12+
runs-on: 'ubuntu-latest'
13+
steps:
14+
- uses: actions/checkout@v3
15+
- uses: actions/setup-python@v4
16+
with:
17+
python-version: '3.12'
18+
cache: 'pip'
19+
- run: pip install -r requirements.txt
20+
- name: Checks
21+
uses: pre-commit/[email protected]
22+
23+
gcc:
24+
runs-on: 'ubuntu-latest'
25+
strategy:
26+
matrix:
27+
cxx: [gcc, clang]
28+
name: ${{ matrix.cxx }}
29+
env:
30+
CXX: ${{ matrix.cxx }}
31+
steps:
32+
- uses: actions/checkout@v4
33+
- name: CMake
34+
run: |
35+
sudo apt-get update
36+
sudo apt-get install libhdf5-dev
37+
cmake -B build
38+
- name: Build
39+
run: make -C build -j `nproc`
40+
- name: Test
41+
run: ctest --test-dir ./build/test/bash

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ target_link_libraries(${PROJECT_NAME} INTERFACE cjson)
2525

2626
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
2727
add_subdirectory(examples)
28+
add_subdirectory(test)
2829
endif()

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add_subdirectory(bash)

test/bash/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
function(download_data url file_name)
2+
set(DATASET_ARCHIVE ${CMAKE_BINARY_DIR}/data/${file_name})
3+
4+
file(DOWNLOAD
5+
${url}
6+
${DATASET_ARCHIVE})
7+
endfunction()
8+
9+
download_data(https://suitesparse-collection-website.herokuapp.com/MM/DIMACS10/chesapeake.tar.gz
10+
chesapeake.tar.gz)
11+
12+
download_data(https://suitesparse-collection-website.herokuapp.com/MM/HB/1138_bus.tar.gz
13+
1138_bus.tar.gz)
14+
15+
download_data(https://suitesparse-collection-website.herokuapp.com/MM/Belcastro/mouse_gene.tar.gz
16+
mouse_gene.tar.gz)
17+
18+
download_data(https://suitesparse-collection-website.herokuapp.com/MM/Pajek/IMDB.tar.gz
19+
IMDB.tar.gz)
20+
21+
find_program(BASH_PROGRAM bash)
22+
23+
enable_testing()
24+
25+
if(BASH_PROGRAM)
26+
add_test(NAME integration.chesapeake COMMAND ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/test.sh ${CMAKE_BINARY_DIR}/data/chesapeake.tar.gz)
27+
add_test(NAME integration.1138_bus COMMAND ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/test.sh ${CMAKE_BINARY_DIR}/data/1138_bus.tar.gz)
28+
add_test(NAME integration.mouse_gene COMMAND ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/test.sh ${CMAKE_BINARY_DIR}/data/mouse_gene.tar.gz)
29+
add_test(NAME integration.IMDB COMMAND ${BASH_PROGRAM} ${CMAKE_CURRENT_SOURCE_DIR}/test.sh ${CMAKE_BINARY_DIR}/data/IMDB.tar.gz)
30+
endif()

test/bash/test.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
convert_ssmc() {
5+
echo "unpacking $1"
6+
fpath=$1
7+
8+
format=$2
9+
10+
if [ -z "$format" ]
11+
then
12+
format=COO
13+
else
14+
format=$2
15+
fi
16+
17+
format_string=`echo ${format} | tr '[:upper:]' '[:lower:]'`
18+
19+
echo "Writing in format ${format}."
20+
21+
fname=`basename ${fpath}`
22+
directory=`dirname ${fpath}`
23+
tar -xf $fpath -C $directory
24+
25+
matrix_name=${fname/.tar.gz/}
26+
27+
main_matrix=$directory/$matrix_name/$matrix_name.mtx
28+
29+
dest_file=$directory/$matrix_name.${format_string}.bsp.h5
30+
31+
# echo "dest file ${dest_file}"
32+
33+
# echo "Primary matrix is \"${main_matrix}\" -> ${dest_file}/root"
34+
echo "mtx2bsp ${main_matrix} ${dest_file} ${format}"
35+
mtx2bsp ${main_matrix} ${dest_file} ${format}
36+
37+
# Set "null option" to return an empty list if no files match glob.
38+
shopt -s nullglob
39+
40+
for secondary_matrix in ${directory}/${matrix_name}/${matrix_name}_*.mtx
41+
do
42+
# echo "Secondary matrix \"${secondary_matrix}\""
43+
secondary_name=`basename ${secondary_matrix}`
44+
secondary_name=${secondary_name/.mtx/}
45+
secondary_name=${secondary_name/${matrix_name}_/}
46+
echo "mtx2bsp ${secondary_matrix} ${dest_file}:${secondary_name}"
47+
mtx2bsp ${secondary_matrix} ${dest_file}:${secondary_name}
48+
done
49+
50+
rm -r ${directory}/${matrix_name}
51+
}
52+
53+
check_ssmc() {
54+
echo "unpacking $1"
55+
fpath=$1
56+
57+
format=$2
58+
59+
if [ -z "$format" ]
60+
then
61+
format=COO
62+
else
63+
format=$2
64+
fi
65+
66+
format_string=`echo ${format} | tr '[:upper:]' '[:lower:]'`
67+
68+
fname=`basename ${fpath}`
69+
directory=`dirname ${fpath}`
70+
tar -xf $fpath -C $directory
71+
72+
matrix_name=${fname/.tar.gz/}
73+
74+
main_matrix=$directory/$matrix_name/$matrix_name.mtx
75+
76+
dest_file=$directory/$matrix_name.${format_string}.bsp.h5
77+
78+
# echo "dest file ${dest_file}"
79+
80+
# echo "Primary matrix is \"${main_matrix}\" -> ${dest_file}/root"
81+
echo "check_equivalence ${main_matrix} ${dest_file}"
82+
check_equivalence ${main_matrix} ${dest_file}
83+
84+
# Set "null option" to return an empty list if no files match glob.
85+
shopt -s nullglob
86+
87+
for secondary_matrix in ${directory}/${matrix_name}/${matrix_name}_*.mtx
88+
do
89+
# echo "Secondary matrix \"${secondary_matrix}\""
90+
secondary_name=`basename ${secondary_matrix}`
91+
secondary_name=${secondary_name/.mtx/}
92+
secondary_name=${secondary_name/${matrix_name}_/}
93+
echo "check_equivalence ${secondary_matrix} ${dest_file}:${secondary_name}"
94+
check_equivalence ${secondary_matrix} ${dest_file}:${secondary_name}
95+
done
96+
97+
rm -r ${directory}/${matrix_name}
98+
}
99+
100+
export PATH=$PATH:$PWD/../../examples
101+
102+
convert_ssmc $1 COO
103+
check_ssmc $1 COO

0 commit comments

Comments
 (0)