From 2415af6b519466ae3b5f78eced21b598ee12d232 Mon Sep 17 00:00:00 2001 From: BrianMarre Date: Sat, 3 Aug 2024 20:59:20 +0200 Subject: [PATCH] add test compile for example scripts --- lib/python/picongpu/pypicongpu/runner.py | 7 ++- test/python/picongpu/compiling/__init__.py | 1 + .../picongpu/compiling/compileexamples.py | 53 +++++++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/python/picongpu/compiling/compileexamples.py diff --git a/lib/python/picongpu/pypicongpu/runner.py b/lib/python/picongpu/pypicongpu/runner.py index c51f42e2383..7194053ada2 100644 --- a/lib/python/picongpu/pypicongpu/runner.py +++ b/lib/python/picongpu/pypicongpu/runner.py @@ -333,7 +333,12 @@ def __run(self): chdir(self.setup_dir) runArgs( "PIConGPU", - r"tbg -s bash -c etc/picongpu/N.cfg -t $PIC_SYSTEM_TEMPLATE_PATH/mpiexec.tpl".split(" ") + [self.run_dir], + ( + ("tbg -s bash -c etc/picongpu/N.cfg -t " + environ("PIC_SYSTEM_TEMPLATE_PATH") + "/mpiexec.tpl").split( + " " + ) + + [self.run_dir] + ), ) def generate(self, printDirToConsole=False): diff --git a/test/python/picongpu/compiling/__init__.py b/test/python/picongpu/compiling/__init__.py index 69c38d59bf9..0f5034d2a09 100644 --- a/test/python/picongpu/compiling/__init__.py +++ b/test/python/picongpu/compiling/__init__.py @@ -3,3 +3,4 @@ from .species import * # pyflakes.ignore from .distribution import * # pyflakes.ignore from .simulation import * # pyflakes.ignore +from .compileexamples import * # pyflakes.ignore diff --git a/test/python/picongpu/compiling/compileexamples.py b/test/python/picongpu/compiling/compileexamples.py new file mode 100644 index 00000000000..c5c97557821 --- /dev/null +++ b/test/python/picongpu/compiling/compileexamples.py @@ -0,0 +1,53 @@ +""" +This file is part of PIConGPU. +Copyright 2021-2023 PIConGPU contributors +Authors: Brian Edward Marre +License: GPLv3+ +""" + +from picongpu import pypicongpu + +import shutil +import importlib.util +import sys + +import unittest + + +class TestExamples(unittest.TestCase): + def __load_example_script(self, path): + """load and execute example PICMI script from given path""" + spec = importlib.util.spec_from_file_location("example", path) + example_script = importlib.util.module_from_spec(spec) + + sys.modules["example"] = example_script + spec.loader.exec_module(example_script) + + sim = example.sim # noqa + output_path = example.OUTPUT_DIRECTORY_PATH # noqa + + return sim, output_path + + def __build_simulation(sim): + """build the given instance of simulation""" + runner = pypicongpu.Runner(sim) + runner.generate(printDirToConsole=True) + runner.build() + + def test_LWFA_example(self): + sim, output_path = self.__load_example_script( + "$PICSRC/share/picongpu/pypicongpu/examples/laser_wakefield/main.py" + ) + + self.__try_to_build(sim) + + # remove generated output + shutil.rmtree(output_path) + + def test_warm_plasma_example(self): + sim, output_path = self.__load_example_script("$PICSRC/share/picongpu/pypicongpu/examples/warm_plasma/main.py") + + self.__try_to_build(sim) + + # remove generated output + shutil.rmtree(output_path)