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