blob: ff80009bc3f6c8aee0ef4eea30028a8a98766c45 [file] [log] [blame]
Alex Deymo42432912013-07-12 20:21:15 -07001// 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 Arnoldcf175a02014-07-10 16:48:47 -07005#ifndef UPDATE_ENGINE_FAKE_HARDWARE_H_
6#define UPDATE_ENGINE_FAKE_HARDWARE_H_
Alex Deymo42432912013-07-12 20:21:15 -07007
Don Garrett83692e42013-11-08 10:11:30 -08008#include <map>
Alex Deymodf632d12014-04-29 20:04:36 -07009#include <string>
10#include <vector>
Don Garrett83692e42013-11-08 10:11:30 -080011
Alex Deymobccbc382014-04-03 13:38:55 -070012#include <base/time/time.h>
13
Alex Deymo42432912013-07-12 20:21:15 -070014#include "update_engine/hardware_interface.h"
15
Alex Deymo42432912013-07-12 20:21:15 -070016namespace chromeos_update_engine {
17
18// Implements a fake hardware interface used for testing.
19class FakeHardware : public HardwareInterface {
20 public:
J. Richard Barnette4da2cc12013-10-28 16:11:10 -070021 FakeHardware()
Don Garrett83692e42013-11-08 10:11:30 -080022 : kernel_device_("/dev/sdz4"),
23 boot_device_("/dev/sdz5"),
Alex Deymo5708ecd2014-04-29 19:44:50 -070024 is_boot_device_removable_(false),
Chris Sosa44b9b7e2014-04-02 13:53:46 -070025 kernel_devices_({"/dev/sdz2", "/dev/sdz4"}),
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070026 is_official_build_(true),
27 is_normal_boot_mode_(true),
Alex Deymobccbc382014-04-03 13:38:55 -070028 is_oobe_complete_(false),
J. Richard Barnette522d36f2013-10-28 17:22:12 -070029 hardware_class_("Fake HWID BLAH-1234"),
30 firmware_version_("Fake Firmware v1.0.1"),
31 ec_version_("Fake EC v1.0a") {}
Alex Deymo42432912013-07-12 20:21:15 -070032
33 // HardwareInterface methods.
Alex Vakulenko157fe302014-08-11 15:59:58 -070034 std::string BootKernelDevice() const override { return kernel_device_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080035
Alex Vakulenko157fe302014-08-11 15:59:58 -070036 std::string BootDevice() const override { return boot_device_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080037
Alex Vakulenko157fe302014-08-11 15:59:58 -070038 bool IsBootDeviceRemovable() const override {
Alex Deymo5708ecd2014-04-29 19:44:50 -070039 return is_boot_device_removable_;
40 }
41
Alex Vakulenko157fe302014-08-11 15:59:58 -070042 std::vector<std::string> GetKernelDevices() const override {
Chris Sosa44b9b7e2014-04-02 13:53:46 -070043 return kernel_devices_;
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080044 }
Alex Vakulenko59e253e2014-02-24 10:40:21 -080045
Alex Vakulenko157fe302014-08-11 15:59:58 -070046 bool IsKernelBootable(const std::string& kernel_device,
47 bool* bootable) const override {
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080048 auto i = is_bootable_.find(kernel_device);
49 *bootable = (i != is_bootable_.end()) ? i->second : true;
50 return true;
51 }
Don Garrett83692e42013-11-08 10:11:30 -080052
Alex Vakulenko157fe302014-08-11 15:59:58 -070053 bool MarkKernelUnbootable(const std::string& kernel_device) override {
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080054 is_bootable_[kernel_device] = false;
55 return true;
56 }
Don Garrett83692e42013-11-08 10:11:30 -080057
Alex Vakulenko157fe302014-08-11 15:59:58 -070058 bool IsOfficialBuild() const override { return is_official_build_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080059
Alex Vakulenko157fe302014-08-11 15:59:58 -070060 bool IsNormalBootMode() const override { return is_normal_boot_mode_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080061
Alex Vakulenko157fe302014-08-11 15:59:58 -070062 bool IsOOBEComplete(base::Time* out_time_of_oobe) const override {
Alex Deymobccbc382014-04-03 13:38:55 -070063 if (out_time_of_oobe != nullptr)
64 *out_time_of_oobe = oobe_timestamp_;
65 return is_oobe_complete_;
66 }
67
Alex Vakulenko157fe302014-08-11 15:59:58 -070068 std::string GetHardwareClass() const override { return hardware_class_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080069
Alex Vakulenko157fe302014-08-11 15:59:58 -070070 std::string GetFirmwareVersion() const override { return firmware_version_; }
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080071
Alex Vakulenko157fe302014-08-11 15:59:58 -070072 std::string GetECVersion() const override { return ec_version_; }
Alex Deymo42432912013-07-12 20:21:15 -070073
74 // Setters
Alex Deymo5708ecd2014-04-29 19:44:50 -070075 void SetBootDevice(const std::string& boot_device) {
Alex Deymo42432912013-07-12 20:21:15 -070076 boot_device_ = boot_device;
77 }
Alex Deymo42432912013-07-12 20:21:15 -070078
Alex Deymo5708ecd2014-04-29 19:44:50 -070079 void SetIsBootDeviceRemovable(bool is_boot_device_removable) {
80 is_boot_device_removable_ = is_boot_device_removable;
81 }
82
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070083 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 Deymobccbc382014-04-03 13:38:55 -070091 // 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 Barnette522d36f2013-10-28 17:22:12 -0700102 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 Deymo42432912013-07-12 20:21:15 -0700114 private:
Don Garrett83692e42013-11-08 10:11:30 -0800115 std::string kernel_device_;
Alex Deymo42432912013-07-12 20:21:15 -0700116 std::string boot_device_;
Alex Deymo5708ecd2014-04-29 19:44:50 -0700117 bool is_boot_device_removable_;
Chris Sosa44b9b7e2014-04-02 13:53:46 -0700118 std::vector<std::string> kernel_devices_;
Don Garrett83692e42013-11-08 10:11:30 -0800119 std::map<std::string, bool> is_bootable_;
J. Richard Barnette056b0ab2013-10-29 15:24:56 -0700120 bool is_official_build_;
121 bool is_normal_boot_mode_;
Alex Deymobccbc382014-04-03 13:38:55 -0700122 bool is_oobe_complete_;
123 base::Time oobe_timestamp_;
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700124 std::string hardware_class_;
125 std::string firmware_version_;
126 std::string ec_version_;
Alex Deymo42432912013-07-12 20:21:15 -0700127
128 DISALLOW_COPY_AND_ASSIGN(FakeHardware);
129};
130
131} // namespace chromeos_update_engine
132
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700133#endif // UPDATE_ENGINE_FAKE_HARDWARE_H_