Skip to content

Commit 6f53899

Browse files
authored
Merge pull request #11032 from mprse/bring_fpga_tests_master_spec
Add test header files and defined behavior for APIs tested using FPGA-Test-Shield
2 parents 92acf95 + 2ff3112 commit 6f53899

23 files changed

+994
-137
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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+
/** \addtogroup hal_analogin_tests */
19+
/** @{*/
20+
21+
#ifndef MBED_FPGA_ANALOG_IN_TEST_H
22+
#define MBED_FPGA_ANALOG_IN_TEST_H
23+
24+
#if DEVICE_ANALOGIN
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
/** Test that the alalogin can be initialized using all possible analogin pins.
31+
*
32+
* Given board provides analogin support.
33+
* When analogin is initialized using valid analogin pin.
34+
* Then the operation is successfull.
35+
*
36+
*/
37+
void fpga_analogin_init_test(PinName pin);
38+
39+
/** Test that analogin correctly interprets given input voltage.
40+
*
41+
* Given board provides analogin support.
42+
* When 0.0/3.3 V is provided to analogin pin.
43+
* Then analogin_read returns 0.0/1.0,
44+
* analogin_read_u16 returns 0/65535.
45+
*
46+
*/
47+
void fpga_analogin_test(PinName pin);
48+
49+
50+
/**@}*/
51+
52+
#ifdef __cplusplus
53+
}
54+
#endif
55+
56+
#endif
57+
58+
#endif
59+
60+
/**@}*/

TESTS/mbed_hal_fpga_ci_test_shield/analogin/main.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
#include "utest/utest.h"
2727
#include "unity/unity.h"
2828
#include "greentea-client/test_env.h"
29-
3029
#include "mbed.h"
3130
#include "pinmap.h"
3231
#include "test_utils.h"
3332
#include "MbedTester.h"
33+
#include "analogin_fpga_test.h"
3434

3535
using namespace utest::v1;
3636

@@ -44,14 +44,15 @@ const PinList *restricted = pinmap_restricted_pins();
4444

4545
MbedTester tester(form_factor, restricted);
4646

47-
void analogin_init(PinName pin)
47+
void fpga_analogin_init_test(PinName pin)
4848
{
4949
analogin_t analogin;
5050

5151
analogin_init(&analogin, pin);
52+
analogin_free(&analogin);
5253
}
5354

54-
void analogin_test(PinName pin)
55+
void fpga_analogin_test(PinName pin)
5556
{
5657
tester.reset();
5758
tester.pin_map_set(pin, MbedTester::LogicalPinGPIO0);
@@ -72,13 +73,15 @@ void analogin_test(PinName pin)
7273

7374
/* Set gpio back to Hi-Z */
7475
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
76+
77+
analogin_free(&analogin);
7578
}
7679

7780
Case cases[] = {
7881
// This will be run for all pins
79-
Case("AnalogIn - init test", all_ports<AnaloginPort, DefaultFormFactor, analogin_init>),
82+
Case("AnalogIn - init test", all_ports<AnaloginPort, DefaultFormFactor, fpga_analogin_init_test>),
8083
// This will be run for single pin
81-
Case("AnalogIn - read test", all_ports<AnaloginPort, DefaultFormFactor, analogin_test>),
84+
Case("AnalogIn - read test", all_ports<AnaloginPort, DefaultFormFactor, fpga_analogin_test>),
8285
};
8386

8487
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
/** \addtogroup hal_gpio_tests */
19+
/** @{*/
20+
21+
#ifndef MBED_FPGA_GPIO_TEST_H
22+
#define MBED_FPGA_GPIO_TEST_H
23+
24+
#ifdef __cplusplus
25+
extern "C" {
26+
#endif
27+
28+
/* Test basic input & output operations.
29+
*
30+
* Given a GPIO instance initialized with a generic gpio_init() function,
31+
* when basic input and output operations are performed,
32+
* then all operations succeed.
33+
*/
34+
void fpga_test_basic_input_output(PinName pin);
35+
36+
/* Test explicit input initialization.
37+
*
38+
* Given a GPIO instance,
39+
* when additional parameters are passed to the input init function,
40+
* then the GPIO is correctly initialized as an input.
41+
*/
42+
void fpga_test_explicit_input(PinName pin);
43+
44+
/* Test explicit output initialization.
45+
*
46+
* Given a GPIO instance,
47+
* when additional parameters are passed to the output init function,
48+
* then the GPIO is correctly initialized as an output.
49+
*/
50+
void fpga_test_explicit_output(PinName pin);
51+
52+
/**@}*/
53+
54+
#ifdef __cplusplus
55+
}
56+
#endif
57+
58+
#endif
59+
60+
61+
/**@}*/

TESTS/mbed_hal_fpga_ci_test_shield/gpio/main.cpp

+21-9
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
#include "unity/unity.h"
2626
#include "greentea-client/test_env.h"
2727
#include "mbed.h"
28-
29-
using namespace utest::v1;
30-
3128
#include "MbedTester.h"
3229
#include "pinmap.h"
3330
#include "test_utils.h"
31+
#include "gpio_fpga_test.h"
32+
33+
using namespace utest::v1;
3434

3535
// This delay is used when reading a floating input that has an internal pull-up
3636
// or pull-down resistor. The voltage response is much slower when the input
@@ -45,7 +45,7 @@ MbedTester tester(DefaultFormFactor::pins(), DefaultFormFactor::restricted_pins(
4545
* when basic input and output operations are performed,
4646
* then all operations succeed.
4747
*/
48-
void test_basic_input_output(PinName pin)
48+
void fpga_test_basic_input_output(PinName pin)
4949
{
5050
// Reset everything and set all tester pins to hi-Z.
5151
tester.reset();
@@ -61,6 +61,7 @@ void test_basic_input_output(PinName pin)
6161
// Test gpio_is_connected() returned value.
6262
gpio_init(&gpio, NC);
6363
TEST_ASSERT_EQUAL_INT(0, gpio_is_connected(&gpio));
64+
gpio_free(&gpio);
6465
gpio_init(&gpio, pin);
6566
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
6667

@@ -120,6 +121,8 @@ void test_basic_input_output(PinName pin)
120121
TEST_ASSERT_EQUAL_INT(1, tester.gpio_read(MbedTester::LogicalPinGPIO0));
121122
gpio_write(&gpio, 0);
122123
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
124+
125+
gpio_free(&gpio);
123126
}
124127

125128
/* Test explicit input initialization.
@@ -128,7 +131,7 @@ void test_basic_input_output(PinName pin)
128131
* when additional parameters are passed to the input init function,
129132
* then the GPIO is correctly initialized as an input.
130133
*/
131-
void test_explicit_input(PinName pin)
134+
void fpga_test_explicit_input(PinName pin)
132135
{
133136
// Reset everything and set all tester pins to hi-Z.
134137
tester.reset();
@@ -148,6 +151,7 @@ void test_explicit_input(PinName pin)
148151
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
149152
wait_us(HI_Z_READ_DELAY_US);
150153
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up
154+
gpio_free(&gpio);
151155

152156
// Initialize GPIO pin as an input, pull-down mode.
153157
memset(&gpio, 0, sizeof gpio);
@@ -156,6 +160,7 @@ void test_explicit_input(PinName pin)
156160
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
157161
wait_us(HI_Z_READ_DELAY_US);
158162
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down
163+
gpio_free(&gpio);
159164

160165
// Initialize GPIO pin as an input, pull-up mode.
161166
memset(&gpio, 0, sizeof gpio);
@@ -164,6 +169,7 @@ void test_explicit_input(PinName pin)
164169
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
165170
wait_us(HI_Z_READ_DELAY_US);
166171
TEST_ASSERT_EQUAL_INT(1, gpio_read(&gpio)); // hi-Z, pulled up
172+
gpio_free(&gpio);
167173

168174
// Initialize GPIO pin as an input, pull-down mode.
169175
memset(&gpio, 0, sizeof gpio);
@@ -172,6 +178,7 @@ void test_explicit_input(PinName pin)
172178
tester.gpio_write(MbedTester::LogicalPinGPIO0, 0, false);
173179
wait_us(HI_Z_READ_DELAY_US);
174180
TEST_ASSERT_EQUAL_INT(0, gpio_read(&gpio)); // hi-Z, pulled down
181+
gpio_free(&gpio);
175182
}
176183

177184
/* Test explicit output initialization.
@@ -180,7 +187,7 @@ void test_explicit_input(PinName pin)
180187
* when additional parameters are passed to the output init function,
181188
* then the GPIO is correctly initialized as an output.
182189
*/
183-
void test_explicit_output(PinName pin)
190+
void fpga_test_explicit_output(PinName pin)
184191
{
185192
// Reset everything and set all tester pins to hi-Z.
186193
tester.reset();
@@ -198,41 +205,46 @@ void test_explicit_output(PinName pin)
198205
gpio_init_out(&gpio, pin);
199206
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
200207
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
208+
gpio_free(&gpio);
201209

202210
// Initialize GPIO pin as an output, output value = 1.
203211
memset(&gpio, 0, sizeof gpio);
204212
gpio_init_out_ex(&gpio, pin, 1);
205213
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
206214
TEST_ASSERT_EQUAL_INT(1, tester.gpio_read(MbedTester::LogicalPinGPIO0));
215+
gpio_free(&gpio);
207216

208217
// Initialize GPIO pin as an output, output value = 0.
209218
memset(&gpio, 0, sizeof gpio);
210219
gpio_init_out_ex(&gpio, pin, 0);
211220
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
212221
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
222+
gpio_free(&gpio);
213223

214224
// Initialize GPIO pin as an output, output value = 1.
215225
memset(&gpio, 0, sizeof gpio);
216226
gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 1);
217227
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
218228
TEST_ASSERT_EQUAL_INT(1, tester.gpio_read(MbedTester::LogicalPinGPIO0));
229+
gpio_free(&gpio);
219230

220231
// Initialize GPIO pin as an output, output value = 0.
221232
memset(&gpio, 0, sizeof gpio);
222233
gpio_init_inout(&gpio, pin, PIN_OUTPUT, PullNone, 0);
223234
TEST_ASSERT_NOT_EQUAL(0, gpio_is_connected(&gpio));
224235
TEST_ASSERT_EQUAL_INT(0, tester.gpio_read(MbedTester::LogicalPinGPIO0));
236+
gpio_free(&gpio);
225237
}
226238

227239
Case cases[] = {
228-
Case("generic init, input & output", all_ports<GPIOPort, DefaultFormFactor, test_basic_input_output>),
240+
Case("generic init, input & output", all_ports<GPIOPort, DefaultFormFactor, fpga_test_basic_input_output>),
229241
// Some targets don't support input pull mode.
230242
#if !defined(TARGET_NANO100) && \
231243
!defined(TARGET_NUC472) && \
232244
!defined(TARGET_M451)
233-
Case("explicit init, input", all_ports<GPIOPort, DefaultFormFactor, test_explicit_input>),
245+
Case("explicit init, input", all_ports<GPIOPort, DefaultFormFactor, fpga_test_explicit_input>),
234246
#endif
235-
Case("explicit init, output", all_ports<GPIOPort, DefaultFormFactor, test_explicit_output>),
247+
Case("explicit init, output", all_ports<GPIOPort, DefaultFormFactor, fpga_test_explicit_output>),
236248
};
237249

238250
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
/** \addtogroup hal_gpioirq_tests */
19+
/** @{*/
20+
21+
#ifndef MBED_FPGA_GPIO_IRQ_TEST_H
22+
#define MBED_FPGA_GPIO_IRQ_TEST_H
23+
24+
#if DEVICE_INTERRUPTIN
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
/** Test that the GPIO IRQ can be initialized/de-initialized using all possible
31+
* GPIO IRQ pins.
32+
*
33+
* Given board provides GPIO IRQ support.
34+
* When GPIO IRQ is initialized (and then de-initialized) using valid GPIO IRQ pin.
35+
* Then the operation is successfull.
36+
*
37+
*/
38+
void fpga_gpio_irq_test(PinName pin);
39+
40+
/** Test that the gpio interrupt is generated correctly.
41+
*
42+
* Given board provides interrupt-in feature.
43+
* When gpio interrupt is configured to fire on rasing/falling/both edge(s).
44+
* Then on rasing/falling/any edge registered interrupt handler is called.
45+
*
46+
*/
47+
void fpga_gpio_irq_init_free_test(PinName pin);
48+
49+
/**@}*/
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif
54+
55+
#endif
56+
57+
#endif
58+
/**@}*/

0 commit comments

Comments
 (0)