Fix libbinder_sdk build warnings
-Wdeprecated-declarations
-Wformat
-Wpessimizing-move
-Wsign-compare
-Wsubobject-linkage
-Wunused-result
-Wzero-as-null-pointer-constant (turned on in ag/4503295)
Bug: 285204695
Test: m libbinder_sdk
Change-Id: Id4a482c511244968e450fdeecf6b9de41bc65b04
diff --git a/libs/binder/tests/Android.bp b/libs/binder/tests/Android.bp
index 6800a8d..bd24a20 100644
--- a/libs/binder/tests/Android.bp
+++ b/libs/binder/tests/Android.bp
@@ -28,6 +28,11 @@
cflags: [
"-Wall",
"-Werror",
+ "-Wformat",
+ "-Wpessimizing-move",
+ "-Wsign-compare",
+ "-Wunused-result",
+ "-Wzero-as-null-pointer-constant",
],
}
diff --git a/libs/binder/tests/RpcTlsUtilsTest.cpp b/libs/binder/tests/RpcTlsUtilsTest.cpp
index 530606c..48e3345 100644
--- a/libs/binder/tests/RpcTlsUtilsTest.cpp
+++ b/libs/binder/tests/RpcTlsUtilsTest.cpp
@@ -52,9 +52,9 @@
<< "\nactual: " << toDebugString(deserializedPkey.get());
}
-INSTANTIATE_TEST_CASE_P(RpcTlsUtilsTest, RpcTlsUtilsKeyTest,
- testing::Values(RpcKeyFormat::PEM, RpcKeyFormat::DER),
- RpcTlsUtilsKeyTest::PrintParamInfo);
+INSTANTIATE_TEST_SUITE_P(RpcTlsUtilsTest, RpcTlsUtilsKeyTest,
+ testing::Values(RpcKeyFormat::PEM, RpcKeyFormat::DER),
+ RpcTlsUtilsKeyTest::PrintParamInfo);
class RpcTlsUtilsCertTest : public testing::TestWithParam<RpcCertificateFormat> {
public:
@@ -75,9 +75,9 @@
EXPECT_EQ(0, X509_cmp(cert.get(), deserializedCert.get()));
}
-INSTANTIATE_TEST_CASE_P(RpcTlsUtilsTest, RpcTlsUtilsCertTest,
- testing::Values(RpcCertificateFormat::PEM, RpcCertificateFormat::DER),
- RpcTlsUtilsCertTest::PrintParamInfo);
+INSTANTIATE_TEST_SUITE_P(RpcTlsUtilsTest, RpcTlsUtilsCertTest,
+ testing::Values(RpcCertificateFormat::PEM, RpcCertificateFormat::DER),
+ RpcTlsUtilsCertTest::PrintParamInfo);
class RpcTlsUtilsKeyAndCertTest
: public testing::TestWithParam<std::tuple<RpcKeyFormat, RpcCertificateFormat>> {
@@ -105,10 +105,10 @@
EXPECT_EQ(0, X509_cmp(cert.get(), deserializedCert.get()));
}
-INSTANTIATE_TEST_CASE_P(RpcTlsUtilsTest, RpcTlsUtilsKeyAndCertTest,
- testing::Combine(testing::Values(RpcKeyFormat::PEM, RpcKeyFormat::DER),
- testing::Values(RpcCertificateFormat::PEM,
- RpcCertificateFormat::DER)),
- RpcTlsUtilsKeyAndCertTest::PrintParamInfo);
+INSTANTIATE_TEST_SUITE_P(RpcTlsUtilsTest, RpcTlsUtilsKeyAndCertTest,
+ testing::Combine(testing::Values(RpcKeyFormat::PEM, RpcKeyFormat::DER),
+ testing::Values(RpcCertificateFormat::PEM,
+ RpcCertificateFormat::DER)),
+ RpcTlsUtilsKeyAndCertTest::PrintParamInfo);
} // namespace android
diff --git a/libs/binder/tests/binderAllocationLimits.cpp b/libs/binder/tests/binderAllocationLimits.cpp
index 7e0b594..c0c0aae 100644
--- a/libs/binder/tests/binderAllocationLimits.cpp
+++ b/libs/binder/tests/binderAllocationLimits.cpp
@@ -114,12 +114,12 @@
{
const auto on_malloc = OnMalloc([&](size_t bytes) {
mallocs++;
- EXPECT_EQ(bytes, 40);
+ EXPECT_EQ(bytes, 40u);
});
imaginary_use = new int[10];
}
- EXPECT_EQ(mallocs, 1);
+ EXPECT_EQ(mallocs, 1u);
}
@@ -196,9 +196,9 @@
// Happens to be SM package length. We could switch to forking
// and registering our own service if it became an issue.
#if defined(__LP64__)
- EXPECT_EQ(bytes, 78);
+ EXPECT_EQ(bytes, 78u);
#else
- EXPECT_EQ(bytes, 70);
+ EXPECT_EQ(bytes, 70u);
#endif
});
@@ -206,7 +206,7 @@
a_binder->getInterfaceDescriptor();
a_binder->getInterfaceDescriptor();
- EXPECT_EQ(mallocs, 1);
+ EXPECT_EQ(mallocs, 1u);
}
TEST(BinderAllocation, SmallTransaction) {
@@ -217,11 +217,11 @@
const auto on_malloc = OnMalloc([&](size_t bytes) {
mallocs++;
// Parcel should allocate a small amount by default
- EXPECT_EQ(bytes, 128);
+ EXPECT_EQ(bytes, 128u);
});
manager->checkService(empty_descriptor);
- EXPECT_EQ(mallocs, 1);
+ EXPECT_EQ(mallocs, 1u);
}
TEST(RpcBinderAllocation, SetupRpcServer) {
@@ -250,8 +250,8 @@
});
ASSERT_EQ(OK, remoteBinder->pingBinder());
}
- EXPECT_EQ(mallocs, 1);
- EXPECT_EQ(totalBytes, 40);
+ EXPECT_EQ(mallocs, 1u);
+ EXPECT_EQ(totalBytes, 40u);
}
int main(int argc, char** argv) {
diff --git a/libs/binder/tests/binderClearBufTest.cpp b/libs/binder/tests/binderClearBufTest.cpp
index e43ee5f..3230a3f 100644
--- a/libs/binder/tests/binderClearBufTest.cpp
+++ b/libs/binder/tests/binderClearBufTest.cpp
@@ -88,7 +88,7 @@
// the buffer must have at least some length for the string, but we will
// just check it has some length, to avoid assuming anything about the
// format
- EXPECT_GT(replyBuffer.size(), 0);
+ EXPECT_GT(replyBuffer.size(), 0u);
for (size_t i = 0; i < replyBuffer.size(); i++) {
EXPECT_EQ(replyBuffer[i], '0') << "reply buffer at " << i;
diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp
index 1f61f18..9788d9d 100644
--- a/libs/binder/tests/binderLibTest.cpp
+++ b/libs/binder/tests/binderLibTest.cpp
@@ -528,8 +528,8 @@
EXPECT_EQ(NO_ERROR, IPCThreadState::self()->getProcessFreezeInfo(pid, &sync_received,
&async_received));
- EXPECT_EQ(sync_received, 1);
- EXPECT_EQ(async_received, 0);
+ EXPECT_EQ(sync_received, 1u);
+ EXPECT_EQ(async_received, 0u);
EXPECT_EQ(NO_ERROR, IPCThreadState::self()->freeze(pid, false, 0));
EXPECT_EQ(NO_ERROR, m_server->transact(BINDER_LIB_TEST_NOP_TRANSACTION, data, &reply));
@@ -1238,13 +1238,13 @@
data.setDataCapacity(1024);
// Write a bogus object at offset 0 to get an entry in the offset table
data.writeFileDescriptor(0);
- EXPECT_EQ(data.objectsCount(), 1);
+ EXPECT_EQ(data.objectsCount(), 1u);
uint8_t *parcelData = const_cast<uint8_t*>(data.data());
// And now, overwrite it with the buffer object
memcpy(parcelData, &obj, sizeof(obj));
data.setDataSize(sizeof(obj));
- EXPECT_EQ(data.objectsCount(), 1);
+ EXPECT_EQ(data.objectsCount(), 1u);
// Either the kernel should reject this transaction (if it's correct), but
// if it's not, the server implementation should return an error if it
@@ -1269,7 +1269,7 @@
data.setDataCapacity(1024);
// Write a bogus object at offset 0 to get an entry in the offset table
data.writeFileDescriptor(0);
- EXPECT_EQ(data.objectsCount(), 1);
+ EXPECT_EQ(data.objectsCount(), 1u);
uint8_t *parcelData = const_cast<uint8_t *>(data.data());
// And now, overwrite it with the weak binder
memcpy(parcelData, &obj, sizeof(obj));
@@ -1279,7 +1279,7 @@
// test with an object that libbinder will actually try to release
EXPECT_EQ(OK, data.writeStrongBinder(sp<BBinder>::make()));
- EXPECT_EQ(data.objectsCount(), 2);
+ EXPECT_EQ(data.objectsCount(), 2u);
// send it many times, since previous error was memory corruption, make it
// more likely that the server crashes
@@ -1648,8 +1648,8 @@
EXPECT_THAT(binder->setRpcClientDebug(std::move(socket), nullptr),
Debuggable(StatusEq(UNEXPECTED_NULL)));
}
-INSTANTIATE_TEST_CASE_P(BinderLibTest, BinderLibRpcTestP, testing::Bool(),
- BinderLibRpcTestP::ParamToString);
+INSTANTIATE_TEST_SUITE_P(BinderLibTest, BinderLibRpcTestP, testing::Bool(),
+ BinderLibRpcTestP::ParamToString);
class BinderLibTestService : public BBinder {
public:
diff --git a/libs/binder/tests/binderRpcBenchmark.cpp b/libs/binder/tests/binderRpcBenchmark.cpp
index 4f10d74..865f0ec 100644
--- a/libs/binder/tests/binderRpcBenchmark.cpp
+++ b/libs/binder/tests/binderRpcBenchmark.cpp
@@ -216,7 +216,7 @@
// by how many binder calls work together (and by factors like the scheduler,
// thermal throttling, core choice, etc..).
std::string str = std::string(getpagesize() * 2, 'a');
- CHECK_EQ(str.size(), getpagesize() * 2);
+ CHECK_EQ(static_cast<ssize_t>(str.size()), getpagesize() * 2);
while (state.KeepRunning()) {
std::string out;
diff --git a/libs/binder/tests/binderRpcTest.cpp b/libs/binder/tests/binderRpcTest.cpp
index 2769a88..f0400d3 100644
--- a/libs/binder/tests/binderRpcTest.cpp
+++ b/libs/binder/tests/binderRpcTest.cpp
@@ -177,7 +177,7 @@
EXPECT_NE(nullptr, session);
EXPECT_NE(nullptr, session->state());
- EXPECT_EQ(0, session->state()->countBinders()) << (session->state()->dump(), "dump:");
+ EXPECT_EQ(0u, session->state()->countBinders()) << (session->state()->dump(), "dump:");
wp<RpcSession> weakSession = session;
session = nullptr;
@@ -235,7 +235,7 @@
if (binder::os::sendMessageOnSocket(transportFd, &iov, 1, &fds) < 0) {
PLOGF("Failed sendMessageOnSocket");
}
- return std::move(sockClient);
+ return sockClient;
}
#endif // BINDER_RPC_TO_TRUSTY_TEST
@@ -623,7 +623,7 @@
for (size_t i = 0; i + 1 < kNumQueued; i++) {
int n;
proc.rootIface->blockingRecvInt(&n);
- EXPECT_EQ(n, i);
+ EXPECT_EQ(n, static_cast<ssize_t>(i));
}
saturateThreadPool(1 + kNumExtraServerThreads, proc.rootIface);
@@ -1148,8 +1148,8 @@
return ret;
}
-INSTANTIATE_TEST_CASE_P(Trusty, BinderRpc, ::testing::ValuesIn(getTrustyBinderRpcParams()),
- BinderRpc::PrintParamInfo);
+INSTANTIATE_TEST_SUITE_P(Trusty, BinderRpc, ::testing::ValuesIn(getTrustyBinderRpcParams()),
+ BinderRpc::PrintParamInfo);
#else // BINDER_RPC_TO_TRUSTY_TEST
bool testSupportVsockLoopback() {
// We don't need to enable TLS to know if vsock is supported.
@@ -1308,8 +1308,8 @@
return ret;
}
-INSTANTIATE_TEST_CASE_P(PerSocket, BinderRpc, ::testing::ValuesIn(getBinderRpcParams()),
- BinderRpc::PrintParamInfo);
+INSTANTIATE_TEST_SUITE_P(PerSocket, BinderRpc, ::testing::ValuesIn(getBinderRpcParams()),
+ BinderRpc::PrintParamInfo);
class BinderRpcServerRootObject
: public ::testing::TestWithParam<std::tuple<bool, bool, RpcSecurity>> {};
@@ -1337,9 +1337,9 @@
EXPECT_EQ((isStrong2 ? binderRaw2 : nullptr), server->getRootObject());
}
-INSTANTIATE_TEST_CASE_P(BinderRpc, BinderRpcServerRootObject,
- ::testing::Combine(::testing::Bool(), ::testing::Bool(),
- ::testing::ValuesIn(RpcSecurityValues())));
+INSTANTIATE_TEST_SUITE_P(BinderRpc, BinderRpcServerRootObject,
+ ::testing::Combine(::testing::Bool(), ::testing::Bool(),
+ ::testing::ValuesIn(RpcSecurityValues())));
class OneOffSignal {
public:
@@ -1384,7 +1384,7 @@
auto binder = sm->checkService(String16("batteryproperties"));
ASSERT_NE(nullptr, binder);
auto descriptor = binder->getInterfaceDescriptor();
- ASSERT_GE(descriptor.size(), 0);
+ ASSERT_GE(descriptor.size(), 0u);
ASSERT_EQ(OK, binder->pingBinder());
auto rpcServer = RpcServer::make();
@@ -1468,10 +1468,10 @@
<< "After server->shutdown() returns true, join() did not stop after 2s";
}
-INSTANTIATE_TEST_CASE_P(BinderRpc, BinderRpcServerOnly,
- ::testing::Combine(::testing::ValuesIn(RpcSecurityValues()),
- ::testing::ValuesIn(testVersions())),
- BinderRpcServerOnly::PrintTestParam);
+INSTANTIATE_TEST_SUITE_P(BinderRpc, BinderRpcServerOnly,
+ ::testing::Combine(::testing::ValuesIn(RpcSecurityValues()),
+ ::testing::ValuesIn(testVersions())),
+ BinderRpcServerOnly::PrintTestParam);
class RpcTransportTestUtils {
public:
@@ -2018,9 +2018,9 @@
server->shutdown();
}
-INSTANTIATE_TEST_CASE_P(BinderRpc, RpcTransportTest,
- ::testing::ValuesIn(RpcTransportTest::getRpcTranportTestParams()),
- RpcTransportTest::PrintParamInfo);
+INSTANTIATE_TEST_SUITE_P(BinderRpc, RpcTransportTest,
+ ::testing::ValuesIn(RpcTransportTest::getRpcTranportTestParams()),
+ RpcTransportTest::PrintParamInfo);
class RpcTransportTlsKeyTest
: public testing::TestWithParam<
@@ -2075,7 +2075,7 @@
client.run();
}
-INSTANTIATE_TEST_CASE_P(
+INSTANTIATE_TEST_SUITE_P(
BinderRpc, RpcTransportTlsKeyTest,
testing::Combine(testing::ValuesIn(testSocketTypes(false /* hasPreconnected*/)),
testing::Values(RpcCertificateFormat::PEM, RpcCertificateFormat::DER),
diff --git a/libs/binder/tests/binderRpcTestCommon.h b/libs/binder/tests/binderRpcTestCommon.h
index 8832f1a..dfce441 100644
--- a/libs/binder/tests/binderRpcTestCommon.h
+++ b/libs/binder/tests/binderRpcTestCommon.h
@@ -210,7 +210,7 @@
return RpcTransportCtxFactoryTls::make(std::move(verifier), std::move(auth));
}
default:
- LOG_ALWAYS_FATAL("Unknown RpcSecurity %d", rpcSecurity);
+ LOG_ALWAYS_FATAL("Unknown RpcSecurity %d", static_cast<int>(rpcSecurity));
}
}
@@ -256,7 +256,7 @@
mValue.reset();
lock.unlock();
mCvEmpty.notify_all();
- return std::move(v);
+ return v;
}
private:
diff --git a/libs/binder/tests/binderRpcTestTrusty.cpp b/libs/binder/tests/binderRpcTestTrusty.cpp
index 18751cc..31c0eba 100644
--- a/libs/binder/tests/binderRpcTestTrusty.cpp
+++ b/libs/binder/tests/binderRpcTestTrusty.cpp
@@ -45,7 +45,7 @@
case RpcSecurity::RAW:
return RpcTransportCtxFactoryTipcTrusty::make();
default:
- LOG_ALWAYS_FATAL("Unknown RpcSecurity %d", rpcSecurity);
+ LOG_ALWAYS_FATAL("Unknown RpcSecurity %d", static_cast<int>(rpcSecurity));
}
}
@@ -110,8 +110,8 @@
return ret;
}
-INSTANTIATE_TEST_CASE_P(Trusty, BinderRpc, ::testing::ValuesIn(getTrustyBinderRpcParams()),
- BinderRpc::PrintParamInfo);
+INSTANTIATE_TEST_SUITE_P(Trusty, BinderRpc, ::testing::ValuesIn(getTrustyBinderRpcParams()),
+ BinderRpc::PrintParamInfo);
} // namespace android