• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
23 using android::base::GetProperty;
24 using android::base::SetProperty;
25 using android::base::WaitForProperty;
26 using namespace std::literals;
27 
TEST(init,oneshot_on)28 TEST(init, oneshot_on) {
29     if (getuid() != 0) {
30         GTEST_SKIP() << "Skipping test, must be run as root.";
31         return;
32     }
33 
34     // 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 }
50