AU: fix bug in GPIO handler that caused failed discovery to be ignored

This solves two issues:

* The GPIO handler will attempt to use GPIO devices even when discovery
  via udev has failed. Not any more.

* GPIO discovery would return success even when it failed on a previous
  attempt. Now it'll reflect the actual result of the discovery attempt.

* Reporting of file descriptor open errors is obscured due to
  intermittent operations that reset errno, now fixed.

* Added test case to ensure that repeat GPIO discovery is not attempted,
  and that test mode check will automatically fail if a previous
  initialization/discovery had failed.

BUG=None
TEST=Passes unit tests
TEST=All symptoms gone on real update attempt w/ x86-alex

Change-Id: I01a7b1e316dbb5b94487a5aad1560d994feae9ff
Reviewed-on: https://gerrit.chromium.org/gerrit/40946
Commit-Queue: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/gpio_mock_udev_interface.h b/gpio_mock_udev_interface.h
index 724a0f4..04c29e0 100644
--- a/gpio_mock_udev_interface.h
+++ b/gpio_mock_udev_interface.h
@@ -129,6 +129,21 @@
   MockDevice gpio_chip2_dev_;
 };
 
+// A udev mock that fails to provide constructs for proper GPIO initialization.
+class FailInitGpioMockUdevInterface : public StandardGpioMockUdevInterface {
+ public:
+  // Default constructor.
+  FailInitGpioMockUdevInterface() : num_init_attempts_(0) {}
+
+  virtual void ExpectNumInitAttempts(unsigned count) const;
+
+ protected:
+  virtual struct udev* New();
+
+ private:
+  unsigned num_init_attempts_;
+};
+
 }  // namespace chromeos_update_engine
 
 #endif  // CHROMEOS_PLATFORM_UPDATE_ENGINE_GPIO_MOCK_UDEV_INTERFACE_H__