Skip to content

Commit b92b497

Browse files
committed
Add header files for fpga spi tests and map test cases to defined behavior.
Also, update names of the test functions (basic test and fpga tests) so they are more consistent and unique.
1 parent 7333acf commit b92b497

File tree

7 files changed

+368
-248
lines changed

7 files changed

+368
-248
lines changed

TESTS/mbed_hal/spi/main.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static void async_handler(spi_t *obj, void *ctx, spi_async_event_t *event)
176176

177177
/* Test that spi_get_module() returns the SPIName - unique identifier to the peripheral associated
178178
* to this SPI channel. */
179-
void test_get_module()
179+
void spi_test_get_module()
180180
{
181181
SPIName spi_name;
182182

@@ -193,7 +193,7 @@ void test_get_module()
193193

194194
/* Test that spi_get_capabilities() fills the given spi_capabilities_t instance with capabilities
195195
* of the specified SPI peripheral. */
196-
void test_get_capabilities()
196+
void spi_test_get_capabilities()
197197
{
198198
spi_capabilities_t capabilities;
199199

@@ -229,7 +229,7 @@ void test_get_capabilities()
229229

230230
/* Test that spi_init() successfully initializes the pins and spi_free() can successfully
231231
* reset the pins to their default state. */
232-
void test_init_free()
232+
void spi_test_init_free()
233233
{
234234
spi_t spi_obj = { 0 };
235235
spi_capabilities_t capabilities = { 0 };
@@ -295,7 +295,7 @@ void test_init_free()
295295
}
296296

297297
/* Test that spi_format() sets/updates the transmission format of the SPI peripheral. */
298-
void test_set_format()
298+
void spi_test_set_format()
299299
{
300300
spi_t spi_obj = { 0 };
301301
spi_capabilities_t capabilities = { 0 };
@@ -343,8 +343,8 @@ void test_set_format()
343343
TEST_ASSERT_TRUE(true);
344344
}
345345

346-
/* Test that test_set_frequency() sets the frequency used during the SPI transfer. */
347-
void test_set_frequency()
346+
/* Test that spi_test_set_frequency() sets the frequency used during the SPI transfer. */
347+
void spi_test_set_frequency()
348348
{
349349
spi_t spi_obj = { 0 };
350350
uint32_t real_freq;
@@ -372,7 +372,7 @@ void test_set_frequency()
372372
/* Test that spi_transfer() can successfully perform transfer in master mode
373373
* (TX/RX buffers are defined and have the same sizes) and returns the number of
374374
* symbols clocked on the bus during this transfer. */
375-
void test_transfer_master()
375+
void spi_test_transfer_master()
376376
{
377377
spi_t spi_obj = { 0 };
378378
spi_capabilities_t capabilities = { 0 };
@@ -420,7 +420,7 @@ void test_transfer_master()
420420
/* Test that spi_transfer() can successfully perform transfer in master mode
421421
* (TX/RX buffers are undefined or have different sizes) and returns the number of
422422
* symbols clocked on the bus during this transfer. */
423-
void test_transfer_master_fill_sym()
423+
void spi_test_transfer_master_fill_sym()
424424
{
425425
spi_t spi_obj = { 0 };
426426
spi_capabilities_t capabilities = { 0 };
@@ -457,7 +457,7 @@ void test_transfer_master_fill_sym()
457457
#ifdef DEVICE_SPI_ASYNCH
458458
/* Test that spi_transfer_async() can successfully perform asynchronous transfer
459459
* in master mode. */
460-
void test_transfer_master_async()
460+
void spi_test_transfer_master_async()
461461
{
462462
spi_t spi_obj = {0};
463463
spi_capabilities_t capabilities = {0};
@@ -521,7 +521,7 @@ void test_transfer_master_async()
521521
}
522522

523523
/* Test that spi_transfer_async_abort() can successfully abort an on-going async transfer. */
524-
void test_transfer_master_async_abort()
524+
void spi_test_transfer_master_async_abort()
525525
{
526526
spi_t spi_obj = {0};
527527
spi_capabilities_t capabilities = {0};
@@ -615,16 +615,16 @@ utest::v1::status_t greentea_failure_handler_abort(const Case *const source, con
615615
}
616616

617617
Case cases[] = {
618-
Case("SPI - get module name test", test_get_module, greentea_failure_handler),
619-
Case("SPI - get capabilities test", test_get_capabilities, greentea_failure_handler),
620-
Case("SPI - init, free test", test_init_free, greentea_failure_handler),
621-
Case("SPI - set format test", test_set_format, greentea_failure_handler),
622-
Case("SPI - set frequency test", test_set_frequency, greentea_failure_handler),
623-
Case("SPI - master transfer test", test_transfer_master, greentea_failure_handler),
624-
Case("SPI - fill symbol test", test_transfer_master_fill_sym, greentea_failure_handler),
618+
Case("SPI - get module name test", spi_test_get_module, greentea_failure_handler),
619+
Case("SPI - get capabilities test", spi_test_get_capabilities, greentea_failure_handler),
620+
Case("SPI - init, free test", spi_test_init_free, greentea_failure_handler),
621+
Case("SPI - set format test", spi_test_set_format, greentea_failure_handler),
622+
Case("SPI - set frequency test", spi_test_set_frequency, greentea_failure_handler),
623+
Case("SPI - master transfer test", spi_test_transfer_master, greentea_failure_handler),
624+
Case("SPI - fill symbol test", spi_test_transfer_master_fill_sym, greentea_failure_handler),
625625
#ifdef DEVICE_SPI_ASYNCH
626-
Case("SPI - master transfer async test", test_transfer_master_async, greentea_failure_handler),
627-
Case("SPI - master transfer async abort test", test_transfer_master_async_abort, greentea_failure_handler),
626+
Case("SPI - master transfer async test", spi_test_transfer_master_async, greentea_failure_handler),
627+
Case("SPI - master transfer async abort test", spi_test_transfer_master_async_abort, greentea_failure_handler),
628628
#endif
629629
};
630630

TESTS/mbed_hal/spi/spi_api_tests.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern "C" {
3838
*
3939
* @note `mosi` or `miso` pin can be undefined (but not both). `mclk` must be defined.
4040
*/
41-
void test_get_module();
41+
void spi_test_get_module();
4242

4343
/** Test that spi_get_capabilities() fills the given spi_capabilities_t instance with capabilities
4444
* of the specified SPI peripheral.
@@ -52,7 +52,7 @@ void test_get_module();
5252
* support_slave_mode capability.
5353
*
5454
*/
55-
void test_get_capabilities();
55+
void spi_test_get_capabilities();
5656

5757
/** Test that spi_init() successfully initializes the pins and spi_free() can successfully
5858
* reset the pins to their default state.
@@ -63,7 +63,7 @@ void test_get_capabilities();
6363
* Then both operations are successfully performed.
6464
*
6565
*/
66-
void test_init_free();
66+
void spi_test_init_free();
6767

6868
/** Test that spi_format() sets/updates the transmission format of the SPI peripheral.
6969
*
@@ -72,19 +72,19 @@ void test_init_free();
7272
* Then function is executed successfully.
7373
*
7474
*/
75-
void test_set_format();
75+
void spi_test_set_format();
7676

77-
/** Test that test_set_frequency() sets the frequency used during the SPI transfer.
77+
/** Test that spi_test_set_frequency() sets the frequency used during the SPI transfer.
7878
*
7979
* Given is platform with SPI support.
80-
* When test_set_frequency() is called and valid frequency is specified.
80+
* When spi_test_set_frequency() is called and valid frequency is specified.
8181
* Then function is executed successfully and actual frequency which will be used during the transfer is returned.
8282
*
8383
* @note Frequency can be only set by SPI peripheral operating in master mode.
8484
* @note Frequency must be in range specified by the capabilities of the SPI peripheral.
8585
*
8686
*/
87-
void test_set_frequency();
87+
void spi_test_set_frequency();
8888

8989
/** Test that spi_transfer() can successfully perform transfer in master mode
9090
* (TX/RX buffers are defined and have the same sizes) and returns the number of
@@ -96,7 +96,7 @@ void test_set_frequency();
9696
* Then function is executed successfully and returns number of symbols clocked on the bus during this transfer.
9797
*
9898
*/
99-
void test_transfer_master();
99+
void spi_test_transfer_master();
100100

101101
/** Test that spi_transfer() can successfully perform transfer in master mode
102102
* (TX/RX buffers are undefined or have different sizes) and returns the number of
@@ -108,7 +108,7 @@ void test_transfer_master();
108108
* Then function is executed successfully and returns number of symbols clocked on the bus during this transfer.
109109
*
110110
*/
111-
void test_transfer_master_fill_sym();
111+
void spi_test_transfer_master_fill_sym();
112112

113113
/** Test that spi_transfer_async() can successfully perform asynchronous transfer
114114
* in master mode.
@@ -119,7 +119,7 @@ void test_transfer_master_fill_sym();
119119
* when the transfer completes (passing the operation status).
120120
*
121121
*/
122-
void test_transfer_master_async();
122+
void spi_test_transfer_master_async();
123123

124124
/** Test that spi_transfer_async_abort() can successfully abort an on-going async transfer.
125125
*
@@ -130,7 +130,7 @@ void test_transfer_master_async();
130130
* the status which indicates that the transfer has been aborted.
131131
*
132132
*/
133-
void test_transfer_master_async_abort();
133+
void spi_test_transfer_master_async_abort();
134134

135135
/**@}*/
136136

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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_spi_tests */
19+
/** @{*/
20+
21+
#ifndef MBED_FPGA_MASTER_SPI_TEST_H
22+
#define MBED_FPGA_MASTER_SPI_TEST_H
23+
24+
#if DEVICE_SPI
25+
26+
#ifdef __cplusplus
27+
extern "C" {
28+
#endif
29+
30+
/** Test that the spi-Master can be initialized/de-initialized using all possible
31+
* SPI pins.
32+
*
33+
* Given board provides SPI-Master support.
34+
* When SPI-Master is initialized (and then de-initialized) using valid set of SPI pins.
35+
* Then the operation is successfull.
36+
*
37+
*/
38+
void fpga_spi_master_test_init_free(PinName mosi, PinName miso, PinName sclk);
39+
40+
/** Test that the spi_get_capabilities() indicates that slave mode is unsupported if the given `ssel`
41+
* pin cannot be managed by hardware.
42+
*
43+
* Given board provides SPI support.
44+
* When `ssel` pin passed to spi_get_capabilities() cannot be managed by hardware.
45+
* Then capabilities should indicate that slave mode is unsupported.
46+
*
47+
*/
48+
void fpga_spi_test_capabilities_ssel(PinName mosi, PinName miso, PinName sclk);
49+
50+
/** Test that the spi_frequency() returns actual SPI frequency.
51+
*
52+
* Given board provides SPI-Master support.
53+
* When specified frequency is selected by means of spi_frequency().
54+
* Then frequency returned by spi_frequency() is used for the transmission.
55+
*
56+
* Additionally we check that spi_format() updates the configuration of the peripheral (format)
57+
* except the baud rate generator.
58+
*/
59+
void fpga_spi_master_test_freq(PinName mosi, PinName miso, PinName sclk);
60+
61+
/** Test that the SPI-Master transfer can be performed in various configurations.
62+
*
63+
* Given board provides SPI-Master support.
64+
* When SPI transmission is performed using different settings.
65+
* Then data is successfully transfered.
66+
*
67+
* Additionally we check that spi_frequency() updates the baud rate generator
68+
* leaving other configurations (format) unchanged.
69+
*/
70+
void fpga_spi_master_test_common(PinName mosi, PinName miso, PinName sclk);
71+
72+
/**@}*/
73+
74+
#ifdef __cplusplus
75+
}
76+
#endif
77+
78+
#endif
79+
80+
#endif
81+
82+
/**@}*/

0 commit comments

Comments
 (0)