forked from devitocodes/devito
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cinterface.py
More file actions
37 lines (25 loc) · 974 Bytes
/
Copy pathtest_cinterface.py
File metadata and controls
37 lines (25 loc) · 974 Bytes
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
import os
from devito import Eq, Grid, Operator, TimeFunction
from devito.types import Timer
def test_basic():
grid = Grid(shape=(4, 4))
f = TimeFunction(name='f', grid=grid)
eq = Eq(f.forward, f + 1.)
name = "foo"
op = Operator(eq, name=name)
# Trigger the generation of a .c and a .h files
ccode, hcode = op.cinterface(force=True)
dirname = op._compiler.get_jit_dir()
assert os.path.isfile(os.path.join(dirname, "%s.c" % name))
assert os.path.isfile(os.path.join(dirname, "%s.h" % name))
ccode = str(ccode)
hcode = str(hcode)
assert 'include "%s.h"' % name in ccode
# The public `struct dataobj` only appears in the header file
assert str(f._C_typedecl) not in ccode
assert str(f._C_typedecl) in hcode
# Same with `struct profiler`
timers = op.parameters[-1]
assert isinstance(timers, Timer)
assert str(timers._C_typedecl) not in ccode
assert str(timers._C_typedecl) in hcode