blob: 161f51a38cbf7ead8cf618b2793b053365586c0c [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 Deymo42432912013-07-12 20:21:15 -070010#include "update_engine/hardware_interface.h"
11
Alex Deymo42432912013-07-12 20:21:15 -070012namespace chromeos_update_engine {
13
14// Implements a fake hardware interface used for testing.
15class FakeHardware : public HardwareInterface {
16 public:
J. Richard Barnette4da2cc12013-10-28 16:11:10 -070017 FakeHardware()
Don Garrett83692e42013-11-08 10:11:30 -080018 : kernel_device_("/dev/sdz4"),
19 boot_device_("/dev/sdz5"),
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080020 bootable_devices_({"/dev/sdz4", "/dev/sdz5"}),
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070021 is_official_build_(true),
22 is_normal_boot_mode_(true),
J. Richard Barnette522d36f2013-10-28 17:22:12 -070023 hardware_class_("Fake HWID BLAH-1234"),
24 firmware_version_("Fake Firmware v1.0.1"),
25 ec_version_("Fake EC v1.0a") {}
Alex Deymo42432912013-07-12 20:21:15 -070026
27 // HardwareInterface methods.
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080028 virtual std::string BootKernelDevice() const override {
29 return kernel_device_;
30 }
31
32 virtual std::string BootDevice() const override { return boot_device_; }
33
34 virtual std::vector<std::string> GetKernelDevices() const override {
35 return bootable_devices_;
36 }
Alex Vakulenko59e253e2014-02-24 10:40:21 -080037
Don Garrett83692e42013-11-08 10:11:30 -080038 virtual bool IsKernelBootable(const std::string& kernel_device,
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080039 bool* bootable) const override {
40 auto i = is_bootable_.find(kernel_device);
41 *bootable = (i != is_bootable_.end()) ? i->second : true;
42 return true;
43 }
Don Garrett83692e42013-11-08 10:11:30 -080044
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080045 virtual bool MarkKernelUnbootable(const std::string& kernel_device) override {
46 is_bootable_[kernel_device] = false;
47 return true;
48 }
Don Garrett83692e42013-11-08 10:11:30 -080049
Alex Vakulenkod0fdfb32014-02-21 15:26:26 -080050 virtual bool IsOfficialBuild() const override { return is_official_build_; }
51
52 virtual bool IsNormalBootMode() const override {
53 return is_normal_boot_mode_;
54 }
55
56 virtual std::string GetHardwareClass() const override {
57 return hardware_class_;
58 }
59
60 virtual std::string GetFirmwareVersion() const override {
61 return firmware_version_;
62 }
63
64 virtual std::string GetECVersion() const override { return ec_version_; }
Alex Deymo42432912013-07-12 20:21:15 -070065
66 // Setters
67 void SetBootDevice(const std::string boot_device) {
68 boot_device_ = boot_device;
69 }
Alex Deymo42432912013-07-12 20:21:15 -070070
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070071 void SetIsOfficialBuild(bool is_official_build) {
72 is_official_build_ = is_official_build;
73 }
74
75 void SetIsNormalBootMode(bool is_normal_boot_mode) {
76 is_normal_boot_mode_ = is_normal_boot_mode;
77 }
78
J. Richard Barnette522d36f2013-10-28 17:22:12 -070079 void SetHardwareClass(std::string hardware_class) {
80 hardware_class_ = hardware_class;
81 }
82
83 void SetFirmwareVersion(std::string firmware_version) {
84 firmware_version_ = firmware_version;
85 }
86
87 void SetECVersion(std::string ec_version) {
88 ec_version_ = ec_version;
89 }
90
Alex Deymo42432912013-07-12 20:21:15 -070091 private:
Don Garrett83692e42013-11-08 10:11:30 -080092 std::string kernel_device_;
Alex Deymo42432912013-07-12 20:21:15 -070093 std::string boot_device_;
Alex Vakulenko59e253e2014-02-24 10:40:21 -080094 std::vector<std::string> bootable_devices_;
Don Garrett83692e42013-11-08 10:11:30 -080095 std::map<std::string, bool> is_bootable_;
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070096 bool is_official_build_;
97 bool is_normal_boot_mode_;
J. Richard Barnette522d36f2013-10-28 17:22:12 -070098 std::string hardware_class_;
99 std::string firmware_version_;
100 std::string ec_version_;
Alex Deymo42432912013-07-12 20:21:15 -0700101
102 DISALLOW_COPY_AND_ASSIGN(FakeHardware);
103};
104
105} // namespace chromeos_update_engine
106
Alex Deymo759c2752014-03-17 21:09:36 -0700107#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H_