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

Commit 9f7cd7e3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "binderRpcTest: Move PrintParamInfo to test fixture" am: c6fd4f30 am:...

Merge "binderRpcTest: Move PrintParamInfo to test fixture" am: c6fd4f30 am: 83a7482c am: 8c124390

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/2480520



Change-Id: I3204f69ed7c223754575a1ac231add96e6a0bcaa
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents f423c613 8c124390
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)));
    }
@@ -1222,7 +1209,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);
@@ -1318,7 +1305,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));
    }
};
@@ -1326,7 +1313,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)));
@@ -1342,7 +1329,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>();
@@ -1391,7 +1378,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: {
@@ -1470,7 +1457,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();
@@ -1575,7 +1562,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();
        }
@@ -1647,7 +1634,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
@@ -116,7 +116,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);