Skip to content

Commit 0ece4dd

Browse files
authored
Merge pull request #28 from wkliao/makefile
use makefiles to run tests
2 parents cdafdb5 + f943ca7 commit 0ece4dd

File tree

8 files changed

+210
-94
lines changed

8 files changed

+210
-94
lines changed

.github/workflows/pnetcdf_c_master.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,7 @@ jobs:
9292
- name: Test PnetCDF-Python
9393
run: |
9494
export PATH=${MPICH_DIR}/bin:${PATH}
95-
96-
chmod 700 ./test_all.sh
97-
export NPROC=3 && ./test_all.sh
98-
export NPROC=8 && ./test_all.sh
99-
export NPROC=10 && ./test_all.sh
100-
101-
cd examples
102-
chmod 700 ./test_all.sh
103-
export NPROC=3 && ./test_all.sh
104-
export NPROC=8 && ./test_all.sh
105-
export NPROC=10 && ./test_all.sh
95+
make ptests
10696
10797
# - name: Tarball
10898
# run: |

.github/workflows/pnetcdf_c_official.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,7 @@ jobs:
9090
- name: Test PnetCDF-Python
9191
run: |
9292
export PATH=${MPICH_DIR}/bin:${PATH}
93-
94-
chmod 700 ./test_all.sh
95-
export NPROC=3 && ./test_all.sh
96-
export NPROC=8 && ./test_all.sh
97-
export NPROC=10 && ./test_all.sh
98-
99-
cd examples
100-
chmod 700 ./test_all.sh
101-
export NPROC=3 && ./test_all.sh
102-
export NPROC=8 && ./test_all.sh
103-
export NPROC=10 && ./test_all.sh
93+
make ptests
10494
10595
# - name: Tarball
10696
# run: |

Makefile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
check:
2+
cd test && make check
3+
cd examples && make check
4+
5+
ptests:
6+
cd test && make ptests
7+
cd examples && make ptests
8+
9+
clean:
10+
cd test && make clean
11+
cd examples && make clean
12+
13+
build-clean:
14+
rm -rf build/
15+
rm -rf src/pnetcdf.egg-info/
16+
rm -rf src/pnetcdf/_Dimension.c
17+
rm -rf src/pnetcdf/_Dimension.*.so
18+
rm -rf src/pnetcdf/_File.c
19+
rm -rf src/pnetcdf/_File.*.so
20+
rm -rf src/pnetcdf/_Variable.c
21+
rm -rf src/pnetcdf/_Variable.*.so
22+
rm -rf src/pnetcdf/_utils.c
23+
rm -rf src/pnetcdf/_utils.*.so
24+
rm -rf src/pnetcdf/__pycache__/
25+
rm -rf test/__pycache__/
26+

README.md

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,17 @@ applications that require parallel access to netCDF files.
2929
CC=/path/to/mpicc PNETCDF_DIR=/path/to/pnetcdf/dir pip install .
3030
```
3131
* Testing
32-
+ Run command below to test all the test programs available in folder
33-
`./test`, which will run 4 MPI processes for each test. The number of
34-
processes can be changed by setting the environment variable `NPROC` to a
35-
different number.
32+
+ Run command `make check` to test all the programs available in folders
33+
`test` and `examples` in parallel on 4 MPI processes.
34+
+ In addition, command `make ptests` runs the same tests but using 3, 4, and
35+
8 MPI processes.
36+
+ To run any individual programs in folders `test` and `examples`, use
37+
command below. For example,
3638
```sh
37-
./test_all.sh [test_file_output_dir]
38-
```
39-
+ To run a specific individual test, run command below
40-
```sh
41-
mpiexec -n [num_process] python test/tst_program.py [test_file_output_dir]
42-
```
43-
* The optional `test_file_output_dir` argument enables the testing program
44-
to save out generated test files in the directory. The default is the
45-
current folder.
46-
+ Similarly, one can test all example programs in the folder `examples` by
47-
running commands below.
48-
```sh
49-
cd examples
50-
./test_all.sh [test_file_output_dir]
39+
mpiexec -n [num_process] python examples/create_open.py [output_dir]
5140
```
41+
* The optional `output_dir` argument is the folder for storing the output
42+
files created by the programs The default is the current folder.
5243

5344
### Additional Resources
5445
* [PnetCDF-python User Guide](https://pnetcdf-python.readthedocs.io/en/latest/)

examples/Makefile

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
check_PROGRAMS = collective_write.py \
3+
create_open.py \
4+
fill_mode.py \
5+
flexible_api.py \
6+
get_info.py \
7+
ghost_cell.py \
8+
global_attribute.py \
9+
hints.py \
10+
nonblocking_write_def.py \
11+
nonblocking_write.py \
12+
put_varn_int.py \
13+
transpose2D.py \
14+
transpose.py \
15+
put_vara.py \
16+
get_vara.py
17+
18+
19+
TESTS_ENVIRONMENT = export check_PROGRAMS="${check_PROGRAMS}";
20+
TESTS_ENVIRONMENT += export PNETCDF_DIR="${PNETCDF_DIR}";
21+
22+
OUTPUT_DIR = _tmp_output
23+
24+
all:
25+
26+
check: ptest4
27+
ptests: ptest3 ptest4 ptest8
28+
29+
ptest3:
30+
@mkdir -p ${OUTPUT_DIR}
31+
@echo "==========================================================="
32+
@echo " examples: Parallel testing on 3 MPI processes"
33+
@echo "==========================================================="
34+
@${TESTS_ENVIRONMENT} export NPROC=3; ./parallel_run.sh ${OUTPUT_DIR} || exit 1
35+
@echo ""
36+
37+
ptest4:
38+
@mkdir -p ${OUTPUT_DIR}
39+
@echo "==========================================================="
40+
@echo " examples: Parallel testing on 4 MPI processes"
41+
@echo "==========================================================="
42+
@${TESTS_ENVIRONMENT} export NPROC=4; ./parallel_run.sh ${OUTPUT_DIR} || exit 1
43+
@echo ""
44+
45+
ptest8:
46+
@mkdir -p ${OUTPUT_DIR}
47+
@echo "==========================================================="
48+
@echo " examples: Parallel testing on 8 MPI processes"
49+
@echo "==========================================================="
50+
@${TESTS_ENVIRONMENT} export NPROC=8; ./parallel_run.sh ${OUTPUT_DIR} || exit 1
51+
@echo ""
52+
53+
clean:
54+
rm -rf ${OUTPUT_DIR}
55+

examples/test_all.sh renamed to examples/parallel_run.sh

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@
77
# Exit immediately if a command exits with a non-zero status.
88
set -e
99

10+
# Get the directory containing this script
11+
if test "x$NPROC" = x ; then
12+
NPROC=4
13+
fi
14+
15+
# get output folder from command line
16+
if test "$#" -gt 0 ; then
17+
args=("$@")
18+
OUT_DIR="${args[0]}"
19+
# check if output folder exists
20+
if ! test -d $OUT_DIR ; then
21+
echo "Error: output folder \"$OUT_DIR\" does not exist."
22+
exit 1
23+
fi
24+
else
25+
# output folder is not set at command line, use current folder
26+
OUT_DIR="."
27+
fi
28+
# echo "OUT_DIR=$OUT_DIR"
29+
1030
MPI4PY_VERSION=`python -c "import mpi4py; print(mpi4py.__version__)"`
1131
MPI4PY_VERSION_MAJOR=`echo ${MPI4PY_VERSION} | cut -d. -f1`
1232
# echo "MPI4PY_VERSION=$MPI4PY_VERSION"
@@ -29,52 +49,16 @@ if test $MPI4PY_VERSION_MAJOR -lt 4 ; then
2949
TEST_FLEXIBLE_API=yes
3050
fi
3151

32-
# Get the directory containing this script
33-
if test "x$NPROC" = x ; then
34-
NPROC=4
35-
fi
36-
37-
# get output folder from command line
38-
if test "$#" -gt 0 ; then
39-
args=("$@")
40-
OUT_DIR="${args[0]}"
41-
# check if output folder exists
42-
if ! test -d $OUT_DIR ; then
43-
echo "Error: output folder \"$OUT_DIR\" does not exist."
44-
exit 1
52+
for prog in $check_PROGRAMS; do
53+
if test "x$TEST_FLEXIBLE_API" = xno &&
54+
test "x$prog" = "xflexible_api.py" ; then
55+
TETS_PROGS+=" flexible_api.py"
56+
printf '%-60s' "Testing $prog"
57+
echo " ---- SKIP"
58+
continue
4559
fi
46-
else
47-
# output folder is not set at command line, use current folder
48-
OUT_DIR="."
49-
fi
50-
51-
echo ""
52-
echo "---- Run programs with $NPROC processes in folder 'examples' --------------"
53-
54-
TETS_PROGS="collective_write.py
55-
create_open.py
56-
fill_mode.py
57-
get_info.py
58-
ghost_cell.py
59-
global_attribute.py
60-
hints.py
61-
nonblocking_write_def.py
62-
nonblocking_write.py
63-
put_varn_int.py
64-
transpose2D.py
65-
transpose.py
66-
put_vara.py
67-
get_vara.py"
68-
69-
if test "x$TEST_FLEXIBLE_API" = xyes ; then
70-
TETS_PROGS+=" flexible_api.py"
71-
fi
72-
# echo "TETS_PROGS=$TETS_PROGS"
7360

74-
for prog in $TETS_PROGS
75-
do
76-
# echo -n "---- Testing $prog with $NPROC MPI processes"
77-
printf '%-60s' "Testing $prog with $NPROC MPI processes"
61+
printf '%-60s' "Testing $prog"
7862

7963
if test $prog = "get_vara.py" ; then
8064
CMD="mpiexec -n $NPROC python $prog -q $OUT_DIR/put_vara.nc"

test/Makefile

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
2+
check_PROGRAMS = tst_atts.py \
3+
tst_default_format.py \
4+
tst_dims.py \
5+
tst_file_fill.py \
6+
tst_file_inq.py \
7+
tst_file_mode.py \
8+
tst_rename.py \
9+
tst_var_bput_var1.py \
10+
tst_var_bput_vara.py \
11+
tst_var_bput_varm.py \
12+
tst_var_bput_varn.py \
13+
tst_var_bput_var.py \
14+
tst_var_bput_vars.py \
15+
tst_var_def_fill.py \
16+
tst_var_get_var1.py \
17+
tst_var_get_vara.py \
18+
tst_var_get_varm.py \
19+
tst_var_get_varn.py \
20+
tst_var_get_var.py \
21+
tst_var_get_vars.py \
22+
tst_var_iget_var1.py \
23+
tst_var_iget_vara.py \
24+
tst_var_iget_varm.py \
25+
tst_var_iget_varn.py \
26+
tst_var_iget_var.py \
27+
tst_var_iget_vars.py \
28+
tst_var_indexer.py \
29+
tst_var_iput_var1.py \
30+
tst_var_iput_vara.py \
31+
tst_var_iput_varm.py \
32+
tst_var_iput_varn.py \
33+
tst_var_iput_var.py \
34+
tst_var_iput_vars.py \
35+
tst_var_put_var1.py \
36+
tst_var_put_vara.py \
37+
tst_var_put_varm.py \
38+
tst_var_put_varn.py \
39+
tst_var_put_var.py \
40+
tst_var_put_vars.py \
41+
tst_var_rec_fill.py \
42+
tst_var_string.py \
43+
tst_var_type.py \
44+
tst_version.py \
45+
tst_wait.py
46+
47+
TESTS_ENVIRONMENT = export check_PROGRAMS="${check_PROGRAMS}";
48+
OUTPUT_DIR = _tmp_output
49+
50+
all:
51+
52+
check: ptest4
53+
ptests: ptest3 ptest4 ptest8
54+
55+
ptest3:
56+
@mkdir -p ${OUTPUT_DIR}
57+
@echo "==========================================================="
58+
@echo " test: Parallel testing on 3 MPI processes"
59+
@echo "==========================================================="
60+
@${TESTS_ENVIRONMENT} export NPROC=3; ./parallel_run.sh ${OUTPUT_DIR} || exit 1
61+
@echo ""
62+
63+
ptest4:
64+
@mkdir -p ${OUTPUT_DIR}
65+
@echo "==========================================================="
66+
@echo " test: Parallel testing on 4 MPI processes"
67+
@echo "==========================================================="
68+
@${TESTS_ENVIRONMENT} export NPROC=4; ./parallel_run.sh ${OUTPUT_DIR} || exit 1
69+
@echo ""
70+
71+
ptest8:
72+
@mkdir -p ${OUTPUT_DIR}
73+
@echo "==========================================================="
74+
@echo " test: Parallel testing on 8 MPI processes"
75+
@echo "==========================================================="
76+
@${TESTS_ENVIRONMENT} export NPROC=8; ./parallel_run.sh ${OUTPUT_DIR} || exit 1
77+
@echo ""
78+
79+
clean:
80+
rm -rf ${OUTPUT_DIR}
81+

test_all.sh renamed to test/parallel_run.sh

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,18 @@ else
2525
# output folder is not set at command line, use current folder
2626
OUT_DIR="."
2727
fi
28-
echo "OUT_DIR=$OUT_DIR"
28+
# echo "OUT_DIR=$OUT_DIR"
2929

30-
TETS_PROGS=`ls test/tst_*.py`
31-
for prog in $TETS_PROGS
32-
do
33-
echo -n "---- Testing $prog with $NPROC MPI processes"
34-
CMD="mpiexec -n $NPROC python $prog $OUT_DIR"
35-
$CMD
36-
status=$?
30+
for prog in ${check_PROGRAMS} ; do
31+
printf '%-60s' "Testing $prog "
32+
33+
CMD="mpiexec -n $NPROC python $prog $OUT_DIR"
34+
$CMD
35+
status=$?
3736
if [ $status -ne 0 ]; then
38-
echo ": FAIL ----"
37+
echo " ---- FAIL"
3938
else
40-
echo ": PASS ----"
39+
echo " ---- PASS"
4140
fi
4241
done
4342

0 commit comments

Comments
 (0)