aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrand SIMONNET <bsimonnet@google.com>2016-05-17 11:26:25 -0700
committerBertrand SIMONNET <bsimonnet@google.com>2016-05-18 11:22:12 -0700
commit4efbbe5718e9a554b66de7900ca6facfe28bfe42 (patch)
treefb09bdaa95829259ffd9d747134623485185669d
parentebffc4c034597531a955805eabecf3d6a2f34f82 (diff)
downloadperipheralmanager-4efbbe5718e9a554b66de7900ca6facfe28bfe42.tar.gz
Make sure BGpio_setValue fails on input.
Setting the value of an input GPIO will fail in the daemon. We need to make sure the error is propagated to the user and an message is logged. This is probably a common error. Giving feedback to the developer will be helpful. Bug: 28765716 Change-Id: I5e9b20e317d73875431e0e09b4589fc61781a1af
-rw-r--r--client/gpio_unittest.cc3
-rw-r--r--daemon/gpio_driver_mock.h13
-rw-r--r--daemon/gpio_driver_sysfs.cc10
3 files changed, 19 insertions, 7 deletions
diff --git a/client/gpio_unittest.cc b/client/gpio_unittest.cc
index 4b1ada2..f5b54bc 100644
--- a/client/gpio_unittest.cc
+++ b/client/gpio_unittest.cc
@@ -103,6 +103,9 @@ TEST_F(GpioTest, CanOpenGpio) {
int value;
EXPECT_EQ(0, BGpio_getValue(gpio, &value));
+ // Setting the value returns an error.
+ EXPECT_EQ(EREMOTEIO, BGpio_setValue(gpio, 1));
+
// Can set the edge type. If the type is unknown, we fail.
EXPECT_EQ(0, BGpio_setEdgeTriggerType(gpio, RISING_EDGE));
EXPECT_EQ(EINVAL, BGpio_setEdgeTriggerType(gpio, -1));
diff --git a/daemon/gpio_driver_mock.h b/daemon/gpio_driver_mock.h
index 4c52f4c..d8e279c 100644
--- a/daemon/gpio_driver_mock.h
+++ b/daemon/gpio_driver_mock.h
@@ -28,21 +28,28 @@ namespace android {
class GpioDriverMock : public GpioDriverInterface {
public:
- GpioDriverMock(void* arg) {}
+ GpioDriverMock(void* arg) : is_input(true) {}
~GpioDriverMock() {}
static std::string Compat() { return "GPIOSYSFS"; }
bool Init(uint32_t index) { return true; }
- bool SetValue(bool val) { return true; };
+ bool SetValue(bool val) { return !is_input; };
+
bool GetValue(bool* val) { return true; };
bool SetActiveType(GpioActiveType type) { return true; };
- bool SetDirection(GpioDirection direction) { return true; };
+
+ bool SetDirection(GpioDirection direction) {
+ is_input = direction == kDirectionIn;
+ return true;
+ };
+
bool SetEdgeType(GpioEdgeType type) { return true; };
bool GetPollingFd(::android::base::unique_fd* fd) { return true; };
private:
+ bool is_input;
DISALLOW_COPY_AND_ASSIGN(GpioDriverMock);
};
diff --git a/daemon/gpio_driver_sysfs.cc b/daemon/gpio_driver_sysfs.cc
index f1b75b0..b49c2ff 100644
--- a/daemon/gpio_driver_sysfs.cc
+++ b/daemon/gpio_driver_sysfs.cc
@@ -88,10 +88,12 @@ bool GpioDriverSysfs::Init(uint32_t index) {
}
bool GpioDriverSysfs::SetValue(bool val) {
- if (val)
- return Enable();
- else
- return Disable();
+ bool success = val ? Enable() : Disable();
+ if (!success) {
+ LOG(WARNING) << "Failed to set the value of the GPIO. Is it configured as "
+ << "output?";
+ }
+ return success;
}
bool GpioDriverSysfs::GetValue(bool* val) {