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