Skip to content

Commit 0ebef8a

Browse files
committed
add test program to test libver() and inq_clibvers()
1 parent 8fc107f commit 0ebef8a

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

test/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ check_PROGRAMS = tst_atts.py \
4747
tst_var_string.py \
4848
tst_var_type.py \
4949
tst_version.py \
50-
tst_wait.py
50+
tst_wait.py \
51+
tst_libver.py
5152

5253
TESTS_ENVIRONMENT = export check_PROGRAMS="${check_PROGRAMS}";
5354
OUTPUT_DIR = _tmp_output

test/parallel_run.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ fi
3030
for prog in ${check_PROGRAMS} ; do
3131
printf '%-60s' "Testing $prog "
3232

33-
CMD="mpiexec -n $NPROC python $prog $OUT_DIR"
33+
if test $prog = "tst_libver.py" ; then
34+
CMD="mpiexec -n $NPROC python $prog -q"
35+
else
36+
CMD="mpiexec -n $NPROC python $prog $OUT_DIR"
37+
fi
3438
$CMD
3539
status=$?
3640
if [ $status -ne 0 ]; then

test/tst_libver.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#
2+
# Copyright (C) 2024, Northwestern University and Argonne National Laboratory
3+
# See COPYRIGHT notice in top-level directory.
4+
#
5+
6+
"""
7+
This program test the followings:
8+
pnetcdf class member: __version__ a string of PnetCDF-Python version
9+
pnetcdf method: libver() a function call to get the version
10+
pnetcdf method: inq_clibvers() a string of PnetCDF-C library version
11+
"""
12+
13+
import sys, argparse
14+
from mpi4py import MPI
15+
import pnetcdf
16+
17+
def parse_help():
18+
help_flag = "-h" in sys.argv or "--help" in sys.argv
19+
if help_flag and rank == 0:
20+
help_text = (
21+
"Usage: {} [-h | -q]\n"
22+
" [-h] Print help\n"
23+
" [-q] Quiet mode (reports when fail)\n"
24+
).format(sys.argv[0])
25+
print(help_text)
26+
return help_flag
27+
28+
if __name__ == "__main__":
29+
30+
rank = MPI.COMM_WORLD.Get_rank()
31+
32+
if parse_help():
33+
MPI.Finalize()
34+
sys.exit(1)
35+
36+
# Get command-line arguments
37+
args = None
38+
parser = argparse.ArgumentParser()
39+
parser.add_argument("-q", help="Quiet mode (reports when fail)", action="store_true")
40+
args = parser.parse_args()
41+
42+
verbose = False if args.q else True
43+
44+
if verbose and rank == 0:
45+
print("test pnetcdf.libver() and pnetcdf.inq_clibvers()")
46+
47+
# Run tests
48+
try:
49+
mlibver = pnetcdf.__version__
50+
if verbose and rank == 0:
51+
print("Test python class member, pnetcdf.__version__ = ", mlibver)
52+
53+
plibver = pnetcdf.libver()
54+
if verbose and rank == 0:
55+
print("test pnetcdf.libver(), PnetCDF Python version : ", plibver)
56+
57+
clibvers = pnetcdf.inq_clibvers()
58+
if verbose and rank == 0:
59+
print("test pnetcdf_python_clibvers(), PnetCDF C library version: ", clibvers)
60+
61+
except BaseException as err:
62+
print("Error: type:", type(err), str(err))
63+
raise
64+
65+
MPI.Finalize()
66+

0 commit comments

Comments
 (0)