blob: 39cbf421d61277834ea75eea7a0febe1560fcc79 [file] [log] [blame]
Alex Deymoaea4c1c2015-08-19 20:24:43 -07001//
2// Copyright (C) 2013 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//
Alex Deymo42432912013-07-12 20:21:15 -070016
Gilad Arnoldcf175a02014-07-10 16:48:47 -070017#ifndef UPDATE_ENGINE_FAKE_HARDWARE_H_
18#define UPDATE_ENGINE_FAKE_HARDWARE_H_
Alex Deymo42432912013-07-12 20:21:15 -070019
Don Garrett83692e42013-11-08 10:11:30 -080020#include <map>
Alex Deymodf632d12014-04-29 20:04:36 -070021#include <string>
22#include <vector>
Don Garrett83692e42013-11-08 10:11:30 -080023
Alex Deymobccbc382014-04-03 13:38:55 -070024#include <base/time/time.h>
25
Alex Deymo42432912013-07-12 20:21:15 -070026#include "update_engine/hardware_interface.h"
27
Alex Deymo42432912013-07-12 20:21:15 -070028namespace chromeos_update_engine {
29
30// Implements a fake hardware interface used for testing.
31class FakeHardware : public HardwareInterface {
32 public:
Alex Deymoebbe7ef2014-10-30 13:02:49 -070033 // Value used to signal that the powerwash_count file is not present. When
34 // this value is used in SetPowerwashCount(), GetPowerwashCount() will return
35 // false.
36 static const int kPowerwashCountNotSet = -1;
37
J. Richard Barnette4da2cc12013-10-28 16:11:10 -070038 FakeHardware()
Don Garrett83692e42013-11-08 10:11:30 -080039 : kernel_device_("/dev/sdz4"),
40 boot_device_("/dev/sdz5"),
Alex Deymo5708ecd2014-04-29 19:44:50 -070041 is_boot_device_removable_(false),
Chris Sosa44b9b7e2014-04-02 13:53:46 -070042 kernel_devices_({"/dev/sdz2", "/dev/sdz4"}),
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070043 is_official_build_(true),
44 is_normal_boot_mode_(true),
Alex Deymobccbc382014-04-03 13:38:55 -070045 is_oobe_complete_(false),
J. Richard Barnette522d36f2013-10-28 17:22:12 -070046 hardware_class_("Fake HWID BLAH-1234"),
47 firmware_version_("Fake Firmware v1.0.1"),
Alex Deymoebbe7ef2014-10-30 13:02:49 -070048 ec_version_("Fake EC v1.0a"),
49 powerwash_count_(kPowerwashCountNotSet) {}
Alex Deymo42432912013-07-12 20:21:15 -070050
51 // HardwareInterface methods.
Alex Vakulenko157fe302014-08-11 15:59:58 -070052 std::string BootKernelDevice() const override { return kernel_device_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080053
Alex Vakulenko157fe302014-08-11 15:59:58 -070054 std::string BootDevice() const override { return boot_device_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080055
Alex Vakulenko157fe302014-08-11 15:59:58 -070056 bool IsBootDeviceRemovable() const override {
Alex Deymo5708ecd2014-04-29 19:44:50 -070057 return is_boot_device_removable_;
58 }
59
Alex Vakulenko157fe302014-08-11 15:59:58 -070060 std::vector<std::string> GetKernelDevices() const override {
Chris Sosa44b9b7e2014-04-02 13:53:46 -070061 return kernel_devices_;
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080062 }
Alex Vakulenko59e253e2014-02-24 10:40:21 -080063
Alex Vakulenko157fe302014-08-11 15:59:58 -070064 bool IsKernelBootable(const std::string& kernel_device,
65 bool* bootable) const override {
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080066 auto i = is_bootable_.find(kernel_device);
67 *bootable = (i != is_bootable_.end()) ? i->second : true;
68 return true;
69 }
Don Garrett83692e42013-11-08 10:11:30 -080070
Alex Vakulenko157fe302014-08-11 15:59:58 -070071 bool MarkKernelUnbootable(const std::string& kernel_device) override {
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080072 is_bootable_[kernel_device] = false;
73 return true;
74 }
Don Garrett83692e42013-11-08 10:11:30 -080075
Alex Vakulenko157fe302014-08-11 15:59:58 -070076 bool IsOfficialBuild() const override { return is_official_build_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080077
Alex Vakulenko157fe302014-08-11 15:59:58 -070078 bool IsNormalBootMode() const override { return is_normal_boot_mode_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080079
Alex Vakulenko157fe302014-08-11 15:59:58 -070080 bool IsOOBEComplete(base::Time* out_time_of_oobe) const override {
Alex Deymobccbc382014-04-03 13:38:55 -070081 if (out_time_of_oobe != nullptr)
82 *out_time_of_oobe = oobe_timestamp_;
83 return is_oobe_complete_;
84 }
85
Alex Vakulenko157fe302014-08-11 15:59:58 -070086 std::string GetHardwareClass() const override { return hardware_class_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080087
Alex Vakulenko157fe302014-08-11 15:59:58 -070088 std::string GetFirmwareVersion() const override { return firmware_version_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080089
Alex Vakulenko157fe302014-08-11 15:59:58 -070090 std::string GetECVersion() const override { return ec_version_; }
Alex Deymo42432912013-07-12 20:21:15 -070091
Alex Deymoebbe7ef2014-10-30 13:02:49 -070092 int GetPowerwashCount() const override { return powerwash_count_; }
93
Alex Deymo42432912013-07-12 20:21:15 -070094 // Setters
Alex Deymo5708ecd2014-04-29 19:44:50 -070095 void SetBootDevice(const std::string& boot_device) {
Alex Deymo42432912013-07-12 20:21:15 -070096 boot_device_ = boot_device;
97 }
Alex Deymo42432912013-07-12 20:21:15 -070098
Alex Deymo5708ecd2014-04-29 19:44:50 -070099 void SetIsBootDeviceRemovable(bool is_boot_device_removable) {
100 is_boot_device_removable_ = is_boot_device_removable;
101 }
102
J. Richard Barnette056b0ab2013-10-29 15:24:56 -0700103 void SetIsOfficialBuild(bool is_official_build) {
104 is_official_build_ = is_official_build;
105 }
106
107 void SetIsNormalBootMode(bool is_normal_boot_mode) {
108 is_normal_boot_mode_ = is_normal_boot_mode;
109 }
110
Alex Deymobccbc382014-04-03 13:38:55 -0700111 // Sets the IsOOBEComplete to True with the given timestamp.
112 void SetIsOOBEComplete(base::Time oobe_timestamp) {
113 is_oobe_complete_ = true;
114 oobe_timestamp_ = oobe_timestamp;
115 }
116
117 // Sets the IsOOBEComplete to False.
118 void UnsetIsOOBEComplete() {
119 is_oobe_complete_ = false;
120 }
121
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700122 void SetHardwareClass(std::string hardware_class) {
123 hardware_class_ = hardware_class;
124 }
125
126 void SetFirmwareVersion(std::string firmware_version) {
127 firmware_version_ = firmware_version;
128 }
129
130 void SetECVersion(std::string ec_version) {
131 ec_version_ = ec_version;
132 }
133
Alex Deymoebbe7ef2014-10-30 13:02:49 -0700134 void SetPowerwashCount(int powerwash_count) {
135 powerwash_count_ = powerwash_count;
136 }
137
Alex Deymo42432912013-07-12 20:21:15 -0700138 private:
Don Garrett83692e42013-11-08 10:11:30 -0800139 std::string kernel_device_;
Alex Deymo42432912013-07-12 20:21:15 -0700140 std::string boot_device_;
Alex Deymo5708ecd2014-04-29 19:44:50 -0700141 bool is_boot_device_removable_;
Chris Sosa44b9b7e2014-04-02 13:53:46 -0700142 std::vector<std::string> kernel_devices_;
Don Garrett83692e42013-11-08 10:11:30 -0800143 std::map<std::string, bool> is_bootable_;
J. Richard Barnette056b0ab2013-10-29 15:24:56 -0700144 bool is_official_build_;
145 bool is_normal_boot_mode_;
Alex Deymobccbc382014-04-03 13:38:55 -0700146 bool is_oobe_complete_;
147 base::Time oobe_timestamp_;
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700148 std::string hardware_class_;
149 std::string firmware_version_;
150 std::string ec_version_;
Alex Deymoebbe7ef2014-10-30 13:02:49 -0700151 int powerwash_count_;
Alex Deymo42432912013-07-12 20:21:15 -0700152
153 DISALLOW_COPY_AND_ASSIGN(FakeHardware);
154};
155
156} // namespace chromeos_update_engine
157
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700158#endif // UPDATE_ENGINE_FAKE_HARDWARE_H_