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_file_descriptor.h b/gpio_mock_file_descriptor.h
index a4fd4e8..c616b41 100644
--- a/gpio_mock_file_descriptor.h
+++ b/gpio_mock_file_descriptor.h
@@ -48,6 +48,10 @@
   // otherwise, will fail the current test.
   virtual bool ExpectAllGpiosRestoredToDefault();
 
+  // Returns true iff the number of open attempts equals the argument;
+  // otherwise, will fail the current test.
+  virtual bool ExpectNumOpenAttempted(unsigned count);
+
  protected:
   // A pair of write value and time at which it was written.
   struct MockGpioWriteEvent {
@@ -135,6 +139,9 @@
 
   // The identifier of the currently accessed GPIO sub-device.
   MockGpioSubdev gpio_subdev_;
+
+  // Counter for the number of files that were opened with this interface.
+  unsigned num_open_attempted_;
 };