Merge "Move ExecTestHelper to using a regex." am: b4d9304628 am: 617c4b5876 am: 60631ec17e

Original change: https://android-review.googlesource.com/c/platform/bionic/+/1843499

Change-Id: I6b42fc4b9e4be4bc3423886030f7b8f4e988c13e
This commit is contained in:
Elliott Hughes 2021-10-02 00:07:30 +00:00 committed by Automerger Merge Worker
commit 5debadd648
2 changed files with 9 additions and 5 deletions

View file

@ -133,7 +133,8 @@ TEST(dl, exec_linker_load_file) {
"helper_func called\n";
ExecTestHelper eth;
eth.SetArgs({ path_to_linker, helper.c_str(), nullptr });
eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str());
eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, nullptr);
ASSERT_EQ(expected_output, eth.GetOutput());
#endif
}
@ -149,7 +150,8 @@ TEST(dl, exec_linker_load_from_zip) {
"helper_func called\n";
ExecTestHelper eth;
eth.SetArgs({ path_to_linker, helper.c_str(), nullptr });
eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, expected_output.c_str());
eth.Run([&]() { execve(path_to_linker, eth.GetArgs(), eth.GetEnv()); }, 0, nullptr);
ASSERT_EQ(expected_output, eth.GetOutput());
#endif
}

View file

@ -229,7 +229,7 @@ class ExecTestHelper {
}
void Run(const std::function<void()>& child_fn, int expected_exit_status,
const char* expected_output) {
const char* expected_output_regex) {
int fds[2];
ASSERT_NE(pipe(fds), -1);
@ -258,8 +258,10 @@ class ExecTestHelper {
std::string error_msg("Test output:\n" + output_);
AssertChildExited(pid, expected_exit_status, &error_msg);
if (expected_output != nullptr) {
ASSERT_EQ(expected_output, output_);
if (expected_output_regex != nullptr) {
if (!std::regex_search(output_, std::regex(expected_output_regex))) {
FAIL() << "regex " << expected_output_regex << " didn't match " << output_;
}
}
}