Skip to content

Commit 134e3f0

Browse files
committed
Merge branch 'master' into beta/2021
2 parents efec4c1 + b0b25d7 commit 134e3f0

File tree

4 files changed

+11
-55
lines changed

4 files changed

+11
-55
lines changed

conda-recipe/run_test.bat

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
call "%ONEAPI_ROOT%/compiler/latest/env/vars.bat"
2-
REM IF %ERRORLEVEL% NEQ 0 exit 1
2+
IF %ERRORLEVEL% NEQ 0 exit 1
3+
4+
@echo on
35

46
"%PYTHON%" -c "import dppl"
57
IF %ERRORLEVEL% NEQ 0 exit 1
68

79
"%PYTHON%" -c "import dppl.ocldrv"
810
IF %ERRORLEVEL% NEQ 0 exit 1
11+
12+
"%PYTHON%" -m unittest -v dppl.tests
13+
IF %ERRORLEVEL% NEQ 0 exit 1

conda-recipe/run_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ source ${ONEAPI_ROOT}/compiler/latest/env/vars.sh || true
77

88
${PYTHON} -c "import dppl"
99
${PYTHON} -c "import dppl.ocldrv"
10+
${PYTHON} -m unittest -v dppl.tests

dppl/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .test_dump_functions import *

dppl/tests/test_dump_functions.py

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,67 +14,16 @@
1414
# limitations under the License.
1515
#******************************************************************************/
1616

17-
from contextlib import contextmanager
18-
import ctypes
19-
import dppl
20-
import io
21-
import os, sys
22-
import tempfile
2317
import unittest
2418

19+
import dppl
2520
import dppl.ocldrv as drv
2621

2722

28-
libc = ctypes.CDLL(None)
29-
c_stdout = ctypes.c_void_p.in_dll(libc, 'stdout')
30-
31-
# Sourced from
32-
# https://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/
33-
@contextmanager
34-
def stdout_redirector(stream):
35-
# The original fd stdout points to. Usually 1 on POSIX systems.
36-
original_stdout_fd = sys.stdout.fileno()
37-
38-
def _redirect_stdout(to_fd):
39-
"""Redirect stdout to the given file descriptor."""
40-
# Flush the C-level buffer stdout
41-
libc.fflush(c_stdout)
42-
# Flush and close sys.stdout - also closes the file descriptor (fd)
43-
sys.stdout.close()
44-
# Make original_stdout_fd point to the same file as to_fd
45-
os.dup2(to_fd, original_stdout_fd)
46-
# Create a new sys.stdout that points to the redirected fd
47-
sys.stdout = io.TextIOWrapper(os.fdopen(original_stdout_fd, 'wb'))
48-
49-
# Save a copy of the original stdout fd in saved_stdout_fd
50-
saved_stdout_fd = os.dup(original_stdout_fd)
51-
try:
52-
# Create a temporary file and redirect stdout to it
53-
tfile = tempfile.TemporaryFile(mode='w+b')
54-
_redirect_stdout(tfile.fileno())
55-
# Yield to caller, then redirect stdout back to the saved fd
56-
yield
57-
_redirect_stdout(saved_stdout_fd)
58-
# Copy contents of temporary file to the given stream
59-
tfile.flush()
60-
tfile.seek(0, io.SEEK_SET)
61-
if stream:
62-
stream.write(tfile.read())
63-
finally:
64-
tfile.close()
65-
os.close(saved_stdout_fd)
66-
67-
6823
class TestDumpMethods(unittest.TestCase):
6924

7025
def test_dppl_dump_runtime(self):
71-
with stdout_redirector(None):
72-
self.assertEqual(dppl.runtime.dump(), 0)
26+
self.assertEqual(dppl.runtime.dump(), 0)
7327

7428
def test_dppl_ocldrv_dump_runtime(self):
75-
with stdout_redirector(None):
76-
self.assertEqual(drv.runtime.dump(), 0)
77-
78-
79-
suite = unittest.TestLoader().loadTestsFromTestCase(TestDumpMethods)
80-
unittest.TextTestRunner(verbosity=2).run(suite)
29+
self.assertEqual(drv.runtime.dump(), 0)

0 commit comments

Comments
 (0)