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: |
J. Richard Barnette | 4da2cc1 | 2013-10-28 16:11:10 -0700 | [diff] [blame] | 21 | FakeHardware() |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 22 | : kernel_device_("/dev/sdz4"), |
| 23 | boot_device_("/dev/sdz5"), |
Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 24 | is_boot_device_removable_(false), |
Chris Sosa | 44b9b7e | 2014-04-02 13:53:46 -0700 | [diff] [blame] | 25 | kernel_devices_({"/dev/sdz2", "/dev/sdz4"}), |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 26 | is_official_build_(true), |
| 27 | is_normal_boot_mode_(true), |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 28 | is_oobe_complete_(false), |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 29 | hardware_class_("Fake HWID BLAH-1234"), |
| 30 | firmware_version_("Fake Firmware v1.0.1"), |
| 31 | ec_version_("Fake EC v1.0a") {} |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 32 | |
| 33 | // HardwareInterface methods. |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 34 | std::string BootKernelDevice() const override { return kernel_device_; } |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 35 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 36 | std::string BootDevice() const override { return boot_device_; } |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 37 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 38 | bool IsBootDeviceRemovable() const override { |
Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 39 | return is_boot_device_removable_; |
| 40 | } |
| 41 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 42 | std::vector<std::string> GetKernelDevices() const override { |
Chris Sosa | 44b9b7e | 2014-04-02 13:53:46 -0700 | [diff] [blame] | 43 | return kernel_devices_; |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 44 | } |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 45 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 46 | bool IsKernelBootable(const std::string& kernel_device, |
| 47 | bool* bootable) const override { |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 48 | auto i = is_bootable_.find(kernel_device); |
| 49 | *bootable = (i != is_bootable_.end()) ? i->second : true; |
| 50 | return true; |
| 51 | } |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 52 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 53 | bool MarkKernelUnbootable(const std::string& kernel_device) override { |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 54 | is_bootable_[kernel_device] = false; |
| 55 | return true; |
| 56 | } |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 57 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 58 | bool IsOfficialBuild() const override { return is_official_build_; } |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 59 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 60 | bool IsNormalBootMode() const override { return is_normal_boot_mode_; } |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 61 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 62 | bool IsOOBEComplete(base::Time* out_time_of_oobe) const override { |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 63 | if (out_time_of_oobe != nullptr) |
| 64 | *out_time_of_oobe = oobe_timestamp_; |
| 65 | return is_oobe_complete_; |
| 66 | } |
| 67 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 68 | std::string GetHardwareClass() const override { return hardware_class_; } |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 69 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 70 | std::string GetFirmwareVersion() const override { return firmware_version_; } |
Alex Vakulenko | d0fdfb3 | 2014-02-21 15:26:26 -0800 | [diff] [blame] | 71 | |
Alex Vakulenko | 157fe30 | 2014-08-11 15:59:58 -0700 | [diff] [blame^] | 72 | std::string GetECVersion() const override { return ec_version_; } |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 73 | |
| 74 | // Setters |
Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 75 | void SetBootDevice(const std::string& boot_device) { |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 76 | boot_device_ = boot_device; |
| 77 | } |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 78 | |
Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 79 | void SetIsBootDeviceRemovable(bool is_boot_device_removable) { |
| 80 | is_boot_device_removable_ = is_boot_device_removable; |
| 81 | } |
| 82 | |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 83 | void SetIsOfficialBuild(bool is_official_build) { |
| 84 | is_official_build_ = is_official_build; |
| 85 | } |
| 86 | |
| 87 | void SetIsNormalBootMode(bool is_normal_boot_mode) { |
| 88 | is_normal_boot_mode_ = is_normal_boot_mode; |
| 89 | } |
| 90 | |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 91 | // Sets the IsOOBEComplete to True with the given timestamp. |
| 92 | void SetIsOOBEComplete(base::Time oobe_timestamp) { |
| 93 | is_oobe_complete_ = true; |
| 94 | oobe_timestamp_ = oobe_timestamp; |
| 95 | } |
| 96 | |
| 97 | // Sets the IsOOBEComplete to False. |
| 98 | void UnsetIsOOBEComplete() { |
| 99 | is_oobe_complete_ = false; |
| 100 | } |
| 101 | |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 102 | void SetHardwareClass(std::string hardware_class) { |
| 103 | hardware_class_ = hardware_class; |
| 104 | } |
| 105 | |
| 106 | void SetFirmwareVersion(std::string firmware_version) { |
| 107 | firmware_version_ = firmware_version; |
| 108 | } |
| 109 | |
| 110 | void SetECVersion(std::string ec_version) { |
| 111 | ec_version_ = ec_version; |
| 112 | } |
| 113 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 114 | private: |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 115 | std::string kernel_device_; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 116 | std::string boot_device_; |
Alex Deymo | 5708ecd | 2014-04-29 19:44:50 -0700 | [diff] [blame] | 117 | bool is_boot_device_removable_; |
Chris Sosa | 44b9b7e | 2014-04-02 13:53:46 -0700 | [diff] [blame] | 118 | std::vector<std::string> kernel_devices_; |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 119 | std::map<std::string, bool> is_bootable_; |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 120 | bool is_official_build_; |
| 121 | bool is_normal_boot_mode_; |
Alex Deymo | bccbc38 | 2014-04-03 13:38:55 -0700 | [diff] [blame] | 122 | bool is_oobe_complete_; |
| 123 | base::Time oobe_timestamp_; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 124 | std::string hardware_class_; |
| 125 | std::string firmware_version_; |
| 126 | std::string ec_version_; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 127 | |
| 128 | DISALLOW_COPY_AND_ASSIGN(FakeHardware); |
| 129 | }; |
| 130 | |
| 131 | } // namespace chromeos_update_engine |
| 132 | |
Gilad Arnold | cf175a0 | 2014-07-10 16:48:47 -0700 | [diff] [blame] | 133 | #endif // UPDATE_ENGINE_FAKE_HARDWARE_H_ |