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