Skip to content

Commit 89fe2b4

Browse files
Make InterruptIn test much more sophisticated
1 parent 89687bd commit 89fe2b4

File tree

6 files changed

+126
-37
lines changed

6 files changed

+126
-37
lines changed

CI-Shield-Tests/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ mbed_greentea_add_test(
4444
HOST_TESTS_DIR host_tests
4545
)
4646

47+
if(NOT "DEVICE_I2CSLAVE=1" IN_LIST MBED_TARGET_DEFINITIONS)
48+
set(I2C_SLAVE_TEST_SKIPPED "No I2C slave support")
49+
endif()
4750
mbed_greentea_add_test(
4851
TEST_NAME testshield-i2c-slave-comms
4952
TEST_SOURCES I2CSlaveCommsTest.cpp
5053
HOST_TESTS_DIR host_tests
54+
TEST_SKIPPED ${I2C_SLAVE_TEST_SKIPPED}
5155
)
5256

5357
mbed_greentea_add_test(
@@ -70,10 +74,14 @@ mbed_greentea_add_test(
7074
HOST_TESTS_DIR host_tests
7175
)
7276

77+
if(NOT "DEVICE_SPISLAVE=1" IN_LIST MBED_TARGET_DEFINITIONS)
78+
set(SPI_SLAVE_TEST_SKIPPED "No SPI slave support")
79+
endif()
7380
mbed_greentea_add_test(
7481
TEST_NAME testshield-spi-slave-comms
7582
TEST_SOURCES SPISlaveCommsTest.cpp
7683
HOST_TESTS_DIR host_tests
84+
TEST_SKIPPED ${SPI_SLAVE_TEST_SKIPPED}
7785
)
7886

7987
mbed_greentea_add_test(

CI-Shield-Tests/InterruptInTest.cpp

Lines changed: 95 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,61 +23,130 @@
2323
#include "unity.h"
2424
#include "utest.h"
2525
#include "ci_test_common.h"
26-
//#include "rtos.h"
26+
27+
#include <atomic>
28+
#include <cinttypes>
2729

2830
using namespace utest::v1;
2931

30-
volatile bool result = false;
32+
std::atomic<uint32_t> callbackCounts;
3133

3234
// Callback for all InterruptInput functions
3335
void cbfn(void)
3436
{
35-
result = true;
37+
++callbackCounts;
3638
}
3739

3840
// Template to check Falling edge and Rising edge interrupts.
3941
template <PinName int_pin, PinName dout_pin>
4042
void InterruptInTest()
4143
{
42-
result = false;
44+
callbackCounts = 0;
4345
InterruptIn intin(int_pin);
44-
DigitalOut dout(dout_pin);
46+
DigitalOut dout(dout_pin, 0);
4547

4648
// Test Rising Edge InterruptIn
4749
DEBUG_PRINTF("***** Rising Edge Test \n");
48-
dout = 0;
49-
result = false;
5050
intin.rise(cbfn);
5151
dout = 1;
5252
wait_us(GPIO_PROPAGATION_TIME);
53-
DEBUG_PRINTF("Value of result is : %d\n",result);
54-
TEST_ASSERT_MESSAGE(result,"cbfn was not triggered on rising edge of pin");
55-
56-
result = false;
53+
DEBUG_PRINTF("Value of callbackCounts is: %" PRIu32 "\n", callbackCounts.load());
54+
TEST_ASSERT_MESSAGE(callbackCounts == 1, "cbfn was not triggered on rising edge of pin");
5755

5856
// Check that callback is not triggered again
5957
for(size_t checkCounter = 0; checkCounter < 10; ++checkCounter)
6058
{
61-
TEST_ASSERT_MESSAGE(!result, "Interrupt was triggered again!")
59+
TEST_ASSERT_MESSAGE(callbackCounts == 1, "Interrupt was triggered again!")
6260
}
6361

62+
dout = 0;
63+
wait_us(GPIO_PROPAGATION_TIME);
64+
TEST_ASSERT_MESSAGE(callbackCounts == 1, "cbfn was triggered on falling edge of pin");
65+
66+
// Clear rising edge interrupt
67+
intin.rise(nullptr);
68+
6469
// Test Falling Edge InterruptIn
6570
DEBUG_PRINTF("***** Falling Edge Test \n");
6671
dout = 1;
67-
result = false;
72+
callbackCounts = 0;
6873
intin.fall(cbfn);
6974
dout = 0;
7075
wait_us(GPIO_PROPAGATION_TIME);
71-
DEBUG_PRINTF("Value of result is : %d\n",result);
72-
TEST_ASSERT_MESSAGE(result,"cbfn was not triggered on falling edge of pin");
73-
74-
result = false;
76+
DEBUG_PRINTF("Value of callbackCounts is: %" PRIu32 "\n", callbackCounts.load());
77+
TEST_ASSERT_MESSAGE(callbackCounts == 1, "cbfn was not triggered on falling edge of pin");
7578

7679
// Check that callback is not triggered again
7780
for(size_t checkCounter = 0; checkCounter < 10; ++checkCounter)
7881
{
79-
TEST_ASSERT_MESSAGE(!result, "Interrupt was triggered again!")
82+
TEST_ASSERT_MESSAGE(callbackCounts == 1, "Interrupt was triggered again!")
8083
}
84+
85+
dout = 1;
86+
wait_us(GPIO_PROPAGATION_TIME);
87+
TEST_ASSERT_MESSAGE(callbackCounts == 1, "cbfn was triggered on rising edge of pin");
88+
89+
// Clear falling edge interrupt
90+
intin.fall(nullptr);
91+
}
92+
93+
// Test that a rising and falling edge callback can both be set at the same time,
94+
// and the correct one will be executed depending on the edge type
95+
template <PinName int_pin, PinName dout_pin>
96+
void InterruptInBothEdgesTest()
97+
{
98+
std::atomic<bool> gotRisingEdge = false;
99+
std::atomic<bool> gotFallingEdge = false;
100+
101+
auto risingEdgeLambda = [&](){ gotRisingEdge = true; };
102+
auto fallingEdgeLambda = [&](){ gotFallingEdge = true; };
103+
104+
InterruptIn intin(int_pin);
105+
DigitalOut dout(dout_pin, 0);
106+
107+
intin.fall(fallingEdgeLambda);
108+
intin.rise(risingEdgeLambda);
109+
110+
DEBUG_PRINTF("***** Rising Edge Test \n");
111+
dout = 1;
112+
wait_us(GPIO_PROPAGATION_TIME);
113+
114+
TEST_ASSERT_MESSAGE(gotRisingEdge, "rising edge callback was not triggered on rising edge of pin");
115+
TEST_ASSERT_MESSAGE(!gotFallingEdge, "falling edge callback was triggered on rising edge of pin!");
116+
117+
gotRisingEdge = false;
118+
119+
DEBUG_PRINTF("***** Falling Edge Test \n");
120+
dout = 0;
121+
wait_us(GPIO_PROPAGATION_TIME);
122+
123+
TEST_ASSERT_MESSAGE(gotFallingEdge, "falling edge callback was not triggered on falling edge of pin");
124+
TEST_ASSERT_MESSAGE(!gotRisingEdge, "rising edge callback was triggered on falling edge of pin!");
125+
}
126+
127+
template <PinName int_pin, PinName dout_pin>
128+
void InterruptInReadValueTest()
129+
{
130+
InterruptIn intin(int_pin);
131+
DigitalOut dout(dout_pin, 0);
132+
133+
dout = 1;
134+
wait_us(GPIO_PROPAGATION_TIME);
135+
TEST_ASSERT_MESSAGE(intin.read(), "InterruptIn read failed with no callback!");
136+
137+
dout = 0;
138+
wait_us(GPIO_PROPAGATION_TIME);
139+
TEST_ASSERT_MESSAGE(!intin.read(), "InterruptIn read failed with no callback!");
140+
141+
intin.rise(cbfn);
142+
143+
dout = 1;
144+
wait_us(GPIO_PROPAGATION_TIME);
145+
TEST_ASSERT_MESSAGE(intin.read(), "InterruptIn read failed with callback!");
146+
147+
dout = 0;
148+
wait_us(GPIO_PROPAGATION_TIME);
149+
TEST_ASSERT_MESSAGE(!intin.read(), "InterruptIn read failed with callback!");
81150
}
82151

83152
utest::v1::status_t test_setup(const size_t number_of_cases)
@@ -102,12 +171,15 @@ utest::v1::status_t greentea_failure_handler(const Case *const source, const fai
102171

103172
// Test cases
104173
Case cases[] = {
105-
Case("Interrupt from GPOUT_2 -> GPIN_2", InterruptInTest<PIN_GPIN_2,PIN_GPOUT_2>,greentea_failure_handler),
106-
Case("Interrupt from GPIN_2 -> GPOUT_2", InterruptInTest<PIN_GPOUT_2,PIN_GPIN_2>,greentea_failure_handler),
107-
Case("Interrupt from GPOUT_1 -> GPIN_1", InterruptInTest<PIN_GPIN_1,PIN_GPOUT_1_PWM>,greentea_failure_handler),
174+
// Case("Interrupt from GPOUT_2 -> GPIN_2", InterruptInTest<PIN_GPIN_2,PIN_GPOUT_2>,greentea_failure_handler),
175+
// Case("Interrupt from GPIN_2 -> GPOUT_2", InterruptInTest<PIN_GPOUT_2,PIN_GPIN_2>,greentea_failure_handler),
176+
// Case("Interrupt from GPOUT_1 -> GPIN_1", InterruptInTest<PIN_GPIN_1,PIN_GPOUT_1_PWM>,greentea_failure_handler),
108177
Case("Interrupt from GPIN_1 -> GPOUT_1", InterruptInTest<PIN_GPOUT_1_PWM,PIN_GPIN_1>,greentea_failure_handler),
109-
Case("Interrupt from GPOUT_0 -> GPIN_0", InterruptInTest<PIN_GPIN_0,PIN_GPOUT_0>,greentea_failure_handler),
110-
Case("Interrupt from GPIN_0 -> GPOUT_0", InterruptInTest<PIN_GPOUT_0,PIN_GPIN_0>,greentea_failure_handler),
178+
// Case("Interrupt from GPOUT_0 -> GPIN_0", InterruptInTest<PIN_GPIN_0,PIN_GPOUT_0>,greentea_failure_handler),
179+
// Case("Interrupt from GPIN_0 -> GPOUT_0", InterruptInTest<PIN_GPOUT_0,PIN_GPIN_0>,greentea_failure_handler),
180+
181+
Case("InterruptIn Both Edges", InterruptInBothEdgesTest<PIN_GPIN_0,PIN_GPOUT_0>, greentea_failure_handler),
182+
Case("InterruptIn Read Value", InterruptInReadValueTest<PIN_GPIN_0,PIN_GPOUT_0>, greentea_failure_handler),
111183
};
112184

113185
Specification specification(test_setup, cases);

CI-Shield-Tests/PWMAndADCTest.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ std::pair<float, float> read_freq_and_duty_cycle_via_host_test()
7373
}
7474

7575
/*
76-
* Generate a failure if the HAL does not provide the new DEVICE_SPI_COUNT /
77-
* spi_get_peripheral_name() functionality.
78-
* See https://github.com/mbed-ce/mbed-os/issues/255 for details.
76+
* Generate a failure if this target's JSON does not set the target.default-adc-vref option
7977
*/
8078
void verify_target_default_adc_vref_set()
8179
{

CI-Shield-Tests/SPIBasicTest.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ void host_assert_standard_message()
145145
void verify_spi_get_peripheral_name_exists()
146146
{
147147
#ifndef DEVICE_SPI_COUNT
148-
TEST_FAIL_MESSAGE("HAL should provide DEVICE_SPI_COUNT and spi_get_peripheral_name()")
148+
TEST_FAIL_MESSAGE("HAL should provide DEVICE_SPI_COUNT and spi_get_peripheral_name()");
149149
#endif
150150
}
151151

@@ -172,7 +172,7 @@ void write_single_word_uint8()
172172
*/
173173
void write_single_word_uint16()
174174
{
175-
TEST_SKIP_UNLESS(supportsThisWordSize<uint16_t>());
175+
TEST_SKIP_UNLESS_MESSAGE(supportsThisWordSize<uint16_t>(), "16-bit SPI words not supported");
176176

177177
host_start_spi_logging();
178178

@@ -467,6 +467,11 @@ void async_queue_and_abort()
467467
// Allow the second transfer to run to completion
468468
rtos::ThisThread::sleep_for(10ms);
469469

470+
// The first transfer should have delivered no flags.
471+
// The second transfer should have delivered a completion flag.
472+
TEST_ASSERT_EQUAL(0, callbackEvent1);
473+
TEST_ASSERT_EQUAL(SPI_EVENT_COMPLETE, callbackEvent2);
474+
470475
// The first transfer should have been canceled after writing at least one byte but before filling the entire Rx buffer
471476
size_t testPatternCountBuf1 = std::count(logMessageRxData1.begin(), logMessageRxData1.end(), TEST_PATTERN);
472477
// Depending on DMA behavior, some or none of the bytes may have been written back to the buffer.
@@ -477,10 +482,6 @@ void async_queue_and_abort()
477482
size_t testPatternCountBuf2 = std::count(logMessageRxData2.begin(), logMessageRxData2.end(), TEST_PATTERN);
478483
TEST_ASSERT_EQUAL(0, testPatternCountBuf2);
479484

480-
// The first transfer should have delivered no flags.
481-
// The second transfer should have delivered a completion flag.
482-
TEST_ASSERT_EQUAL(0, callbackEvent1);
483-
TEST_ASSERT_EQUAL(SPI_EVENT_COMPLETE, callbackEvent2);
484485

485486
greentea_send_kv("verify_queue_and_abort_test", "please");
486487
assert_next_message_from_host("verify_queue_and_abort_test", "pass");

CI-Shield-Tests/SPIMicroSDTest.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ void test_sd_file()
199199
// sizeof(SD_TEST_STRING) - 1 chars.
200200
char read_string[SD_TEST_STRING_MAX] = {0};
201201
file = fopen("/sd/test_sd_w.txt", "r");
202-
TEST_ASSERT_MESSAGE(file != nullptr,"Failed to open file");
202+
if(!file)
203+
{
204+
TEST_FAIL_MESSAGE("Failed to open file");
205+
return;
206+
}
203207

204208
ret = fread(read_string, sizeof(char), sizeof(SD_TEST_STRING) - 1, file);
205209
TEST_ASSERT_MESSAGE(ret == (sizeof(SD_TEST_STRING) - 1), "Failed to read data");
@@ -252,12 +256,12 @@ Case cases[] = {
252256
Case("SPI - Write, Read, and Delete File (100kHz)", test_sd_file<100000, false, DMA_USAGE_NEVER>),
253257

254258
#if DEVICE_SPI_ASYNCH
255-
Case("[Async Interrupts] SPI - SD card present (1MHz)", test_card_present<1000000, true, DMA_USAGE_NEVER>),
256-
Case("[Async Interrupts] SPI - Mount FS, Create File (1MHz)", mount_fs_create_file<1000000, true, DMA_USAGE_NEVER>),
257-
Case("[Async Interrupts] SPI - Write, Read, and Delete File (1MHz)", test_sd_file<1000000, true, DMA_USAGE_NEVER>),
258259
Case("[Async DMA] SPI - SD card present (1MHz)", test_card_present<1000000, true, DMA_USAGE_ALWAYS>),
259260
Case("[Async DMA] SPI - Mount FS, Create File (1MHz)", mount_fs_create_file<1000000, true, DMA_USAGE_ALWAYS>),
260261
Case("[Async DMA] SPI - Write, Read, and Delete File (1MHz)", test_sd_file<1000000, true, DMA_USAGE_ALWAYS>),
262+
Case("[Async Interrupts] SPI - SD card present (1MHz)", test_card_present<1000000, true, DMA_USAGE_NEVER>),
263+
Case("[Async Interrupts] SPI - Mount FS, Create File (1MHz)", mount_fs_create_file<1000000, true, DMA_USAGE_NEVER>),
264+
Case("[Async Interrupts] SPI - Write, Read, and Delete File (1MHz)", test_sd_file<1000000, true, DMA_USAGE_NEVER>),
261265
#endif
262266
};
263267

CI-Shield-Tests/mbed_app.json5

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
"platform.stdio-buffered-serial": 1,
66
"target.components_add" : ["SD", "I2CEE"],
77
"sd.CRC_ENABLED": 1,
8-
"drivers.spi_transaction_queue_len": 3
8+
"drivers.spi_transaction_queue_len": 3,
9+
10+
// Don't auto reboot on error, it makes debugging harder
11+
"fatal-error-auto-reboot-enabled": false,
12+
13+
// Emit a KV pair when an assert fail or hardfault occurs
14+
"platform.mbed-error-emit-greentea-kv": true,
915
},
1016
"STM32L452xE": {
1117
// This was added because not using it seemed to cause intermittent

0 commit comments

Comments
 (0)