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

Commit 4851c8ee authored by Bart Van Assche's avatar Bart Van Assche Committed by Automerger Merge Worker
Browse files

Merge "init: Add a unit test for the "start console" action" am: 208f9304...

Merge "init: Add a unit test for the "start console" action" am: 208f9304 am: eb7c4f3e am: 13edec66

Original change: https://android-review.googlesource.com/c/platform/system/core/+/2301275



Change-Id: Iea0bf61067beed1d010b0bfd55cc867c8dcc9014
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 6d131c81 13edec66
Loading
Loading
Loading
Loading
+26 −0
Original line number Diff line number Diff line
@@ -193,6 +193,32 @@ service A something
    EXPECT_TRUE(service->is_override());
}

TEST(init, StartConsole) {
    std::string init_script = R"init(
service console /system/bin/sh
    class core
    console console
    disabled
    user root
    group root shell log readproc
    seclabel u:r:su:s0
    setenv HOSTNAME console
)init";

    ActionManager action_manager;
    ServiceList service_list;
    TestInitText(init_script, BuiltinFunctionMap(), {}, &action_manager, &service_list);
    ASSERT_EQ(std::distance(service_list.begin(), service_list.end()), 1);

    auto service = service_list.begin()->get();
    ASSERT_NE(service, nullptr);
    ASSERT_RESULT_OK(service->Start());
    const pid_t pid = service->pid();
    ASSERT_GT(pid, 0);
    EXPECT_EQ(getsid(pid), pid);
    service->Stop();
}

static std::string GetSecurityContext() {
    char* ctx;
    if (getcon(&ctx) == -1) {