blob: 13c3341c6dc1588d00309fd5130aa06f076ca281 [file] [log] [blame]
Alex Deymo42432912013-07-12 20:21:15 -07001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Gilad Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_FAKE_HARDWARE_H_
6#define UPDATE_ENGINE_FAKE_HARDWARE_H_
Alex Deymo42432912013-07-12 20:21:15 -07007
Don Garrett83692e42013-11-08 10:11:30 -08008#include <map>
Alex Deymodf632d12014-04-29 20:04:36 -07009#include <string>
10#include <vector>
Don Garrett83692e42013-11-08 10:11:30 -080011
Alex Deymobccbc382014-04-03 13:38:55 -070012#include <base/time/time.h>
13
Alex Deymo42432912013-07-12 20:21:15 -070014#include "update_engine/hardware_interface.h"
15
Alex Deymo42432912013-07-12 20:21:15 -070016namespace chromeos_update_engine {
17
18// Implements a fake hardware interface used for testing.
19class FakeHardware : public HardwareInterface {
20 public:
Alex Deymoebbe7ef2014-10-30 13:02:49 -070021 // Value used to signal that the powerwash_count file is not present. When
22 // this value is used in SetPowerwashCount(), GetPowerwashCount() will return
23 // false.
24 static const int kPowerwashCountNotSet = -1;
25
J. Richard Barnette4da2cc12013-10-28 16:11:10 -070026 FakeHardware()
Don Garrett83692e42013-11-08 10:11:30 -080027 : kernel_device_("/dev/sdz4"),
28 boot_device_("/dev/sdz5"),
Alex Deymo5708ecd2014-04-29 19:44:50 -070029 is_boot_device_removable_(false),
Chris Sosa44b9b7e2014-04-02 13:53:46 -070030 kernel_devices_({"/dev/sdz2", "/dev/sdz4"}),
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070031 is_official_build_(true),
32 is_normal_boot_mode_(true),
Alex Deymobccbc382014-04-03 13:38:55 -070033 is_oobe_complete_(false),
J. Richard Barnette522d36f2013-10-28 17:22:12 -070034 hardware_class_("Fake HWID BLAH-1234"),
35 firmware_version_("Fake Firmware v1.0.1"),
Alex Deymoebbe7ef2014-10-30 13:02:49 -070036 ec_version_("Fake EC v1.0a"),
37 powerwash_count_(kPowerwashCountNotSet) {}
Alex Deymo42432912013-07-12 20:21:15 -070038
39 // HardwareInterface methods.
Alex Vakulenko157fe302014-08-11 15:59:58 -070040 std::string BootKernelDevice() const override { return kernel_device_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080041
Alex Vakulenko157fe302014-08-11 15:59:58 -070042 std::string BootDevice() const override { return boot_device_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080043
Alex Vakulenko157fe302014-08-11 15:59:58 -070044 bool IsBootDeviceRemovable() const override {
Alex Deymo5708ecd2014-04-29 19:44:50 -070045 return is_boot_device_removable_;
46 }
47
Alex Vakulenko157fe302014-08-11 15:59:58 -070048 std::vector<std::string> GetKernelDevices() const override {
Chris Sosa44b9b7e2014-04-02 13:53:46 -070049 return kernel_devices_;
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080050 }
Alex Vakulenko59e253e2014-02-24 10:40:21 -080051
Alex Vakulenko157fe302014-08-11 15:59:58 -070052 bool IsKernelBootable(const std::string& kernel_device,
53 bool* bootable) const override {
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080054 auto i = is_bootable_.find(kernel_device);
55 *bootable = (i != is_bootable_.end()) ? i->second : true;
56 return true;
57 }
Don Garrett83692e42013-11-08 10:11:30 -080058
Alex Vakulenko157fe302014-08-11 15:59:58 -070059 bool MarkKernelUnbootable(const std::string& kernel_device) override {
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080060 is_bootable_[kernel_device] = false;
61 return true;
62 }
Don Garrett83692e42013-11-08 10:11:30 -080063
Alex Vakulenko157fe302014-08-11 15:59:58 -070064 bool IsOfficialBuild() const override { return is_official_build_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080065
Alex Vakulenko157fe302014-08-11 15:59:58 -070066 bool IsNormalBootMode() const override { return is_normal_boot_mode_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080067
Alex Vakulenko157fe302014-08-11 15:59:58 -070068 bool IsOOBEComplete(base::Time* out_time_of_oobe) const override {
Alex Deymobccbc382014-04-03 13:38:55 -070069 if (out_time_of_oobe != nullptr)
70 *out_time_of_oobe = oobe_timestamp_;
71 return is_oobe_complete_;
72 }
73
Alex Vakulenko157fe302014-08-11 15:59:58 -070074 std::string GetHardwareClass() const override { return hardware_class_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080075
Alex Vakulenko157fe302014-08-11 15:59:58 -070076 std::string GetFirmwareVersion() const override { return firmware_version_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080077
Alex Vakulenko157fe302014-08-11 15:59:58 -070078 std::string GetECVersion() const override { return ec_version_; }
Alex Deymo42432912013-07-12 20:21:15 -070079
Alex Deymoebbe7ef2014-10-30 13:02:49 -070080 int GetPowerwashCount() const override { return powerwash_count_; }
81
Alex Deymo42432912013-07-12 20:21:15 -070082 // Setters
Alex Deymo5708ecd2014-04-29 19:44:50 -070083 void SetBootDevice(const std::string& boot_device) {
Alex Deymo42432912013-07-12 20:21:15 -070084 boot_device_ = boot_device;
85 }
Alex Deymo42432912013-07-12 20:21:15 -070086
Alex Deymo5708ecd2014-04-29 19:44:50 -070087 void SetIsBootDeviceRemovable(bool is_boot_device_removable) {
88 is_boot_device_removable_ = is_boot_device_removable;
89 }
90
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070091 void SetIsOfficialBuild(bool is_official_build) {
92 is_official_build_ = is_official_build;
93 }
94
95 void SetIsNormalBootMode(bool is_normal_boot_mode) {
96 is_normal_boot_mode_ = is_normal_boot_mode;
97 }
98
Alex Deymobccbc382014-04-03 13:38:55 -070099 // Sets the IsOOBEComplete to True with the given timestamp.
100 void SetIsOOBEComplete(base::Time oobe_timestamp) {
101 is_oobe_complete_ = true;
102 oobe_timestamp_ = oobe_timestamp;
103 }
104
105 // Sets the IsOOBEComplete to False.
106 void UnsetIsOOBEComplete() {
107 is_oobe_complete_ = false;
108 }
109
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700110 void SetHardwareClass(std::string hardware_class) {
111 hardware_class_ = hardware_class;
112 }
113
114 void SetFirmwareVersion(std::string firmware_version) {
115 firmware_version_ = firmware_version;
116 }
117
118 void SetECVersion(std::string ec_version) {
119 ec_version_ = ec_version;
120 }
121
Alex Deymoebbe7ef2014-10-30 13:02:49 -0700122 void SetPowerwashCount(int powerwash_count) {
123 powerwash_count_ = powerwash_count;
124 }
125
Alex Deymo42432912013-07-12 20:21:15 -0700126 private:
Don Garrett83692e42013-11-08 10:11:30 -0800127 std::string kernel_device_;
Alex Deymo42432912013-07-12 20:21:15 -0700128 std::string boot_device_;
Alex Deymo5708ecd2014-04-29 19:44:50 -0700129 bool is_boot_device_removable_;
Chris Sosa44b9b7e2014-04-02 13:53:46 -0700130 std::vector<std::string> kernel_devices_;
Don Garrett83692e42013-11-08 10:11:30 -0800131 std::map<std::string, bool> is_bootable_;
J. Richard Barnette056b0ab2013-10-29 15:24:56 -0700132 bool is_official_build_;
133 bool is_normal_boot_mode_;
Alex Deymobccbc382014-04-03 13:38:55 -0700134 bool is_oobe_complete_;
135 base::Time oobe_timestamp_;
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700136 std::string hardware_class_;
137 std::string firmware_version_;
138 std::string ec_version_;
Alex Deymoebbe7ef2014-10-30 13:02:49 -0700139 int powerwash_count_;
Alex Deymo42432912013-07-12 20:21:15 -0700140
141 DISALLOW_COPY_AND_ASSIGN(FakeHardware);
142};
143
144} // namespace chromeos_update_engine
145
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700146#endif // UPDATE_ENGINE_FAKE_HARDWARE_H_