blob: 97ab8dd80708a629b6e29c88b86bb72933494ab8 [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"),
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070020 is_official_build_(true),
21 is_normal_boot_mode_(true),
J. Richard Barnette522d36f2013-10-28 17:22:12 -070022 hardware_class_("Fake HWID BLAH-1234"),
23 firmware_version_("Fake Firmware v1.0.1"),
24 ec_version_("Fake EC v1.0a") {}
Alex Deymo42432912013-07-12 20:21:15 -070025
26 // HardwareInterface methods.
Don Garrett83692e42013-11-08 10:11:30 -080027 virtual const std::string BootKernelDevice() { return kernel_device_; }
Alex Deymo42432912013-07-12 20:21:15 -070028 virtual const std::string BootDevice() { return boot_device_; }
Don Garrett83692e42013-11-08 10:11:30 -080029 virtual bool IsKernelBootable(const std::string& kernel_device,
30 bool* bootable)
31 { std::map<std::string, bool>::const_iterator i =
32 is_bootable_.find(kernel_device);
33 *bootable = (i != is_bootable_.end()) ? i->second : true;
34 return true; }
35
36 virtual bool MarkKernelUnbootable(const std::string& kernel_device)
37 { is_bootable_[kernel_device] = false; return true;}
38
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070039 virtual bool IsOfficialBuild() { return is_official_build_; }
40 virtual bool IsNormalBootMode() { return is_normal_boot_mode_; }
J. Richard Barnette522d36f2013-10-28 17:22:12 -070041 virtual std::string GetHardwareClass() { return hardware_class_; }
42 virtual std::string GetFirmwareVersion() { return firmware_version_; }
43 virtual std::string GetECVersion() { return ec_version_; }
Alex Deymo42432912013-07-12 20:21:15 -070044
45 // Setters
46 void SetBootDevice(const std::string boot_device) {
47 boot_device_ = boot_device;
48 }
Alex Deymo42432912013-07-12 20:21:15 -070049
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070050 void SetIsOfficialBuild(bool is_official_build) {
51 is_official_build_ = is_official_build;
52 }
53
54 void SetIsNormalBootMode(bool is_normal_boot_mode) {
55 is_normal_boot_mode_ = is_normal_boot_mode;
56 }
57
J. Richard Barnette522d36f2013-10-28 17:22:12 -070058 void SetHardwareClass(std::string hardware_class) {
59 hardware_class_ = hardware_class;
60 }
61
62 void SetFirmwareVersion(std::string firmware_version) {
63 firmware_version_ = firmware_version;
64 }
65
66 void SetECVersion(std::string ec_version) {
67 ec_version_ = ec_version;
68 }
69
Alex Deymo42432912013-07-12 20:21:15 -070070 private:
Don Garrett83692e42013-11-08 10:11:30 -080071 std::string kernel_device_;
Alex Deymo42432912013-07-12 20:21:15 -070072 std::string boot_device_;
Don Garrett83692e42013-11-08 10:11:30 -080073 std::map<std::string, bool> is_bootable_;
J. Richard Barnette056b0ab2013-10-29 15:24:56 -070074 bool is_official_build_;
75 bool is_normal_boot_mode_;
J. Richard Barnette522d36f2013-10-28 17:22:12 -070076 std::string hardware_class_;
77 std::string firmware_version_;
78 std::string ec_version_;
Alex Deymo42432912013-07-12 20:21:15 -070079
80 DISALLOW_COPY_AND_ASSIGN(FakeHardware);
81};
82
83} // namespace chromeos_update_engine
84
85#endif // CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__