blob: 06f1c30c63e6b7db1b801162a449277d9ed6296b [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
Alex Deymo759c2752014-03-17 21:09:36 -07005#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H_
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H_
Alex Deymo42432912013-07-12 20:21:15 -07007
Don Garrett83692e42013-11-08 10:11:30 -08008#include <map>
9
Alex Deymobccbc382014-04-03 13:38:55 -070010#include <base/time/time.h>
11
Alex Deymo42432912013-07-12 20:21:15 -070012#include "update_engine/hardware_interface.h"
13
Alex Deymo42432912013-07-12 20:21:15 -070014namespace chromeos_update_engine {
15
16// Implements a fake hardware interface used for testing.
17class FakeHardware : public HardwareInterface {
18 public:
J. Richard Barnette4da2cc12013-10-28 16:11:10 -070019 FakeHardware()
Don Garrett83692e42013-11-08 10:11:30 -080020 : kernel_device_("/dev/sdz4"),
21 boot_device_("/dev/sdz5"),
Chris Sosa44b9b7e2014-04-02 13:53:46 -070022 kernel_devices_({"/dev/sdz2", "/dev/sdz4"}),
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070023 is_official_build_(true),
24 is_normal_boot_mode_(true),
Alex Deymobccbc382014-04-03 13:38:55 -070025 is_oobe_complete_(false),
J. Richard Barnette522d36f2013-10-28 17:22:12 -070026 hardware_class_("Fake HWID BLAH-1234"),
27 firmware_version_("Fake Firmware v1.0.1"),
28 ec_version_("Fake EC v1.0a") {}
Alex Deymo42432912013-07-12 20:21:15 -070029
30 // HardwareInterface methods.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080031 virtual std::string BootKernelDevice() const override {
32 return kernel_device_;
33 }
34
35 virtual std::string BootDevice() const override { return boot_device_; }
36
37 virtual std::vector<std::string> GetKernelDevices() const override {
Chris Sosa44b9b7e2014-04-02 13:53:46 -070038 return kernel_devices_;
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080039 }
Alex Vakulenko59e253e2014-02-24 10:40:21 -080040
Don Garrett83692e42013-11-08 10:11:30 -080041 virtual bool IsKernelBootable(const std::string& kernel_device,
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080042 bool* bootable) const override {
43 auto i = is_bootable_.find(kernel_device);
44 *bootable = (i != is_bootable_.end()) ? i->second : true;
45 return true;
46 }
Don Garrett83692e42013-11-08 10:11:30 -080047
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080048 virtual bool MarkKernelUnbootable(const std::string& kernel_device) override {
49 is_bootable_[kernel_device] = false;
50 return true;
51 }
Don Garrett83692e42013-11-08 10:11:30 -080052
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080053 virtual bool IsOfficialBuild() const override { return is_official_build_; }
54
55 virtual bool IsNormalBootMode() const override {
56 return is_normal_boot_mode_;
57 }
58
Alex Deymobccbc382014-04-03 13:38:55 -070059 virtual bool IsOOBEComplete(base::Time* out_time_of_oobe) const override {
60 if (out_time_of_oobe != nullptr)
61 *out_time_of_oobe = oobe_timestamp_;
62 return is_oobe_complete_;
63 }
64
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080065 virtual std::string GetHardwareClass() const override {
66 return hardware_class_;
67 }
68
69 virtual std::string GetFirmwareVersion() const override {
70 return firmware_version_;
71 }
72
73 virtual std::string GetECVersion() const override { return ec_version_; }
Alex Deymo42432912013-07-12 20:21:15 -070074
75 // Setters
76 void SetBootDevice(const std::string boot_device) {
77 boot_device_ = boot_device;
78 }
Alex Deymo42432912013-07-12 20:21:15 -070079
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070080 void SetIsOfficialBuild(bool is_official_build) {
81 is_official_build_ = is_official_build;
82 }
83
84 void SetIsNormalBootMode(bool is_normal_boot_mode) {
85 is_normal_boot_mode_ = is_normal_boot_mode;
86 }
87
Alex Deymobccbc382014-04-03 13:38:55 -070088 // Sets the IsOOBEComplete to True with the given timestamp.
89 void SetIsOOBEComplete(base::Time oobe_timestamp) {
90 is_oobe_complete_ = true;
91 oobe_timestamp_ = oobe_timestamp;
92 }
93
94 // Sets the IsOOBEComplete to False.
95 void UnsetIsOOBEComplete() {
96 is_oobe_complete_ = false;
97 }
98
J. Richard Barnette522d36f2013-10-28 17:22:12 -070099 void SetHardwareClass(std::string hardware_class) {
100 hardware_class_ = hardware_class;
101 }
102
103 void SetFirmwareVersion(std::string firmware_version) {
104 firmware_version_ = firmware_version;
105 }
106
107 void SetECVersion(std::string ec_version) {
108 ec_version_ = ec_version;
109 }
110
Alex Deymo42432912013-07-12 20:21:15 -0700111 private:
Don Garrett83692e42013-11-08 10:11:30 -0800112 std::string kernel_device_;
Alex Deymo42432912013-07-12 20:21:15 -0700113 std::string boot_device_;
Chris Sosa44b9b7e2014-04-02 13:53:46 -0700114 std::vector<std::string> kernel_devices_;
Don Garrett83692e42013-11-08 10:11:30 -0800115 std::map<std::string, bool> is_bootable_;
J. Richard Barnette056b0ab2013-10-29 15:24:56 -0700116 bool is_official_build_;
117 bool is_normal_boot_mode_;
Alex Deymobccbc382014-04-03 13:38:55 -0700118 bool is_oobe_complete_;
119 base::Time oobe_timestamp_;
J. Richard Barnette522d36f2013-10-28 17:22:12 -0700120 std::string hardware_class_;
121 std::string firmware_version_;
122 std::string ec_version_;
Alex Deymo42432912013-07-12 20:21:15 -0700123
124 DISALLOW_COPY_AND_ASSIGN(FakeHardware);
125};
126
127} // namespace chromeos_update_engine
128
Alex Deymo759c2752014-03-17 21:09:36 -0700129#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H_