-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathtest_headers.py
More file actions
51 lines (43 loc) · 1.41 KB
/
test_headers.py
File metadata and controls
51 lines (43 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import pytest
import dpctl
@pytest.fixture(scope="session")
def dpctl_c_extension(tmp_path_factory):
import os
import os.path
import shutil
import subprocess
import sys
import sysconfig
curr_dir = os.path.dirname(__file__)
dr = tmp_path_factory.mktemp("_c_ext")
for fn in ["_c_ext.c", "setup_c_ext.py"]:
shutil.copy(
src=os.path.join(curr_dir, fn),
dst=dr,
follow_symlinks=False,
)
res = subprocess.run(
[sys.executable, "setup_c_ext.py", "build_ext", "--inplace"],
cwd=dr,
env=os.environ,
)
if res.returncode == 0:
import glob
from importlib.util import module_from_spec, spec_from_file_location
sfx = sysconfig.get_config_vars()["EXT_SUFFIX"]
pth = glob.glob(os.path.join(dr, "_c_ext*" + sfx))
if not pth:
pytest.fail("C extension was not built")
spec = spec_from_file_location("_c_ext", pth[0])
builder_module = module_from_spec(spec)
spec.loader.exec_module(builder_module)
return builder_module
else:
pytest.fail("C extension could not be built")
def test_c_headers(dpctl_c_extension):
try:
q = dpctl.SyclQueue()
except (dpctl.SyclDeviceCreationError, dpctl.SyclQueueCreationError):
pytest.skip()
assert dpctl_c_extension.is_sycl_queue(q)
assert dpctl_c_extension.check_queue_ref(q)