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

Commit 87c03cf9 authored by Connor O'Brien's avatar Connor O'Brien
Browse files

Enable multiple concurrent binderLibTest instances



Each instance tries to register a service with the
same name, so suffix the service name with the
instance's PID to avoid collisions.

Test: Tests run and pass in 2 processes at once
Change-Id: I685b01fbfbad4e9bd3eb6ea06f46ffc157169909
Signed-off-by: default avatarConnor O'Brien <connoro@google.com>
parent a3408388
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ using namespace android;

static testing::Environment* binder_env;
static char *binderservername;
static char *binderserversuffix;
static char binderserverarg[] = "--binderserver";

static String16 binderLibTestServiceName = String16("test.binderLib");
@@ -70,6 +71,7 @@ pid_t start_server_process(int arg2)
        binderserverarg,
        stri,
        strpipefd1,
        binderserversuffix,
        NULL
    };

@@ -898,6 +900,8 @@ class BinderLibTestService : public BBinder

int run_server(int index, int readypipefd)
{
    binderLibTestServiceName += String16(binderserversuffix);

    status_t ret;
    sp<IServiceManager> sm = defaultServiceManager();
    {
@@ -928,15 +932,19 @@ int run_server(int index, int readypipefd)
int main(int argc, char **argv) {
    int ret;

    if (argc == 3 && !strcmp(argv[1], "--servername")) {
    if (argc == 4 && !strcmp(argv[1], "--servername")) {
        binderservername = argv[2];
    } else {
        binderservername = argv[0];
    }

    if (argc == 4 && !strcmp(argv[1], binderserverarg)) {
    if (argc == 5 && !strcmp(argv[1], binderserverarg)) {
        binderserversuffix = argv[4];
        return run_server(atoi(argv[2]), atoi(argv[3]));
    }
    binderserversuffix = new char[16];
    snprintf(binderserversuffix, 16, "%d", getpid());
    binderLibTestServiceName += String16(binderserversuffix);

    ::testing::InitGoogleTest(&argc, argv);
    binder_env = AddGlobalTestEnvironment(new BinderLibTestEnv());