|
1 | 1 | import os |
| 2 | +import sys |
| 3 | +from contextlib import suppress |
2 | 4 |
|
3 | 5 | from devito import Eq, Grid, Operator, TimeFunction, configuration |
4 | 6 | from devito.types import Timer |
@@ -37,3 +39,31 @@ def test_basic(): |
37 | 39 | assert isinstance(timers, Timer) |
38 | 40 | assert 'struct profiler\n{' not in ccode |
39 | 41 | assert 'struct profiler\n{' in hcode |
| 42 | + |
| 43 | + |
| 44 | +def test_load_without_source(): |
| 45 | + grid = Grid(shape=(4, 4)) |
| 46 | + |
| 47 | + f = TimeFunction(name='f', grid=grid) |
| 48 | + |
| 49 | + eq = Eq(f.forward, f + 1.) |
| 50 | + |
| 51 | + name = "foo" |
| 52 | + op = Operator(eq, name=name) |
| 53 | + |
| 54 | + # Make sure the so file is not present |
| 55 | + dirname = op._compiler.get_jit_dir() |
| 56 | + soname = op._soname |
| 57 | + ext = '.dylib' if sys.platform == "darwin" else '.so' |
| 58 | + with suppress(FileNotFoundError): |
| 59 | + os.remove(f"{os.path.join(dirname, soname)}{ext}") |
| 60 | + |
| 61 | + # Trigger compilation |
| 62 | + recompiled, src_file = op._compiler.jit_compile(op._soname, str(op)) |
| 63 | + assert recompiled |
| 64 | + |
| 65 | + os.remove(src_file) |
| 66 | + # Trigger compilation again. It should skip the C part and directly load the .so file |
| 67 | + recompiled, src_file = op._compiler.jit_compile(op._soname, str(op)) |
| 68 | + assert not recompiled |
| 69 | + assert not os.path.isfile(src_file) |
0 commit comments