mirror of https://github.com/ARMmbed/mbed-os.git
Add few non-peripheral tests from mbedmicro/mbed/libraries/tests/mbed
Tested on K64F: ``` $ mbedgt -VS -n TESTS-mbedmicro-mbed* ``` ``` mbedgt: test suite report: +--------------+---------------+---------------------------------------+--------+--------------------+-------------+ | target | platform_name | test suite | result | elapsed_time (sec) | copy_method | +--------------+---------------+---------------------------------------+--------+--------------------+-------------+ | K64F-GCC_ARM | K64F | tests-mbedmicro-mbed-call_before_main | OK | 10.53 | shell | | K64F-GCC_ARM | K64F | tests-mbedmicro-mbed-cpp | OK | 10.64 | shell | | K64F-GCC_ARM | K64F | tests-mbedmicro-mbed-div | OK | 10.64 | shell | | K64F-GCC_ARM | K64F | tests-mbedmicro-mbed-heap_and_stack | OK | 30.32 | shell | +--------------+---------------+---------------------------------------+--------+--------------------+-------------+ mbedgt: test suite results: 4 OK mbedgt: test case report: +--------------+---------------+---------------------------------------+---------------------------------------+--------+--------+--------+--------------------+ | target | platform_name | test suite | test case | passed | failed | result | elapsed_time (sec) | +--------------+---------------+---------------------------------------+---------------------------------------+--------+--------+--------+--------------------+ | K64F-GCC_ARM | K64F | tests-mbedmicro-mbed-call_before_main | tests-mbedmicro-mbed-call_before_main | 1 | 0 | OK | 10.53 | | K64F-GCC_ARM | K64F | tests-mbedmicro-mbed-cpp | tests-mbedmicro-mbed-cpp | 1 | 0 | OK | 10.64 | | K64F-GCC_ARM | K64F | tests-mbedmicro-mbed-div | tests-mbedmicro-mbed-div | 1 | 0 | OK | 10.64 | | K64F-GCC_ARM | K64F | tests-mbedmicro-mbed-heap_and_stack | tests-mbedmicro-mbed-heap_and_stack | 1 | 0 | OK | 30.32 | +--------------+---------------+---------------------------------------+---------------------------------------+--------+--------+--------+--------------------+ mbedgt: test case results: 4 OK mbedgt: completed in 62.25 sec ```
parent
68b0b7b9cd
commit
3b3745e008
|
@ -0,0 +1,16 @@
|
||||||
|
#include "greentea-client/test_env.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
bool mbed_main_called = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" void mbed_main() {
|
||||||
|
printf("MBED: mbed_main() call before main()\r\n");
|
||||||
|
mbed_main_called = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
GREENTEA_SETUP(5, "default_auto");
|
||||||
|
printf("MBED: main() starts now!\r\n");
|
||||||
|
GREENTEA_TESTSUITE_RESULT(mbed_main_called);
|
||||||
|
}
|
|
@ -0,0 +1,83 @@
|
||||||
|
#include "greentea-client/test_env.h"
|
||||||
|
|
||||||
|
#define PATTERN_CHECK_VALUE 0xF0F0ADAD
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* name;
|
||||||
|
const int pattern;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Test(const char* _name) : name(_name), pattern(PATTERN_CHECK_VALUE) {
|
||||||
|
print("init");
|
||||||
|
}
|
||||||
|
|
||||||
|
void print(const char *message) {
|
||||||
|
printf("%s::%s\n", name, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool check_init(void) {
|
||||||
|
bool result = (pattern == PATTERN_CHECK_VALUE);
|
||||||
|
print(result ? "check_init: OK" : "check_init: ERROR");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void stack_test(void) {
|
||||||
|
print("stack_test");
|
||||||
|
Test t("Stack");
|
||||||
|
t.hello();
|
||||||
|
}
|
||||||
|
|
||||||
|
void hello(void) {
|
||||||
|
print("hello");
|
||||||
|
}
|
||||||
|
|
||||||
|
~Test() {
|
||||||
|
print("destroy");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Check C++ startup initialisation */
|
||||||
|
Test s("Static");
|
||||||
|
|
||||||
|
/* EXPECTED OUTPUT:
|
||||||
|
*******************
|
||||||
|
Static::init
|
||||||
|
Static::stack_test
|
||||||
|
Stack::init
|
||||||
|
Stack::hello
|
||||||
|
Stack::destroy
|
||||||
|
Static::check_init: OK
|
||||||
|
Heap::init
|
||||||
|
Heap::hello
|
||||||
|
Heap::destroy
|
||||||
|
*******************/
|
||||||
|
int main (void) {
|
||||||
|
GREENTEA_SETUP(10, "default_auto");
|
||||||
|
|
||||||
|
bool result = true;
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
GREENTEA_TESTSUITE_RESULT(result);
|
||||||
|
}
|
|
@ -0,0 +1,41 @@
|
||||||
|
#include <utility> // std::pair
|
||||||
|
#include "mbed.h"
|
||||||
|
#include "greentea-client/test_env.h"
|
||||||
|
|
||||||
|
uint32_t test_64(uint64_t ticks) {
|
||||||
|
ticks >>= 3; // divide by 8
|
||||||
|
if (ticks > 0xFFFFFFFF) {
|
||||||
|
ticks /= 3;
|
||||||
|
} else {
|
||||||
|
ticks = (ticks * 0x55555556) >> 32; // divide by 3
|
||||||
|
}
|
||||||
|
return (uint32_t)(0xFFFFFFFF & ticks);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *result_str(bool result) {
|
||||||
|
return result ? "[OK]" : "[FAIL]";
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
{ // 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
GREENTEA_TESTSUITE_RESULT(result);
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "greentea-client/test_env.h"
|
||||||
|
|
||||||
|
static char *initial_stack_p;
|
||||||
|
static char *initial_heap_p;
|
||||||
|
|
||||||
|
static char line[256];
|
||||||
|
static unsigned int iterations = 0;
|
||||||
|
|
||||||
|
void report_iterations(void) {
|
||||||
|
unsigned int tot = (0x100 * iterations)*2;
|
||||||
|
printf("\nAllocated (%d)Kb in (%u) iterations\n", tot/1024, iterations);
|
||||||
|
#if !defined(TOOLCHAIN_GCC_CR)
|
||||||
|
// EA: This causes a crash when compiling with GCC_CR???
|
||||||
|
printf("%.2f\n", ((float)(tot)/(float)(initial_stack_p - initial_heap_p))*100.);
|
||||||
|
#endif
|
||||||
|
#ifdef TOOLCHAIN_ARM
|
||||||
|
#ifndef __MICROLIB
|
||||||
|
__heapvalid((__heapprt) fprintf, stdout, 1);
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void stack_test(char *latest_heap_pointer) {
|
||||||
|
char stack_line[256];
|
||||||
|
iterations++;
|
||||||
|
|
||||||
|
sprintf(stack_line, "\nstack pointer: %p", &stack_line[255]);
|
||||||
|
puts(stack_line);
|
||||||
|
|
||||||
|
char *heap_pointer = (char*)malloc(0x100);
|
||||||
|
|
||||||
|
if (heap_pointer == NULL) {
|
||||||
|
int diff = (&stack_line[255] - latest_heap_pointer);
|
||||||
|
if (diff > 0x200) {
|
||||||
|
sprintf(stack_line, "\n[WARNING] Malloc failed to allocate memory too soon. There are (0x%x) free bytes", diff);
|
||||||
|
report_iterations();
|
||||||
|
puts(stack_line);
|
||||||
|
} else {
|
||||||
|
puts("\n[SUCCESS] Stack/Heap collision detected");
|
||||||
|
report_iterations();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
heap_pointer += 0x100;
|
||||||
|
sprintf(line, "heap pointer: %p", heap_pointer);
|
||||||
|
puts(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((&stack_line[255]) > heap_pointer) {
|
||||||
|
stack_test(heap_pointer);
|
||||||
|
} else {
|
||||||
|
puts("\n[WARNING] The Stack/Heap collision was not detected");
|
||||||
|
report_iterations();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main (void) {
|
||||||
|
GREENTEA_SETUP(30, "default_auto");
|
||||||
|
|
||||||
|
char c;
|
||||||
|
initial_stack_p = &c;
|
||||||
|
|
||||||
|
initial_heap_p = (char*)malloc(1);
|
||||||
|
if (initial_heap_p == NULL) {
|
||||||
|
printf("Unable to malloc a single byte\n");
|
||||||
|
GREENTEA_TESTSUITE_RESULT(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Initial stack/heap geometry:\n");
|
||||||
|
printf(" stack pointer:V %p\n", initial_stack_p);
|
||||||
|
printf(" heap pointer :^ %p\n", initial_heap_p);
|
||||||
|
|
||||||
|
initial_heap_p++;
|
||||||
|
stack_test(initial_heap_p);
|
||||||
|
|
||||||
|
GREENTEA_TESTSUITE_RESULT(true);
|
||||||
|
}
|
Loading…
Reference in New Issue