diff options
author | 2022-06-28 21:45:45 +0000 | |
---|---|---|
committer | 2022-06-28 21:45:45 +0000 | |
commit | 90156609e44f329c9421efbf3f25bdedf13f044c (patch) | |
tree | 51d71a674432a13d55bd74abafc04ef1d44b920b | |
parent | e24992253f2b1b59040f67dc053950fee03a56bb (diff) | |
parent | a12b096448beae54d66d6979ae0423a374fa3917 (diff) |
Merge "libbinder: Check the sub-process exit status in binderRpcTest"
-rw-r--r-- | libs/binder/tests/binderRpcTest.cpp | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/libs/binder/tests/binderRpcTest.cpp b/libs/binder/tests/binderRpcTest.cpp index 141fa38114..194553f872 100644 --- a/libs/binder/tests/binderRpcTest.cpp +++ b/libs/binder/tests/binderRpcTest.cpp @@ -23,6 +23,7 @@ #include <android-base/file.h> #include <android-base/logging.h> #include <android-base/properties.h> +#include <android-base/stringprintf.h> #include <android/binder_auto_utils.h> #include <android/binder_libbinder.h> #include <binder/Binder.h> @@ -331,6 +332,16 @@ public: }; sp<IBinder> MyBinderRpcTest::mHeldBinder; +static std::string WaitStatusToString(int wstatus) { + if (WIFEXITED(wstatus)) { + return base::StringPrintf("exit status %d", WEXITSTATUS(wstatus)); + } + if (WIFSIGNALED(wstatus)) { + return base::StringPrintf("term signal %d", WTERMSIG(wstatus)); + } + return base::StringPrintf("unexpected state %d", wstatus); +} + class Process { public: Process(Process&&) = default; @@ -351,13 +362,25 @@ public: } ~Process() { if (mPid != 0) { - waitpid(mPid, nullptr, 0); + int wstatus; + waitpid(mPid, &wstatus, 0); + if (mCustomExitStatusCheck) { + mCustomExitStatusCheck(wstatus); + } else { + EXPECT_TRUE(WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == 0) + << "server process failed: " << WaitStatusToString(wstatus); + } } } android::base::borrowed_fd readEnd() { return mReadEnd; } android::base::borrowed_fd writeEnd() { return mWriteEnd; } + void setCustomExitStatusCheck(std::function<void(int wstatus)> f) { + mCustomExitStatusCheck = std::move(f); + } + private: + std::function<void(int wstatus)> mCustomExitStatusCheck; pid_t mPid = 0; android::base::unique_fd mReadEnd; android::base::unique_fd mWriteEnd; @@ -1297,6 +1320,12 @@ TEST_P(BinderRpc, Callbacks) { // need to manually shut it down EXPECT_TRUE(proc.proc.sessions.at(0).session->shutdownAndWait(true)); + proc.proc.host.setCustomExitStatusCheck([](int wstatus) { + // Flaky. Sometimes gets SIGABRT. + EXPECT_TRUE((WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == 0) || + (WIFSIGNALED(wstatus) && WTERMSIG(wstatus) == SIGABRT)) + << "server process failed: " << WaitStatusToString(wstatus); + }); proc.expectAlreadyShutdown = true; } } @@ -1326,6 +1355,10 @@ TEST_P(BinderRpc, Die) { EXPECT_EQ(DEAD_OBJECT, proc.rootIface->die(doDeathCleanup).transactionError()) << "Do death cleanup: " << doDeathCleanup; + proc.proc.host.setCustomExitStatusCheck([](int wstatus) { + EXPECT_TRUE(WIFEXITED(wstatus) && WEXITSTATUS(wstatus) == 1) + << "server process failed incorrectly: " << WaitStatusToString(wstatus); + }); proc.expectAlreadyShutdown = true; } } @@ -1349,6 +1382,10 @@ TEST_P(BinderRpc, UseKernelBinderCallingId) { // second time! we catch the error :) EXPECT_EQ(DEAD_OBJECT, proc.rootIface->useKernelBinderCallingId().transactionError()); + proc.proc.host.setCustomExitStatusCheck([](int wstatus) { + EXPECT_TRUE(WIFSIGNALED(wstatus) && WTERMSIG(wstatus) == SIGABRT) + << "server process failed incorrectly: " << WaitStatusToString(wstatus); + }); proc.expectAlreadyShutdown = true; } |