blob: 6f4be77f84381d1aa9bfbeae4f9f42a3e660a841 [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
5#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__
6#define CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__
7
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 Vakulenko59e253e2014-02-24 10:40:21 -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.
Don Garrett83692e42013-11-08 10:11:30 -080028 virtual const std::string BootKernelDevice() { return kernel_device_; }
Alex Deymo42432912013-07-12 20:21:15 -070029 virtual const std::string BootDevice() { return boot_device_; }
Alex Vakulenko59e253e2014-02-24 10:40:21 -080030 virtual std::vector<std::string> GetKernelDevices() override
31 { return bootable_devices_; }
32
Don Garrett83692e42013-11-08 10:11:30 -080033 virtual bool IsKernelBootable(const std::string& kernel_device,
34 bool* bootable)
35 { std::map<std::string, bool>::const_iterator i =
36 is_bootable_.find(kernel_device);
37 *bootable = (i != is_bootable_.end()) ? i->second : true;
38 return true; }
39
40 virtual bool MarkKernelUnbootable(const std::string& kernel_device)
41 { is_bootable_[kernel_device] = false; return true;}
42
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070043 virtual bool IsOfficialBuild() { return is_official_build_; }
44 virtual bool IsNormalBootMode() { return is_normal_boot_mode_; }
J. Richard Barnette522d36f2013-10-28 17:22:12 -070045 virtual std::string GetHardwareClass() { return hardware_class_; }
46 virtual std::string GetFirmwareVersion() { return firmware_version_; }
47 virtual std::string GetECVersion() { return ec_version_; }
Alex Deymo42432912013-07-12 20:21:15 -070048
49 // Setters
50 void SetBootDevice(const std::string boot_device) {
51 boot_device_ = boot_device;
52 }
Alex Deymo42432912013-07-12 20:21:15 -070053
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070054 void SetIsOfficialBuild(bool is_official_build) {
55 is_official_build_ = is_official_build;
56 }
57
58 void SetIsNormalBootMode(bool is_normal_boot_mode) {
59 is_normal_boot_mode_ = is_normal_boot_mode;
60 }
61
J. Richard Barnette522d36f2013-10-28 17:22:12 -070062 void SetHardwareClass(std::string hardware_class) {
63 hardware_class_ = hardware_class;
64 }
65
66 void SetFirmwareVersion(std::string firmware_version) {
67 firmware_version_ = firmware_version;
68 }
69
70 void SetECVersion(std::string ec_version) {
71 ec_version_ = ec_version;
72 }
73
Alex Deymo42432912013-07-12 20:21:15 -070074 private:
Don Garrett83692e42013-11-08 10:11:30 -080075 std::string kernel_device_;
Alex Deymo42432912013-07-12 20:21:15 -070076 std::string boot_device_;
Alex Vakulenko59e253e2014-02-24 10:40:21 -080077 std::vector<std::string> bootable_devices_;
Don Garrett83692e42013-11-08 10:11:30 -080078 std::map<std::string, bool> is_bootable_;
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070079 bool is_official_build_;
80 bool is_normal_boot_mode_;
J. Richard Barnette522d36f2013-10-28 17:22:12 -070081 std::string hardware_class_;
82 std::string firmware_version_;
83 std::string ec_version_;
Alex Deymo42432912013-07-12 20:21:15 -070084
85 DISALLOW_COPY_AND_ASSIGN(FakeHardware);
86};
87
88} // namespace chromeos_update_engine
89
90#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__