Skip to content

Commit 6693ae3

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

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+
249+
with tmpdir.as_cwd():
250+
cwd = os.getcwd()
251+
subprocess.check_output(["mpirun",
252+
"--allow-run-as-root",
253+
"-n",
254+
f"{n_ranks}",
255+
"-x",
256+
f"LD_PRELOAD={darshan_lib_path}",
257+
"-x",
258+
f"DARSHAN_LOGPATH={cwd}",
259+
"python",
260+
f"{test_script_path}"])
261+
262+
log_file_list = glob.glob("*.darshan")
263+
# only a single log file should be generated
264+
# by darshan
265+
assert len(log_file_list) == 1
266+
path_to_log = os.path.join(cwd, log_file_list[0])
267+
# numpy will read a bunch of python files but we only care about the
268+
# numpy file
269+
report = darshan.DarshanReport(path_to_log, filter_patterns=[".npy"], filter_mode='include')
270+
print("report:", report)
271+
272+
# common stuff done. Real check for the "dup via fcntl" issue
273+
posix_counters = report.records['POSIX'].to_dict()[0]["counters"]
274+
assert posix_counters['POSIX_BYTES_WRITTEN'] == 928

0 commit comments

Comments
 (0)