Source code for taucmdr.cf.software.tests.test_tau_installation

#
# Copyright (c) 2016, ParaTools, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# (1) Redistributions of source code must retain the above copyright notice,
#     this list of conditions and the following disclaimer.
# (2) Redistributions in binary form must reproduce the above copyright notice,
#     this list of conditions and the following disclaimer in the documentation
#     and/or other materials provided with the distribution.
# (3) Neither the name of ParaTools, Inc. nor the names of its contributors may
#     be used to endorse or promote products derived from this software without
#     specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""Test functions.

Functions used for unit tests of tau_installation.py.
"""

import os
import tempfile
from taucmdr import tests
from taucmdr.cf.software.tau_installation import TauInstallation


[docs]class TauInstallationTest(tests.TestCase): """Tests for TauInstallation CUPTI detection and tagging."""
[docs] def setUp(self): super().setUp() # Give each test its own isolated temp directory so tests don't # pollute each other's filesystem state. self._cuda_tmpdir = tempfile.mkdtemp()
[docs] def tearDown(self): import shutil shutil.rmtree(self._cuda_tmpdir, ignore_errors=True) super().tearDown()
# ------------------------------------------------------------------ # # Helpers # # ------------------------------------------------------------------ #
[docs] def _make_cupti_header(self, *path_parts): """Create a fake cupti_events.h under the per-test cuda tmpdir.""" inc = os.path.join(self._cuda_tmpdir, *path_parts, 'include') os.makedirs(inc, exist_ok=True) open(os.path.join(inc, 'cupti_events.h'), 'w').close()
def _fake_self(self, cuda_prefix): class _FakeSelf: pass fs = _FakeSelf() fs.cuda_prefix = cuda_prefix return fs # ------------------------------------------------------------------ # # _find_cupti_prefix # # ------------------------------------------------------------------ #
[docs] def test_find_cupti_standard_sdk_layout(self): """extras/CUPTI/include/cupti_events.h — first candidate.""" self._make_cupti_header('extras', 'CUPTI') result = TauInstallation._find_cupti_prefix(self._fake_self(self._cuda_tmpdir)) self.assertEqual(result, os.path.join(self._cuda_tmpdir, 'extras', 'CUPTI'))
[docs] def test_find_cupti_system_packaged_layout(self): """<cuda>/include/cupti_events.h — third candidate (e.g. /usr).""" self._make_cupti_header() result = TauInstallation._find_cupti_prefix(self._fake_self(self._cuda_tmpdir)) self.assertEqual(result, self._cuda_tmpdir)
[docs] def test_find_cupti_orig_layout(self): """extras/CUPTI.orig/include/cupti_events.h — fourth candidate.""" self._make_cupti_header('extras', 'CUPTI.orig') result = TauInstallation._find_cupti_prefix(self._fake_self(self._cuda_tmpdir)) self.assertEqual(result, os.path.join(self._cuda_tmpdir, 'extras', 'CUPTI.orig'))
[docs] def test_find_cupti_returns_none_when_missing(self): """No headers present: returns None.""" result = TauInstallation._find_cupti_prefix(self._fake_self(self._cuda_tmpdir)) self.assertIsNone(result)
[docs] def test_find_cupti_returns_none_when_no_cuda_prefix(self): """No cuda_prefix: returns None without touching filesystem.""" result = TauInstallation._find_cupti_prefix(self._fake_self(None)) self.assertIsNone(result)