blob: 650f0650b24978507f9a8047a9f1737d6dce6728 [file] [log] [blame]
Tom Cherrybdbf5042020-03-04 10:52:08 -08001/*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <gtest/gtest.h>
18
19#include <chrono>
20
21#include <android-base/properties.h>
22
23using android::base::GetProperty;
24using android::base::SetProperty;
25using android::base::WaitForProperty;
26using namespace std::literals;
27
28TEST(init, oneshot_on) {
Tom Cherry14f4afd2020-03-30 09:11:23 -070029 if (getuid() != 0) {
30 GTEST_SKIP() << "Skipping test, must be run as root.";
31 return;
32 }
33
Tom Cherrybdbf5042020-03-04 10:52:08 -080034 // Bootanim shouldn't be running once the device has booted.
35 ASSERT_EQ("stopped", GetProperty("init.svc.bootanim", ""));
36
37 SetProperty("ctl.oneshot_off", "bootanim");
38 SetProperty("ctl.start", "bootanim");
39
40 // Bootanim exits quickly when the device is fully booted, so check that it goes back to the
41 // 'restarting' state that non-oneshot services enter once they've restarted.
42 EXPECT_TRUE(WaitForProperty("init.svc.bootanim", "restarting", 10s));
43
44 SetProperty("ctl.oneshot_on", "bootanim");
45 SetProperty("ctl.start", "bootanim");
46
47 // Now that oneshot is enabled again, bootanim should transition into the 'stopped' state.
48 EXPECT_TRUE(WaitForProperty("init.svc.bootanim", "stopped", 10s));
49}