blob: 26cbe9090cd0cf4c34fe114aad68d3dff17a7f83 [file] [log] [blame]
Amin Hassani0882a512018-04-05 16:25:44 -07001//
2// Copyright (C) 2018 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 "update_engine/update_boot_flags_action.h"
18
19#include <memory>
20#include <utility>
21
22#include <base/bind.h>
23#include <gtest/gtest.h>
24
Amin Hassaniec7bc112020-10-29 16:47:58 -070025#include "update_engine/common/fake_boot_control.h"
Amin Hassani0882a512018-04-05 16:25:44 -070026
27namespace chromeos_update_engine {
28
29class UpdateBootFlagsActionTest : public ::testing::Test {
Amin Hassaniec7bc112020-10-29 16:47:58 -070030 protected:
31 FakeBootControl boot_control_;
Amin Hassani0882a512018-04-05 16:25:44 -070032};
33
34TEST_F(UpdateBootFlagsActionTest, SimpleTest) {
Amin Hassaniec7bc112020-10-29 16:47:58 -070035 auto action = std::make_unique<UpdateBootFlagsAction>(&boot_control_);
Amin Hassani0882a512018-04-05 16:25:44 -070036 ActionProcessor processor;
37 processor.EnqueueAction(std::move(action));
38
39 EXPECT_FALSE(UpdateBootFlagsAction::updated_boot_flags_);
40 EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
41 processor.StartProcessing();
42 EXPECT_TRUE(UpdateBootFlagsAction::updated_boot_flags_);
43 EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
44}
45
46TEST_F(UpdateBootFlagsActionTest, DoubleActionTest) {
47 // Reset the static flags.
48 UpdateBootFlagsAction::updated_boot_flags_ = false;
49 UpdateBootFlagsAction::is_running_ = false;
50
Amin Hassaniec7bc112020-10-29 16:47:58 -070051 auto action1 = std::make_unique<UpdateBootFlagsAction>(&boot_control_);
52 auto action2 = std::make_unique<UpdateBootFlagsAction>(&boot_control_);
Amin Hassani0882a512018-04-05 16:25:44 -070053 ActionProcessor processor1, processor2;
54 processor1.EnqueueAction(std::move(action1));
55 processor2.EnqueueAction(std::move(action2));
56
57 EXPECT_FALSE(UpdateBootFlagsAction::updated_boot_flags_);
58 EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
59 processor1.StartProcessing();
60 EXPECT_TRUE(UpdateBootFlagsAction::updated_boot_flags_);
61 EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
62 processor2.StartProcessing();
63 EXPECT_TRUE(UpdateBootFlagsAction::updated_boot_flags_);
64 EXPECT_FALSE(UpdateBootFlagsAction::is_running_);
65}
66
67} // namespace chromeos_update_engine