Merge pull request #12378 from jamesbeyond/test_update

TEST: Refactor mbedmicro tests to use utest framework
pull/12431/head
Martin Kojtal 2020-02-13 08:16:13 +00:00 committed by GitHub
commit f502b4166e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 109 additions and 44 deletions

View File

@ -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.
@ -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 = 5;
namespace {
bool mbed_main_called = false;
@ -21,13 +30,31 @@ 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);
}

View File

@ -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.
@ -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
@ -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();
if (m->check_init() == false) {
result = false;
}
delete m;
break;
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");
}
GREENTEA_TESTSUITE_RESULT(result);
}
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);
}
utest::v1::Specification specification(greentea_test_setup, cases);
int main()
{
return !utest::v1::Harness::run(specification);
}

View File

@ -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.
@ -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)
{
@ -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);
}