From 1d88f690a48b0a8c22c3475e91c783dd3f2fd823 Mon Sep 17 00:00:00 2001 From: Tamara Dahlgren <35777542+tldahlgren@users.noreply.github.com> Date: Sun, 28 May 2023 00:46:31 -0700 Subject: tests/darshan-runtime: convert to new stand-alone test process (#37838) --- .../builtin/packages/darshan-runtime/package.py | 99 ++++++++-------------- 1 file changed, 34 insertions(+), 65 deletions(-) diff --git a/var/spack/repos/builtin/packages/darshan-runtime/package.py b/var/spack/repos/builtin/packages/darshan-runtime/package.py index f3eff99a7f..b5fd554dce 100644 --- a/var/spack/repos/builtin/packages/darshan-runtime/package.py +++ b/var/spack/repos/builtin/packages/darshan-runtime/package.py @@ -144,70 +144,39 @@ class DarshanRuntime(AutotoolsPackage): test_inputs = [join_path(self.basepath, "mpi-io-test.c")] self.cache_extra_test_sources(test_inputs) - def _test_intercept(self): + def test_mpi_io_test(self): + """build, run, and check outputs""" + if "+mpi" not in self.spec: + raise SkipTest("Test requires +mpi build") + testdir = "intercept-test" + logname = join_path(os.getcwd(), testdir, "test.darshan") + testexe = "mpi-io-test" + with working_dir(testdir, create=True): - if "+mpi" in self.spec: - # compile a test program - logname = join_path(os.getcwd(), "test.darshan") - fname = join_path( - self.test_suite.current_test_cache_dir, - join_path(self.basepath, "mpi-io-test.c"), - ) - cc = Executable(self.spec["mpi"].mpicc) - compile_opt = ["-c", fname] - link_opt = ["-o", "mpi-io-test", "mpi-io-test.o"] - cc(*(compile_opt)) - cc(*(link_opt)) - - # run test program and intercept - purpose = "Test running code built against darshan" - exe = "./mpi-io-test" - options = ["-f", "tmp.dat"] - status = [0] - installed = False - expected_output = [ - r"Write bandwidth = \d+.\d+ Mbytes/sec", - r"Read bandwidth = \d+.\d+ Mbytes/sec", - ] - env["LD_PRELOAD"] = "libdarshan.so" - env["DARSHAN_LOGFILE"] = logname - self.run_test( - exe, - options, - expected_output, - status, - installed, - purpose, - skip_missing=False, - work_dir=None, - ) - env.pop("LD_PRELOAD") - - import llnl.util.tty as tty - - # verify existence of log and size is > 0 - tty.msg("Test for existince of log:") - if os.path.exists(logname): - sr = os.stat(logname) - print("PASSED") - tty.msg("Test for size of log:") - if not sr.st_size > 0: - exc = BaseException("log size is 0") - m = None - if spack.config.get("config:fail_fast", False): - raise TestFailure([(exc, m)]) - else: - self.test_failures.append((exc, m)) - else: - print("PASSED") - else: - exc = BaseException("log does not exist") - m = None - if spack.config.get("config:fail_fast", False): - raise TestFailure([(exc, m)]) - else: - self.test_failures.append((exc, m)) - - def test(self): - self._test_intercept() + env["LD_PRELOAD"] = join_path(self.prefix.lib, "libdarshan.so") + env["DARSHAN_LOGFILE"] = logname + + # compile the program + fname = join_path( + self.test_suite.current_test_cache_dir, self.basepath, f"{testexe}.c" + ) + cc = Executable(self.spec["mpi"].mpicc) + compile_opt = ["-c", fname] + link_opt = ["-o", "mpi-io-test", "mpi-io-test.o"] + cc(*(compile_opt)) + cc(*(link_opt)) + + # run test program and intercept + mpi_io_test = which(join_path(".", testexe)) + out = mpi_io_test("-f", "tmp.dat", output=str.split, error=str.split) + env.pop("LD_PRELOAD") + + expected_output = [ + r"Write bandwidth = \d+.\d+ Mbytes/sec", + r"Read bandwidth = \d+.\d+ Mbytes/sec", + ] + check_outputs(expected_output, out) + + assert os.path.exists(logname), f"Expected {logname} to exist" + assert (os.stat(logname)).st_size > 0, f"Expected non-empty {logname}" -- cgit v1.2.3-70-g09d2