Skip to content

Commit 8c0a9d0

Browse files
authored
Refactor unit tests to move everything under tests. (#59)
* Reorganize tests and minor fixes to change dppl to dpctl. * Change test class name. * Fix names in docstrings. * Fix names etc. * Rename function from is_in_dpctl_ctxt to is_in_device_context. * Fix names of test cases. * Update dpctl/tests/test_sycl_queue_manager.py
1 parent fa60313 commit 8c0a9d0

File tree

6 files changed

+84
-41
lines changed

6 files changed

+84
-41
lines changed

dpctl/sycl_core.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ cdef class _SyclQueueManager:
199199
'''
200200
DPPLPlatform_DumpInfo()
201201

202-
def is_in_dppl_ctxt (self):
202+
def is_in_device_context (self):
203203
cdef size_t num = DPPLQueueMgr_GetNumActivatedQueues()
204204
if num:
205205
return True
@@ -219,7 +219,7 @@ has_cpu_queues = _qmgr.has_cpu_queues
219219
has_gpu_queues = _qmgr.has_gpu_queues
220220
has_sycl_platforms = _qmgr.has_sycl_platforms
221221
set_default_queue = _qmgr.set_default_queue
222-
is_in_dppl_ctxt = _qmgr.is_in_dppl_ctxt
222+
is_in_device_context = _qmgr.is_in_device_context
223223

224224
from contextlib import contextmanager
225225

dpctl/tests/__init__.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,27 @@
1+
##===-------- tests/dpctl_tests/__init__.py - dpctl ------*- Python -*----===##
2+
##
3+
## Data Parallel Control (dpCtl)
4+
##
5+
## Copyright 2020 Intel Corporation
6+
##
7+
## Licensed under the Apache License, Version 2.0 (the "License");
8+
## you may not use this file except in compliance with the License.
9+
## You may obtain a copy of the License at
10+
##
11+
## http://www.apache.org/licenses/LICENSE-2.0
12+
##
13+
## Unless required by applicable law or agreed to in writing, software
14+
## distributed under the License is distributed on an "AS IS" BASIS,
15+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
## See the License for the specific language governing permissions and
17+
## limitations under the License.
18+
##
19+
##===----------------------------------------------------------------------===##
20+
##
21+
## \file
22+
## Top-level module of all dpctl Python unit test cases.
23+
##===----------------------------------------------------------------------===##
24+
25+
from .test_sycl_queue_manager import *
26+
from .test_sycl_usm import *
127
from .test_dump_functions import *
2-
from .dppl_tests import *

dpctl/tests/dppl_tests/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

dpctl/tests/test_dump_functions.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
1-
#*******************************************************************************
2-
# Copyright 2020 Intel Corporation
3-
#
4-
# Licensed under the Apache License, Version 2.0 (the "License");
5-
# you may not use this file except in compliance with the License.
6-
# You may obtain a copy of the License at
7-
#
8-
# http://www.apache.org/licenses/LICENSE-2.0
9-
#
10-
# Unless required by applicable law or agreed to in writing, software
11-
# distributed under the License is distributed on an "AS IS" BASIS,
12-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
# See the License for the specific language governing permissions and
14-
# limitations under the License.
15-
#******************************************************************************/
1+
##===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*----===##
2+
##
3+
## Data Parallel Control (dpCtl)
4+
##
5+
## Copyright 2020 Intel Corporation
6+
##
7+
## Licensed under the Apache License, Version 2.0 (the "License");
8+
## you may not use this file except in compliance with the License.
9+
## You may obtain a copy of the License at
10+
##
11+
## http://www.apache.org/licenses/LICENSE-2.0
12+
##
13+
## Unless required by applicable law or agreed to in writing, software
14+
## distributed under the License is distributed on an "AS IS" BASIS,
15+
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
## See the License for the specific language governing permissions and
17+
## limitations under the License.
18+
##
19+
##===----------------------------------------------------------------------===##
20+
###
21+
### \file
22+
### A basic unit test to verify that dpctl and dpct.ocldrv exist.
23+
##===----------------------------------------------------------------------===##
1624

1725
import unittest
1826

@@ -22,19 +30,24 @@
2230

2331
class TestDumpMethods(unittest.TestCase):
2432

25-
def test_dppl_dump (self):
33+
def test_dpctl_dump (self):
2634
try:
2735
dpctl.dump()
2836
except Exception:
2937
self.fail("Encountered an exception inside dump().")
3038

31-
def test_dppl_dump_device_info (self):
39+
def test_dpctl_dump_device_info (self):
3240
q = dpctl.get_current_queue()
3341
try:
3442
q.get_sycl_device().dump_device_info()
3543
except Exception:
3644
self.fail("Encountered an exception inside dump_device_info().")
3745

46+
def test_dpctl_ocldrv_dump (self):
47+
try:
48+
dpctl.ocldrv.runtime.dump()
49+
except Exception:
50+
self.fail("Encountered an exception inside dump_device_info().")
3851

3952
if __name__ == '__main__':
4053
unittest.main()

dpctl/tests/dppl_tests/test_sycl_queue_manager.py renamed to dpctl/tests/test_sycl_queue_manager.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
##===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*-----===##
1+
##===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*----===##
22
##
3-
## Python Data Parallel Processing Library (PyDPPL)
3+
## Data Parallel Control (dpCtl)
44
##
55
## Copyright 2020 Intel Corporation
66
##
@@ -19,51 +19,51 @@
1919
##===----------------------------------------------------------------------===##
2020
###
2121
### \file
22-
### This file has unit test cases to for the SyclQueueManager class
23-
### in sycl_core.pyx.
22+
### Defines unit test cases for the SyclQueueManager class in sycl_core.pyx.
2423
##===----------------------------------------------------------------------===##
2524

2625
import dpctl
2726
import unittest
2827

2928
class TestGetNumPlatforms (unittest.TestCase):
30-
@unittest.skipIf(not dpctl.has_sycl_platforms(), "No SYCL platforms available")
31-
def test_dppl_get_num_platforms (self):
29+
@unittest.skipIf(not dpctl.has_sycl_platforms(),
30+
"No SYCL platforms available")
31+
def test_dpctl_get_num_platforms (self):
3232
if(dpctl.has_sycl_platforms):
3333
self.assertGreaterEqual(dpctl.get_num_platforms(), 1)
3434

3535
@unittest.skipIf(not dpctl.has_sycl_platforms(), "No SYCL platforms available")
3636
class TestDumpMethods (unittest.TestCase):
37-
def test_dppl_dump (self):
37+
def test_dpctl_dump (self):
3838
try:
3939
dpctl.dump()
4040
except Exception:
4141
self.fail("Encountered an exception inside dump().")
4242

43-
def test_dppl_dump_device_info (self):
43+
def test_dpctl_dump_device_info (self):
4444
q = dpctl.get_current_queue()
4545
try:
4646
q.get_sycl_device().dump_device_info()
4747
except Exception:
4848
self.fail("Encountered an exception inside dump_device_info().")
4949

5050
@unittest.skipIf(not dpctl.has_sycl_platforms(), "No SYCL platforms available")
51-
class TestDPPLIsInDPPLCtxt (unittest.TestCase):
51+
class TestIsInDeviceContext (unittest.TestCase):
5252

53-
def test_is_in_dppl_ctxt_outside_device_ctxt (self):
54-
self.assertFalse(dpctl.is_in_dppl_ctxt())
53+
def test_is_in_device_context_outside_device_ctxt (self):
54+
self.assertFalse(dpctl.is_in_device_context())
5555

56-
def test_is_in_dppl_ctxt_inside_device_ctxt (self):
56+
def test_is_in_device_context_inside_device_ctxt (self):
5757
with dpctl.device_context(dpctl.device_type.gpu):
58-
self.assertTrue(dpctl.is_in_dppl_ctxt())
58+
self.assertTrue(dpctl.is_in_device_context())
5959

6060
@unittest.skipIf(not dpctl.has_cpu_queues(), "No CPU platforms available")
61-
def test_is_in_dppl_ctxt_inside_nested_device_ctxt (self):
61+
def test_is_in_device_context_inside_nested_device_ctxt (self):
6262
with dpctl.device_context(dpctl.device_type.cpu):
6363
with dpctl.device_context(dpctl.device_type.gpu):
64-
self.assertTrue(dpctl.is_in_dppl_ctxt())
65-
self.assertTrue(dpctl.is_in_dppl_ctxt())
66-
self.assertFalse(dpctl.is_in_dppl_ctxt())
64+
self.assertTrue(dpctl.is_in_device_context())
65+
self.assertTrue(dpctl.is_in_device_context())
66+
self.assertFalse(dpctl.is_in_device_context())
6767

6868
@unittest.skipIf(not dpctl.has_sycl_platforms(), "No SYCL platforms available")
6969
class TestGetCurrentQueueInMultipleThreads (unittest.TestCase):

dpctl/tests/dppl_tests/test_sycl_usm.py renamed to dpctl/tests/test_sycl_usm.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
##===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*-----===##
1+
##===---------- test_sycl_queue_manager.py - dpctl -------*- Python -*----===##
22
##
3-
## Python Data Parallel Processing Library (PyDPPL)
3+
## Data Parallel Control (dpCtl)
44
##
55
## Copyright 2020 Intel Corporation
66
##
@@ -17,6 +17,10 @@
1717
## limitations under the License.
1818
##
1919
##===----------------------------------------------------------------------===##
20+
##
21+
## \file
22+
## Defines unit test cases for the Memory classes in _memory.pyx.
23+
##===----------------------------------------------------------------------===##
2024

2125
import unittest
2226
import dpctl
@@ -111,3 +115,6 @@ class TestMemoryUSMDevice(TestMemoryUSMBase, unittest.TestCase):
111115

112116
MemoryUSMClass = MemoryUSMDevice
113117
usm_type = 'device'
118+
119+
if __name__ == '__main__':
120+
unittest.main()

0 commit comments

Comments
 (0)