| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 1 | // 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 Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 5 | #ifndef UPDATE_ENGINE_FAKE_HARDWARE_H_ | 
|  | 6 | #define UPDATE_ENGINE_FAKE_HARDWARE_H_ | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 7 |  | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 8 | #include <map> | 
| Alex Deymo | df632d1 | 2014-04-29 20:04:36 -0700 | [diff] [blame] | 9 | #include <string> | 
|  | 10 | #include <vector> | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 11 |  | 
| Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 12 | #include <base/time/time.h> | 
|  | 13 |  | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 14 | #include "update_engine/hardware_interface.h" | 
|  | 15 |  | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 16 | namespace chromeos_update_engine { | 
|  | 17 |  | 
|  | 18 | // Implements a fake hardware interface used for testing. | 
|  | 19 | class FakeHardware : public HardwareInterface { | 
|  | 20 | public: | 
| Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 21 | // 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 Barnette | 4da2cc1 | 2013-10-28 16:11:10 -0700 | [diff] [blame] | 26 | FakeHardware() | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 27 | : kernel_device_("/dev/sdz4"), | 
|  | 28 | boot_device_("/dev/sdz5"), | 
| Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 29 | is_boot_device_removable_(false), | 
| Chris Sosa | 44b9b7e | 2014-04-02 13:53:46 -0700 | [diff] [blame] | 30 | kernel_devices_({"/dev/sdz2", "/dev/sdz4"}), | 
| J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 31 | is_official_build_(true), | 
|  | 32 | is_normal_boot_mode_(true), | 
| Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 33 | is_oobe_complete_(false), | 
| J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 34 | hardware_class_("Fake HWID BLAH-1234"), | 
|  | 35 | firmware_version_("Fake Firmware v1.0.1"), | 
| Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 36 | ec_version_("Fake EC v1.0a"), | 
|  | 37 | powerwash_count_(kPowerwashCountNotSet) {} | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 38 |  | 
|  | 39 | // HardwareInterface methods. | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 40 | std::string BootKernelDevice() const override { return kernel_device_; } | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 41 |  | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 42 | std::string BootDevice() const override { return boot_device_; } | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 43 |  | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 44 | bool IsBootDeviceRemovable() const override { | 
| Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 45 | return is_boot_device_removable_; | 
|  | 46 | } | 
|  | 47 |  | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 48 | std::vector<std::string> GetKernelDevices() const override { | 
| Chris Sosa | 44b9b7e | 2014-04-02 13:53:46 -0700 | [diff] [blame] | 49 | return kernel_devices_; | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 50 | } | 
| Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 51 |  | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 52 | bool IsKernelBootable(const std::string& kernel_device, | 
|  | 53 | bool* bootable) const override { | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 54 | auto i = is_bootable_.find(kernel_device); | 
|  | 55 | *bootable = (i != is_bootable_.end()) ? i->second : true; | 
|  | 56 | return true; | 
|  | 57 | } | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 58 |  | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 59 | bool MarkKernelUnbootable(const std::string& kernel_device) override { | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 60 | is_bootable_[kernel_device] = false; | 
|  | 61 | return true; | 
|  | 62 | } | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 63 |  | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 64 | bool IsOfficialBuild() const override { return is_official_build_; } | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 65 |  | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 66 | bool IsNormalBootMode() const override { return is_normal_boot_mode_; } | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 67 |  | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 68 | bool IsOOBEComplete(base::Time* out_time_of_oobe) const override { | 
| Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 69 | if (out_time_of_oobe != nullptr) | 
|  | 70 | *out_time_of_oobe = oobe_timestamp_; | 
|  | 71 | return is_oobe_complete_; | 
|  | 72 | } | 
|  | 73 |  | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 74 | std::string GetHardwareClass() const override { return hardware_class_; } | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 75 |  | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 76 | std::string GetFirmwareVersion() const override { return firmware_version_; } | 
| Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 77 |  | 
| Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame] | 78 | std::string GetECVersion() const override { return ec_version_; } | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 79 |  | 
| Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 80 | int GetPowerwashCount() const override { return powerwash_count_; } | 
|  | 81 |  | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 82 | // Setters | 
| Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 83 | void SetBootDevice(const std::string& boot_device) { | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 84 | boot_device_ = boot_device; | 
|  | 85 | } | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 86 |  | 
| Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 87 | void SetIsBootDeviceRemovable(bool is_boot_device_removable) { | 
|  | 88 | is_boot_device_removable_ = is_boot_device_removable; | 
|  | 89 | } | 
|  | 90 |  | 
| J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 91 | 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 Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 99 | // 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 Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 110 | 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 Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 122 | void SetPowerwashCount(int powerwash_count) { | 
|  | 123 | powerwash_count_ = powerwash_count; | 
|  | 124 | } | 
|  | 125 |  | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 126 | private: | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 127 | std::string kernel_device_; | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 128 | std::string boot_device_; | 
| Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 129 | bool is_boot_device_removable_; | 
| Chris Sosa | 44b9b7e | 2014-04-02 13:53:46 -0700 | [diff] [blame] | 130 | std::vector<std::string>  kernel_devices_; | 
| Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 131 | std::map<std::string, bool> is_bootable_; | 
| J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 132 | bool is_official_build_; | 
|  | 133 | bool is_normal_boot_mode_; | 
| Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 134 | bool is_oobe_complete_; | 
|  | 135 | base::Time oobe_timestamp_; | 
| J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 136 | std::string hardware_class_; | 
|  | 137 | std::string firmware_version_; | 
|  | 138 | std::string ec_version_; | 
| Alex Deymo | ebbe7ef | 2014-10-30 13:02:49 -0700 | [diff] [blame] | 139 | int powerwash_count_; | 
| Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 140 |  | 
|  | 141 | DISALLOW_COPY_AND_ASSIGN(FakeHardware); | 
|  | 142 | }; | 
|  | 143 |  | 
|  | 144 | }  // namespace chromeos_update_engine | 
|  | 145 |  | 
| Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 146 | #endif  // UPDATE_ENGINE_FAKE_HARDWARE_H_ |