Skip to content

Commit

Permalink
added tests for Darshan
Browse files Browse the repository at this point in the history
  • Loading branch information
mtitov committed Mar 19, 2024
1 parent 0cb4d9a commit e9c7651
Showing 1 changed file with 77 additions and 13 deletions.
90 changes: 77 additions & 13 deletions tests/test_utils/test_tools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# pylint: disable=protected-access

from unittest import TestCase
import os
import shutil
import tempfile

from unittest import TestCase, mock

import radical.utils as ru

import radical.entk as re
import radical.entk.tools.darshan as re_darshan
Expand All @@ -14,19 +20,19 @@ class TestTools(TestCase):
#
def test_cache_darshan_env(self):

re_darshan._darshan_activation_cmds = None
re_darshan._darshan_env = None
re_darshan._darshan_runtime_root = None

with self.assertRaises(RuntimeError):
# should be set with either env variable or an absolute path
re_darshan.cache_darshan_env(darshan_runtime_root='dir_name')

self.assertIsNone(re_darshan._darshan_activation_cmds)
self.assertIsNone(re_darshan._darshan_env)
self.assertIsNone(re_darshan._darshan_runtime_root)

re_darshan.cache_darshan_env(darshan_runtime_root='$DARSHAN_ROOT',
re_darshan.cache_darshan_env(darshan_runtime_root='$DARSHAN_ROOT_TEST',
modules=['test_module'],
env={'TEST_VAR': 'test_value'})

self.assertEqual(re_darshan._darshan_runtime_root, '$DARSHAN_ROOT')
self.assertEqual(re_darshan._darshan_runtime_root, '$DARSHAN_ROOT_TEST')
self.assertEqual(re_darshan._darshan_activation_cmds,
['module load test_module',
'export TEST_VAR="test_value"'])
Expand Down Expand Up @@ -57,12 +63,70 @@ def test_enable_darshan(self):
# Darshan is not enabled for tasks with no executable
self.assertFalse(task.executable)

task.executable = 'test_exec'
re_darshan.enable_darshan(task)
# `test_cache_darshan_env` had already activated the env
self.assertTrue('LD_PRELOAD' in task.executable)
# non-MPI task
self.assertTrue('DARSHAN_ENABLE_NONMPI=1' in task.executable)
# enable darshan using decorator
@re_darshan.with_darshan
def get_pipeline():
t1 = re.Task()
t1.cpu_reqs = {'cpu_processes': 1}
t1.executable = 'test_exec1'
t2 = re.Task()
t2.cpu_reqs = {'cpu_processes': 10}
t2.executable = 'test_exec2'
s0 = re.Stage()
s0.add_tasks([t1, t2])
p0 = re.Pipeline()
p0.add_stages(s0)
return p0

pipeline = get_pipeline()
for s in pipeline.stages:
for t in s.tasks:
self.assertTrue('LD_PRELOAD' in t.executable)

non_mpi_statement = 'DARSHAN_ENABLE_NONMPI=1' in t.executable
if t.cpu_reqs.cpu_processes == 1:
# non-MPI task
self.assertTrue(non_mpi_statement)
else:
self.assertFalse(non_mpi_statement)

# darshan is already enabled
re_darshan.enable_darshan(t)
self.assertEqual(t.executable.count('LD_PRELOAD'), 1)

# --------------------------------------------------------------------------
#
@mock.patch('radical.utils.sh_callout',
return_value=['1:/tmp/test_file.txt\n0:random\n', '', 0])
def test_annotate_task_with_darshan(self, mocked_sh_callout):

tmp_dir = tempfile.gettempdir()
log_dir = os.path.join(tmp_dir, 'darshan_logs')
ru.rec_makedir(log_dir)

# keeping inside log_dir a random file
tempfile.mkstemp(dir=log_dir)

task = re_darshan.enable_darshan(re.Task({
'executable': 'test_exec',
'arguments' : ['> arg_output.txt'],
'cpu_reqs' : {'cpu_processes': 1},
'sandbox' : tmp_dir,
'path' : tmp_dir
}))

re_darshan.annotate_task_with_darshan(task)

ta = task.annotations
# file "test_file.txt" is presented in both "inputs" and "outputs",
# because the way we mocked method "sh_callout"
self.assertIn('/test_file.txt', ' '.join(ta['inputs']))
self.assertIn('/test_file.txt', ' '.join(ta['outputs']))
self.assertIn('/arg_output.txt', ' '.join(ta['outputs']))

self.assertNotIn('random', ' '.join(ta['outputs']))

shutil.rmtree(log_dir)

# ------------------------------------------------------------------------------

0 comments on commit e9c7651

Please sign in to comment.