Skip to content

Commit afa2d74

Browse files
committed
test for numpy (dup via fcntl) not logging writes
1 parent dd0c2e7 commit afa2d74

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python3
2+
3+
from mpi4py import MPI
4+
import numpy as np
5+
import os
6+
7+
def main():
8+
comm = MPI.COMM_WORLD
9+
arr1 = np.arange(50)
10+
np.save('single_array.npy', arr1)
11+
os.remove('single_array.npy')
12+
13+
14+
if __name__ == "__main__":
15+
main()

darshan-test/python_runtime_tests.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,44 @@ def test_forked_process_mpi(tmpdir):
231231
# regression test for gh-786, mpi version
232232
darshan_install_path = os.environ.get("DARSHAN_INSTALL_PATH")
233233
do_forked_process_test(tmpdir, darshan_install_path)
234+
235+
def test_os_dup(tmpdir):
236+
# numpy calls Python's os.dup() which in turn was duplicating a file
237+
# descriptor via fcntl
238+
n_ranks = 1
239+
root_path = os.environ.get("DARSHAN_ROOT_PATH")
240+
darshan_install_path = os.environ.get("DARSHAN_INSTALL_PATH")
241+
test_script_path = os.path.join(root_path,
242+
"darshan-test",
243+
"python_mpi_scripts",
244+
"runtime_prog_issue_690.py")
245+
darshan_lib_path = os.path.join(darshan_install_path,
246+
"lib",
247+
"libdarshan.so")
248+
hdf5_lib_path = os.environ.get("HDF5_LIB")
249+
250+
with tmpdir.as_cwd():
251+
cwd = os.getcwd()
252+
subprocess.check_output(["mpirun",
253+
"--allow-run-as-root",
254+
"-n",
255+
f"{n_ranks}",
256+
"-x",
257+
f"LD_PRELOAD={darshan_lib_path}:{hdf5_lib_path}",
258+
"-x",
259+
f"DARSHAN_LOGPATH={cwd}",
260+
"python",
261+
f"{test_script_path}"])
262+
263+
log_file_list = glob.glob("*.darshan")
264+
# only a single log file should be generated
265+
# by darshan
266+
assert len(log_file_list) == 1
267+
path_to_log = os.path.join(cwd, log_file_list[0])
268+
# numpy will read a bunch of python files but we only care about the
269+
# numpy file
270+
report = darshan.DarshanReport(path_to_log, filter_patterns=[".npy"], filter_mode='include')
271+
# common stuff done. Real check for the "dup via fcntl" issue
272+
273+
posix_counters = report.records['POSIX'].to_dict()["counters"]
274+
assert posix_counters['POSIX_BYTES_WRITTEN'] == 928

0 commit comments

Comments
 (0)