Skip to content

TEST: Refactor mbedmicro tests to use utest framework #12378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions TESTS/mbedmicro-mbed/call_before_main/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
* Copyright (c) 2017-2020 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,21 +15,46 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "utest/utest.h"
#include "unity/unity.h"

using utest::v1::Case;

static const int test_timeout = 5;

namespace {
bool mbed_main_called = false;
}

extern "C" void mbed_main()
{
printf("MBED: mbed_main() call before main()\r\n");
utest_printf("MBED: mbed_main() call before main()\r\n");
mbed_main_called = true;
}

void test_call_before_main(void)
{

utest_printf("MBED: main() starts now!\r\n");
TEST_ASSERT_MESSAGE(mbed_main_called, "mbed_main didn't called before main");
}

// Test cases
Case cases[] = {
Case("Test mbed_main called before main ", test_call_before_main),
};

utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(test_timeout, "default_auto");
return utest::v1::greentea_test_setup_handler(number_of_cases);
}

utest::v1::Specification specification(greentea_test_setup, cases);

int main()
{
GREENTEA_SETUP(5, "default_auto");
printf("MBED: main() starts now!\r\n");
GREENTEA_TESTSUITE_RESULT(mbed_main_called);
return !utest::v1::Harness::run(specification);
}
66 changes: 44 additions & 22 deletions TESTS/mbedmicro-mbed/cpp/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
* Copyright (c) 2017-2020 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,7 +15,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "utest/utest.h"
#include "unity/unity.h"

using utest::v1::Case;

static const int test_timeout = 10;

#define PATTERN_CHECK_VALUE 0xF0F0ADAD

Expand Down Expand Up @@ -76,30 +85,43 @@ Heap::init
Heap::hello
Heap::destroy
*******************/
int main(void)
void test_static(void)
{
GREENTEA_SETUP(10, "default_auto");

bool result = true;
for (;;) {
s.print("init");
// Global stack object simple test
s.stack_test();
if (s.check_init() == false) {
result = false;
break;
}

// Heap test object simple test
Test *m = new Test("Heap");
m->hello();
s.print("init");
// Global stack object simple test
s.stack_test();
if (s.check_init() == false) {
TEST_ASSERT_MESSAGE(false, "Global stack initialization check failed");
}

if (m->check_init() == false) {
result = false;
}
delete m;
break;
}

void test_heap(void)
{
// Heap test object simple test
Test *m = new Test("Heap");
m->hello();
if (m->check_init() == false) {
TEST_ASSERT_MESSAGE(false, "Heap object initialization check failed");
}
}

// Test cases
Case cases[] = {
Case("Test stack object", test_static),
Case("Test heap object", test_heap),
};

utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(test_timeout, "default_auto");
return utest::v1::greentea_test_setup_handler(number_of_cases);
}

GREENTEA_TESTSUITE_RESULT(result);
utest::v1::Specification specification(greentea_test_setup, cases);

int main()
{
return !utest::v1::Harness::run(specification);
}
48 changes: 32 additions & 16 deletions TESTS/mbedmicro-mbed/div/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* mbed Microcontroller Library
* Copyright (c) 2017 ARM Limited
* Copyright (c) 2017-2020 ARM Limited
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +18,12 @@
#include <utility> // std::pair
#include "mbed.h"
#include "greentea-client/test_env.h"
#include "utest/utest.h"
#include "unity/unity.h"

using utest::v1::Case;

static const int test_timeout = 5;

uint32_t test_64(uint64_t ticks)
{
Expand All @@ -28,34 +36,42 @@ uint32_t test_64(uint64_t ticks)
return (uint32_t)(0xFFFFFFFF & ticks);
}

const char *result_str(bool result)
{
return result ? "[OK]" : "[FAIL]";
}

int main()
void test_division(void)
{
GREENTEA_SETUP(5, "default_auto");

bool result = true;

{
// 0xFFFFFFFF * 8 = 0x7fffffff8
std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
uint32_t test_ret = test_64(values.second);
bool test_res = values.first == test_ret;
result = result && test_res;
printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
utest_printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX \r\n", values.first, test_ret);
TEST_ASSERT_EQUAL_UINT32(values.first, test_ret);
}

{
// 0xFFFFFFFF * 24 = 0x17ffffffe8
std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
uint32_t test_ret = test_64(values.second);
bool test_res = values.first == test_ret;
result = result && test_res;
printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
utest_printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX \r\n", values.first, test_ret);
TEST_ASSERT_EQUAL_UINT32(values.first, test_ret);
}

GREENTEA_TESTSUITE_RESULT(result);
}

// Test cases
Case cases[] = {
Case("Test division", test_division),
};

utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(test_timeout, "default_auto");
return utest::v1::greentea_test_setup_handler(number_of_cases);
}

utest::v1::Specification specification(greentea_test_setup, cases);

int main()
{
return !utest::v1::Harness::run(specification);
}