Skip to content

Commit

Permalink
Update mbed unit testing example
Browse files Browse the repository at this point in the history
Refactoring according to the latest changes in Mbed OS6
  • Loading branch information
valeros committed Jul 28, 2020
1 parent c3f6d1f commit f0f4e09
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
11 changes: 11 additions & 0 deletions unit-testing/mbed-blink/mbed_app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"requires": ["bare-metal"],
"target_overrides": {
"*": {
"target.c_lib": "small",
"target.printf_lib": "minimal-printf",
"platform.minimal-printf-enable-floating-point": false,
"platform.stdio-minimal-console-only": true
}
}
}
7 changes: 7 additions & 0 deletions unit-testing/mbed-blink/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@
platform = ststm32
framework = mbed
board = nucleo_f401re

[env:nucleo_f401re_legacy]
platform = ststm32
framework = mbed
board = nucleo_f401re
platform_packages =
framework-mbed @ ~6.51504.0
23 changes: 12 additions & 11 deletions unit-testing/mbed-blink/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/*
* Blink
* Turns on an LED on for one second,
* then off for one second, repeatedly.
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*/

#include "mbed.h"

DigitalOut myled(LED1);
#define WAIT_TIME_MS 500

int main() {
while(1) {
myled = 1;
wait(1);
myled = 0;
wait(1);
DigitalOut led1(LED1);

int main()
{
while (true)
{
led1 = !led1;
thread_sleep_for(WAIT_TIME_MS);
}
}
10 changes: 5 additions & 5 deletions unit-testing/mbed-blink/test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ DigitalOut myled(LED1);
// }

void test_pin_is_connected(void) {
TEST_ASSERT_EQUAL(myled.is_connected(), 1);
TEST_ASSERT_EQUAL(1, myled.is_connected());
}

void test_led_state_high(void) {
myled.write(1);
TEST_ASSERT_EQUAL(myled.read(), 1);
TEST_ASSERT_EQUAL(1, myled.read());
}

void test_led_state_low(void) {
myled.write(0);
TEST_ASSERT_EQUAL(myled.read(), 0);
TEST_ASSERT_EQUAL(0, myled.read());
}

int main() {
Expand All @@ -47,9 +47,9 @@ int main() {

for (int i = 0; i < 5; ++i){
RUN_TEST(test_led_state_high);
wait_ms(500);
thread_sleep_for(500);
RUN_TEST(test_led_state_low);
wait_ms(500);
thread_sleep_for(500);
i++;
}

Expand Down

0 comments on commit f0f4e09

Please sign in to comment.