Skip to content

Commit

Permalink
add test compile for example scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianMarre committed Aug 3, 2024
1 parent cfe0bf5 commit 2415af6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/python/picongpu/pypicongpu/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions test/python/picongpu/compiling/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .species import * # pyflakes.ignore
from .distribution import * # pyflakes.ignore
from .simulation import * # pyflakes.ignore
from .compileexamples import * # pyflakes.ignore
53 changes: 53 additions & 0 deletions test/python/picongpu/compiling/compileexamples.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 2415af6

Please sign in to comment.