Skip to content

Commit d6f4f3f

Browse files
authored
Merge branch 'develop' into tst/inifix-5.1
2 parents 27662ed + b6136e4 commit d6f4f3f

10 files changed

Lines changed: 271 additions & 91 deletions

File tree

doc/source/testing/testLauncher.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,12 @@ In addition there is some extra keys which are dedicated to the json interpretat
191191
* - ``multirun``
192192
- ``{}``
193193
- See the multi-run section below.
194+
* - ``callPyFunctionBefore``
195+
-
196+
- Call a python function before executing the test (see dedicated section at the end of this file).
197+
* - ``callPyFunctionAfter``
198+
-
199+
- Call a python function after executing the test (see dedicated section at the end of this file).
194200

195201
Looping over parameters
196202
-----------------------
@@ -374,6 +380,33 @@ They are described like :
374380
},
375381
}
376382
383+
Calling a Python function
384+
-------------------------
385+
386+
In some cases (example in ``test/utils/lookupTable``) you might need to call a custom
387+
python function before running the test to prepare the data or after the test to perform
388+
some extra check.
389+
390+
You can simply implement the functions you want to call in the python file in the test
391+
directory (ideally named ``testmelib.py``) :
392+
393+
.. code-block:: python
394+
395+
def callMeAtStart():
396+
print("This is called at test start !")
397+
398+
def callMeAtEnd():
399+
print("This is called at test end !")
400+
401+
And add the keys in ``testme.json``:
402+
403+
.. code-block:: json
404+
405+
"default": {
406+
"callPyFunctionBefore": "testmelib.py:callMeAtStart",
407+
"callPyFunctionAfter": "testmelib.py:callMeAtEnd"
408+
}
409+
377410
Using the idfxTest options
378411
--------------------------
379412

pytools/idfx_test_run.py

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import copy
99
import glob
10+
import importlib
1011
import json
1112
import os
1213
import sys
@@ -135,6 +136,58 @@ def genTests(self) -> list:
135136
# ok
136137
return result
137138

139+
def buildPyHooks(self, config: dict) -> dict:
140+
# init
141+
result = {}
142+
key: str
143+
144+
# extract and build dict
145+
for key, value in config.items():
146+
if key.startswith("callPyFunction"):
147+
when = key.replace("callPyFunction", "")
148+
result[when] = value
149+
150+
# ok
151+
return result
152+
153+
# https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
154+
def importFromPath(self, moduleName: str, filePath: str):
155+
spec = importlib.util.spec_from_file_location(moduleName, filePath)
156+
module = importlib.util.module_from_spec(spec)
157+
# sys.modules[moduleName] = module
158+
spec.loader.exec_module(module)
159+
return module
160+
161+
def callPyHook(self, dir: str, hooks: dict, name: str) -> None:
162+
# nothing to do
163+
if name not in hooks:
164+
return
165+
166+
# split file:funcName
167+
params = hooks[name].split(":", 1)
168+
filePath = params[0]
169+
funcName = params[1]
170+
171+
# complete
172+
fileFullPath = os.path.join(dir, filePath)
173+
174+
# log
175+
print("************** CALLING PY FUNCTION ****************")
176+
print(f"Hook: {name}")
177+
print(f"HookValue: {hooks[name]}")
178+
print(f"Import {fileFullPath}")
179+
print(f"Call: {funcName}")
180+
print("***************************************************")
181+
182+
# import the module
183+
module = self.importFromPath("idefix_test_py_hooks", fileFullPath)
184+
185+
# get function
186+
function = getattr(module, funcName)
187+
188+
# call it
189+
function()
190+
138191
def run(self, config: dict) -> None:
139192
# clone before modify to not modity for caller
140193
config = copy.deepcopy(config)
@@ -155,6 +208,7 @@ def run(self, config: dict) -> None:
155208
nonRegressionTestIni = config.get("nonRegressionTestIni", None)
156209
check_file_produced = config.get("check_file_produced", [])
157210
problemDir = os.path.dirname(testfile)
211+
pyHooks = self.buildPyHooks(config)
158212

159213
# cleanup some keyword not handled at the
160214
# level of idx_test so we don't perturbate it
@@ -169,6 +223,12 @@ def run(self, config: dict) -> None:
169223
del config["nonRegressionTest"]
170224
if "nonRegressionTestIni" in config:
171225
del config["nonRegressionTestIni"]
226+
for hook in pyHooks:
227+
del config[f"callPyFunction{hook}"]
228+
229+
# call hook before
230+
with moveInDir(problemDir):
231+
self.callPyHook(problemDir, pyHooks, "Before")
172232

173233
# if switch from test, rebuild the runner (a runner make for one dir)
174234
if self.currentTestFile != testfile:
@@ -189,11 +249,16 @@ def run(self, config: dict) -> None:
189249
)
190250

191251
# check produced
192-
for file in check_file_produced:
193-
if not os.path.exists(file) and not self.currentTestRunner.fake:
194-
raise Exception(
195-
f"Don't find expected file to be produced by the run : {file} !"
196-
)
252+
with moveInDir(problemDir):
253+
for file in check_file_produced:
254+
if not os.path.exists(file) and not self.currentTestRunner.fake:
255+
raise Exception(
256+
f"Don't find expected file to be produced by the run : {file} !"
257+
)
258+
259+
# call hook after
260+
with moveInDir(problemDir):
261+
self.callPyHook(problemDir, pyHooks, "After")
197262

198263
def _runNonRegression(
199264
self,
@@ -365,7 +430,7 @@ def main(self, all: bool = False):
365430
os.environ["IDEFIX_TEST_FILTER_SUBDIR"] = idefixTest.filterSubdir
366431

367432
if idefixTest.all:
368-
pytest.main(
433+
status = pytest.main(
369434
[
370435
"-v",
371436
"--no-header",
@@ -375,6 +440,7 @@ def main(self, all: bool = False):
375440
+ idefixTest.remainingArgs
376441
+ [self.parentScritFile]
377442
)
443+
sys.exit(status)
378444
else:
379445
raise NotImplementedError("Not yet supported !")
380446
# elif self.check:

src/fluid/RiemannSolver/MHDsolvers/storeFlux.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ KOKKOS_FORCEINLINE_FUNCTION void K_StoreHLL( const int i, const int j, const int
5555
const IdefixArray3D<real> &dL,
5656
const IdefixArray3D<real> &dR) {
5757
EXPAND( ,
58-
constexpr int Xt = (DIR == IDIR ? MX2 : MX1); ,
59-
constexpr int Xb = (DIR == KDIR ? MX2 : MX3); )
58+
[[maybe_unused]] constexpr int Xt = (DIR == IDIR ? MX2 : MX1); ,
59+
[[maybe_unused]] constexpr int Xb = (DIR == KDIR ? MX2 : MX3); )
6060

6161
real ar = std::fmax(ZERO_F, sr);
6262
real al = std::fmin(ZERO_F, sl);

src/fluid/boundary/axis.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ void Axis::ExchangeMPI(int side) {
392392
idfx::pushRegion("Axis::ExchangeMPI");
393393
#ifdef WITH_MPI
394394
// Load the buffers with data
395-
int ibeg,iend,jbeg,jend,kbeg,kend,offset;
395+
[[maybe_unused]] int ibeg,iend,jbeg,jend,kbeg,kend;
396+
int offset;
396397
int ny;
397398
Buffer bufferSend = this->bufferSend;
398399
IdefixArray1D<int> map = this->mapVars;
@@ -491,12 +492,12 @@ void Axis::ExchangeMPI(int side) {
491492
//unpack Vs face-centered
492493
BoundingBox recvBoxVsIdir = baseBox;
493494
recvBoxVsIdir[IDIR][1] += 1;
494-
bufferRecv.UnpackJDirSymetric(Vs, IDIR, sVs(IDIR), recvBoxVsIdir);
495+
bufferRecv.UnpackJDirSymetric(Vs, IDIR, sVs, recvBoxVsIdir);
495496

496497
//unpack Vs face-centered
497498
BoundingBox recvBoxVsKdir = baseBox;
498499
recvBoxVsKdir[KDIR][1] += 1;
499-
bufferRecv.UnpackJDirSymetric(Vs, KDIR, sVs(KDIR), recvBoxVsKdir);
500+
bufferRecv.UnpackJDirSymetric(Vs, KDIR, sVs, recvBoxVsKdir);
500501
}
501502
} else if(side==right) {
502503
//unpack Vc on right part
@@ -514,14 +515,14 @@ void Axis::ExchangeMPI(int side) {
514515
recvBoxVsIdir[IDIR][1] += 1;
515516
recvBoxVsIdir[JDIR][0] += offset;
516517
recvBoxVsIdir[JDIR][1] += offset;
517-
bufferRecv.UnpackJDirSymetric(Vs, IDIR, sVs(IDIR), recvBoxVsIdir);
518+
bufferRecv.UnpackJDirSymetric(Vs, IDIR, sVs, recvBoxVsIdir);
518519

519520
//unpack Vs face-centered on right part
520521
BoundingBox recvBoxVsKdir = baseBox;
521522
recvBoxVsKdir[KDIR][1] += 1;
522523
recvBoxVsKdir[JDIR][0] += offset;
523524
recvBoxVsKdir[JDIR][1] += offset;
524-
bufferRecv.UnpackJDirSymetric(Vs, KDIR, sVs(KDIR), recvBoxVsKdir);
525+
bufferRecv.UnpackJDirSymetric(Vs, KDIR, sVs, recvBoxVsKdir);
525526
} // MHD
526527
}
527528

src/fluid/constrainedTransport/EMFexchange.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void ConstrainedTransport<Phys>::ExchangeX1(IdefixArray3D<real> ey, IdefixArray3
7575
sendBoxEy[KDIR][1] += 1;
7676
sendBoxEy[IDIR][0] = iright;
7777
sendBoxEy[IDIR][1] = iright + 1;
78-
BufferRight.Pack(ez, sendBoxEy);
78+
BufferRight.Pack(ey, sendBoxEy);
7979
#endif
8080

8181
// Wait for completion before sending out everything
@@ -239,11 +239,11 @@ void ConstrainedTransport<Phys>::ExchangeX3(IdefixArray3D<real> ex, IdefixArray3
239239
baseBox[KDIR][1] = data->end[KDIR];
240240

241241
//extend by one the end on jdir && take the ghost on k
242-
BoundingBox sendBoxEz = baseBox;
243-
sendBoxEz[JDIR][1] += 1;
244-
sendBoxEz[KDIR][0] = kright;
245-
sendBoxEz[KDIR][1] = kright + 1;
246-
BufferRight.Pack(ez, sendBoxEz);
242+
BoundingBox sendBoxEx = baseBox;
243+
sendBoxEx[JDIR][1] += 1;
244+
sendBoxEx[KDIR][0] = kright;
245+
sendBoxEx[KDIR][1] = kright + 1;
246+
BufferRight.Pack(ex, sendBoxEx);
247247

248248
//extend by one the end on idir && take the ghost on k
249249
BoundingBox sendBoxEy = baseBox;

0 commit comments

Comments
 (0)