Skip to content

Commit

Permalink
Merge pull request #1784 from buildtesters/display_output_and_test
Browse files Browse the repository at this point in the history
Add option --display to display output and test in buildtest build
  • Loading branch information
shahzebsiddiqui committed Jun 4, 2024
2 parents b515c44 + 3b841e2 commit 207d071
Show file tree
Hide file tree
Showing 11 changed files with 184 additions and 118 deletions.
2 changes: 1 addition & 1 deletion bash_completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ _buildtest ()
case "$next" in
build|bd)
local shortoption="-b -e -et -f -m -n -s -t -u -x -xt"
local longoption="--buildspec --dry-run --executor --executor-type --exclude --exclude-tags --filter --helpfilter --limit --maxpendtime --max-jobs --modules --module-purge --name --nodes --pollinterval --procs --profile --rerun --remove-stagedir --retry --save-profile --strict --tags --timeout --unload-modules --validate --write-config-file"
local longoption="--account --buildspec --display --dry-run --executor --executor-type --exclude --exclude-tags --filter --helpfilter --limit --maxpendtime --max-jobs --modules --module-purge --name --nodes --pollinterval --procs --profile --rebuild --rerun --remove-stagedir --retry --save-profile --strict --tags --testdir --timeout --unload-modules --validate --write-config-file"
local allopts="${longoption} ${shortoption}"

COMPREPLY=( $( compgen -W "$allopts" -- "${cur}" ) )
Expand Down
103 changes: 56 additions & 47 deletions buildtest/builders/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def __init__(
numprocs=None,
numnodes=None,
compiler=None,
display=None,
):
"""The BuilderBase provides common functions for any builder. The builder
is an instance of BuilderBase. The initializer method will setup the builder
Expand All @@ -82,6 +83,7 @@ def __init__(
buildspec (str): Full path to buildspec file
buildexecutor (:obj:`buildtest.executors.setup.BuildExecutor`): An instance of BuildExecutor class used for accessing executors
testdir (str): Test directory where tests are written. Must be full path on filesystem.
display (list, optional): Display content of output/error or test.
"""

self.name = name
Expand All @@ -95,7 +97,7 @@ def __init__(
self.fflags = None
self.ldflags = None
self.cppflags = None

self.display = display or []
self.metadata = {}

self.duration = 0
Expand Down Expand Up @@ -378,21 +380,22 @@ def execute_post_run_script(self):
f"[blue]{self}[/]: Post run script exit code: {post_run.returncode()}"
)

print_content(
output,
title=f"[blue]{self}[/]: Start of Post Run Output",
theme="monokai",
lexer="text",
show_last_lines=10,
)
if "output" in self.display:
print_content(
output,
title=f"[blue]{self}[/]: Start of Post Run Output",
theme="monokai",
lexer="text",
show_last_lines=10,
)

print_content(
error,
title=f"[blue]{self}[/]: Start of Post Run Error",
theme="monokai",
lexer="text",
show_last_lines=10,
)
print_content(
error,
title=f"[blue]{self}[/]: Start of Post Run Error",
theme="monokai",
lexer="text",
show_last_lines=10,
)

def handle_run_result(self, command_result, timeout):
"""This method will handle the result of running test. If the test is successful we will record endtime,
Expand All @@ -405,26 +408,28 @@ def handle_run_result(self, command_result, timeout):
output_msg = "".join(command_result.get_output())
err_msg = "".join(command_result.get_error())

print_content(
output_msg,
title=f"[blue]{self}[/]: Start of Output",
theme="monokai",
lexer="text",
show_last_lines=10,
)
if "output" in self.display:
print_content(
output_msg,
title=f"[blue]{self}[/]: Start of Output",
theme="monokai",
lexer="text",
show_last_lines=10,
)

if not self._retry or ret == 0:
return command_result

console.print(f"[red]{self}: failed to submit job with returncode: {ret}")

print_content(
err_msg,
title=f"[blue]{self}[/]: Start of Error",
theme="monokai",
lexer="text",
show_last_lines=30,
)
if "output" in self.display:
print_content(
err_msg,
title=f"[blue]{self}[/]: Start of Error",
theme="monokai",
lexer="text",
show_last_lines=30,
)

console.print(
f"[red]{self}: Detected failure in running test, will attempt to retry test: {self._retry} times"
Expand Down Expand Up @@ -663,12 +668,14 @@ def _write_build_script(self, modules=None, modulepurge=None, unload_modules=Non

self.build_script = dest
self.metadata["build_script"] = self.build_script
print_file_content(
file_path=self.build_script,
title=f"[blue]{self}[/]: Start of Build Script",
lexer="bash",
theme="monokai",
)

if "test" in self.display:
print_file_content(
file_path=self.build_script,
title=f"[blue]{self}[/]: Start of Build Script",
lexer="bash",
theme="monokai",
)

def _write_post_run_script(self):
"""This method will write the content of post run script that is run after the test is complete.
Expand All @@ -690,12 +697,13 @@ def _write_post_run_script(self):
console.print(
f"[blue]{self}[/]: Writing Post Run Script: {self.post_run_script}"
)
print_file_content(
file_path=self.post_run_script,
title=f"[blue]{self}[/]: Start of Post Run Script",
lexer="bash",
theme="monokai",
)
if "test" in self.display:
print_file_content(
file_path=self.post_run_script,
title=f"[blue]{self}[/]: Start of Post Run Script",
lexer="bash",
theme="monokai",
)

def _write_test(self):
"""This method is responsible for invoking ``generate_script`` that
Expand All @@ -722,12 +730,13 @@ def _write_test(self):
shutil.copy2(
self.testpath, os.path.join(self.test_root, os.path.basename(self.testpath))
)
print_file_content(
file_path=self.testpath,
title=f"[blue]{self}[/]: Start of Test Script",
lexer="bash",
theme="monokai",
)
if "test" in self.display:
print_file_content(
file_path=self.testpath,
title=f"[blue]{self}[/]: Start of Test Script",
lexer="bash",
theme="monokai",
)

def get_container_invocation(self):
"""This method returns a list of lines containing the container invocation"""
Expand Down
2 changes: 2 additions & 0 deletions buildtest/builders/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def __init__(
numnodes=None,
compiler=None,
strict=None,
display=None,
):
super().__init__(
name=name,
Expand All @@ -37,6 +38,7 @@ def __init__(
numprocs=numprocs,
numnodes=numnodes,
compiler=compiler,
display=display,
)
self.compiler_settings = {"vars": None, "env": None, "modules": None}

Expand Down
2 changes: 2 additions & 0 deletions buildtest/builders/spack.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def __init__(
numprocs=None,
numnodes=None,
strict=None,
display=None,
):
super().__init__(
name=name,
Expand All @@ -38,6 +39,7 @@ def __init__(
testdir=testdir,
numprocs=numprocs,
numnodes=numnodes,
display=display,
)
self.strict = strict
self.status = deep_get(
Expand Down
11 changes: 9 additions & 2 deletions buildtest/buildsystem/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(
executor_type=None,
exclude_tags=None,
strict=None,
display=None,
):
"""Based on a loaded Buildspec file, return the correct builder
for each based on the type. Each type is associated with a known
Expand All @@ -52,13 +53,13 @@ def __init__(
executor_type (str, optional): Filter test by executor type (local, batch)
exclude_tags (list, optional): List of tags to exclude tests from buildspec file
strict (bool, optional): This is a boolean used for enable strict mode for test that will run the 'set' command in test.
display (list, optional): Show content of test or output via ``buildtest build --display``
"""

self.configuration = configuration
self.logger = logging.getLogger(__name__)
self.testdir = testdir
self.buildexecutor = buildexecutor

self.rebuild = rebuild or 1
self.numprocs = numprocs
self.numnodes = numnodes
Expand All @@ -68,7 +69,7 @@ def __init__(
self.bp = bp
self.bc = buildtest_compilers
self.filters = filters

self.display = display
self.builders = []

# skip property defined at top-level then skip test
Expand Down Expand Up @@ -172,6 +173,7 @@ def create_script_builders(
testdir=self.testdir,
compiler=compiler_name,
strict=self.strict,
display=self.display,
)
builders.append(builder)

Expand All @@ -188,6 +190,7 @@ def create_script_builders(
numnodes=node,
compiler=compiler_name,
strict=self.strict,
display=self.display,
)
builders.append(builder)
if procs:
Expand All @@ -203,6 +206,7 @@ def create_script_builders(
numprocs=proc,
compiler=compiler_name,
strict=self.strict,
display=self.display,
)
builders.append(builder)

Expand All @@ -228,6 +232,7 @@ def create_spack_builders(self, name, recipe, executor, nodes=None, procs=None):
buildexecutor=self.buildexecutor,
testdir=self.testdir,
strict=self.strict,
display=self.display,
)
builders.append(builder)

Expand All @@ -242,6 +247,7 @@ def create_spack_builders(self, name, recipe, executor, nodes=None, procs=None):
testdir=self.testdir,
numnodes=node,
strict=self.strict,
display=self.display,
)
builders.append(builder)
if procs:
Expand All @@ -255,6 +261,7 @@ def create_spack_builders(self, name, recipe, executor, nodes=None, procs=None):
testdir=self.testdir,
numprocs=proc,
strict=self.strict,
display=self.display,
)
builders.append(builder)

Expand Down
9 changes: 9 additions & 0 deletions buildtest/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,15 @@ def build_menu(self):
),
],
"extra": [
(
["--display"],
{
"action": "append",
"type": str,
"help": "Display content of output/error or test",
"choices": ["output", "test"],
},
),
(
["--dry-run"],
{
Expand Down
Loading

0 comments on commit 207d071

Please sign in to comment.