Send an UMA metric when failed to boot into the new partition.

When a payload is successfully applied, the /other/ partition
is marked as valid and a reboot is needed, the reboot into this
new partition can fail due to several reasons. If than happens,
the firmware can rollback to the previous partition.

When this happens, this fix sends a new UMA metric with the
attempt number of this failing payload.

In order to test this functionality we need to fake the
utils::BootDevice() to emulate a reboot into the same or
a different partition. To achieve this, this function is
moved to a new "HardwareInterface" that can be faked
using the FakeHardware class that can hold similar hardware
related functions. Implementations and unittest were
refactored as needed.

BUG=chromium:243572
TEST=unittests

Change-Id: I1a4242df0bd61e2718ab881ead603b1d3705b877
Reviewed-on: https://gerrit.chromium.org/gerrit/61815
Commit-Queue: Alex Deymo <deymo@chromium.org>
Reviewed-by: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
diff --git a/fake_hardware.h b/fake_hardware.h
new file mode 100644
index 0000000..8b570b2
--- /dev/null
+++ b/fake_hardware.h
@@ -0,0 +1,43 @@
+// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__
+#define CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__
+
+#include "update_engine/hardware_interface.h"
+
+#include "base/basictypes.h"
+
+#include <map>
+
+namespace chromeos_update_engine {
+
+// Implements a fake hardware interface used for testing.
+class FakeHardware : public HardwareInterface {
+ public:
+  FakeHardware() {}
+
+  // HardwareInterface methods.
+  virtual const std::string BootDevice() { return boot_device_; }
+  virtual const std::string KernelDeviceOfBootDevice(
+      const std::string& boot_device);
+
+  // Setters
+  void SetBootDevice(const std::string boot_device) {
+    boot_device_ = boot_device;
+  }
+  void SetKernelDeviceOfBootDevice(const std::string& boot_device,
+                                   const std::string& kernel_device);
+
+ private:
+  std::string boot_device_;
+  typedef std::map<std::string, std::string> KernelDevicesMap;
+  KernelDevicesMap kernel_devices_;
+
+  DISALLOW_COPY_AND_ASSIGN(FakeHardware);
+};
+
+}  // namespace chromeos_update_engine
+
+#endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_FAKE_HARDWARE_H__