diff options
author | 2024-06-21 15:45:26 -0700 | |
---|---|---|
committer | 2024-07-02 15:44:44 -0700 | |
commit | 052c51302e797260763a44b537820b7d54b18226 (patch) | |
tree | b188121ad8b28ed8519a27831d8d41c4d455e68e | |
parent | 90946c74069e740960a3ccb1cac2f42c6c99f411 (diff) |
Binder: enable/fix some warnings
Bug: 341997808
Test: mma
Change-Id: Ibd44eda768a714e85399a15f3c8e534d715f87ce
-rw-r--r-- | libs/binder/IPCThreadState.cpp | 2 | ||||
-rw-r--r-- | libs/binder/PersistableBundle.cpp | 4 | ||||
-rw-r--r-- | libs/binder/Utils.h | 13 | ||||
-rw-r--r-- | libs/binder/ndk/include_ndk/android/persistable_bundle.h | 5 | ||||
-rw-r--r-- | libs/binder/ndk/service_manager.cpp | 3 | ||||
-rw-r--r-- | libs/binder/ndk/tests/Android.bp | 5 | ||||
-rw-r--r-- | libs/binder/ndk/tests/iface.cpp | 7 | ||||
-rw-r--r-- | libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp | 108 | ||||
-rw-r--r-- | libs/binder/tests/binderClearBufTest.cpp | 5 | ||||
-rw-r--r-- | libs/binder/tests/binderDriverInterfaceTest.cpp | 12 | ||||
-rw-r--r-- | libs/binder/tests/binderLibTest.cpp | 27 | ||||
-rw-r--r-- | libs/binder/tests/binderStabilityTest.cpp | 18 |
12 files changed, 110 insertions, 99 deletions
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index 94f947fce1..984c93d370 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -285,7 +285,9 @@ static const void* printCommand(std::ostream& out, const void* _cmd) { return cmd; } +LIBBINDER_IGNORE("-Wzero-as-null-pointer-constant") static pthread_mutex_t gTLSMutex = PTHREAD_MUTEX_INITIALIZER; +LIBBINDER_IGNORE_END() static std::atomic<bool> gHaveTLS(false); static pthread_key_t gTLS = 0; static std::atomic<bool> gShutdown = false; diff --git a/libs/binder/PersistableBundle.cpp b/libs/binder/PersistableBundle.cpp index 5b157cc7c3..abb6612a1c 100644 --- a/libs/binder/PersistableBundle.cpp +++ b/libs/binder/PersistableBundle.cpp @@ -113,7 +113,7 @@ status_t PersistableBundle::writeToParcel(Parcel* parcel) const { // Backpatch length. This length value includes the length header. parcel->setDataPosition(length_pos); size_t length = end_pos - start_pos; - if (length > std::numeric_limits<int32_t>::max()) { + if (length > static_cast<size_t>(std::numeric_limits<int32_t>::max())) { ALOGE("Parcel length (%zu) too large to store in 32-bit signed int", length); return BAD_VALUE; } @@ -319,7 +319,7 @@ status_t PersistableBundle::writeToParcelInner(Parcel* parcel) const { * pairs themselves. */ size_t num_entries = size(); - if (num_entries > std::numeric_limits<int32_t>::max()) { + if (num_entries > static_cast<size_t>(std::numeric_limits<int32_t>::max())) { ALOGE("The size of this PersistableBundle (%zu) too large to store in 32-bit signed int", num_entries); return BAD_VALUE; diff --git a/libs/binder/Utils.h b/libs/binder/Utils.h index 5e1012af01..881cdf3f4c 100644 --- a/libs/binder/Utils.h +++ b/libs/binder/Utils.h @@ -58,6 +58,19 @@ } \ } while (0) +#define LIBBINDER_PRAGMA(arg) _Pragma(#arg) +#if defined(__clang__) +#define LIBBINDER_PRAGMA_FOR_COMPILER(arg) LIBBINDER_PRAGMA(clang arg) +#elif defined(__GNUC__) +#define LIBBINDER_PRAGMA_FOR_COMPILER(arg) LIBBINDER_PRAGMA(GCC arg) +#else +#define LIBBINDER_PRAGMA_FOR_COMPILER(arg) +#endif +#define LIBBINDER_IGNORE(warning_flag) \ + LIBBINDER_PRAGMA_FOR_COMPILER(diagnostic push) \ + LIBBINDER_PRAGMA_FOR_COMPILER(diagnostic ignored warning_flag) +#define LIBBINDER_IGNORE_END() LIBBINDER_PRAGMA_FOR_COMPILER(diagnostic pop) + namespace android { /** diff --git a/libs/binder/ndk/include_ndk/android/persistable_bundle.h b/libs/binder/ndk/include_ndk/android/persistable_bundle.h index 42ae15ae61..5e0d4da97b 100644 --- a/libs/binder/ndk/include_ndk/android/persistable_bundle.h +++ b/libs/binder/ndk/include_ndk/android/persistable_bundle.h @@ -29,6 +29,11 @@ #include <sys/cdefs.h> #include <sys/types.h> +#ifndef __clang__ +#define _Nullable +#define _Nonnull +#endif + __BEGIN_DECLS /* diff --git a/libs/binder/ndk/service_manager.cpp b/libs/binder/ndk/service_manager.cpp index 4436dbeed7..d6ac4acc29 100644 --- a/libs/binder/ndk/service_manager.cpp +++ b/libs/binder/ndk/service_manager.cpp @@ -18,6 +18,7 @@ #include <binder/IServiceManager.h> #include <binder/LazyServiceRegistrar.h> +#include "../Utils.h" #include "ibinder_internal.h" #include "status_internal.h" @@ -89,7 +90,9 @@ AIBinder* AServiceManager_getService(const char* instance) { } sp<IServiceManager> sm = defaultServiceManager(); + LIBBINDER_IGNORE("-Wdeprecated-declarations") sp<IBinder> binder = sm->getService(String16(instance)); + LIBBINDER_IGNORE_END() sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(binder); AIBinder_incStrong(ret.get()); diff --git a/libs/binder/ndk/tests/Android.bp b/libs/binder/ndk/tests/Android.bp index 8fb755cdac..c61a16413b 100644 --- a/libs/binder/ndk/tests/Android.bp +++ b/libs/binder/ndk/tests/Android.bp @@ -34,6 +34,11 @@ cc_defaults { cflags: [ "-O0", "-g", + "-Wall", + "-Wextra", + "-Wextra-semi", + "-Werror", + "-Winconsistent-missing-override", ], } diff --git a/libs/binder/ndk/tests/iface.cpp b/libs/binder/ndk/tests/iface.cpp index ca927272f8..08b857fab2 100644 --- a/libs/binder/ndk/tests/iface.cpp +++ b/libs/binder/ndk/tests/iface.cpp @@ -20,6 +20,8 @@ #include <android/binder_auto_utils.h> +#include "../../Utils.h" + using ::android::sp; using ::android::wp; @@ -157,10 +159,9 @@ binder_status_t IFoo::addService(const char* instance) { } sp<IFoo> IFoo::getService(const char* instance, AIBinder** outBinder) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") AIBinder* binder = AServiceManager_getService(instance); // maybe nullptr -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() if (binder == nullptr) { return nullptr; } diff --git a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp index 6d638d0b3a..f518a22902 100644 --- a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +++ b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp @@ -42,6 +42,7 @@ #include <mutex> #include <thread> +#include "../Utils.h" #include "android/binder_ibinder.h" using namespace android; @@ -69,21 +70,21 @@ class MyTestFoo : public IFoo { }; class MyBinderNdkUnitTest : public aidl::BnBinderNdkUnitTest { - ndk::ScopedAStatus repeatInt(int32_t in, int32_t* out) { + ndk::ScopedAStatus repeatInt(int32_t in, int32_t* out) override { *out = in; return ndk::ScopedAStatus::ok(); } - ndk::ScopedAStatus takeInterface(const std::shared_ptr<aidl::IEmpty>& empty) { + ndk::ScopedAStatus takeInterface(const std::shared_ptr<aidl::IEmpty>& empty) override { (void)empty; return ndk::ScopedAStatus::ok(); } - ndk::ScopedAStatus forceFlushCommands() { + ndk::ScopedAStatus forceFlushCommands() override { // warning: this is assuming that libbinder_ndk is using the same copy // of libbinder that we are. android::IPCThreadState::self()->flushCommands(); return ndk::ScopedAStatus::ok(); } - ndk::ScopedAStatus getsRequestedSid(bool* out) { + ndk::ScopedAStatus getsRequestedSid(bool* out) override { const char* sid = AIBinder_getCallingSid(); std::cout << "Got security context: " << (sid ?: "null") << std::endl; *out = sid != nullptr; @@ -97,11 +98,11 @@ class MyBinderNdkUnitTest : public aidl::BnBinderNdkUnitTest { fsync(out); return STATUS_OK; } - ndk::ScopedAStatus forcePersist(bool persist) { + ndk::ScopedAStatus forcePersist(bool persist) override { AServiceManager_forceLazyServicesPersist(persist); return ndk::ScopedAStatus::ok(); } - ndk::ScopedAStatus setCustomActiveServicesCallback() { + ndk::ScopedAStatus setCustomActiveServicesCallback() override { AServiceManager_setActiveServicesCallback(activeServicesCallback, this); return ndk::ScopedAStatus::ok(); } @@ -342,10 +343,9 @@ TEST(NdkBinder, UnimplementedShell) { // libbinder across processes to the NDK service which doesn't implement // shell static const sp<android::IServiceManager> sm(android::defaultServiceManager()); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") sp<IBinder> testService = sm->getService(String16(IFoo::kSomeInstanceName)); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() Vector<String16> argsVec; EXPECT_EQ(OK, IBinder::shellCommand(testService, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, @@ -388,10 +388,9 @@ TEST(NdkBinder, GetTestServiceStressTest) { // checkService on it, since the other process serving it might not be started yet. { // getService, not waitForService, to take advantage of timeout -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") auto binder = ndk::SpAIBinder(AServiceManager_getService(IFoo::kSomeInstanceName)); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() ASSERT_NE(nullptr, binder.get()); } @@ -425,7 +424,7 @@ TEST(NdkBinder, GetDeclaredInstances) { // At the time of writing this test, there is no good interface guaranteed // to be on all devices. Cuttlefish has light, so this will generally test // things. - EXPECT_EQ(count, hasLight ? 1 : 0); + EXPECT_EQ(count, hasLight ? 1u : 0u); } TEST(NdkBinder, GetLazyService) { @@ -515,7 +514,7 @@ void LambdaOnDeath(void* cookie) { // may reference other cookie members (*funcs->onDeath)(); -}; +} void LambdaOnUnlink(void* cookie) { auto funcs = static_cast<DeathRecipientCookie*>(cookie); (*funcs->onUnlink)(); @@ -523,7 +522,7 @@ void LambdaOnUnlink(void* cookie) { // may reference other cookie members delete funcs; -}; +} TEST(NdkBinder, DeathRecipient) { using namespace std::chrono_literals; @@ -701,7 +700,7 @@ TEST(NdkBinder, DeathRecipientDropBinderOnDied) { void LambdaOnUnlinkMultiple(void* cookie) { auto funcs = static_cast<DeathRecipientCookie*>(cookie); (*funcs->onUnlink)(); -}; +} TEST(NdkBinder, DeathRecipientMultipleLinks) { using namespace std::chrono_literals; @@ -733,7 +732,7 @@ TEST(NdkBinder, DeathRecipientMultipleLinks) { ndk::ScopedAIBinder_DeathRecipient recipient(AIBinder_DeathRecipient_new(LambdaOnDeath)); AIBinder_DeathRecipient_setOnUnlinked(recipient.get(), LambdaOnUnlinkMultiple); - for (int32_t i = 0; i < kNumberOfLinksToDeath; i++) { + for (uint32_t i = 0; i < kNumberOfLinksToDeath; i++) { EXPECT_EQ(STATUS_OK, AIBinder_linkToDeath(binder.get(), recipient.get(), static_cast<void*>(cookie))); } @@ -745,14 +744,13 @@ TEST(NdkBinder, DeathRecipientMultipleLinks) { EXPECT_TRUE(unlinkCv.wait_for(lockUnlink, 5s, [&] { return unlinkReceived; })) << "countdown: " << countdown; EXPECT_TRUE(unlinkReceived); - EXPECT_EQ(countdown, 0); + EXPECT_EQ(countdown, 0u); } TEST(NdkBinder, RetrieveNonNdkService) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") AIBinder* binder = AServiceManager_getService(kExistingNonNdkService); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() ASSERT_NE(nullptr, binder); EXPECT_TRUE(AIBinder_isRemote(binder)); EXPECT_TRUE(AIBinder_isAlive(binder)); @@ -766,10 +764,9 @@ void OnBinderDeath(void* cookie) { } TEST(NdkBinder, LinkToDeath) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") AIBinder* binder = AServiceManager_getService(kExistingNonNdkService); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() ASSERT_NE(nullptr, binder); AIBinder_DeathRecipient* recipient = AIBinder_DeathRecipient_new(OnBinderDeath); @@ -799,10 +796,9 @@ TEST(NdkBinder, SetInheritRt) { } TEST(NdkBinder, SetInheritRtNonLocal) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") AIBinder* binder = AServiceManager_getService(kExistingNonNdkService); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() ASSERT_NE(binder, nullptr); ASSERT_TRUE(AIBinder_isRemote(binder)); @@ -838,14 +834,13 @@ TEST(NdkBinder, GetServiceInProcess) { } TEST(NdkBinder, EqualityOfRemoteBinderPointer) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") AIBinder* binderA = AServiceManager_getService(kExistingNonNdkService); ASSERT_NE(nullptr, binderA); AIBinder* binderB = AServiceManager_getService(kExistingNonNdkService); ASSERT_NE(nullptr, binderB); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() EXPECT_EQ(binderA, binderB); @@ -859,10 +854,9 @@ TEST(NdkBinder, ToFromJavaNullptr) { } TEST(NdkBinder, ABpBinderRefCount) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") AIBinder* binder = AServiceManager_getService(kExistingNonNdkService); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() AIBinder_Weak* wBinder = AIBinder_Weak_new(binder); ASSERT_NE(nullptr, binder); @@ -885,10 +879,9 @@ TEST(NdkBinder, AddServiceMultipleTimes) { } TEST(NdkBinder, RequestedSidWorks) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") ndk::SpAIBinder binder(AServiceManager_getService(kBinderNdkUnitTestService)); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() std::shared_ptr<aidl::IBinderNdkUnitTest> service = aidl::IBinderNdkUnitTest::fromBinder(binder); @@ -911,10 +904,9 @@ TEST(NdkBinder, SentAidlBinderCanBeDestroyed) { std::shared_ptr<MyEmpty> empty = ndk::SharedRefBase::make<MyEmpty>(); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") ndk::SpAIBinder binder(AServiceManager_getService(kBinderNdkUnitTestService)); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() std::shared_ptr<aidl::IBinderNdkUnitTest> service = aidl::IBinderNdkUnitTest::fromBinder(binder); @@ -935,14 +927,11 @@ TEST(NdkBinder, SentAidlBinderCanBeDestroyed) { } TEST(NdkBinder, ConvertToPlatformBinder) { - for (const ndk::SpAIBinder& binder : - {// remote -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - ndk::SpAIBinder(AServiceManager_getService(kBinderNdkUnitTestService)), -#pragma clang diagnostic pop - // local - ndk::SharedRefBase::make<MyBinderNdkUnitTest>()->asBinder()}) { + LIBBINDER_IGNORE("-Wdeprecated-declarations") + ndk::SpAIBinder remoteBinder(AServiceManager_getService(kBinderNdkUnitTestService)); + LIBBINDER_IGNORE_END() + auto localBinder = ndk::SharedRefBase::make<MyBinderNdkUnitTest>()->asBinder(); + for (const ndk::SpAIBinder& binder : {remoteBinder, localBinder}) { // convert to platform binder EXPECT_NE(binder, nullptr); sp<IBinder> platformBinder = AIBinder_toPlatformBinder(binder.get()); @@ -971,14 +960,11 @@ TEST(NdkBinder, ConvertToPlatformParcel) { } TEST(NdkBinder, GetAndVerifyScopedAIBinder_Weak) { - for (const ndk::SpAIBinder& binder : - {// remote -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - ndk::SpAIBinder(AServiceManager_getService(kBinderNdkUnitTestService)), -#pragma clang diagnostic pop - // local - ndk::SharedRefBase::make<MyBinderNdkUnitTest>()->asBinder()}) { + LIBBINDER_IGNORE("-Wdeprecated-declarations") + ndk::SpAIBinder remoteBinder(AServiceManager_getService(kBinderNdkUnitTestService)); + LIBBINDER_IGNORE_END() + auto localBinder = ndk::SharedRefBase::make<MyBinderNdkUnitTest>()->asBinder(); + for (const ndk::SpAIBinder& binder : {remoteBinder, localBinder}) { // get a const ScopedAIBinder_Weak and verify promote EXPECT_NE(binder.get(), nullptr); const ndk::ScopedAIBinder_Weak wkAIBinder = @@ -1047,7 +1033,7 @@ std::string shellCmdToString(sp<IBinder> unitTestService, const std::vector<cons sp<MyResultReceiver> resultReceiver = new MyResultReceiver(); Vector<String16> argsVec; - for (int i = 0; i < args.size(); i++) { + for (size_t i = 0; i < args.size(); i++) { argsVec.add(String16(args[i])); } status_t error = IBinder::shellCommand(unitTestService, inFd[0], outFd[0], errFd[0], argsVec, @@ -1071,10 +1057,9 @@ std::string shellCmdToString(sp<IBinder> unitTestService, const std::vector<cons TEST(NdkBinder, UseHandleShellCommand) { static const sp<android::IServiceManager> sm(android::defaultServiceManager()); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") sp<IBinder> testService = sm->getService(String16(kBinderNdkUnitTestService)); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() EXPECT_EQ("", shellCmdToString(testService, {})); EXPECT_EQ("", shellCmdToString(testService, {"", ""})); @@ -1084,10 +1069,9 @@ TEST(NdkBinder, UseHandleShellCommand) { TEST(NdkBinder, FlaggedServiceAccessible) { static const sp<android::IServiceManager> sm(android::defaultServiceManager()); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") sp<IBinder> testService = sm->getService(String16(kBinderNdkUnitTestServiceFlagged)); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() ASSERT_NE(nullptr, testService); } diff --git a/libs/binder/tests/binderClearBufTest.cpp b/libs/binder/tests/binderClearBufTest.cpp index 3230a3f904..63254cddd9 100644 --- a/libs/binder/tests/binderClearBufTest.cpp +++ b/libs/binder/tests/binderClearBufTest.cpp @@ -75,10 +75,9 @@ class FooBar : public BBinder { }; TEST(BinderClearBuf, ClearKernelBuffer) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") sp<IBinder> binder = defaultServiceManager()->getService(kServerName); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() ASSERT_NE(nullptr, binder); std::string replyBuffer; diff --git a/libs/binder/tests/binderDriverInterfaceTest.cpp b/libs/binder/tests/binderDriverInterfaceTest.cpp index de9d42bac0..7be4f21cee 100644 --- a/libs/binder/tests/binderDriverInterfaceTest.cpp +++ b/libs/binder/tests/binderDriverInterfaceTest.cpp @@ -94,8 +94,9 @@ class BinderDriverInterfaceTest : public ::testing::Test { ret = ioctl(m_binderFd, cmd, arg); EXPECT_EQ(expect_ret, ret); if (ret < 0) { - if (errno != accept_errno) + if (errno != accept_errno) { EXPECT_EQ(expect_errno, errno); + } } } void binderTestIoctlErr2(int cmd, void *arg, int expect_errno, int accept_errno) { @@ -275,12 +276,15 @@ TEST_F(BinderDriverInterfaceTest, Transaction) { binderTestIoctl(BINDER_WRITE_READ, &bwr); } EXPECT_EQ(offsetof(typeof(br), pad), bwr.read_consumed); - if (bwr.read_consumed > offsetof(typeof(br), cmd0)) + if (bwr.read_consumed > offsetof(typeof(br), cmd0)) { EXPECT_EQ(BR_NOOP, br.cmd0); - if (bwr.read_consumed > offsetof(typeof(br), cmd1)) + } + if (bwr.read_consumed > offsetof(typeof(br), cmd1)) { EXPECT_EQ(BR_TRANSACTION_COMPLETE, br.cmd1); - if (bwr.read_consumed > offsetof(typeof(br), cmd2)) + } + if (bwr.read_consumed > offsetof(typeof(br), cmd2)) { EXPECT_EQ(BR_REPLY, br.cmd2); + } if (bwr.read_consumed >= offsetof(typeof(br), pad)) { EXPECT_EQ(0u, br.arg2.target.ptr); EXPECT_EQ(0u, br.arg2.cookie); diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp index 5582a96ac1..9b1ba01146 100644 --- a/libs/binder/tests/binderLibTest.cpp +++ b/libs/binder/tests/binderLibTest.cpp @@ -47,10 +47,9 @@ #include <sys/socket.h> #include <sys/un.h> +#include "../Utils.h" #include "../binder_module.h" -#define ARRAY_SIZE(array) (sizeof array / sizeof array[0]) - using namespace android; using namespace android::binder::impl; using namespace std::string_literals; @@ -216,10 +215,9 @@ class BinderLibTestEnv : public ::testing::Environment { sp<IServiceManager> sm = defaultServiceManager(); //printf("%s: pid %d, get service\n", __func__, m_pid); -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") m_server = sm->getService(binderLibTestServiceName); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() ASSERT_TRUE(m_server != nullptr); //printf("%s: pid %d, get service done\n", __func__, m_pid); } @@ -566,7 +564,7 @@ TEST_F(BinderLibTest, Freeze) { TEST_F(BinderLibTest, SetError) { int32_t testValue[] = { 0, -123, 123 }; - for (size_t i = 0; i < ARRAY_SIZE(testValue); i++) { + for (size_t i = 0; i < countof(testValue); i++) { Parcel data, reply; data.writeInt32(testValue[i]); EXPECT_THAT(m_server->transact(BINDER_LIB_TEST_SET_ERROR_TRANSACTION, data, &reply), @@ -597,8 +595,8 @@ TEST_F(BinderLibTest, IndirectGetId2) Parcel data, reply; int32_t serverId[3]; - data.writeInt32(ARRAY_SIZE(serverId)); - for (size_t i = 0; i < ARRAY_SIZE(serverId); i++) { + data.writeInt32(countof(serverId)); + for (size_t i = 0; i < countof(serverId); i++) { sp<IBinder> server; BinderLibTestBundle datai; @@ -616,7 +614,7 @@ TEST_F(BinderLibTest, IndirectGetId2) EXPECT_EQ(0, id); ASSERT_THAT(reply.readInt32(&count), StatusEq(NO_ERROR)); - EXPECT_EQ(ARRAY_SIZE(serverId), (size_t)count); + EXPECT_EQ(countof(serverId), (size_t)count); for (size_t i = 0; i < (size_t)count; i++) { BinderLibTestBundle replyi(&reply); @@ -636,8 +634,8 @@ TEST_F(BinderLibTest, IndirectGetId3) Parcel data, reply; int32_t serverId[3]; - data.writeInt32(ARRAY_SIZE(serverId)); - for (size_t i = 0; i < ARRAY_SIZE(serverId); i++) { + data.writeInt32(countof(serverId)); + for (size_t i = 0; i < countof(serverId); i++) { sp<IBinder> server; BinderLibTestBundle datai; BinderLibTestBundle datai2; @@ -662,7 +660,7 @@ TEST_F(BinderLibTest, IndirectGetId3) EXPECT_EQ(0, id); ASSERT_THAT(reply.readInt32(&count), StatusEq(NO_ERROR)); - EXPECT_EQ(ARRAY_SIZE(serverId), (size_t)count); + EXPECT_EQ(countof(serverId), (size_t)count); for (size_t i = 0; i < (size_t)count; i++) { int32_t counti; @@ -2112,10 +2110,9 @@ int run_server(int index, int readypipefd, bool usePoll) if (index == 0) { ret = sm->addService(binderLibTestServiceName, testService); } else { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") sp<IBinder> server = sm->getService(binderLibTestServiceName); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() Parcel data, reply; data.writeInt32(index); data.writeStrongBinder(testService); diff --git a/libs/binder/tests/binderStabilityTest.cpp b/libs/binder/tests/binderStabilityTest.cpp index 3d993588a4..7a8f48e0eb 100644 --- a/libs/binder/tests/binderStabilityTest.cpp +++ b/libs/binder/tests/binderStabilityTest.cpp @@ -27,8 +27,9 @@ #include <sys/prctl.h> -#include "aidl/BnBinderStabilityTest.h" +#include "../Utils.h" #include "BnBinderStabilityTest.h" +#include "aidl/BnBinderStabilityTest.h" using namespace android; using namespace ndk; @@ -155,10 +156,9 @@ TEST(BinderStability, NdkForceDowngradeToLocalStability) { } TEST(BinderStability, ForceDowngradeToVendorStability) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") sp<IBinder> serverBinder = android::defaultServiceManager()->getService(kSystemStabilityServer); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() auto server = interface_cast<IBinderStabilityTest>(serverBinder); ASSERT_NE(nullptr, server.get()); @@ -209,10 +209,9 @@ TEST(BinderStability, ConnectionInfoRequiresManifestEntries) { EXPECT_EQ(connectionInfo, std::nullopt); } TEST(BinderStability, CantCallVendorBinderInSystemContext) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") sp<IBinder> serverBinder = android::defaultServiceManager()->getService(kSystemStabilityServer); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() auto server = interface_cast<IBinderStabilityTest>(serverBinder); ASSERT_NE(nullptr, server.get()); @@ -316,11 +315,10 @@ static AIBinder_Class* kNdkBadStableBinder = extern "C" void AIBinder_markVendorStability(AIBinder* binder); // <- BAD DO NOT COPY TEST(BinderStability, NdkCantCallVendorBinderInSystemContext) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" + LIBBINDER_IGNORE("-Wdeprecated-declarations") SpAIBinder binder = SpAIBinder(AServiceManager_getService( String8(kSystemStabilityServer).c_str())); -#pragma clang diagnostic pop + LIBBINDER_IGNORE_END() std::shared_ptr<aidl::IBinderStabilityTest> remoteServer = aidl::IBinderStabilityTest::fromBinder(binder); |