Skip to content

Commit 66f446b

Browse files
committed
Add GPIO NC test
Check two items of defined behaviour - that you can initialise a gpio_t with NC, and you can detect that state with gpio_is_connected().
1 parent e502eb5 commit 66f446b

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

TESTS/mbed_hal/gpio/main.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "utest/utest.h"
19+
#include "unity/unity.h"
20+
#include "greentea-client/test_env.h"
21+
22+
using namespace utest::v1;
23+
24+
#include "PinNames.h"
25+
#include "gpio_api.h"
26+
27+
static void gpio_nc_test()
28+
{
29+
gpio_t nc_obj;
30+
gpio_init(&nc_obj, NC);
31+
TEST_ASSERT_FALSE(gpio_is_connected(&nc_obj));
32+
33+
gpio_t led_obj;
34+
gpio_init(&led_obj, LED1);
35+
if (LED1 == NC) {
36+
TEST_ASSERT_FALSE(gpio_is_connected(&led_obj));
37+
} else {
38+
TEST_ASSERT_TRUE(gpio_is_connected(&led_obj));
39+
}
40+
}
41+
42+
Case cases[] = {
43+
Case("gpio NC test", gpio_nc_test)
44+
};
45+
46+
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
47+
{
48+
GREENTEA_SETUP(20, "default_auto");
49+
return greentea_test_setup_handler(number_of_cases);
50+
}
51+
52+
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
53+
54+
int main()
55+
{
56+
Harness::run(specification);
57+
}

hal/gpio_api.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ extern "C" {
3131
* \defgroup hal_gpio GPIO HAL functions
3232
*
3333
* # Defined behavior
34-
* * ::gpio_init and other init functions can be called with NC or a valid PinName for the target.
35-
* * ::gpio_is_connected can be used to test whether a gpio_t object was initialized with NC.
34+
* * ::gpio_init and other init functions can be called with NC or a valid PinName for the target - Verified by ::gpio_nc_test
35+
* * ::gpio_is_connected can be used to test whether a gpio_t object was initialized with NC - Verified by ::gpio_nc_test
3636
*
3737
* # Undefined behavior
3838
* * Calling any ::gpio_mode, ::gpio_dir, ::gpio_write or ::gpio_read on a gpio_t object that was initialized

0 commit comments

Comments
 (0)