xref: /aosp_15_r20/system/extras/simpleperf/cmd_boot_record_test.cpp (revision 288bf5226967eb3dac5cce6c939ccc2a7f2b4fe5)
1 /*
2  * Copyright (C) 2022 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 <android-base/properties.h>
20 
21 #include "command.h"
22 #include "test_util.h"
23 #include "workload.h"
24 
25 using namespace simpleperf;
26 
BootRecordCmd()27 static std::unique_ptr<Command> BootRecordCmd() {
28   return CreateCommandInstance("boot-record");
29 }
30 
31 // @CddTest = 6.1/C-0-2
TEST(cmd_boot_record,smoke)32 TEST(cmd_boot_record, smoke) {
33   TEST_REQUIRE_ROOT();
34   ASSERT_TRUE(BootRecordCmd()->Run({"--enable", "-a -g --duration 1"}));
35   ASSERT_EQ(android::base::GetProperty("persist.simpleperf.boot_record", ""), "-a -g --duration 1");
36   // After reboot, init script will run boot-record cmd with --record. But since we can't reboot
37   // the device to test the option, run it directly here.
38   ASSERT_TRUE(BootRecordCmd()->Run({"--record", "-a --duration 0.001"}));
39   ASSERT_TRUE(BootRecordCmd()->Run({"--disable"}));
40   ASSERT_EQ(android::base::GetProperty("persist.simpleperf.boot_record", ""), "");
41   ASSERT_TRUE(Workload::RunCmd({"rm", "-rf", "/data/simpleperf_boot_data"}));
42 }
43