Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <exception>
#include <filesystem>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <regex>
Expand Down Expand Up @@ -287,12 +289,14 @@ auto _activate =

//======================================================================================//
//
// entry point
// instrument implementation
//
//======================================================================================//
//
namespace
{
int
main(int argc, char** argv)
run_instrumentation(int argc, char** argv)
{
argv0 = argv[0];

Expand Down Expand Up @@ -1185,8 +1189,9 @@ main(int argc, char** argv)
// mutname was resolved against the search paths in the argument pre-scan
if(!path::is_regular_file(mutname))
{
fprintf(stderr, "Error! Application '%s' does not exist or is not a regular "
"file. Nothing to instrument.\n",
fprintf(stderr,
"Error! Application '%s' does not exist or is not a regular "
"file. Nothing to instrument.\n",
_cmdv[0]);
return EXIT_FAILURE;
}
Expand Down Expand Up @@ -2886,6 +2891,26 @@ main(int argc, char** argv)
}
return code;
}
} // namespace

//======================================================================================//
//
// entry point
//
//======================================================================================//
//
int
main(int argc, char** argv)
{
try
{
return run_instrumentation(argc, argv);
} catch(const std::exception& err)
{
std::cerr << "[rocprof-sys] error: " << err.what() << '\n';
return EXIT_FAILURE;
}
}

//======================================================================================//
// query_instr -- check whether there are one or more instrumentation points
Expand Down
100 changes: 100 additions & 0 deletions projects/rocprofiler-systems/tests/pytest/test_binaries.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,106 @@ def test_max_library_functions(self):
)
self.assert_regex(result, pass_regex=pass_regex)

def _assert_usage_error(self, result, pass_regex):
self.assert_regex(
result,
pass_regex=pass_regex,
fail_regex=[
r"terminate called after throwing",
r"Signal 6 caught",
r"Killing process",
],
use_abort_fail_regex=False,
)
if result.returncode != 1:
pytest.fail(f"invalid input should exit 1, got {result.returncode}")

@pytest.mark.timeout(60)
def test_invalid_input_non_elf(self, test_output_dir):
"""A non-ELF text file is a usage error and must exit 1, not SIGABRT."""
bad_file = test_output_dir / "not-an-elf.txt"
bad_file.write_text("This is not an ELF binary.\n")

result = self.run_test(
"baseline",
target=self.target,
run_args=["--", str(bad_file)],
fail_on_not_found=True,
fail_on_pass=True,
)
self._assert_usage_error(
result,
[r"is a text file", r"only supports instrumenting binary files"],
)

@pytest.mark.timeout(60)
def test_invalid_input_missing_target(self, test_output_dir):
"""A missing target is a usage error and must exit 1, not SIGABRT."""
missing = test_output_dir / "does-not-exist"

result = self.run_test(
"baseline",
target=self.target,
run_args=["--", str(missing)],
fail_on_not_found=True,
fail_on_pass=True,
)
self._assert_usage_error(
result, [r"does not exist or is not a regular file\. Nothing to instrument"]
)

@pytest.mark.timeout(180)
def test_invalid_input_reinstrument(self, test_output_dir, rocprof_config):
"""Reject a second rewrite, and leave the first instrumented binary runnable.

Use a built ELF example rather than /usr/bin/true: on RHEL that path is a
text coreutils wrapper, so instrumentation refuses it before rewrite.
"""
try:
source_bin = str(rocprof_config.get_target_executable("parallel-overhead"))
except FileNotFoundError:
pytest.skip("parallel-overhead example not built")

first_inst = test_output_dir / "first.inst"
second_inst = test_output_dir / "second.inst"

baseline = self.run_test(
"baseline",
target=self.target,
run_args=["-o", str(first_inst), "--", source_bin],
working_directory=test_output_dir,
fail_on_not_found=True,
)
self.assert_regex(baseline)
self.assert_file_exists(first_inst)

rejected = self.run_test(
"baseline",
target=self.target,
run_args=["-o", str(second_inst), "--", str(first_inst)],
working_directory=test_output_dir,
fail_on_pass=True,
fail_on_not_found=True,
)
self._assert_usage_error(
rejected,
[
r"unable to open/reinstrument previously instrumented binary",
r"Failed to open binary",
],
)
if second_inst.exists():
pytest.fail(f"rejected rewrite wrote {second_inst}")

# Keep the instrumented binary runnable; tiny args so the check stays fast.
kept = self.run_test(
"baseline",
target="rocprof-sys-run",
run_args=["--", str(first_inst), "1", "1", "1"],
fail_on_not_found=True,
)
self.assert_regex(kept)


# ============================================================================
# rocprof-sys-avail tests
Expand Down
Loading