summaryrefslogtreecommitdiff
path: root/runtime/exec_utils_test.cc
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2022-07-07 20:36:59 +0000
committer Jiakai Zhang <jiakaiz@google.com> 2022-07-11 12:23:56 +0000
commita9f772730fb493c5c3fa412fc0b91f2e9b8dbe17 (patch)
tree85cf686a26e365a567c1e4af883eec0b68b897ed /runtime/exec_utils_test.cc
parenta968731b013c39d33c92a447cce98ba871cd1c01 (diff)
Revert^2 "Update ExecUtils to support artd use cases."
This reverts commit ff95ad517297384d4a2ea589490019f90d637e17. Reason for revert: Fix available (aosp/2148047) Test: Presubmit Change-Id: I952960949267a7b6e63cd7966a347cb1f3374b85 Merged-In: I375034162cded6fdf09ee4d4cd783a0d3987af49
Diffstat (limited to 'runtime/exec_utils_test.cc')
-rw-r--r--runtime/exec_utils_test.cc40
1 files changed, 37 insertions, 3 deletions
diff --git a/runtime/exec_utils_test.cc b/runtime/exec_utils_test.cc
index dc789aa292..aa53739cfa 100644
--- a/runtime/exec_utils_test.cc
+++ b/runtime/exec_utils_test.cc
@@ -16,16 +16,34 @@
#include "exec_utils.h"
+#include <unistd.h>
+
#include "android-base/stringprintf.h"
#include "base/file_utils.h"
#include "base/memory_tool.h"
#include "common_runtime_test.h"
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
namespace art {
std::string PrettyArguments(const char* signature);
std::string PrettyReturnType(const char* signature);
+bool IsPidfdSupported() {
+#ifdef __BIONIC__
+ return true;
+#else
+ constexpr int SYS_pidfd_open = 434;
+ int pidfd = syscall(SYS_pidfd_open, getpid(), /*flags=*/0);
+ if (pidfd < 0) {
+ return false;
+ }
+ close(pidfd);
+ return true;
+#endif
+}
+
class ExecUtilsTest : public CommonRuntimeTest {};
TEST_F(ExecUtilsTest, ExecSuccess) {
@@ -44,9 +62,6 @@ TEST_F(ExecUtilsTest, ExecSuccess) {
}
TEST_F(ExecUtilsTest, ExecError) {
- // This will lead to error messages in the log.
- ScopedLogSeverity sls(LogSeverity::FATAL);
-
std::vector<std::string> command;
command.push_back("bogus");
std::string error_msg;
@@ -115,6 +130,10 @@ static std::vector<std::string> SleepCommand(int sleep_seconds) {
}
TEST_F(ExecUtilsTest, ExecTimeout) {
+ if (!IsPidfdSupported()) {
+ GTEST_SKIP() << "pidfd not supported";
+ }
+
static constexpr int kSleepSeconds = 5;
static constexpr int kWaitSeconds = 1;
std::vector<std::string> command = SleepCommand(kSleepSeconds);
@@ -125,6 +144,10 @@ TEST_F(ExecUtilsTest, ExecTimeout) {
}
TEST_F(ExecUtilsTest, ExecNoTimeout) {
+ if (!IsPidfdSupported()) {
+ GTEST_SKIP() << "pidfd not supported";
+ }
+
static constexpr int kSleepSeconds = 1;
static constexpr int kWaitSeconds = 5;
std::vector<std::string> command = SleepCommand(kSleepSeconds);
@@ -134,4 +157,15 @@ TEST_F(ExecUtilsTest, ExecNoTimeout) {
EXPECT_FALSE(timed_out);
}
+TEST_F(ExecUtilsTest, ExecTimeoutNotSupported) {
+ if (IsPidfdSupported()) {
+ GTEST_SKIP() << "pidfd supported";
+ }
+
+ std::string error_msg;
+ bool timed_out;
+ ASSERT_EQ(ExecAndReturnCode({"command"}, /*timeout_sec=*/0, &timed_out, &error_msg), -1);
+ EXPECT_THAT(error_msg, testing::HasSubstr("pidfd_open failed for pid"));
+}
+
} // namespace art