mirror of https://github.com/ARMmbed/mbed-os.git
TEST: Refactor mbedmicro tests to use utest framework
parent
0b7c78be8a
commit
c37df2efca
|
@ -13,7 +13,14 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include "mbed.h"
|
||||||
#include "greentea-client/test_env.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 {
|
namespace {
|
||||||
bool mbed_main_called = false;
|
bool mbed_main_called = false;
|
||||||
|
@ -21,13 +28,31 @@ bool mbed_main_called = false;
|
||||||
|
|
||||||
extern "C" void mbed_main()
|
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;
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
GREENTEA_SETUP(5, "default_auto");
|
return !utest::v1::Harness::run(specification);
|
||||||
printf("MBED: main() starts now!\r\n");
|
|
||||||
GREENTEA_TESTSUITE_RESULT(mbed_main_called);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,14 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
#include "mbed.h"
|
||||||
#include "greentea-client/test_env.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
|
#define PATTERN_CHECK_VALUE 0xF0F0ADAD
|
||||||
|
|
||||||
|
@ -76,30 +83,43 @@ Heap::init
|
||||||
Heap::hello
|
Heap::hello
|
||||||
Heap::destroy
|
Heap::destroy
|
||||||
*******************/
|
*******************/
|
||||||
int main(void)
|
void test_static(void)
|
||||||
{
|
{
|
||||||
GREENTEA_SETUP(10, "default_auto");
|
|
||||||
|
|
||||||
bool result = true;
|
s.print("init");
|
||||||
for (;;) {
|
// Global stack object simple test
|
||||||
s.print("init");
|
s.stack_test();
|
||||||
// Global stack object simple test
|
if (s.check_init() == false) {
|
||||||
s.stack_test();
|
TEST_ASSERT_MESSAGE(false, "Global stack initialization check failed");
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,12 @@
|
||||||
#include <utility> // std::pair
|
#include <utility> // std::pair
|
||||||
#include "mbed.h"
|
#include "mbed.h"
|
||||||
#include "greentea-client/test_env.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)
|
uint32_t test_64(uint64_t ticks)
|
||||||
{
|
{
|
||||||
|
@ -28,34 +34,42 @@ uint32_t test_64(uint64_t ticks)
|
||||||
return (uint32_t)(0xFFFFFFFF & 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
|
// 0xFFFFFFFF * 8 = 0x7fffffff8
|
||||||
std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
|
std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
|
||||||
uint32_t test_ret = test_64(values.second);
|
uint32_t test_ret = test_64(values.second);
|
||||||
bool test_res = values.first == test_ret;
|
utest_printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX \r\n", values.first, test_ret);
|
||||||
result = result && test_res;
|
TEST_ASSERT_EQUAL_UINT32(values.first, test_ret);
|
||||||
printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
// 0xFFFFFFFF * 24 = 0x17ffffffe8
|
// 0xFFFFFFFF * 24 = 0x17ffffffe8
|
||||||
std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
|
std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
|
||||||
uint32_t test_ret = test_64(values.second);
|
uint32_t test_ret = test_64(values.second);
|
||||||
bool test_res = values.first == test_ret;
|
utest_printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX \r\n", values.first, test_ret);
|
||||||
result = result && test_res;
|
TEST_ASSERT_EQUAL_UINT32(values.first, test_ret);
|
||||||
printf("64bit: 0x17FFFFFFE8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(test_res));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue