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 | |
| 5 | #ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__ |
| 6 | #define CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__ |
| 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 | 59e253e | 2014-02-24 10:40:21 -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. |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 28 | virtual const std::string BootKernelDevice() { return kernel_device_; } |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 29 | virtual const std::string BootDevice() { return boot_device_; } |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 30 | virtual std::vector<std::string> GetKernelDevices() override |
| 31 | { return bootable_devices_; } |
| 32 | |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 33 | virtual bool IsKernelBootable(const std::string& kernel_device, |
| 34 | bool* bootable) |
| 35 | { std::map<std::string, bool>::const_iterator i = |
| 36 | is_bootable_.find(kernel_device); |
| 37 | *bootable = (i != is_bootable_.end()) ? i->second : true; |
| 38 | return true; } |
| 39 | |
| 40 | virtual bool MarkKernelUnbootable(const std::string& kernel_device) |
| 41 | { is_bootable_[kernel_device] = false; return true;} |
| 42 | |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 43 | virtual bool IsOfficialBuild() { return is_official_build_; } |
| 44 | virtual bool IsNormalBootMode() { return is_normal_boot_mode_; } |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 45 | virtual std::string GetHardwareClass() { return hardware_class_; } |
| 46 | virtual std::string GetFirmwareVersion() { return firmware_version_; } |
| 47 | virtual std::string GetECVersion() { return ec_version_; } |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 48 | |
| 49 | // Setters |
| 50 | void SetBootDevice(const std::string boot_device) { |
| 51 | boot_device_ = boot_device; |
| 52 | } |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 53 | |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 54 | void SetIsOfficialBuild(bool is_official_build) { |
| 55 | is_official_build_ = is_official_build; |
| 56 | } |
| 57 | |
| 58 | void SetIsNormalBootMode(bool is_normal_boot_mode) { |
| 59 | is_normal_boot_mode_ = is_normal_boot_mode; |
| 60 | } |
| 61 | |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 62 | void SetHardwareClass(std::string hardware_class) { |
| 63 | hardware_class_ = hardware_class; |
| 64 | } |
| 65 | |
| 66 | void SetFirmwareVersion(std::string firmware_version) { |
| 67 | firmware_version_ = firmware_version; |
| 68 | } |
| 69 | |
| 70 | void SetECVersion(std::string ec_version) { |
| 71 | ec_version_ = ec_version; |
| 72 | } |
| 73 | |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 74 | private: |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 75 | std::string kernel_device_; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 76 | std::string boot_device_; |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 77 | std::vector<std::string> bootable_devices_; |
Don Garrett | 83692e4 | 2013-11-08 10:11:30 -0800 | [diff] [blame] | 78 | std::map<std::string, bool> is_bootable_; |
J. Richard Barnette | 056b0ab | 2013-10-29 15:24:56 -0700 | [diff] [blame] | 79 | bool is_official_build_; |
| 80 | bool is_normal_boot_mode_; |
J. Richard Barnette | 522d36f | 2013-10-28 17:22:12 -0700 | [diff] [blame] | 81 | std::string hardware_class_; |
| 82 | std::string firmware_version_; |
| 83 | std::string ec_version_; |
Alex Deymo | 4243291 | 2013-07-12 20:21:15 -0700 | [diff] [blame] | 84 | |
| 85 | DISALLOW_COPY_AND_ASSIGN(FakeHardware); |
| 86 | }; |
| 87 | |
| 88 | } // namespace chromeos_update_engine |
| 89 | |
| 90 | #endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__ |