Skip to content

Commit a44770e

Browse files
Added tests to check GetDPCPPVersion, dpctl.get_include, and dpctl.__version__
1 parent 33031a2 commit a44770e

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

dpctl/tests/test_service.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# Data Parallel Control (dpctl)
2+
#
3+
# Copyright 2020-2021 Intel Corporation
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
""" Defines unit test cases for miscellaneous functions.
18+
"""
19+
20+
import ctypes
21+
import ctypes.util
22+
import glob
23+
import os
24+
import os.path
25+
import re
26+
27+
import dpctl
28+
29+
30+
def _get_mkl_version_if_present():
31+
class MKLVersion(ctypes.Structure):
32+
_fields_ = [
33+
("MajorVersion", ctypes.c_int),
34+
("MinorVersion", ctypes.c_int),
35+
("UpdateVersion", ctypes.c_int),
36+
("ProductStatus", ctypes.c_char_p),
37+
("Build", ctypes.c_char_p),
38+
("Processor", ctypes.c_char_p),
39+
("Platform", ctypes.c_char_p),
40+
]
41+
42+
lib = ctypes.util.find_library("mkl_rt")
43+
if lib is None:
44+
return None
45+
try:
46+
lib = ctypes.cdll.LoadLibrary(lib)
47+
get_ver_fn = lib.mkl_get_version
48+
except Exception:
49+
return None
50+
get_ver_fn.argtypes = []
51+
get_ver_fn.restype = MKLVersion
52+
mkl_ver = get_ver_fn()
53+
return ".".join(
54+
[
55+
str(mkl_ver.MajorVersion),
56+
str(mkl_ver.UpdateVersion),
57+
str(mkl_ver.MinorVersion),
58+
]
59+
)
60+
61+
62+
def test_get_include():
63+
incl = dpctl.get_include()
64+
assert type(incl) is str
65+
assert incl != ""
66+
assert os.path.isdir(incl)
67+
68+
69+
def test_get_dpcppversion():
70+
incl_dir = dpctl.get_include()
71+
libs = glob.glob(os.path.join(incl_dir, "..", "*DPCTLSyclInterface*"))
72+
libs = sorted(libs)
73+
assert len(libs) > 0
74+
lib = ctypes.cdll.LoadLibrary(libs[0])
75+
fn = lib.DPCTLService_GetDPCPPVersion
76+
fn.restype = ctypes.c_char_p
77+
fn.argtypes = []
78+
dpcpp_ver = fn()
79+
assert len(dpcpp_ver) > 0
80+
dpcpp_ver = dpcpp_ver.decode("utf-8")
81+
mkl_ver = _get_mkl_version_if_present()
82+
assert mkl_ver is None or mkl_ver == dpcpp_ver
83+
84+
85+
def test___version__():
86+
dpctl_ver = getattr(dpctl, "__version__", None)
87+
assert type(dpctl_ver) is str
88+
assert "unknown" not in dpctl_ver
89+
# Reg expr from PEP-440
90+
reg_expr = (
91+
r"^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))"
92+
r"*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))?(\.dev("
93+
r"0|[1-9][0-9]*))?(\+.*)?$"
94+
)
95+
assert re.match(reg_expr, dpctl_ver) is not None

0 commit comments

Comments
 (0)