This repository has been archived by the owner on Jan 14, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathruntest.sh
executable file
·96 lines (86 loc) · 2.19 KB
/
runtest.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
abort() {
# Aborts script execution and returns 1 as exit code.
echo >&2 "[ERROR] Stopping execution !!!"
exit 1
}
assert() {
# Uses regex to compare to strings aborts script if
# substring not found
#
# Parameters
# ----------
#
# `$1`: Base string for comparision.
#
# `$2`: Substring which should be in $1
#
if [[ ! "$1" =~ "$2" ]]; then
echo >&2 "[ERROR] Assertion failed"
abort
fi
}
run() {
# Executes a commend in a specified docker container and
# checks if the outputs matches a substring.
#
# Parameters
# ----------
#
# `$1`: Docker container to be used for execution.
#
# `$2`: Command which will be executed in docker container.
#
# `$3`: (Optional) String to which should be contained
# in the output.
#
echo "> on '$1' running: $2"
cmd="docker run --user $(id -u):$(id -g) -v $(pwd):/project $1 bash -c '$2'"
output=$(eval $cmd)
[ $? -ne 0 ] && abort
if [[ -n $3 ]]; then
assert "$output" "$3"
fi
}
# tmp directory for output
if [ ! -d test/tmp_output ]; then
mkdir test/tmp_output
fi
######################################################################
# TESTS
######################################################################
# checks user name
run "$1" 'id' "$(id -u)"
# gcc latest
run \
"$1" \
'gcc ${HPC_C_COMPILE_ARGS} ${HPC_C_LINK_ARGS} -o test/tmp_output/hello-mpi-c.out test/hello_mpi.c'
run \
"$1" \
'test/tmp_output/hello-mpi-c.out' \
'hello from MPI in C'
run \
"$1" \
'gfortran ${HPC_F_COMPILE_ARGS} ${HPC_F_LINK_ARGS} -o test/tmp_output/hello-mpi-fortran.out test/hello_mpi.f90'
run \
"$1" \
'test/tmp_output/hello-mpi-fortran.out' \
'hello from MPI in Fortran'
run \
"$1" \
'gcc ${HPC_C_COMPILE_ARGS} ${HPC_C_LINK_ARGS} -o test/tmp_output/hello-hdf5-c.out test/hello_hdf5.c'
run \
"$1" \
'test/tmp_output/hello-hdf5-c.out' \
'hello from HDF5 in C'
run \
"$1" \
'gfortran ${HPC_F_COMPILE_ARGS} ${HPC_F_LINK_ARGS} -o test/tmp_output/hello-hdf5-fortran.out test/hello_hdf5.f90'
run \
"$1" \
'test/tmp_output/hello-hdf5-fortran.out' \
'hello from HDF5 in Fortran'
# cleanup build directory
if [ -d test/tmp_output ]; then
rm -rf test/tmp_output
fi