blob: a133ac705ec2f4089c688ac03457869b509b38dd [file] [log] [blame]
Gilad Arnold4d740eb2012-05-15 08:48:13 -07001// 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
17namespace chromeos_update_engine {
18
19class StandardGpioHandlerTest : public ::testing::Test {};
20
21TEST(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
31TEST(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
40TEST(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
49TEST(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