Gilad Arnold | 4d740eb | 2012-05-15 08:48:13 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 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 | #include <gtest/gtest.h> |
| 6 | |
| 7 | #include "update_engine/gpio_handler.h" |
| 8 | #include "update_engine/gpio_mock_udev_interface.h" |
| 9 | |
| 10 | // Some common strings used by the different cooperating mocks for this module. |
| 11 | // We use preprocessor constants to allow concatenation at compile-time. |
| 12 | #define MOCK_GPIO_CHIP_ID "100" |
| 13 | #define MOCK_DUTFLAGA_GPIO_ID "101" |
| 14 | #define MOCK_DUTFLAGB_GPIO_ID "102" |
| 15 | #define MOCK_SYSFS_PREFIX "/mock/sys/class/gpio" |
| 16 | |
| 17 | namespace chromeos_update_engine { |
| 18 | |
| 19 | class StandardGpioHandlerTest : public ::testing::Test {}; |
| 20 | |
| 21 | TEST(StandardGpioHandlerTest, NormalInitTest) { |
| 22 | // Ensure that initialization of the GPIO module works as expected, and that |
| 23 | // all udev resources are deallocated afterwards. The mock file descriptor is |
| 24 | // not to be used. |
| 25 | StandardGpioMockUdevInterface mock_udev; |
| 26 | StandardGpioHandler gpio_hander(&mock_udev, false); |
| 27 | mock_udev.ExpectAllResourcesDeallocated(); |
| 28 | mock_udev.ExpectDiscoverySuccess(); |
| 29 | } |
| 30 | |
| 31 | TEST(StandardGpioHandlerTest, MultiGpioChipInitTest) { |
| 32 | // Attempt GPIO discovery with a udev mock that returns two GPIO chip devices. |
| 33 | // It should fail, of course. The mock file descriptor is not to be used. |
| 34 | MultiChipGpioMockUdevInterface mock_udev; |
| 35 | StandardGpioHandler gpio_handler(&mock_udev, false); |
| 36 | mock_udev.ExpectAllResourcesDeallocated(); |
| 37 | mock_udev.ExpectDiscoveryFail(); |
| 38 | } |
| 39 | |
| 40 | TEST(StandardGpioHandlerTest, NormalModeGpioSignalingTest) { |
| 41 | // Initialize the GPIO module, run the signaling procedure, ensure that it |
| 42 | // concluded that this is a normal mode run. |
| 43 | StandardGpioMockUdevInterface mock_udev; |
| 44 | StandardGpioHandler gpio_handler(&mock_udev, false); |
| 45 | EXPECT_FALSE(gpio_handler.IsTestModeSignaled()); |
| 46 | mock_udev.ExpectAllResourcesDeallocated(); |
| 47 | } |
| 48 | |
| 49 | TEST(StandardGpioHandlerTest, DeferredInitNormalModeGpioSignalingTest) { |
| 50 | // Initialize the GPIO module with deferred discovery, run the signaling |
| 51 | // procedure, ensure that it concluded that this is a normal mode run. |
| 52 | StandardGpioMockUdevInterface mock_udev; |
| 53 | StandardGpioHandler gpio_handler(&mock_udev, true); |
| 54 | EXPECT_FALSE(gpio_handler.IsTestModeSignaled()); |
| 55 | mock_udev.ExpectAllResourcesDeallocated(); |
| 56 | } |
| 57 | |
| 58 | } // namespace chromeos_update_engine |