blob: 5b48ce23f137dcdcc6774d82871aec89f2f74fcd [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 Vakulenkod0fdfb32014-02-21 15:26:26 -080034 virtual std::string BootKernelDevice() const override {
35 return kernel_device_;
36 }
37
38 virtual std::string BootDevice() const override { return boot_device_; }
39
Alex Deymo5708ecd2014-04-29 19:44:50 -070040 virtual bool IsBootDeviceRemovable() const override {
41 return is_boot_device_removable_;
42 }
43
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080044 virtual std::vector<std::string> GetKernelDevices() const override {
Chris Sosa44b9b7e2014-04-02 13:53:46 -070045 return kernel_devices_;
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080046 }
Alex Vakulenko59e253e2014-02-24 10:40:21 -080047
Don Garrett83692e42013-11-08 10:11:30 -080048 virtual bool IsKernelBootable(const std::string& kernel_device,
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080049 bool* bootable) const override {
50 auto i = is_bootable_.find(kernel_device);
51 *bootable = (i != is_bootable_.end()) ? i->second : true;
52 return true;
53 }
Don Garrett83692e42013-11-08 10:11:30 -080054
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080055 virtual bool MarkKernelUnbootable(const std::string& kernel_device) override {
56 is_bootable_[kernel_device] = false;
57 return true;
58 }
Don Garrett83692e42013-11-08 10:11:30 -080059
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080060 virtual bool IsOfficialBuild() const override { return is_official_build_; }
61
62 virtual bool IsNormalBootMode() const override {
63 return is_normal_boot_mode_;
64 }
65
Alex Deymobccbc382014-04-03 13:38:55 -070066 virtual bool IsOOBEComplete(base::Time* out_time_of_oobe) const override {
67 if (out_time_of_oobe != nullptr)
68 *out_time_of_oobe = oobe_timestamp_;
69 return is_oobe_complete_;
70 }
71
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080072 virtual std::string GetHardwareClass() const override {
73 return hardware_class_;
74 }
75
76 virtual std::string GetFirmwareVersion() const override {
77 return firmware_version_;
78 }
79
80 virtual std::string GetECVersion() const override { return ec_version_; }
Alex Deymo42432912013-07-12 20:21:15 -070081
82 // Setters
Alex Deymo5708ecd2014-04-29 19:44:50 -070083 void SetBootDevice(const std::string& boot_device) {
Alex Deymo42432912013-07-12 20:21:15 -070084 boot_device_ = boot_device;
85 }
Alex Deymo42432912013-07-12 20:21:15 -070086
Alex Deymo5708ecd2014-04-29 19:44:50 -070087 void SetIsBootDeviceRemovable(bool is_boot_device_removable) {
88 is_boot_device_removable_ = is_boot_device_removable;
89 }
90
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070091 void SetIsOfficialBuild(bool is_official_build) {
92 is_official_build_ = is_official_build;
93 }
94
95 void SetIsNormalBootMode(bool is_normal_boot_mode) {
96 is_normal_boot_mode_ = is_normal_boot_mode;
97 }
98
Alex Deymobccbc382014-04-03 13:38:55 -070099 // Sets the IsOOBEComplete to True with the given timestamp.
100 void SetIsOOBEComplete(base::Time oobe_timestamp) {
101 is_oobe_complete_ = true;
102 oobe_timestamp_ = oobe_timestamp;
103 }
104
105 // Sets the IsOOBEComplete to False.
106 void UnsetIsOOBEComplete() {
107 is_oobe_complete_ = false;
108 }
109
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700110 void SetHardwareClass(std::string hardware_class) {
111 hardware_class_ = hardware_class;
112 }
113
114 void SetFirmwareVersion(std::string firmware_version) {
115 firmware_version_ = firmware_version;
116 }
117
118 void SetECVersion(std::string ec_version) {
119 ec_version_ = ec_version;
120 }
121
Alex Deymo42432912013-07-12 20:21:15 -0700122 private:
Don Garrett83692e42013-11-08 10:11:30 -0800123 std::string kernel_device_;
Alex Deymo42432912013-07-12 20:21:15 -0700124 std::string boot_device_;
Alex Deymo5708ecd2014-04-29 19:44:50 -0700125 bool is_boot_device_removable_;
Chris Sosa44b9b7e2014-04-02 13:53:46 -0700126 std::vector<std::string> kernel_devices_;
Don Garrett83692e42013-11-08 10:11:30 -0800127 std::map<std::string, bool> is_bootable_;
J. Richard Barnette056b0ab2013-10-29 15:24:56 -0700128 bool is_official_build_;
129 bool is_normal_boot_mode_;
Alex Deymobccbc382014-04-03 13:38:55 -0700130 bool is_oobe_complete_;
131 base::Time oobe_timestamp_;
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700132 std::string hardware_class_;
133 std::string firmware_version_;
134 std::string ec_version_;
Alex Deymo42432912013-07-12 20:21:15 -0700135
136 DISALLOW_COPY_AND_ASSIGN(FakeHardware);
137};
138
139} // namespace chromeos_update_engine
140
Gilad Arnoldcf175a02014-07-10 16:48:47 -0700141#endif // UPDATE_ENGINE_FAKE_HARDWARE_H_