Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f30148ca authored by Andrei Homescu's avatar Andrei Homescu
Browse files

binderRpcTest: Move PrintParamInfo to test fixture

Both the Android and Trusty copies of binderRpcTest
had identical copies of PrintParamInfo. This moves
the function into the common binderRpcTestFixture
header to avoid duplication.

Bug: N/A
Test: binderRpcTest
Change-Id: Id3817469b255951564a85e1e470caf79b510f554
parent ddae51e1
Loading
Loading
Loading
Loading
+11 −24
Original line number Diff line number Diff line
@@ -231,21 +231,8 @@ static base::unique_fd connectToUnixBootstrap(const RpcTransportFd& transportFd)
    return std::move(sockClient);
}

std::string BinderRpc::PrintParamInfo(const testing::TestParamInfo<ParamType>& info) {
    auto [type, security, clientVersion, serverVersion, singleThreaded, noKernel] = info.param;
    auto ret = PrintToString(type) + "_" + newFactory(security)->toCString() + "_clientV" +
            std::to_string(clientVersion) + "_serverV" + std::to_string(serverVersion);
    if (singleThreaded) {
        ret += "_single_threaded";
    } else {
        ret += "_multi_threaded";
    }
    if (noKernel) {
        ret += "_no_kernel";
    } else {
        ret += "_with_kernel";
    }
    return ret;
std::unique_ptr<RpcTransportCtxFactory> BinderRpc::newFactory(RpcSecurity rpcSecurity) {
    return newTlsFactory(rpcSecurity);
}

// This creates a new process serving an interface on a certain number of
@@ -321,7 +308,7 @@ std::unique_ptr<ProcessSession> BinderRpc::createRpcTestSocketServerProcessEtc(
            LOG_ALWAYS_FATAL("TIPC socket type only supported on vendor");
#endif
        } else {
            factory = newFactory(rpcSecurity, certVerifier);
            factory = newTlsFactory(rpcSecurity, certVerifier);
        }
        sessions.emplace_back(RpcSession::make(std::move(factory)));
    }
@@ -1230,7 +1217,7 @@ TEST_P(BinderRpcServerRootObject, WeakRootObject) {
    };

    auto [isStrong1, isStrong2, rpcSecurity] = GetParam();
    auto server = RpcServer::make(newFactory(rpcSecurity));
    auto server = RpcServer::make(newTlsFactory(rpcSecurity));
    auto binder1 = sp<BBinder>::make();
    IBinder* binderRaw1 = binder1.get();
    setRootObject(isStrong1)(server.get(), binder1);
@@ -1326,7 +1313,7 @@ TEST(BinderRpc, Java) {
class BinderRpcServerOnly : public ::testing::TestWithParam<std::tuple<RpcSecurity, uint32_t>> {
public:
    static std::string PrintTestParam(const ::testing::TestParamInfo<ParamType>& info) {
        return std::string(newFactory(std::get<0>(info.param))->toCString()) + "_serverV" +
        return std::string(newTlsFactory(std::get<0>(info.param))->toCString()) + "_serverV" +
                std::to_string(std::get<1>(info.param));
    }
};
@@ -1334,7 +1321,7 @@ public:
TEST_P(BinderRpcServerOnly, SetExternalServerTest) {
    base::unique_fd sink(TEMP_FAILURE_RETRY(open("/dev/null", O_RDWR)));
    int sinkFd = sink.get();
    auto server = RpcServer::make(newFactory(std::get<0>(GetParam())));
    auto server = RpcServer::make(newTlsFactory(std::get<0>(GetParam())));
    server->setProtocolVersion(std::get<1>(GetParam()));
    ASSERT_FALSE(server->hasServer());
    ASSERT_EQ(OK, server->setupExternalServer(std::move(sink)));
@@ -1350,7 +1337,7 @@ TEST_P(BinderRpcServerOnly, Shutdown) {
    }

    auto addr = allocateSocketAddress();
    auto server = RpcServer::make(newFactory(std::get<0>(GetParam())));
    auto server = RpcServer::make(newTlsFactory(std::get<0>(GetParam())));
    server->setProtocolVersion(std::get<1>(GetParam()));
    ASSERT_EQ(OK, server->setupUnixDomainServer(addr.c_str()));
    auto joinEnds = std::make_shared<OneOffSignal>();
@@ -1399,7 +1386,7 @@ public:
                const Param& param,
                std::unique_ptr<RpcAuth> auth = std::make_unique<RpcAuthSelfSigned>()) {
            auto [socketType, rpcSecurity, certificateFormat, serverVersion] = param;
            auto rpcServer = RpcServer::make(newFactory(rpcSecurity));
            auto rpcServer = RpcServer::make(newTlsFactory(rpcSecurity));
            rpcServer->setProtocolVersion(serverVersion);
            switch (socketType) {
                case SocketType::PRECONNECTED: {
@@ -1478,7 +1465,7 @@ public:
            }
            mFd = rpcServer->releaseServer();
            if (!mFd.fd.ok()) return AssertionFailure() << "releaseServer returns invalid fd";
            mCtx = newFactory(rpcSecurity, mCertVerifier, std::move(auth))->newServerCtx();
            mCtx = newTlsFactory(rpcSecurity, mCertVerifier, std::move(auth))->newServerCtx();
            if (mCtx == nullptr) return AssertionFailure() << "newServerCtx";
            mSetup = true;
            return AssertionSuccess();
@@ -1583,7 +1570,7 @@ public:
            auto [socketType, rpcSecurity, certificateFormat, serverVersion] = param;
            (void)serverVersion;
            mFdTrigger = FdTrigger::make();
            mCtx = newFactory(rpcSecurity, mCertVerifier)->newClientCtx();
            mCtx = newTlsFactory(rpcSecurity, mCertVerifier)->newClientCtx();
            if (mCtx == nullptr) return AssertionFailure() << "newClientCtx";
            return AssertionSuccess();
        }
@@ -1655,7 +1642,7 @@ public:
    using Client = RpcTransportTestUtils::Client;
    static inline std::string PrintParamInfo(const testing::TestParamInfo<ParamType>& info) {
        auto [socketType, rpcSecurity, certificateFormat, serverVersion] = info.param;
        auto ret = PrintToString(socketType) + "_" + newFactory(rpcSecurity)->toCString();
        auto ret = PrintToString(socketType) + "_" + newTlsFactory(rpcSecurity)->toCString();
        if (certificateFormat.has_value()) ret += "_" + PrintToString(*certificateFormat);
        ret += "_serverV" + std::to_string(serverVersion);
        return ret;
+1 −1
Original line number Diff line number Diff line
@@ -170,7 +170,7 @@ static inline T readFromFd(android::base::borrowed_fd fd) {
    return object;
}

static inline std::unique_ptr<RpcTransportCtxFactory> newFactory(
static inline std::unique_ptr<RpcTransportCtxFactory> newTlsFactory(
        RpcSecurity rpcSecurity, std::shared_ptr<RpcCertificateVerifier> verifier = nullptr,
        std::unique_ptr<RpcAuth> auth = nullptr) {
    switch (rpcSecurity) {
+18 −1
Original line number Diff line number Diff line
@@ -133,9 +133,26 @@ public:
        return ret;
    }

    static std::string PrintParamInfo(const testing::TestParamInfo<ParamType>& info);
    static std::string PrintParamInfo(const testing::TestParamInfo<ParamType>& info) {
        auto [type, security, clientVersion, serverVersion, singleThreaded, noKernel] = info.param;
        auto ret = PrintToString(type) + "_" + newFactory(security)->toCString() + "_clientV" +
                std::to_string(clientVersion) + "_serverV" + std::to_string(serverVersion);
        if (singleThreaded) {
            ret += "_single_threaded";
        } else {
            ret += "_multi_threaded";
        }
        if (noKernel) {
            ret += "_no_kernel";
        } else {
            ret += "_with_kernel";
        }
        return ret;
    }

protected:
    static std::unique_ptr<RpcTransportCtxFactory> newFactory(RpcSecurity rpcSecurity);

    std::unique_ptr<ProcessSession> createRpcTestSocketServerProcessEtc(
            const BinderRpcOptions& options);
};
+1 −1
Original line number Diff line number Diff line
@@ -104,7 +104,7 @@ int main(int argc, char* argv[]) {
    }

    auto certVerifier = std::make_shared<RpcCertificateVerifierSimple>();
    sp<RpcServer> server = RpcServer::make(newFactory(rpcSecurity, certVerifier));
    sp<RpcServer> server = RpcServer::make(newTlsFactory(rpcSecurity, certVerifier));

    server->setProtocolVersion(serverConfig.serverVersion);
    server->setMaxThreads(serverConfig.numThreads);
+8 −16
Original line number Diff line number Diff line
@@ -39,21 +39,13 @@ public:
    void terminate() override { LOG_ALWAYS_FATAL("terminate() not supported"); }
};

std::string BinderRpc::PrintParamInfo(const testing::TestParamInfo<ParamType>& info) {
    auto [type, security, clientVersion, serverVersion, singleThreaded, noKernel] = info.param;
    auto ret = PrintToString(type) + "_clientV" + std::to_string(clientVersion) + "_serverV" +
            std::to_string(serverVersion);
    if (singleThreaded) {
        ret += "_single_threaded";
    } else {
        ret += "_multi_threaded";
std::unique_ptr<RpcTransportCtxFactory> BinderRpc::newFactory(RpcSecurity rpcSecurity) {
    switch (rpcSecurity) {
        case RpcSecurity::RAW:
            return RpcTransportCtxFactoryTipcTrusty::make();
        default:
            LOG_ALWAYS_FATAL("Unknown RpcSecurity %d", rpcSecurity);
    }
    if (noKernel) {
        ret += "_no_kernel";
    } else {
        ret += "_with_kernel";
    }
    return ret;
}

// This creates a new process serving an interface on a certain number of
@@ -64,6 +56,7 @@ std::unique_ptr<ProcessSession> BinderRpc::createRpcTestSocketServerProcessEtc(
                        "Non-zero incoming connections %zu on Trusty",
                        options.numIncomingConnections);

    RpcSecurity rpcSecurity = std::get<1>(GetParam());
    uint32_t clientVersion = std::get<2>(GetParam());
    uint32_t serverVersion = std::get<3>(GetParam());

@@ -71,8 +64,7 @@ std::unique_ptr<ProcessSession> BinderRpc::createRpcTestSocketServerProcessEtc(

    status_t status;
    for (size_t i = 0; i < options.numSessions; i++) {
        auto factory = android::RpcTransportCtxFactoryTipcTrusty::make();
        auto session = android::RpcSession::make(std::move(factory));
        auto session = android::RpcSession::make(newFactory(rpcSecurity));

        EXPECT_TRUE(session->setProtocolVersion(clientVersion));
        session->setMaxOutgoingConnections(options.numOutgoingConnections);