tests: astyle fix

All tests should comply to our coding standard now
pull/7605/head
Martin Kojtal 2018-07-27 10:17:07 +01:00
parent 8f7024a226
commit e52bb68f93
110 changed files with 2958 additions and 2025 deletions

View File

@ -21,7 +21,7 @@
#include "utest.h" #include "utest.h"
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using namespace utest::v1; using namespace utest::v1;
@ -38,32 +38,38 @@ using namespace utest::v1;
volatile bool touched = false; volatile bool touched = false;
// static functions // static functions
void func5(int a0, int a1, int a2, int a3, int a4) { void func5(int a0, int a1, int a2, int a3, int a4)
{
touched = true; touched = true;
TEST_ASSERT_EQUAL(a0 | a1 | a2 | a3 | a4, 0x1f); TEST_ASSERT_EQUAL(a0 | a1 | a2 | a3 | a4, 0x1f);
} }
void func4(int a0, int a1, int a2, int a3) { void func4(int a0, int a1, int a2, int a3)
{
touched = true; touched = true;
TEST_ASSERT_EQUAL(a0 | a1 | a2 | a3, 0xf); TEST_ASSERT_EQUAL(a0 | a1 | a2 | a3, 0xf);
} }
void func3(int a0, int a1, int a2) { void func3(int a0, int a1, int a2)
{
touched = true; touched = true;
TEST_ASSERT_EQUAL(a0 | a1 | a2, 0x7); TEST_ASSERT_EQUAL(a0 | a1 | a2, 0x7);
} }
void func2(int a0, int a1) { void func2(int a0, int a1)
{
touched = true; touched = true;
TEST_ASSERT_EQUAL(a0 | a1, 0x3); TEST_ASSERT_EQUAL(a0 | a1, 0x3);
} }
void func1(int a0) { void func1(int a0)
{
touched = true; touched = true;
TEST_ASSERT_EQUAL(a0, 0x1); TEST_ASSERT_EQUAL(a0, 0x1);
} }
void func0() { void func0()
{
touched = true; touched = true;
} }
@ -95,40 +101,44 @@ SIMPLE_POSTS_TEST(1, 0x01)
SIMPLE_POSTS_TEST(0) SIMPLE_POSTS_TEST(0)
void time_func(Timer *t, int ms) { void time_func(Timer *t, int ms)
{
TEST_ASSERT_INT_WITHIN(DELTA(ms), ms, t->read_ms()); TEST_ASSERT_INT_WITHIN(DELTA(ms), ms, t->read_ms());
t->reset(); t->reset();
} }
template <int N> template <int N>
void call_in_test() { void call_in_test()
{
Timer tickers[N]; Timer tickers[N];
EventQueue queue(TEST_EQUEUE_SIZE); EventQueue queue(TEST_EQUEUE_SIZE);
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
tickers[i].start(); tickers[i].start();
queue.call_in((i+1)*100, time_func, &tickers[i], (i+1)*100); queue.call_in((i + 1) * 100, time_func, &tickers[i], (i + 1) * 100);
} }
queue.dispatch(N*100); queue.dispatch(N * 100);
} }
template <int N> template <int N>
void call_every_test() { void call_every_test()
{
Timer tickers[N]; Timer tickers[N];
EventQueue queue(TEST_EQUEUE_SIZE); EventQueue queue(TEST_EQUEUE_SIZE);
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
tickers[i].start(); tickers[i].start();
queue.call_every((i+1)*100, time_func, &tickers[i], (i+1)*100); queue.call_every((i + 1) * 100, time_func, &tickers[i], (i + 1) * 100);
} }
queue.dispatch(N*100); queue.dispatch(N * 100);
} }
void allocate_failure_test() { void allocate_failure_test()
{
EventQueue queue(TEST_EQUEUE_SIZE); EventQueue queue(TEST_EQUEUE_SIZE);
int id; int id;
@ -139,12 +149,14 @@ void allocate_failure_test() {
TEST_ASSERT(!id); TEST_ASSERT(!id);
} }
void no() { void no()
{
TEST_ASSERT(false); TEST_ASSERT(false);
} }
template <int N> template <int N>
void cancel_test1() { void cancel_test1()
{
EventQueue queue(TEST_EQUEUE_SIZE); EventQueue queue(TEST_EQUEUE_SIZE);
int ids[N]; int ids[N];
@ -153,7 +165,7 @@ void cancel_test1() {
ids[i] = queue.call_in(1000, no); ids[i] = queue.call_in(1000, no);
} }
for (int i = N-1; i >= 0; i--) { for (int i = N - 1; i >= 0; i--) {
queue.cancel(ids[i]); queue.cancel(ids[i]);
} }
@ -164,31 +176,38 @@ void cancel_test1() {
// Testing the dynamic arguments to the event class // Testing the dynamic arguments to the event class
unsigned counter = 0; unsigned counter = 0;
void count5(unsigned a0, unsigned a1, unsigned a2, unsigned a3, unsigned a5) { void count5(unsigned a0, unsigned a1, unsigned a2, unsigned a3, unsigned a5)
{
counter += a0 + a1 + a2 + a3 + a5; counter += a0 + a1 + a2 + a3 + a5;
} }
void count4(unsigned a0, unsigned a1, unsigned a2, unsigned a3) { void count4(unsigned a0, unsigned a1, unsigned a2, unsigned a3)
{
counter += a0 + a1 + a2 + a3; counter += a0 + a1 + a2 + a3;
} }
void count3(unsigned a0, unsigned a1, unsigned a2) { void count3(unsigned a0, unsigned a1, unsigned a2)
{
counter += a0 + a1 + a2; counter += a0 + a1 + a2;
} }
void count2(unsigned a0, unsigned a1) { void count2(unsigned a0, unsigned a1)
{
counter += a0 + a1; counter += a0 + a1;
} }
void count1(unsigned a0) { void count1(unsigned a0)
{
counter += a0; counter += a0;
} }
void count0() { void count0()
{
counter += 0; counter += 0;
} }
void event_class_test() { void event_class_test()
{
counter = 0; counter = 0;
EventQueue queue(TEST_EQUEUE_SIZE); EventQueue queue(TEST_EQUEUE_SIZE);
@ -211,7 +230,8 @@ void event_class_test() {
TEST_ASSERT_EQUAL(counter, 30); TEST_ASSERT_EQUAL(counter, 30);
} }
void event_class_helper_test() { void event_class_helper_test()
{
counter = 0; counter = 0;
EventQueue queue(TEST_EQUEUE_SIZE); EventQueue queue(TEST_EQUEUE_SIZE);
@ -234,7 +254,8 @@ void event_class_helper_test() {
TEST_ASSERT_EQUAL(counter, 15); TEST_ASSERT_EQUAL(counter, 15);
} }
void event_inference_test() { void event_inference_test()
{
counter = 0; counter = 0;
EventQueue queue(TEST_EQUEUE_SIZE); EventQueue queue(TEST_EQUEUE_SIZE);
@ -259,23 +280,26 @@ void event_inference_test() {
int timeleft_events[2]; int timeleft_events[2];
void check_time_left(EventQueue* queue, int index, int expected) { void check_time_left(EventQueue *queue, int index, int expected)
{
const int event_id = timeleft_events[index]; const int event_id = timeleft_events[index];
TEST_ASSERT_INT_WITHIN(2, expected, queue->time_left(event_id)); TEST_ASSERT_INT_WITHIN(2, expected, queue->time_left(event_id));
touched = true; touched = true;
} }
void time_left(EventQueue* queue, int index) { void time_left(EventQueue *queue, int index)
{
const int event_id = timeleft_events[index]; const int event_id = timeleft_events[index];
TEST_ASSERT_EQUAL(0, queue->time_left(event_id)); TEST_ASSERT_EQUAL(0, queue->time_left(event_id));
} }
void time_left_test() { void time_left_test()
{
EventQueue queue(TEST_EQUEUE_SIZE); EventQueue queue(TEST_EQUEUE_SIZE);
// Enque check events // Enque check events
TEST_ASSERT(queue.call_in(50, check_time_left, &queue, 0, 100-50)); TEST_ASSERT(queue.call_in(50, check_time_left, &queue, 0, 100 - 50));
TEST_ASSERT(queue.call_in(200, check_time_left, &queue, 1, 200-200)); TEST_ASSERT(queue.call_in(200, check_time_left, &queue, 1, 200 - 200));
// Enque events to be checked // Enque events to be checked
timeleft_events[0] = queue.call_in(100, time_left, &queue, 0); timeleft_events[0] = queue.call_in(100, time_left, &queue, 0);
@ -299,7 +323,8 @@ void time_left_test() {
} }
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(20, "default_auto"); GREENTEA_SETUP(20, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -327,7 +352,8 @@ const Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -25,7 +25,7 @@
using namespace utest::v1; using namespace utest::v1;
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
// Test delay // Test delay
@ -42,16 +42,18 @@ using namespace utest::v1;
#endif #endif
// Random number generation to skew timing values // Random number generation to skew timing values
float gauss(float mu, float sigma) { float gauss(float mu, float sigma)
float x = (float)rand() / ((float)RAND_MAX+1); {
float y = (float)rand() / ((float)RAND_MAX+1); float x = (float)rand() / ((float)RAND_MAX + 1);
float x2pi = x*2.0*M_PI; float y = (float)rand() / ((float)RAND_MAX + 1);
float g2rad = sqrt(-2.0 * log(1.0-y)); float x2pi = x * 2.0 * M_PI;
float g2rad = sqrt(-2.0 * log(1.0 - y));
float z = cos(x2pi) * g2rad; float z = cos(x2pi) * g2rad;
return mu + z*sigma; return mu + z * sigma;
} }
float chisq(float sigma) { float chisq(float sigma)
{
return pow(gauss(0, sqrt(sigma)), 2); return pow(gauss(0, sqrt(sigma)), 2);
} }
@ -62,12 +64,13 @@ DigitalOut led(LED1);
equeue_sema_t sema; equeue_sema_t sema;
// Timer timing test // Timer timing test
void timer_timing_test() { void timer_timing_test()
{
timer.reset(); timer.reset();
timer.start(); timer.start();
int prev = timer.read_us(); int prev = timer.read_us();
while (prev < TEST_EVENTS_TIMING_TIME*1000) { while (prev < TEST_EVENTS_TIMING_TIME * 1000) {
int next = timer.read_us(); int next = timer.read_us();
if (next < prev) { if (next < prev) {
printf("backwards drift %d -> %d (%08x -> %08x)\r\n", printf("backwards drift %d -> %d (%08x -> %08x)\r\n",
@ -79,7 +82,8 @@ void timer_timing_test() {
} }
// equeue tick timing test // equeue tick timing test
void tick_timing_test() { void tick_timing_test()
{
unsigned start = equeue_tick(); unsigned start = equeue_tick();
int prev = 0; int prev = 0;
@ -95,7 +99,8 @@ void tick_timing_test() {
} }
// equeue semaphore timing test // equeue semaphore timing test
void semaphore_timing_test() { void semaphore_timing_test()
{
srand(0); srand(0);
timer.reset(); timer.reset();
timer.start(); timer.start();
@ -124,8 +129,9 @@ void semaphore_timing_test() {
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
GREENTEA_SETUP((number_of_cases+1)*TEST_EVENTS_TIMING_TIME/1000, "default_auto"); {
GREENTEA_SETUP((number_of_cases + 1)*TEST_EVENTS_TIMING_TIME / 1000, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -137,7 +143,8 @@ const Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -15,7 +15,8 @@
*/ */
#include "test_env.h" #include "test_env.h"
int main() { int main()
{
GREENTEA_SETUP(15, "default_auto"); GREENTEA_SETUP(15, "default_auto");
GREENTEA_TESTSUITE_RESULT(true); GREENTEA_TESTSUITE_RESULT(true);
} }

View File

@ -29,21 +29,20 @@
#define SX1276 0xEE #define SX1276 0xEE
#if (MBED_CONF_APP_LORA_RADIO == SX1272) #if (MBED_CONF_APP_LORA_RADIO == SX1272)
#include "SX1272_LoRaRadio.h" #include "SX1272_LoRaRadio.h"
#elif (MBED_CONF_APP_LORA_RADIO == SX1276) #elif (MBED_CONF_APP_LORA_RADIO == SX1276)
#include "SX1276_LoRaRadio.h" #include "SX1276_LoRaRadio.h"
#else #else
#error [NOT_SUPPORTED] Requires parameters from application config file. #error [NOT_SUPPORTED] Requires parameters from application config file.
#endif #endif
using namespace utest::v1; using namespace utest::v1;
static LoRaRadio* radio = NULL; static LoRaRadio *radio = NULL;
rtos::Semaphore event_sem(0); rtos::Semaphore event_sem(0);
enum event_t enum event_t {
{
EV_NONE, EV_NONE,
EV_TX_DONE, EV_TX_DONE,
EV_TX_TIMEOUT, EV_TX_TIMEOUT,
@ -94,8 +93,7 @@ static void rx_error()
TEST_ASSERT_EQUAL(osOK, event_sem.release()); TEST_ASSERT_EQUAL(osOK, event_sem.release());
} }
static radio_events radio_callbacks = static radio_events radio_callbacks = {
{
.tx_done = tx_done, .tx_done = tx_done,
.tx_timeout = tx_timeout, .tx_timeout = tx_timeout,
.rx_done = rx_done, .rx_done = rx_done,
@ -187,7 +185,8 @@ void test_check_rf_frequency()
} }
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(20, "default_auto"); GREENTEA_SETUP(20, "default_auto");
mbed_trace_init(); mbed_trace_init();
@ -240,7 +239,7 @@ utest::v1::status_t case_setup_handler(const Case *const source, const size_t in
MBED_CONF_APP_LORA_TCXO); MBED_CONF_APP_LORA_TCXO);
#else #else
#error [NOT_SUPPORTED] Unknown LoRa radio specified (SX1272,SX1276 are valid) #error [NOT_SUPPORTED] Unknown LoRa radio specified (SX1272,SX1276 are valid)
#endif #endif
TEST_ASSERT(radio); TEST_ASSERT(radio);
@ -255,11 +254,11 @@ utest::v1::status_t case_teardown_handler(const Case *const source, const size_t
radio->sleep(); radio->sleep();
#if (MBED_CONF_APP_LORA_RADIO == SX1272) #if (MBED_CONF_APP_LORA_RADIO == SX1272)
delete static_cast<SX1272_LoRaRadio*>(radio); delete static_cast<SX1272_LoRaRadio *>(radio);
#elif (MBED_CONF_APP_LORA_RADIO == SX1276) #elif (MBED_CONF_APP_LORA_RADIO == SX1276)
delete static_cast<SX1276_LoRaRadio*>(radio); delete static_cast<SX1276_LoRaRadio *>(radio);
#else #else
#error [NOT_SUPPORTED] Unknown LoRa radio specified (SX1272,SX1276 are valid) #error [NOT_SUPPORTED] Unknown LoRa radio specified (SX1272,SX1276 are valid)
#endif #endif
radio = NULL; radio = NULL;
@ -277,6 +276,7 @@ const Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -33,68 +33,76 @@ static char buffer[256] = {0};
using namespace utest::v1; using namespace utest::v1;
void test_case_c_string_i_d() { void test_case_c_string_i_d()
{
CLEAN_BUFFER; CLEAN_BUFFER;
sprintf(buffer, "%i %d %i %d %i %d %i %d %i %d %i %i", NEGATIVE_INTEGERS); sprintf(buffer, "%i %d %i %d %i %d %i %d %i %d %i %i", NEGATIVE_INTEGERS);
TEST_ASSERT_EQUAL_STRING("-32768 -3214 -999 -100 -1 0 -1 -4231 -999 -4123 -32760 -99999", buffer); TEST_ASSERT_EQUAL_STRING("-32768 -3214 -999 -100 -1 0 -1 -4231 -999 -4123 -32760 -99999", buffer);
} }
void test_case_c_string_u_d() { void test_case_c_string_u_d()
{
CLEAN_BUFFER; CLEAN_BUFFER;
sprintf(buffer, "%u %d %u %d %u %d %u %d %u %d %u %d", POSITIVE_INTEGERS); sprintf(buffer, "%u %d %u %d %u %d %u %d %u %d %u %d", POSITIVE_INTEGERS);
TEST_ASSERT_EQUAL_STRING("32768 3214 999 100 1 0 1 4231 999 4123 32760 99999", buffer); TEST_ASSERT_EQUAL_STRING("32768 3214 999 100 1 0 1 4231 999 4123 32760 99999", buffer);
} }
void test_case_c_string_x_E() { void test_case_c_string_x_E()
{
CLEAN_BUFFER; CLEAN_BUFFER;
sprintf(buffer, "%x %X %x %X %x %X %x %X %x %X %x %X", POSITIVE_INTEGERS); sprintf(buffer, "%x %X %x %X %x %X %x %X %x %X %x %X", POSITIVE_INTEGERS);
TEST_ASSERT_EQUAL_STRING("8000 C8E 3e7 64 1 0 1 1087 3e7 101B 7ff8 1869F", buffer); TEST_ASSERT_EQUAL_STRING("8000 C8E 3e7 64 1 0 1 1087 3e7 101B 7ff8 1869F", buffer);
} }
void test_case_c_string_f_f() { void test_case_c_string_f_f()
{
CLEAN_BUFFER; CLEAN_BUFFER;
sprintf(buffer, "%f %f %f %f %f %f %f %f %f %f", FLOATS); sprintf(buffer, "%f %f %f %f %f %f %f %f %f %f", FLOATS);
TEST_ASSERT_EQUAL_STRING("0.002000 0.924300 15.913200 791.773680 6208.200000 25719.495200 426815.982588 6429271.046000 42468024.930000 212006462.910000", buffer); TEST_ASSERT_EQUAL_STRING("0.002000 0.924300 15.913200 791.773680 6208.200000 25719.495200 426815.982588 6429271.046000 42468024.930000 212006462.910000", buffer);
} }
void test_case_c_string_g_g() { void test_case_c_string_g_g()
{
CLEAN_BUFFER; CLEAN_BUFFER;
sprintf(buffer, "%g %g %g %g %g %g %g %g %g %g", FLOATS); sprintf(buffer, "%g %g %g %g %g %g %g %g %g %g", FLOATS);
TEST_ASSERT_EQUAL_STRING("0.002 0.9243 15.9132 791.774 6208.2 25719.5 426816 6.42927e+06 4.2468e+07 2.12006e+08", buffer); TEST_ASSERT_EQUAL_STRING("0.002 0.9243 15.9132 791.774 6208.2 25719.5 426816 6.42927e+06 4.2468e+07 2.12006e+08", buffer);
} }
void test_case_c_string_e_E() { void test_case_c_string_e_E()
{
CLEAN_BUFFER; CLEAN_BUFFER;
sprintf(buffer, "%e %E %e %E %e %E %e %E %e %E", FLOATS); sprintf(buffer, "%e %E %e %E %e %E %e %E %e %E", FLOATS);
TEST_ASSERT_EQUAL_STRING("2.000000e-03 9.243000E-01 1.591320e+01 7.917737E+02 6.208200e+03 2.571950E+04 4.268160e+05 6.429271E+06 4.246802e+07 2.120065E+08", buffer); TEST_ASSERT_EQUAL_STRING("2.000000e-03 9.243000E-01 1.591320e+01 7.917737E+02 6.208200e+03 2.571950E+04 4.268160e+05 6.429271E+06 4.246802e+07 2.120065E+08", buffer);
} }
void test_case_c_string_strtok() { void test_case_c_string_strtok()
{
CLEAN_BUFFER; CLEAN_BUFFER;
char str[] ="- This, a sample string."; char str[] = "- This, a sample string.";
char * pch = strtok (str," ,.-"); char *pch = strtok(str, " ,.-");
while (pch != NULL) { while (pch != NULL) {
strcat(buffer, pch); strcat(buffer, pch);
pch = strtok (NULL, " ,.-"); pch = strtok(NULL, " ,.-");
} }
TEST_ASSERT_EQUAL_STRING("Thisasamplestring", buffer); TEST_ASSERT_EQUAL_STRING("Thisasamplestring", buffer);
} }
void test_case_c_string_strpbrk() { void test_case_c_string_strpbrk()
{
CLEAN_BUFFER; CLEAN_BUFFER;
char str[] = "This is a sample string"; char str[] = "This is a sample string";
char key[] = "aeiou"; char key[] = "aeiou";
char *pch = strpbrk(str, key); char *pch = strpbrk(str, key);
while (pch != NULL) while (pch != NULL) {
{
char buf[2] = {*pch, '\0'}; char buf[2] = {*pch, '\0'};
strcat(buffer, buf); strcat(buffer, buf);
pch = strpbrk(pch + 1,key); pch = strpbrk(pch + 1, key);
} }
TEST_ASSERT_EQUAL_STRING("iiaaei", buffer); TEST_ASSERT_EQUAL_STRING("iiaaei", buffer);
} }
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{
greentea_case_failure_abort_handler(source, reason); greentea_case_failure_abort_handler(source, reason);
return STATUS_CONTINUE; return STATUS_CONTINUE;
} }
@ -110,13 +118,15 @@ Case cases[] = {
Case("C strings: %g %g float formatting", test_case_c_string_g_g, greentea_failure_handler), Case("C strings: %g %g float formatting", test_case_c_string_g_g, greentea_failure_handler),
}; };
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(5, "default_auto"); GREENTEA_SETUP(5, "default_auto");
return greentea_test_setup_handler(number_of_cases); return greentea_test_setup_handler(number_of_cases);
} }
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
Harness::run(specification); Harness::run(specification);
} }

View File

@ -30,27 +30,27 @@ void test_supported_polynomials()
{ {
MbedCRC<POLY_7BIT_SD, 7> ct; MbedCRC<POLY_7BIT_SD, 7> ct;
TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char*)test), &crc)); TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char *)test), &crc));
TEST_ASSERT_EQUAL(0xEA, crc); TEST_ASSERT_EQUAL(0xEA, crc);
} }
{ {
MbedCRC<POLY_8BIT_CCITT, 8> ct; MbedCRC<POLY_8BIT_CCITT, 8> ct;
TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char*)test), &crc)); TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char *)test), &crc));
TEST_ASSERT_EQUAL(0xF4, crc); TEST_ASSERT_EQUAL(0xF4, crc);
} }
{ {
MbedCRC<POLY_16BIT_CCITT, 16> ct; MbedCRC<POLY_16BIT_CCITT, 16> ct;
TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char*)test), &crc)); TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char *)test), &crc));
TEST_ASSERT_EQUAL(0x29B1, crc); TEST_ASSERT_EQUAL(0x29B1, crc);
} }
{ {
MbedCRC<POLY_16BIT_IBM, 16> ct; MbedCRC<POLY_16BIT_IBM, 16> ct;
TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char*)test), &crc)); TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char *)test), &crc));
TEST_ASSERT_EQUAL(0xBB3D, crc); TEST_ASSERT_EQUAL(0xBB3D, crc);
} }
{ {
MbedCRC<POLY_32BIT_ANSI, 32> ct; MbedCRC<POLY_32BIT_ANSI, 32> ct;
TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char*)test), &crc)); TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char *)test), &crc));
TEST_ASSERT_EQUAL(0xCBF43926, crc); TEST_ASSERT_EQUAL(0xCBF43926, crc);
} }
} }
@ -82,7 +82,7 @@ void test_sd_crc()
test[3] = 0x00; test[3] = 0x00;
test[4] = 0x00; test[4] = 0x00;
TEST_ASSERT_EQUAL(0, crc7.compute((void *)test, 5, &crc)); TEST_ASSERT_EQUAL(0, crc7.compute((void *)test, 5, &crc));
crc = (crc | 0x1 ) & 0xFF; crc = (crc | 0x1) & 0xFF;
TEST_ASSERT_EQUAL(0x95, crc); TEST_ASSERT_EQUAL(0x95, crc);
test[0] = 0x48; test[0] = 0x48;
@ -91,7 +91,7 @@ void test_sd_crc()
test[3] = 0x01; test[3] = 0x01;
test[4] = 0xAA; test[4] = 0xAA;
TEST_ASSERT_EQUAL(0, crc7.compute((void *)test, 5, &crc)); TEST_ASSERT_EQUAL(0, crc7.compute((void *)test, 5, &crc));
crc = (crc | 0x1 ) & 0xFF; crc = (crc | 0x1) & 0xFF;
TEST_ASSERT_EQUAL(0x87, crc); TEST_ASSERT_EQUAL(0x87, crc);
test[0] = 0x51; test[0] = 0x51;
@ -100,7 +100,7 @@ void test_sd_crc()
test[3] = 0x00; test[3] = 0x00;
test[4] = 0x00; test[4] = 0x00;
TEST_ASSERT_EQUAL(0, crc7.compute((void *)test, 5, &crc)); TEST_ASSERT_EQUAL(0, crc7.compute((void *)test, 5, &crc));
crc = (crc | 0x1 ) & 0xFF; crc = (crc | 0x1) & 0xFF;
TEST_ASSERT_EQUAL(0x55, crc); TEST_ASSERT_EQUAL(0x55, crc);
MbedCRC<POLY_16BIT_CCITT, 16> crc16(0, 0, false, false); MbedCRC<POLY_16BIT_CCITT, 16> crc16(0, 0, false, false);
@ -115,12 +115,12 @@ void test_any_polynomial()
uint32_t crc; uint32_t crc;
{ {
MbedCRC<0x3D65, 16> ct(0x0, 0xFFFF, 0, 0); MbedCRC<0x3D65, 16> ct(0x0, 0xFFFF, 0, 0);
TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char*)test), &crc)); TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char *)test), &crc));
TEST_ASSERT_EQUAL(0xC2B7, crc); TEST_ASSERT_EQUAL(0xC2B7, crc);
} }
{ {
MbedCRC<0x1EDC6F41, 32> ct(0xFFFFFFFF, 0xFFFFFFFF, 1, 1); MbedCRC<0x1EDC6F41, 32> ct(0xFFFFFFFF, 0xFFFFFFFF, 1, 1);
TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char*)test), &crc)); TEST_ASSERT_EQUAL(0, ct.compute((void *)test, strlen((const char *)test), &crc));
TEST_ASSERT_EQUAL(0xE3069283, crc); TEST_ASSERT_EQUAL(0xE3069283, crc);
} }
} }
@ -132,13 +132,15 @@ Case cases[] = {
Case("Test not supported polynomials", test_any_polynomial) Case("Test not supported polynomials", test_any_polynomial)
}; };
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(15, "default_auto"); GREENTEA_SETUP(15, "default_auto");
return greentea_test_setup_handler(number_of_cases); return greentea_test_setup_handler(number_of_cases);
} }
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
Harness::run(specification); Harness::run(specification);
} }

View File

@ -22,17 +22,20 @@ public:
DevNull(const char *name = NULL) : Stream(name) {} DevNull(const char *name = NULL) : Stream(name) {}
protected: protected:
virtual int _getc() { virtual int _getc()
{
return 0; return 0;
} }
virtual int _putc(int c) { virtual int _putc(int c)
{
return c; return c;
} }
}; };
DevNull null("null"); DevNull null("null");
int main() { int main()
{
GREENTEA_SETUP(2, "dev_null_auto"); GREENTEA_SETUP(2, "dev_null_auto");
printf("MBED: before re-routing stdout to /null\n"); // This shouldn't appear printf("MBED: before re-routing stdout to /null\n"); // This shouldn't appear
@ -45,7 +48,7 @@ int main() {
printf("MBED: this printf is already redirected to /null\n"); printf("MBED: this printf is already redirected to /null\n");
} }
while(1) { while (1) {
// Success is determined by the host test at this point, so busy wait // Success is determined by the host test at this point, so busy wait
} }
} }

View File

@ -26,7 +26,8 @@
using namespace utest::v1; using namespace utest::v1;
// Fill a buffer with a slice of the ASCII alphabet. // Fill a buffer with a slice of the ASCII alphabet.
void fill_buffer(char* buffer, unsigned int length, unsigned int index) { void fill_buffer(char *buffer, unsigned int length, unsigned int index)
{
unsigned int start = length * index; unsigned int start = length * index;
for (int i = 0; i < length - 1; i++) { for (int i = 0; i < length - 1; i++) {
buffer[i] = 'a' + ((start + i) % 26); buffer[i] = 'a' + ((start + i) % 26);
@ -36,7 +37,8 @@ void fill_buffer(char* buffer, unsigned int length, unsigned int index) {
// Echo server (echo payload to host) // Echo server (echo payload to host)
template<int N> template<int N>
void test_case_echo_server_x() { void test_case_echo_server_x()
{
char _key[11] = {}; char _key[11] = {};
char _tx_value[PAYLOAD_LENGTH + 1] = {}; char _tx_value[PAYLOAD_LENGTH + 1] = {};
char _rx_value[PAYLOAD_LENGTH + 1] = {}; char _rx_value[PAYLOAD_LENGTH + 1] = {};
@ -55,7 +57,7 @@ void test_case_echo_server_x() {
} while (expected_key); } while (expected_key);
TEST_ASSERT_EQUAL_INT(echo_count, atoi(_rx_value)); TEST_ASSERT_EQUAL_INT(echo_count, atoi(_rx_value));
for (int i=0; i < echo_count; ++i) { for (int i = 0; i < echo_count; ++i) {
fill_buffer(_tx_value, PAYLOAD_LENGTH, i); fill_buffer(_tx_value, PAYLOAD_LENGTH, i);
greentea_send_kv(_echo_key_const, _tx_value); greentea_send_kv(_echo_key_const, _tx_value);
do { do {
@ -67,7 +69,8 @@ void test_case_echo_server_x() {
} }
} }
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{
greentea_case_failure_abort_handler(source, reason); greentea_case_failure_abort_handler(source, reason);
return STATUS_CONTINUE; return STATUS_CONTINUE;
} }
@ -76,13 +79,15 @@ Case cases[] = {
Case("Echo server: x16", test_case_echo_server_x<16>, greentea_failure_handler), Case("Echo server: x16", test_case_echo_server_x<16>, greentea_failure_handler),
}; };
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(30, "device_echo"); GREENTEA_SETUP(30, "device_echo");
return greentea_test_setup_handler(number_of_cases); return greentea_test_setup_handler(number_of_cases);
} }
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
Harness::run(specification); Harness::run(specification);
} }

View File

@ -16,7 +16,7 @@
*/ */
#if !DEVICE_FLASH #if !DEVICE_FLASH
#error [NOT_SUPPORTED] Flash API not supported for this target #error [NOT_SUPPORTED] Flash API not supported for this target
#endif #endif
#include "utest/utest.h" #include "utest/utest.h"
@ -266,13 +266,15 @@ Case cases[] = {
Case("FlashIAP - timing", flashiap_timing_test), Case("FlashIAP - timing", flashiap_timing_test),
}; };
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(120, "default_auto"); GREENTEA_SETUP(120, "default_auto");
return greentea_test_setup_handler(number_of_cases); return greentea_test_setup_handler(number_of_cases);
} }
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
Harness::run(specification); Harness::run(specification);
} }

View File

@ -28,48 +28,56 @@ using namespace utest::v1;
class CppTestCaseHelperClass { class CppTestCaseHelperClass {
private: private:
const char* name; const char *name;
const unsigned pattern; const unsigned pattern;
public: public:
CppTestCaseHelperClass(const char* _name) : name(_name), pattern(PATTERN_CHECK_VALUE) { CppTestCaseHelperClass(const char *_name) : name(_name), pattern(PATTERN_CHECK_VALUE)
{
print("init"); print("init");
} }
void print(const char *message) { void print(const char *message)
{
printf("%s::%s\n", name, message); printf("%s::%s\n", name, message);
} }
bool check_init(void) { bool check_init(void)
{
bool result = (pattern == PATTERN_CHECK_VALUE); bool result = (pattern == PATTERN_CHECK_VALUE);
print(result ? "check_init: OK" : "check_init: ERROR"); print(result ? "check_init: OK" : "check_init: ERROR");
return result; return result;
} }
void stack_test(void) { void stack_test(void)
{
print("stack_test"); print("stack_test");
CppTestCaseHelperClass t("Stack"); CppTestCaseHelperClass t("Stack");
t.hello(); t.hello();
} }
void hello(void) { void hello(void)
{
print("hello"); print("hello");
} }
~CppTestCaseHelperClass() { ~CppTestCaseHelperClass()
{
print("destroy"); print("destroy");
} }
}; };
void test_case_basic() { void test_case_basic()
{
TEST_ASSERT_TRUE(true); TEST_ASSERT_TRUE(true);
TEST_ASSERT_FALSE(false); TEST_ASSERT_FALSE(false);
TEST_ASSERT_EQUAL_STRING("The quick brown fox jumps over the lazy dog", TEST_ASSERT_EQUAL_STRING("The quick brown fox jumps over the lazy dog",
"The quick brown fox jumps over the lazy dog"); "The quick brown fox jumps over the lazy dog");
} }
void test_case_blinky() { void test_case_blinky()
{
static DigitalOut myled(LED1); static DigitalOut myled(LED1);
const int cnt_max = 1024; const int cnt_max = 1024;
for (int cnt = 0; cnt < cnt_max; ++cnt) { for (int cnt = 0; cnt < cnt_max; ++cnt) {
@ -77,7 +85,8 @@ void test_case_blinky() {
} }
} }
void test_case_cpp_stack() { void test_case_cpp_stack()
{
// Check C++ start-up initialisation // Check C++ start-up initialisation
CppTestCaseHelperClass s("Static"); CppTestCaseHelperClass s("Static");
@ -86,7 +95,8 @@ void test_case_cpp_stack() {
TEST_ASSERT_TRUE_MESSAGE(s.check_init(), "s.check_init() failed"); TEST_ASSERT_TRUE_MESSAGE(s.check_init(), "s.check_init() failed");
} }
void test_case_cpp_heap() { void test_case_cpp_heap()
{
// Heap test object simple test // Heap test object simple test
CppTestCaseHelperClass *m = new CppTestCaseHelperClass("Heap"); CppTestCaseHelperClass *m = new CppTestCaseHelperClass("Heap");
m->hello(); m->hello();
@ -94,7 +104,8 @@ void test_case_cpp_heap() {
delete m; delete m;
} }
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{
greentea_case_failure_abort_handler(source, reason); greentea_case_failure_abort_handler(source, reason);
return STATUS_CONTINUE; return STATUS_CONTINUE;
} }
@ -107,13 +118,15 @@ Case cases[] = {
Case("C++ heap", test_case_cpp_heap, greentea_failure_handler) Case("C++ heap", test_case_cpp_heap, greentea_failure_handler)
}; };
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(20, "default_auto"); GREENTEA_SETUP(20, "default_auto");
return greentea_test_setup_handler(number_of_cases); return greentea_test_setup_handler(number_of_cases);
} }
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
Harness::run(specification); Harness::run(specification);
} }

View File

@ -20,7 +20,7 @@
#if !DEVICE_LPTICKER #if !DEVICE_LPTICKER
#error [NOT_SUPPORTED] Low power ticker not supported for this target #error [NOT_SUPPORTED] Low power ticker not supported for this target
#endif #endif
using utest::v1::Case; using utest::v1::Case;
@ -53,12 +53,12 @@ void sem_release(Semaphore *sem)
void stop_gtimer_set_flag(void) void stop_gtimer_set_flag(void)
{ {
gtimer.stop(); gtimer.stop();
core_util_atomic_incr_u32((uint32_t*)&ticker_callback_flag, 1); core_util_atomic_incr_u32((uint32_t *)&ticker_callback_flag, 1);
} }
void increment_multi_counter(void) void increment_multi_counter(void)
{ {
core_util_atomic_incr_u32((uint32_t*)&multi_counter, 1);; core_util_atomic_incr_u32((uint32_t *)&multi_counter, 1);;
} }
/** Test many tickers run one after the other /** Test many tickers run one after the other
@ -125,7 +125,7 @@ void test_multi_call_time(void)
gtimer.start(); gtimer.start();
ticker.attach_us(callback(stop_gtimer_set_flag), MULTI_TICKER_TIME_MS * 1000); ticker.attach_us(callback(stop_gtimer_set_flag), MULTI_TICKER_TIME_MS * 1000);
while(!ticker_callback_flag); while (!ticker_callback_flag);
time_diff = gtimer.read_us(); time_diff = gtimer.read_us();
TEST_ASSERT_UINT32_WITHIN(TOLERANCE_US(MULTI_TICKER_TIME_MS * 1000), MULTI_TICKER_TIME_MS * 1000, time_diff); TEST_ASSERT_UINT32_WITHIN(TOLERANCE_US(MULTI_TICKER_TIME_MS * 1000), MULTI_TICKER_TIME_MS * 1000, time_diff);
@ -174,7 +174,7 @@ void test_attach_time(void)
gtimer.reset(); gtimer.reset();
gtimer.start(); gtimer.start();
ticker.attach(callback(stop_gtimer_set_flag), ((float)DELAY_US) / 1000000.0f); ticker.attach(callback(stop_gtimer_set_flag), ((float)DELAY_US) / 1000000.0f);
while(!ticker_callback_flag); while (!ticker_callback_flag);
ticker.detach(); ticker.detach();
const int time_diff = gtimer.read_us(); const int time_diff = gtimer.read_us();
@ -196,7 +196,7 @@ void test_attach_us_time(void)
gtimer.reset(); gtimer.reset();
gtimer.start(); gtimer.start();
ticker.attach_us(callback(stop_gtimer_set_flag), DELAY_US); ticker.attach_us(callback(stop_gtimer_set_flag), DELAY_US);
while(!ticker_callback_flag); while (!ticker_callback_flag);
ticker.detach(); ticker.detach();
const int time_diff = gtimer.read_us(); const int time_diff = gtimer.read_us();

View File

@ -15,7 +15,7 @@
*/ */
#if !DEVICE_LPTICKER #if !DEVICE_LPTICKER
#error [NOT_SUPPORTED] Low power timer not supported for this target #error [NOT_SUPPORTED] Low power timer not supported for this target
#endif #endif
#include "mbed.h" #include "mbed.h"
@ -26,7 +26,7 @@
using namespace utest::v1; using namespace utest::v1;
utest::v1::status_t greentea_failure_handler(const Case * const source, const failure_t reason) utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{ {
greentea_case_failure_abort_handler(source, reason); greentea_case_failure_abort_handler(source, reason);
return STATUS_CONTINUE; return STATUS_CONTINUE;

View File

@ -35,17 +35,17 @@ extern uint32_t SystemCoreClock;
* timer we need to adjust delta. * timer we need to adjust delta.
*/ */
/* /*
* Define tolerance as follows: * Define tolerance as follows:
* tolerance = 500 us + 5% of measured time * tolerance = 500 us + 5% of measured time
* *
* e.g. * e.g.
* 1 ms delay: tolerance = 550 us * 1 ms delay: tolerance = 550 us
* 10 ms delay: tolerance = 1000 us * 10 ms delay: tolerance = 1000 us
* 100 ms delay: tolerance = 5500 us * 100 ms delay: tolerance = 5500 us
* 1000 ms delay: tolerance = 50500 us * 1000 ms delay: tolerance = 50500 us
* *
* */ * */
#define US_PER_SEC 1000000 #define US_PER_SEC 1000000
#define US_PER_MSEC 1000 #define US_PER_MSEC 1000
@ -292,7 +292,7 @@ void test_lptimer_float_operator()
lp_timer.stop(); lp_timer.stop();
/* Check result - 10 ms elapsed. */ /* Check result - 10 ms elapsed. */
TEST_ASSERT_FLOAT_WITHIN(DELTA_S(10), 0.010f, (float )(lp_timer)); TEST_ASSERT_FLOAT_WITHIN(DELTA_S(10), 0.010f, (float)(lp_timer));
} }
/* This test verifies if time counted by the low power timer is /* This test verifies if time counted by the low power timer is
@ -320,7 +320,7 @@ void test_lptimer_time_measurement()
lp_timer.stop(); lp_timer.stop();
/* Check results - wait_val_us us have elapsed. */ /* Check results - wait_val_us us have elapsed. */
TEST_ASSERT_FLOAT_WITHIN(DELTA_S(delta_ms), (float )wait_val_us / 1000000, lp_timer.read()); TEST_ASSERT_FLOAT_WITHIN(DELTA_S(delta_ms), (float)wait_val_us / 1000000, lp_timer.read());
TEST_ASSERT_INT32_WITHIN(DELTA_MS(delta_ms), wait_val_us / 1000, lp_timer.read_ms()); TEST_ASSERT_INT32_WITHIN(DELTA_MS(delta_ms), wait_val_us / 1000, lp_timer.read_ms());
TEST_ASSERT_INT32_WITHIN(DELTA_US(delta_ms), wait_val_us, lp_timer.read_us()); TEST_ASSERT_INT32_WITHIN(DELTA_US(delta_ms), wait_val_us, lp_timer.read_us());
TEST_ASSERT_UINT64_WITHIN(DELTA_US(delta_ms), wait_val_us, lp_timer.read_high_resolution_us()); TEST_ASSERT_UINT64_WITHIN(DELTA_US(delta_ms), wait_val_us, lp_timer.read_high_resolution_us());

View File

@ -25,7 +25,7 @@
#include <stdarg.h> #include <stdarg.h>
#ifndef MBED_MEM_TRACING_ENABLED #ifndef MBED_MEM_TRACING_ENABLED
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using utest::v1::Case; using utest::v1::Case;
@ -99,7 +99,7 @@ extern "C" void test_trace_cb(uint8_t op, void *res, void *caller, ...)
va_start(va, caller); va_start(va, caller);
pmem->op = op; pmem->op = op;
pmem->res = res; pmem->res = res;
switch(op) { switch (op) {
case MBED_MEM_TRACE_MALLOC: case MBED_MEM_TRACE_MALLOC:
pmem->malloc_info.arg_size = va_arg(va, size_t); pmem->malloc_info.arg_size = va_arg(va, size_t);
break; break;
@ -180,7 +180,7 @@ void malloc_free(volatile bool *thread_continue)
{ {
const size_t block_size = 126; const size_t block_size = 126;
while(*thread_continue) { while (*thread_continue) {
void *p = malloc(block_size); void *p = malloc(block_size);
TEST_ASSERT_NOT_EQUAL(p, NULL); TEST_ASSERT_NOT_EQUAL(p, NULL);
free(p); free(p);
@ -403,8 +403,7 @@ static void test_case_multithread_malloc_free()
static Case cases[] = static Case cases[] = {
{
Case("Test single malloc/free trace", test_case_single_malloc_free), Case("Test single malloc/free trace", test_case_single_malloc_free),
Case("Test all memory operations trace", test_case_all_memory_ops), Case("Test all memory operations trace", test_case_all_memory_ops),
Case("Test trace off", test_case_trace_off), Case("Test trace off", test_case_trace_off),

View File

@ -23,7 +23,7 @@
#include <stdio.h> #include <stdio.h>
#ifdef MBED_RTOS_SINGLE_THREAD #ifdef MBED_RTOS_SINGLE_THREAD
#error [NOT_SUPPORTED] test not supported for single threaded enviroment #error [NOT_SUPPORTED] test not supported for single threaded enviroment
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
@ -37,21 +37,24 @@ static uint32_t instance_count = 0;
class TestClass { class TestClass {
public: public:
TestClass() { TestClass()
{
Thread::wait(500); Thread::wait(500);
instance_count++; instance_count++;
} }
void do_something() { void do_something()
{
Thread::wait(100); Thread::wait(100);
} }
~TestClass() { ~TestClass()
{
instance_count--; instance_count--;
} }
}; };
static TestClass* get_test_class() static TestClass *get_test_class()
{ {
static TestClass tc; static TestClass tc;
return &tc; return &tc;

View File

@ -294,7 +294,7 @@ void test_time_read_RTC_func_undefined()
seconds = time(NULL); seconds = time(NULL);
/* Check if expected value has been returned. */ /* Check if expected value has been returned. */
TEST_ASSERT_EQUAL((time_t)-1, seconds); TEST_ASSERT_EQUAL((time_t) -1, seconds);
} }
/* This test verifies if time() function stores /* This test verifies if time() function stores
@ -490,6 +490,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -16,7 +16,7 @@
*/ */
#if !DEVICE_SLEEP #if !DEVICE_SLEEP
#error [NOT_SUPPORTED] Sleep not supported for this target #error [NOT_SUPPORTED] Sleep not supported for this target
#endif #endif
#include "utest/utest.h" #include "utest/utest.h"
@ -120,13 +120,15 @@ Case cases[] = {
Case("timer lock test", timer_lock_test), Case("timer lock test", timer_lock_test),
}; };
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(20, "default_auto"); GREENTEA_SETUP(20, "default_auto");
return greentea_test_setup_handler(number_of_cases); return greentea_test_setup_handler(number_of_cases);
} }
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
Harness::run(specification); Harness::run(specification);
} }

View File

@ -39,16 +39,17 @@ using namespace utest::v1;
namespace { namespace {
template <class T, class F> template <class T, class F>
void BubbleSort(T& _array, size_t array_size, F functor) { void BubbleSort(T &_array, size_t array_size, F functor)
{
bool flag = true; bool flag = true;
size_t numLength = array_size; size_t numLength = array_size;
for(size_t i = 1; (i <= numLength) && flag; i++) { for (size_t i = 1; (i <= numLength) && flag; i++) {
flag = false; flag = false;
for (size_t j = 0; j < (numLength - 1); j++) { for (size_t j = 0; j < (numLength - 1); j++) {
if (functor(_array[j+1], _array[j])) { if (functor(_array[j + 1], _array[j])) {
int temp = _array[j]; int temp = _array[j];
_array[j] = _array[j + 1]; _array[j] = _array[j + 1];
_array[j+1] = temp; _array[j + 1] = temp;
flag = true; flag = true;
} }
} }
@ -56,27 +57,33 @@ void BubbleSort(T& _array, size_t array_size, F functor) {
} }
struct greaterAbs { struct greaterAbs {
bool operator()(int a, int b) { return abs(a) > abs(b); } bool operator()(int a, int b)
{
return abs(a) > abs(b);
}
}; };
} // namespace } // namespace
void test_case_stl_equal() { void test_case_stl_equal()
{
const int n_integers[] = {NEGATIVE_INTEGERS}; const int n_integers[] = {NEGATIVE_INTEGERS};
std::vector<int> v_pints(n_integers, n_integers + TABLE_SIZE(n_integers)); std::vector<int> v_pints(n_integers, n_integers + TABLE_SIZE(n_integers));
TEST_ASSERT_TRUE(std::equal(v_pints.begin(), v_pints.end(), n_integers)); TEST_ASSERT_TRUE(std::equal(v_pints.begin(), v_pints.end(), n_integers));
} }
void test_case_stl_transform() { void test_case_stl_transform()
{
const float floats[] = {FLOATS}; const float floats[] = {FLOATS};
const char* floats_str[] = {FLOATS_STR}; const char *floats_str[] = {FLOATS_STR};
float floats_transform[TABLE_SIZE(floats_str)] = {0.0}; float floats_transform[TABLE_SIZE(floats_str)] = {0.0};
std::transform(floats_str, floats_str + TABLE_SIZE(floats_str), floats_transform, atof); std::transform(floats_str, floats_str + TABLE_SIZE(floats_str), floats_transform, atof);
TEST_ASSERT_TRUE(std::equal(floats_transform, floats_transform + TABLE_SIZE(floats_transform), floats)); TEST_ASSERT_TRUE(std::equal(floats_transform, floats_transform + TABLE_SIZE(floats_transform), floats));
} }
void test_case_stl_sort_greater() { void test_case_stl_sort_greater()
{
int n_integers[] = {NEGATIVE_INTEGERS}; int n_integers[] = {NEGATIVE_INTEGERS};
int n_integers2[] = {NEGATIVE_INTEGERS}; int n_integers2[] = {NEGATIVE_INTEGERS};
@ -87,7 +94,8 @@ void test_case_stl_sort_greater() {
} }
void test_case_stl_sort_abs() { void test_case_stl_sort_abs()
{
int n_integers[] = {NEGATIVE_INTEGERS}; int n_integers[] = {NEGATIVE_INTEGERS};
int n_integers2[] = {NEGATIVE_INTEGERS}; int n_integers2[] = {NEGATIVE_INTEGERS};
@ -98,7 +106,8 @@ void test_case_stl_sort_abs() {
} }
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{
greentea_case_failure_abort_handler(source, reason); greentea_case_failure_abort_handler(source, reason);
return STATUS_CONTINUE; return STATUS_CONTINUE;
} }
@ -110,13 +119,15 @@ Case cases[] = {
Case("STL std::sort abs", test_case_stl_sort_abs, greentea_failure_handler) Case("STL std::sort abs", test_case_stl_sort_abs, greentea_failure_handler)
}; };
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(5, "default_auto"); GREENTEA_SETUP(5, "default_auto");
return greentea_test_setup_handler(number_of_cases); return greentea_test_setup_handler(number_of_cases);
} }
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
Harness::run(specification); Harness::run(specification);
} }

View File

@ -19,7 +19,7 @@
#include "unity/unity.h" #include "unity/unity.h"
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using utest::v1::Case; using utest::v1::Case;
@ -48,7 +48,7 @@ volatile int ticker_count = 0;
void switch_led1_state(void) void switch_led1_state(void)
{ {
// blink 3 times per second // blink 3 times per second
if((callback_trigger_count % 333) == 0) { if ((callback_trigger_count % 333) == 0) {
led1 = !led1; led1 = !led1;
} }
} }
@ -57,7 +57,7 @@ void switch_led2_state(void)
{ {
// blink 3 times per second // blink 3 times per second
// make led2 blink at the same callback_trigger_count value as led1 // make led2 blink at the same callback_trigger_count value as led1
if(((callback_trigger_count - 1) % 333) == 0) { if (((callback_trigger_count - 1) % 333) == 0) {
led2 = !led2; led2 = !led2;
} }
} }
@ -84,12 +84,12 @@ void sem_release(Semaphore *sem)
void stop_gtimer_set_flag(void) void stop_gtimer_set_flag(void)
{ {
gtimer.stop(); gtimer.stop();
core_util_atomic_incr_u32((uint32_t*)&ticker_callback_flag, 1); core_util_atomic_incr_u32((uint32_t *)&ticker_callback_flag, 1);
} }
void increment_multi_counter(void) void increment_multi_counter(void)
{ {
core_util_atomic_incr_u32((uint32_t*)&multi_counter, 1); core_util_atomic_incr_u32((uint32_t *)&multi_counter, 1);
} }
@ -130,7 +130,7 @@ void test_case_1x_ticker()
//get the results from host //get the results from host
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
TEST_ASSERT_EQUAL_STRING_MESSAGE("pass", _key,"Host side script reported a fail..."); TEST_ASSERT_EQUAL_STRING_MESSAGE("pass", _key, "Host side script reported a fail...");
} }
/* Tests is to measure the accuracy of Ticker over a period of time /* Tests is to measure the accuracy of Ticker over a period of time
@ -174,7 +174,7 @@ void test_case_2x_ticker()
//get the results from host //get the results from host
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
TEST_ASSERT_EQUAL_STRING_MESSAGE("pass", _key,"Host side script reported a fail..."); TEST_ASSERT_EQUAL_STRING_MESSAGE("pass", _key, "Host side script reported a fail...");
} }
/** Test many tickers run one after the other /** Test many tickers run one after the other
@ -241,7 +241,7 @@ void test_multi_call_time(void)
gtimer.start(); gtimer.start();
ticker.attach_us(callback(stop_gtimer_set_flag), MULTI_TICKER_TIME_MS * 1000); ticker.attach_us(callback(stop_gtimer_set_flag), MULTI_TICKER_TIME_MS * 1000);
while(!ticker_callback_flag); while (!ticker_callback_flag);
time_diff = gtimer.read_us(); time_diff = gtimer.read_us();
TEST_ASSERT_UINT32_WITHIN(TOLERANCE_US, MULTI_TICKER_TIME_MS * 1000, time_diff); TEST_ASSERT_UINT32_WITHIN(TOLERANCE_US, MULTI_TICKER_TIME_MS * 1000, time_diff);
@ -290,7 +290,7 @@ void test_attach_time(void)
gtimer.reset(); gtimer.reset();
gtimer.start(); gtimer.start();
ticker.attach(callback(stop_gtimer_set_flag), ((float)DELAY_US) / 1000000.0f); ticker.attach(callback(stop_gtimer_set_flag), ((float)DELAY_US) / 1000000.0f);
while(!ticker_callback_flag); while (!ticker_callback_flag);
ticker.detach(); ticker.detach();
const int time_diff = gtimer.read_us(); const int time_diff = gtimer.read_us();
@ -312,7 +312,7 @@ void test_attach_us_time(void)
gtimer.reset(); gtimer.reset();
gtimer.start(); gtimer.start();
ticker.attach_us(callback(stop_gtimer_set_flag), DELAY_US); ticker.attach_us(callback(stop_gtimer_set_flag), DELAY_US);
while(!ticker_callback_flag); while (!ticker_callback_flag);
ticker.detach(); ticker.detach();
const int time_diff = gtimer.read_us(); const int time_diff = gtimer.read_us();

View File

@ -25,7 +25,7 @@
using namespace utest::v1; using namespace utest::v1;
utest::v1::status_t greentea_failure_handler(const Case * const source, const failure_t reason) utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{ {
greentea_case_failure_abort_handler(source, reason); greentea_case_failure_abort_handler(source, reason);
return STATUS_CONTINUE; return STATUS_CONTINUE;

View File

@ -23,7 +23,7 @@
#include "hal/us_ticker_api.h" #include "hal/us_ticker_api.h"
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using namespace utest::v1; using namespace utest::v1;
@ -34,17 +34,17 @@ extern uint32_t SystemCoreClock;
#define US_PER_MSEC 1000 #define US_PER_MSEC 1000
#define MSEC_PER_SEC 1000 #define MSEC_PER_SEC 1000
/* /*
* Define tolerance as follows: * Define tolerance as follows:
* tolerance = 500 us + 2% of measured time * tolerance = 500 us + 2% of measured time
* *
* e.g. * e.g.
* 1 ms delay: tolerance = 520 us * 1 ms delay: tolerance = 520 us
* 10 ms delay: tolerance = 700 us * 10 ms delay: tolerance = 700 us
* 100 ms delay: tolerance = 2500 us * 100 ms delay: tolerance = 2500 us
* 1000 ms delay: tolerance = 20500 us * 1000 ms delay: tolerance = 20500 us
* *
* */ * */
#ifdef NO_SYSTICK #ifdef NO_SYSTICK
#define TOLERANCE 5 #define TOLERANCE 5
#else #else
@ -112,7 +112,7 @@ static void stub_free(void)
ticker_info_t info = ticker_info_t info =
{ TICKER_FREQ_1MHZ, TICKER_BITS }; { TICKER_FREQ_1MHZ, TICKER_BITS };
const ticker_info_t * stub_get_info(void) const ticker_info_t *stub_get_info(void)
{ {
return &info; return &info;
} }
@ -139,7 +139,7 @@ static const ticker_data_t us_data = {
}; };
/* Function which returns user ticker data. */ /* Function which returns user ticker data. */
const ticker_data_t* get_user_ticker_data(void) const ticker_data_t *get_user_ticker_data(void)
{ {
return &us_data; return &us_data;
} }
@ -740,7 +740,8 @@ void test_timer_time_measurement()
TEST_ASSERT_UINT64_WITHIN(DELTA_US(wait_val_us / US_PER_MSEC), wait_val_us, p_timer->read_high_resolution_us()); TEST_ASSERT_UINT64_WITHIN(DELTA_US(wait_val_us / US_PER_MSEC), wait_val_us, p_timer->read_high_resolution_us());
} }
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(15, "default_auto"); GREENTEA_SETUP(15, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -769,7 +770,8 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -28,7 +28,7 @@
using namespace utest::v1; using namespace utest::v1;
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#define TEST_DELAY_US 50000ULL #define TEST_DELAY_US 50000ULL
@ -37,22 +37,26 @@ using namespace utest::v1;
class TestTimerEvent: public TimerEvent { class TestTimerEvent: public TimerEvent {
private: private:
Semaphore sem; Semaphore sem;
virtual void handler() { virtual void handler()
{
sem.release(); sem.release();
} }
public: public:
TestTimerEvent() : TestTimerEvent() :
TimerEvent(), sem(0, 1) { TimerEvent(), sem(0, 1)
{
sleep_manager_lock_deep_sleep(); sleep_manager_lock_deep_sleep();
} }
TestTimerEvent(const ticker_data_t *data) : TestTimerEvent(const ticker_data_t *data) :
TimerEvent(data), sem(0, 1) { TimerEvent(data), sem(0, 1)
{
} }
virtual ~TestTimerEvent() { virtual ~TestTimerEvent()
{
sleep_manager_unlock_deep_sleep(); sleep_manager_unlock_deep_sleep();
} }
@ -61,7 +65,8 @@ public:
using TimerEvent::insert_absolute; using TimerEvent::insert_absolute;
using TimerEvent::remove; using TimerEvent::remove;
int32_t sem_wait(uint32_t millisec) { int32_t sem_wait(uint32_t millisec)
{
return sem.wait(millisec); return sem.wait(millisec);
} }
}; };
@ -70,19 +75,23 @@ class TestTimerEventRelative: public TestTimerEvent {
public: public:
static const int32_t SEM_SLOTS_AFTER_PAST_TS_INSERTED = 0; static const int32_t SEM_SLOTS_AFTER_PAST_TS_INSERTED = 0;
TestTimerEventRelative() : TestTimerEventRelative() :
TestTimerEvent() { TestTimerEvent()
{
} }
TestTimerEventRelative(const ticker_data_t *data) : TestTimerEventRelative(const ticker_data_t *data) :
TestTimerEvent(data) { TestTimerEvent(data)
{
} }
// Set relative timestamp of internal event to present_time + ts // Set relative timestamp of internal event to present_time + ts
void set_future_timestamp(timestamp_t ts) { void set_future_timestamp(timestamp_t ts)
{
insert(::ticker_read(_ticker_data) + ts); insert(::ticker_read(_ticker_data) + ts);
} }
void set_past_timestamp(void) { void set_past_timestamp(void)
{
insert(::ticker_read(_ticker_data) - 1UL); insert(::ticker_read(_ticker_data) - 1UL);
} }
}; };
@ -91,19 +100,23 @@ class TestTimerEventAbsolute: public TestTimerEvent {
public: public:
static const int32_t SEM_SLOTS_AFTER_PAST_TS_INSERTED = 1; static const int32_t SEM_SLOTS_AFTER_PAST_TS_INSERTED = 1;
TestTimerEventAbsolute() : TestTimerEventAbsolute() :
TestTimerEvent() { TestTimerEvent()
{
} }
TestTimerEventAbsolute(const ticker_data_t *data) : TestTimerEventAbsolute(const ticker_data_t *data) :
TestTimerEvent(data) { TestTimerEvent(data)
{
} }
// Set absolute timestamp of internal event to present_time + ts // Set absolute timestamp of internal event to present_time + ts
void set_future_timestamp(us_timestamp_t ts) { void set_future_timestamp(us_timestamp_t ts)
{
insert_absolute(::ticker_read_us(_ticker_data) + ts); insert_absolute(::ticker_read_us(_ticker_data) + ts);
} }
void set_past_timestamp(void) { void set_past_timestamp(void)
{
insert_absolute(::ticker_read_us(_ticker_data) - 1ULL); insert_absolute(::ticker_read_us(_ticker_data) - 1ULL);
} }
}; };
@ -123,7 +136,8 @@ public:
* Then an event handler is called * Then an event handler is called
*/ */
template<typename T> template<typename T>
void test_insert(void) { void test_insert(void)
{
T tte; T tte;
tte.set_future_timestamp(TEST_DELAY_US); tte.set_future_timestamp(TEST_DELAY_US);
@ -151,7 +165,8 @@ void test_insert(void) {
* Then the event handler is never called * Then the event handler is never called
*/ */
template<typename T> template<typename T>
void test_remove(void) { void test_remove(void)
{
T tte; T tte;
tte.set_future_timestamp(TEST_DELAY_US * 2); tte.set_future_timestamp(TEST_DELAY_US * 2);
@ -168,7 +183,8 @@ void test_remove(void) {
* When a timestamp of 0 us is set with @a insert_absolute() * When a timestamp of 0 us is set with @a insert_absolute()
* Then an event handler is called instantly * Then an event handler is called instantly
*/ */
void test_insert_zero(void) { void test_insert_zero(void)
{
TestTimerEvent tte; TestTimerEvent tte;
tte.insert_absolute(0ULL); tte.insert_absolute(0ULL);
@ -194,7 +210,8 @@ void test_insert_zero(void) {
* Then an event handler is called instantly * Then an event handler is called instantly
*/ */
template<typename T> template<typename T>
void test_insert_past(void) { void test_insert_past(void)
{
T tte; T tte;
tte.set_past_timestamp(); tte.set_past_timestamp();
@ -205,7 +222,7 @@ void test_insert_past(void) {
} }
utest::v1::status_t test_setup(const size_t number_of_cases) utest::v1::status_t test_setup(const size_t number_of_cases)
{ {
GREENTEA_SETUP(5, "default_auto"); GREENTEA_SETUP(5, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }

View File

@ -24,22 +24,34 @@ using namespace utest::v1;
// static functions // static functions
template <typename T> template <typename T>
T static_func0() T static_func0()
{ return 0; } {
return 0;
}
template <typename T> template <typename T>
T static_func1(T a0) T static_func1(T a0)
{ return 0 | a0; } {
return 0 | a0;
}
template <typename T> template <typename T>
T static_func2(T a0, T a1) T static_func2(T a0, T a1)
{ return 0 | a0 | a1; } {
return 0 | a0 | a1;
}
template <typename T> template <typename T>
T static_func3(T a0, T a1, T a2) T static_func3(T a0, T a1, T a2)
{ return 0 | a0 | a1 | a2; } {
return 0 | a0 | a1 | a2;
}
template <typename T> template <typename T>
T static_func4(T a0, T a1, T a2, T a3) T static_func4(T a0, T a1, T a2, T a3)
{ return 0 | a0 | a1 | a2 | a3; } {
return 0 | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T static_func5(T a0, T a1, T a2, T a3, T a4) T static_func5(T a0, T a1, T a2, T a3, T a4)
{ return 0 | a0 | a1 | a2 | a3 | a4; } {
return 0 | a0 | a1 | a2 | a3 | a4;
}
// class functions // class functions
template <typename T> template <typename T>
@ -48,205 +60,349 @@ struct Thing {
Thing() : t(0x80) {} Thing() : t(0x80) {}
T member_func0() T member_func0()
{ return t; } {
return t;
}
T member_func1(T a0) T member_func1(T a0)
{ return t | a0; } {
return t | a0;
}
T member_func2(T a0, T a1) T member_func2(T a0, T a1)
{ return t | a0 | a1; } {
return t | a0 | a1;
}
T member_func3(T a0, T a1, T a2) T member_func3(T a0, T a1, T a2)
{ return t | a0 | a1 | a2; } {
return t | a0 | a1 | a2;
}
T member_func4(T a0, T a1, T a2, T a3) T member_func4(T a0, T a1, T a2, T a3)
{ return t | a0 | a1 | a2 | a3; } {
return t | a0 | a1 | a2 | a3;
}
T member_func5(T a0, T a1, T a2, T a3, T a4) T member_func5(T a0, T a1, T a2, T a3, T a4)
{ return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0 | a1 | a2 | a3 | a4;
}
T const_member_func0() const T const_member_func0() const
{ return t; } {
return t;
}
T const_member_func1(T a0) const T const_member_func1(T a0) const
{ return t | a0; } {
return t | a0;
}
T const_member_func2(T a0, T a1) const T const_member_func2(T a0, T a1) const
{ return t | a0 | a1; } {
return t | a0 | a1;
}
T const_member_func3(T a0, T a1, T a2) const T const_member_func3(T a0, T a1, T a2) const
{ return t | a0 | a1 | a2; } {
return t | a0 | a1 | a2;
}
T const_member_func4(T a0, T a1, T a2, T a3) const T const_member_func4(T a0, T a1, T a2, T a3) const
{ return t | a0 | a1 | a2 | a3; } {
return t | a0 | a1 | a2 | a3;
}
T const_member_func5(T a0, T a1, T a2, T a3, T a4) const T const_member_func5(T a0, T a1, T a2, T a3, T a4) const
{ return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0 | a1 | a2 | a3 | a4;
}
T volatile_member_func0() volatile T volatile_member_func0() volatile
{ return t; } {
return t;
}
T volatile_member_func1(T a0) volatile T volatile_member_func1(T a0) volatile
{ return t | a0; } {
return t | a0;
}
T volatile_member_func2(T a0, T a1) volatile T volatile_member_func2(T a0, T a1) volatile
{ return t | a0 | a1; } {
return t | a0 | a1;
}
T volatile_member_func3(T a0, T a1, T a2) volatile T volatile_member_func3(T a0, T a1, T a2) volatile
{ return t | a0 | a1 | a2; } {
return t | a0 | a1 | a2;
}
T volatile_member_func4(T a0, T a1, T a2, T a3) volatile T volatile_member_func4(T a0, T a1, T a2, T a3) volatile
{ return t | a0 | a1 | a2 | a3; } {
return t | a0 | a1 | a2 | a3;
}
T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile
{ return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0 | a1 | a2 | a3 | a4;
}
T const_volatile_member_func0() const volatile T const_volatile_member_func0() const volatile
{ return t; } {
return t;
}
T const_volatile_member_func1(T a0) const volatile T const_volatile_member_func1(T a0) const volatile
{ return t | a0; } {
return t | a0;
}
T const_volatile_member_func2(T a0, T a1) const volatile T const_volatile_member_func2(T a0, T a1) const volatile
{ return t | a0 | a1; } {
return t | a0 | a1;
}
T const_volatile_member_func3(T a0, T a1, T a2) const volatile T const_volatile_member_func3(T a0, T a1, T a2) const volatile
{ return t | a0 | a1 | a2; } {
return t | a0 | a1 | a2;
}
T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile
{ return t | a0 | a1 | a2 | a3; } {
return t | a0 | a1 | a2 | a3;
}
T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile
{ return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0 | a1 | a2 | a3 | a4;
}
}; };
// bound functions // bound functions
template <typename T> template <typename T>
T bound_func0(Thing<T> *t) T bound_func0(Thing<T> *t)
{ return t->t; } {
return t->t;
}
template <typename T> template <typename T>
T bound_func1(Thing<T> *t, T a0) T bound_func1(Thing<T> *t, T a0)
{ return t->t | a0; } {
return t->t | a0;
}
template <typename T> template <typename T>
T bound_func2(Thing<T> *t, T a0, T a1) T bound_func2(Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; } {
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T bound_func3(Thing<T> *t, T a0, T a1, T a2) T bound_func3(Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; } {
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3) T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; } {
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4) T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; } {
return t->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T const_bound_func0(const Thing<T> *t) T const_bound_func0(const Thing<T> *t)
{ return t->t; } {
return t->t;
}
template <typename T> template <typename T>
T const_bound_func1(const Thing<T> *t, T a0) T const_bound_func1(const Thing<T> *t, T a0)
{ return t->t | a0; } {
return t->t | a0;
}
template <typename T> template <typename T>
T const_bound_func2(const Thing<T> *t, T a0, T a1) T const_bound_func2(const Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; } {
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T const_bound_func3(const Thing<T> *t, T a0, T a1, T a2) T const_bound_func3(const Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; } {
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_bound_func4(const Thing<T> *t, T a0, T a1, T a2, T a3) T const_bound_func4(const Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; } {
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_bound_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4) T const_bound_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; } {
return t->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T volatile_bound_func0(volatile Thing<T> *t) T volatile_bound_func0(volatile Thing<T> *t)
{ return t->t; } {
return t->t;
}
template <typename T> template <typename T>
T volatile_bound_func1(volatile Thing<T> *t, T a0) T volatile_bound_func1(volatile Thing<T> *t, T a0)
{ return t->t | a0; } {
return t->t | a0;
}
template <typename T> template <typename T>
T volatile_bound_func2(volatile Thing<T> *t, T a0, T a1) T volatile_bound_func2(volatile Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; } {
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T volatile_bound_func3(volatile Thing<T> *t, T a0, T a1, T a2) T volatile_bound_func3(volatile Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; } {
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T volatile_bound_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3) T volatile_bound_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; } {
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T volatile_bound_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) T volatile_bound_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; } {
return t->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T const_volatile_bound_func0(const volatile Thing<T> *t) T const_volatile_bound_func0(const volatile Thing<T> *t)
{ return t->t; } {
return t->t;
}
template <typename T> template <typename T>
T const_volatile_bound_func1(const volatile Thing<T> *t, T a0) T const_volatile_bound_func1(const volatile Thing<T> *t, T a0)
{ return t->t | a0; } {
return t->t | a0;
}
template <typename T> template <typename T>
T const_volatile_bound_func2(const volatile Thing<T> *t, T a0, T a1) T const_volatile_bound_func2(const volatile Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; } {
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T const_volatile_bound_func3(const volatile Thing<T> *t, T a0, T a1, T a2) T const_volatile_bound_func3(const volatile Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; } {
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_volatile_bound_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3) T const_volatile_bound_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; } {
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_volatile_bound_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) T const_volatile_bound_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; } {
return t->t | a0 | a1 | a2 | a3 | a4;
}
// void functions // void functions
template <typename T> template <typename T>
T void_func0(void *t) T void_func0(void *t)
{ return static_cast<Thing<T>*>(t)->t; } {
return static_cast<Thing<T>*>(t)->t;
}
template <typename T> template <typename T>
T void_func1(void *t, T a0) T void_func1(void *t, T a0)
{ return static_cast<Thing<T>*>(t)->t | a0; } {
return static_cast<Thing<T>*>(t)->t | a0;
}
template <typename T> template <typename T>
T void_func2(void *t, T a0, T a1) T void_func2(void *t, T a0, T a1)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1; } {
return static_cast<Thing<T>*>(t)->t | a0 | a1;
}
template <typename T> template <typename T>
T void_func3(void *t, T a0, T a1, T a2) T void_func3(void *t, T a0, T a1, T a2)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2; } {
return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T void_func4(void *t, T a0, T a1, T a2, T a3) T void_func4(void *t, T a0, T a1, T a2, T a3)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } {
return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T void_func5(void *t, T a0, T a1, T a2, T a3, T a4) T void_func5(void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } {
return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T const_void_func0(const void *t) T const_void_func0(const void *t)
{ return static_cast<const Thing<T>*>(t)->t; } {
return static_cast<const Thing<T>*>(t)->t;
}
template <typename T> template <typename T>
T const_void_func1(const void *t, T a0) T const_void_func1(const void *t, T a0)
{ return static_cast<const Thing<T>*>(t)->t | a0; } {
return static_cast<const Thing<T>*>(t)->t | a0;
}
template <typename T> template <typename T>
T const_void_func2(const void *t, T a0, T a1) T const_void_func2(const void *t, T a0, T a1)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1; } {
return static_cast<const Thing<T>*>(t)->t | a0 | a1;
}
template <typename T> template <typename T>
T const_void_func3(const void *t, T a0, T a1, T a2) T const_void_func3(const void *t, T a0, T a1, T a2)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2; } {
return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_void_func4(const void *t, T a0, T a1, T a2, T a3) T const_void_func4(const void *t, T a0, T a1, T a2, T a3)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } {
return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_void_func5(const void *t, T a0, T a1, T a2, T a3, T a4) T const_void_func5(const void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } {
return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T volatile_void_func0(volatile void *t) T volatile_void_func0(volatile void *t)
{ return static_cast<volatile Thing<T>*>(t)->t; } {
return static_cast<volatile Thing<T>*>(t)->t;
}
template <typename T> template <typename T>
T volatile_void_func1(volatile void *t, T a0) T volatile_void_func1(volatile void *t, T a0)
{ return static_cast<volatile Thing<T>*>(t)->t | a0; } {
return static_cast<volatile Thing<T>*>(t)->t | a0;
}
template <typename T> template <typename T>
T volatile_void_func2(volatile void *t, T a0, T a1) T volatile_void_func2(volatile void *t, T a0, T a1)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1; } {
return static_cast<volatile Thing<T>*>(t)->t | a0 | a1;
}
template <typename T> template <typename T>
T volatile_void_func3(volatile void *t, T a0, T a1, T a2) T volatile_void_func3(volatile void *t, T a0, T a1, T a2)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2; } {
return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T volatile_void_func4(volatile void *t, T a0, T a1, T a2, T a3) T volatile_void_func4(volatile void *t, T a0, T a1, T a2, T a3)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } {
return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T volatile_void_func5(volatile void *t, T a0, T a1, T a2, T a3, T a4) T volatile_void_func5(volatile void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } {
return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T const_volatile_void_func0(const volatile void *t) T const_volatile_void_func0(const volatile void *t)
{ return static_cast<const volatile Thing<T>*>(t)->t; } {
return static_cast<const volatile Thing<T>*>(t)->t;
}
template <typename T> template <typename T>
T const_volatile_void_func1(const volatile void *t, T a0) T const_volatile_void_func1(const volatile void *t, T a0)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0; } {
return static_cast<const volatile Thing<T>*>(t)->t | a0;
}
template <typename T> template <typename T>
T const_volatile_void_func2(const volatile void *t, T a0, T a1) T const_volatile_void_func2(const volatile void *t, T a0, T a1)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1; } {
return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1;
}
template <typename T> template <typename T>
T const_volatile_void_func3(const volatile void *t, T a0, T a1, T a2) T const_volatile_void_func3(const volatile void *t, T a0, T a1, T a2)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2; } {
return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_volatile_void_func4(const volatile void *t, T a0, T a1, T a2, T a3) T const_volatile_void_func4(const volatile void *t, T a0, T a1, T a2, T a3)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } {
return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_volatile_void_func5(const volatile void *t, T a0, T a1, T a2, T a3, T a4) T const_volatile_void_func5(const volatile void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } {
return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4;
}
// Inheriting class // Inheriting class
template <typename T> template <typename T>
@ -257,73 +413,85 @@ class Thing2 : public Thing<T> {
// function call and result verification // function call and result verification
template <typename T> template <typename T>
struct Verifier { struct Verifier {
static void verify0(Callback<T()> func) { static void verify0(Callback<T()> func)
{
T result = func(); T result = func();
TEST_ASSERT_EQUAL(result, 0x00); TEST_ASSERT_EQUAL(result, 0x00);
} }
template <typename O, typename M> template <typename O, typename M>
static void verify0(O *obj, M method) { static void verify0(O *obj, M method)
{
Callback<T()> func(obj, method); Callback<T()> func(obj, method);
T result = func(); T result = func();
TEST_ASSERT_EQUAL(result, 0x80); TEST_ASSERT_EQUAL(result, 0x80);
} }
static void verify1(Callback<T(T)> func) { static void verify1(Callback<T(T)> func)
{
T result = func((1 << 0)); T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify1(O *obj, M method) { static void verify1(O *obj, M method)
{
Callback<T(T)> func(obj, method); Callback<T(T)> func(obj, method);
T result = func((1 << 0)); T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0));
} }
static void verify2(Callback<T(T, T)> func) { static void verify2(Callback<T(T, T)> func)
{
T result = func((1 << 0), (1 << 1)); T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify2(O *obj, M method) { static void verify2(O *obj, M method)
{
Callback<T(T, T)> func(obj, method); Callback<T(T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1)); T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1));
} }
static void verify3(Callback<T(T, T, T)> func) { static void verify3(Callback<T(T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2)); T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify3(O *obj, M method) { static void verify3(O *obj, M method)
{
Callback<T(T, T, T)> func(obj, method); Callback<T(T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2)); T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2));
} }
static void verify4(Callback<T(T, T, T, T)> func) { static void verify4(Callback<T(T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify4(O *obj, M method) { static void verify4(O *obj, M method)
{
Callback<T(T, T, T, T)> func(obj, method); Callback<T(T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
} }
static void verify5(Callback<T(T, T, T, T, T)> func) { static void verify5(Callback<T(T, T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify5(O *obj, M method) { static void verify5(O *obj, M method)
{
Callback<T(T, T, T, T, T)> func(obj, method); Callback<T(T, T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
@ -333,24 +501,25 @@ struct Verifier {
// test dispatch // test dispatch
template <typename T> template <typename T>
void test_dispatch0() { void test_dispatch0()
{
Thing<T> thing; Thing<T> thing;
Thing2<T> thing2; Thing2<T> thing2;
Verifier<T>::verify0(static_func0<T>); Verifier<T>::verify0(static_func0<T>);
Verifier<T>::verify0(&thing, &Thing<T>::member_func0); Verifier<T>::verify0(&thing, &Thing<T>::member_func0);
Verifier<T>::verify0((const Thing<T>*)&thing, &Thing<T>::const_member_func0); Verifier<T>::verify0((const Thing<T> *)&thing, &Thing<T>::const_member_func0);
Verifier<T>::verify0((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func0); Verifier<T>::verify0((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func0);
Verifier<T>::verify0((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func0); Verifier<T>::verify0((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func0);
Verifier<T>::verify0(&thing2, &Thing2<T>::member_func0); Verifier<T>::verify0(&thing2, &Thing2<T>::member_func0);
Verifier<T>::verify0(&bound_func0<T>, &thing); Verifier<T>::verify0(&bound_func0<T>, &thing);
Verifier<T>::verify0(&const_bound_func0<T>, (const Thing<T>*)&thing); Verifier<T>::verify0(&const_bound_func0<T>, (const Thing<T> *)&thing);
Verifier<T>::verify0(&volatile_bound_func0<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify0(&volatile_bound_func0<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify0(&const_volatile_bound_func0<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify0(&const_volatile_bound_func0<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify0(&bound_func0<T>, &thing2); Verifier<T>::verify0(&bound_func0<T>, &thing2);
Verifier<T>::verify0(&void_func0<T>, &thing); Verifier<T>::verify0(&void_func0<T>, &thing);
Verifier<T>::verify0(&const_void_func0<T>, (const Thing<T>*)&thing); Verifier<T>::verify0(&const_void_func0<T>, (const Thing<T> *)&thing);
Verifier<T>::verify0(&volatile_void_func0<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify0(&volatile_void_func0<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify0(&const_volatile_void_func0<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify0(&const_volatile_void_func0<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify0(callback(static_func0<T>)); Verifier<T>::verify0(callback(static_func0<T>));
Callback<T()> cb(static_func0); Callback<T()> cb(static_func0);
@ -359,28 +528,29 @@ void test_dispatch0() {
Verifier<T>::verify0(cb); Verifier<T>::verify0(cb);
cb.attach(&bound_func0<T>, &thing); cb.attach(&bound_func0<T>, &thing);
Verifier<T>::verify0(&cb, &Callback<T()>::call); Verifier<T>::verify0(&cb, &Callback<T()>::call);
Verifier<T>::verify0(&Callback<T()>::thunk, (void*)&cb); Verifier<T>::verify0(&Callback<T()>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch1() { void test_dispatch1()
{
Thing<T> thing; Thing<T> thing;
Thing2<T> thing2; Thing2<T> thing2;
Verifier<T>::verify1(static_func1<T>); Verifier<T>::verify1(static_func1<T>);
Verifier<T>::verify1(&thing, &Thing<T>::member_func1); Verifier<T>::verify1(&thing, &Thing<T>::member_func1);
Verifier<T>::verify1((const Thing<T>*)&thing, &Thing<T>::const_member_func1); Verifier<T>::verify1((const Thing<T> *)&thing, &Thing<T>::const_member_func1);
Verifier<T>::verify1((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func1); Verifier<T>::verify1((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func1);
Verifier<T>::verify1((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func1); Verifier<T>::verify1((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func1);
Verifier<T>::verify1(&thing2, &Thing2<T>::member_func1); Verifier<T>::verify1(&thing2, &Thing2<T>::member_func1);
Verifier<T>::verify1(&bound_func1<T>, &thing); Verifier<T>::verify1(&bound_func1<T>, &thing);
Verifier<T>::verify1(&const_bound_func1<T>, (const Thing<T>*)&thing); Verifier<T>::verify1(&const_bound_func1<T>, (const Thing<T> *)&thing);
Verifier<T>::verify1(&volatile_bound_func1<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify1(&volatile_bound_func1<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify1(&const_volatile_bound_func1<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify1(&const_volatile_bound_func1<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify1(&bound_func1<T>, &thing2); Verifier<T>::verify1(&bound_func1<T>, &thing2);
Verifier<T>::verify1(&void_func1<T>, &thing); Verifier<T>::verify1(&void_func1<T>, &thing);
Verifier<T>::verify1(&const_void_func1<T>, (const Thing<T>*)&thing); Verifier<T>::verify1(&const_void_func1<T>, (const Thing<T> *)&thing);
Verifier<T>::verify1(&volatile_void_func1<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify1(&volatile_void_func1<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify1(&const_volatile_void_func1<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify1(&const_volatile_void_func1<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify1(callback(static_func1<T>)); Verifier<T>::verify1(callback(static_func1<T>));
Callback<T(T)> cb(static_func1); Callback<T(T)> cb(static_func1);
@ -389,28 +559,29 @@ void test_dispatch1() {
Verifier<T>::verify1(cb); Verifier<T>::verify1(cb);
cb.attach(&bound_func1<T>, &thing); cb.attach(&bound_func1<T>, &thing);
Verifier<T>::verify1(&cb, &Callback<T(T)>::call); Verifier<T>::verify1(&cb, &Callback<T(T)>::call);
Verifier<T>::verify1(&Callback<T(T)>::thunk, (void*)&cb); Verifier<T>::verify1(&Callback<T(T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch2() { void test_dispatch2()
{
Thing<T> thing; Thing<T> thing;
Thing2<T> thing2; Thing2<T> thing2;
Verifier<T>::verify2(static_func2<T>); Verifier<T>::verify2(static_func2<T>);
Verifier<T>::verify2(&thing, &Thing<T>::member_func2); Verifier<T>::verify2(&thing, &Thing<T>::member_func2);
Verifier<T>::verify2((const Thing<T>*)&thing, &Thing<T>::const_member_func2); Verifier<T>::verify2((const Thing<T> *)&thing, &Thing<T>::const_member_func2);
Verifier<T>::verify2((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func2); Verifier<T>::verify2((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func2);
Verifier<T>::verify2((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func2); Verifier<T>::verify2((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func2);
Verifier<T>::verify2(&thing2, &Thing2<T>::member_func2); Verifier<T>::verify2(&thing2, &Thing2<T>::member_func2);
Verifier<T>::verify2(&bound_func2<T>, &thing); Verifier<T>::verify2(&bound_func2<T>, &thing);
Verifier<T>::verify2(&const_bound_func2<T>, (const Thing<T>*)&thing); Verifier<T>::verify2(&const_bound_func2<T>, (const Thing<T> *)&thing);
Verifier<T>::verify2(&volatile_bound_func2<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify2(&volatile_bound_func2<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify2(&const_volatile_bound_func2<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify2(&const_volatile_bound_func2<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify2(&bound_func2<T>, &thing2); Verifier<T>::verify2(&bound_func2<T>, &thing2);
Verifier<T>::verify2(&void_func2<T>, &thing); Verifier<T>::verify2(&void_func2<T>, &thing);
Verifier<T>::verify2(&const_void_func2<T>, (const Thing<T>*)&thing); Verifier<T>::verify2(&const_void_func2<T>, (const Thing<T> *)&thing);
Verifier<T>::verify2(&volatile_void_func2<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify2(&volatile_void_func2<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify2(&const_volatile_void_func2<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify2(&const_volatile_void_func2<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify2(callback(static_func2<T>)); Verifier<T>::verify2(callback(static_func2<T>));
Callback<T(T, T)> cb(static_func2); Callback<T(T, T)> cb(static_func2);
@ -419,28 +590,29 @@ void test_dispatch2() {
Verifier<T>::verify2(cb); Verifier<T>::verify2(cb);
cb.attach(&bound_func2<T>, &thing); cb.attach(&bound_func2<T>, &thing);
Verifier<T>::verify2(&cb, &Callback<T(T, T)>::call); Verifier<T>::verify2(&cb, &Callback<T(T, T)>::call);
Verifier<T>::verify2(&Callback<T(T, T)>::thunk, (void*)&cb); Verifier<T>::verify2(&Callback<T(T, T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch3() { void test_dispatch3()
{
Thing<T> thing; Thing<T> thing;
Thing2<T> thing2; Thing2<T> thing2;
Verifier<T>::verify3(static_func3<T>); Verifier<T>::verify3(static_func3<T>);
Verifier<T>::verify3(&thing, &Thing<T>::member_func3); Verifier<T>::verify3(&thing, &Thing<T>::member_func3);
Verifier<T>::verify3((const Thing<T>*)&thing, &Thing<T>::const_member_func3); Verifier<T>::verify3((const Thing<T> *)&thing, &Thing<T>::const_member_func3);
Verifier<T>::verify3((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func3); Verifier<T>::verify3((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func3);
Verifier<T>::verify3((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func3); Verifier<T>::verify3((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func3);
Verifier<T>::verify3(&thing2, &Thing2<T>::member_func3); Verifier<T>::verify3(&thing2, &Thing2<T>::member_func3);
Verifier<T>::verify3(&bound_func3<T>, &thing); Verifier<T>::verify3(&bound_func3<T>, &thing);
Verifier<T>::verify3(&const_bound_func3<T>, (const Thing<T>*)&thing); Verifier<T>::verify3(&const_bound_func3<T>, (const Thing<T> *)&thing);
Verifier<T>::verify3(&volatile_bound_func3<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify3(&volatile_bound_func3<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify3(&const_volatile_bound_func3<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify3(&const_volatile_bound_func3<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify3(&bound_func3<T>, &thing2); Verifier<T>::verify3(&bound_func3<T>, &thing2);
Verifier<T>::verify3(&void_func3<T>, &thing); Verifier<T>::verify3(&void_func3<T>, &thing);
Verifier<T>::verify3(&const_void_func3<T>, (const Thing<T>*)&thing); Verifier<T>::verify3(&const_void_func3<T>, (const Thing<T> *)&thing);
Verifier<T>::verify3(&volatile_void_func3<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify3(&volatile_void_func3<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify3(&const_volatile_void_func3<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify3(&const_volatile_void_func3<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify3(callback(static_func3<T>)); Verifier<T>::verify3(callback(static_func3<T>));
Callback<T(T, T, T)> cb(static_func3); Callback<T(T, T, T)> cb(static_func3);
@ -449,28 +621,29 @@ void test_dispatch3() {
Verifier<T>::verify3(cb); Verifier<T>::verify3(cb);
cb.attach(&bound_func3<T>, &thing); cb.attach(&bound_func3<T>, &thing);
Verifier<T>::verify3(&cb, &Callback<T(T, T, T)>::call); Verifier<T>::verify3(&cb, &Callback<T(T, T, T)>::call);
Verifier<T>::verify3(&Callback<T(T, T, T)>::thunk, (void*)&cb); Verifier<T>::verify3(&Callback<T(T, T, T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch4() { void test_dispatch4()
{
Thing<T> thing; Thing<T> thing;
Thing2<T> thing2; Thing2<T> thing2;
Verifier<T>::verify4(static_func4<T>); Verifier<T>::verify4(static_func4<T>);
Verifier<T>::verify4(&thing, &Thing<T>::member_func4); Verifier<T>::verify4(&thing, &Thing<T>::member_func4);
Verifier<T>::verify4((const Thing<T>*)&thing, &Thing<T>::const_member_func4); Verifier<T>::verify4((const Thing<T> *)&thing, &Thing<T>::const_member_func4);
Verifier<T>::verify4((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func4); Verifier<T>::verify4((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func4);
Verifier<T>::verify4((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func4); Verifier<T>::verify4((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func4);
Verifier<T>::verify4(&thing2, &Thing2<T>::member_func4); Verifier<T>::verify4(&thing2, &Thing2<T>::member_func4);
Verifier<T>::verify4(&bound_func4<T>, &thing); Verifier<T>::verify4(&bound_func4<T>, &thing);
Verifier<T>::verify4(&const_bound_func4<T>, (const Thing<T>*)&thing); Verifier<T>::verify4(&const_bound_func4<T>, (const Thing<T> *)&thing);
Verifier<T>::verify4(&volatile_bound_func4<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify4(&volatile_bound_func4<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify4(&const_volatile_bound_func4<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify4(&const_volatile_bound_func4<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify4(&bound_func4<T>, &thing2); Verifier<T>::verify4(&bound_func4<T>, &thing2);
Verifier<T>::verify4(&void_func4<T>, &thing); Verifier<T>::verify4(&void_func4<T>, &thing);
Verifier<T>::verify4(&const_void_func4<T>, (const Thing<T>*)&thing); Verifier<T>::verify4(&const_void_func4<T>, (const Thing<T> *)&thing);
Verifier<T>::verify4(&volatile_void_func4<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify4(&volatile_void_func4<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify4(&const_volatile_void_func4<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify4(&const_volatile_void_func4<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify4(callback(static_func4<T>)); Verifier<T>::verify4(callback(static_func4<T>));
Callback<T(T, T, T, T)> cb(static_func4); Callback<T(T, T, T, T)> cb(static_func4);
@ -479,28 +652,29 @@ void test_dispatch4() {
Verifier<T>::verify4(cb); Verifier<T>::verify4(cb);
cb.attach(&bound_func4<T>, &thing); cb.attach(&bound_func4<T>, &thing);
Verifier<T>::verify4(&cb, &Callback<T(T, T, T, T)>::call); Verifier<T>::verify4(&cb, &Callback<T(T, T, T, T)>::call);
Verifier<T>::verify4(&Callback<T(T, T, T, T)>::thunk, (void*)&cb); Verifier<T>::verify4(&Callback<T(T, T, T, T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch5() { void test_dispatch5()
{
Thing<T> thing; Thing<T> thing;
Thing2<T> thing2; Thing2<T> thing2;
Verifier<T>::verify5(static_func5<T>); Verifier<T>::verify5(static_func5<T>);
Verifier<T>::verify5(&thing, &Thing<T>::member_func5); Verifier<T>::verify5(&thing, &Thing<T>::member_func5);
Verifier<T>::verify5((const Thing<T>*)&thing, &Thing<T>::const_member_func5); Verifier<T>::verify5((const Thing<T> *)&thing, &Thing<T>::const_member_func5);
Verifier<T>::verify5((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func5); Verifier<T>::verify5((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func5);
Verifier<T>::verify5((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func5); Verifier<T>::verify5((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func5);
Verifier<T>::verify5(&thing2, &Thing2<T>::member_func5); Verifier<T>::verify5(&thing2, &Thing2<T>::member_func5);
Verifier<T>::verify5(&bound_func5<T>, &thing); Verifier<T>::verify5(&bound_func5<T>, &thing);
Verifier<T>::verify5(&const_bound_func5<T>, (const Thing<T>*)&thing); Verifier<T>::verify5(&const_bound_func5<T>, (const Thing<T> *)&thing);
Verifier<T>::verify5(&volatile_bound_func5<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify5(&volatile_bound_func5<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify5(&const_volatile_bound_func5<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify5(&const_volatile_bound_func5<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify5(&bound_func5<T>, &thing2); Verifier<T>::verify5(&bound_func5<T>, &thing2);
Verifier<T>::verify5(&void_func5<T>, &thing); Verifier<T>::verify5(&void_func5<T>, &thing);
Verifier<T>::verify5(&const_void_func5<T>, (const Thing<T>*)&thing); Verifier<T>::verify5(&const_void_func5<T>, (const Thing<T> *)&thing);
Verifier<T>::verify5(&volatile_void_func5<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify5(&volatile_void_func5<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify5(&const_volatile_void_func5<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify5(&const_volatile_void_func5<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify5(callback(static_func5<T>)); Verifier<T>::verify5(callback(static_func5<T>));
Callback<T(T, T, T, T, T)> cb(static_func5); Callback<T(T, T, T, T, T)> cb(static_func5);
@ -509,12 +683,13 @@ void test_dispatch5() {
Verifier<T>::verify5(cb); Verifier<T>::verify5(cb);
cb.attach(&bound_func5<T>, &thing); cb.attach(&bound_func5<T>, &thing);
Verifier<T>::verify5(&cb, &Callback<T(T, T, T, T, T)>::call); Verifier<T>::verify5(&cb, &Callback<T(T, T, T, T, T)>::call);
Verifier<T>::verify5(&Callback<T(T, T, T, T, T)>::thunk, (void*)&cb); Verifier<T>::verify5(&Callback<T(T, T, T, T, T)>::thunk, (void *)&cb);
} }
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto"); GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -530,6 +705,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -23,17 +23,35 @@ using namespace utest::v1;
// static functions // static functions
template <typename T> template <typename T>
T static_func0() { return 0; } T static_func0()
{
return 0;
}
template <typename T> template <typename T>
T static_func1(T a0) { return 0 | a0; } T static_func1(T a0)
{
return 0 | a0;
}
template <typename T> template <typename T>
T static_func2(T a0, T a1) { return 0 | a0 | a1; } T static_func2(T a0, T a1)
{
return 0 | a0 | a1;
}
template <typename T> template <typename T>
T static_func3(T a0, T a1, T a2) { return 0 | a0 | a1 | a2; } T static_func3(T a0, T a1, T a2)
{
return 0 | a0 | a1 | a2;
}
template <typename T> template <typename T>
T static_func4(T a0, T a1, T a2, T a3) { return 0 | a0 | a1 | a2 | a3; } T static_func4(T a0, T a1, T a2, T a3)
{
return 0 | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T static_func5(T a0, T a1, T a2, T a3, T a4) { return 0 | a0 | a1 | a2 | a3 | a4; } T static_func5(T a0, T a1, T a2, T a3, T a4)
{
return 0 | a0 | a1 | a2 | a3 | a4;
}
// class functions // class functions
template <typename T> template <typename T>
@ -41,162 +59,318 @@ struct Thing {
T t; T t;
Thing() : t(0x80) {} Thing() : t(0x80) {}
T member_func0() { return t; } T member_func0()
T member_func1(T a0) { return t | a0; } {
T member_func2(T a0, T a1) { return t | a0 | a1; } return t;
T member_func3(T a0, T a1, T a2) { return t | a0 | a1 | a2; } }
T member_func4(T a0, T a1, T a2, T a3) { return t | a0 | a1 | a2 | a3; } T member_func1(T a0)
T member_func5(T a0, T a1, T a2, T a3, T a4) { return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0;
}
T member_func2(T a0, T a1)
{
return t | a0 | a1;
}
T member_func3(T a0, T a1, T a2)
{
return t | a0 | a1 | a2;
}
T member_func4(T a0, T a1, T a2, T a3)
{
return t | a0 | a1 | a2 | a3;
}
T member_func5(T a0, T a1, T a2, T a3, T a4)
{
return t | a0 | a1 | a2 | a3 | a4;
}
T const_member_func0() const { return t; } T const_member_func0() const
T const_member_func1(T a0) const { return t | a0; } {
T const_member_func2(T a0, T a1) const { return t | a0 | a1; } return t;
T const_member_func3(T a0, T a1, T a2) const { return t | a0 | a1 | a2; } }
T const_member_func4(T a0, T a1, T a2, T a3) const { return t | a0 | a1 | a2 | a3; } T const_member_func1(T a0) const
T const_member_func5(T a0, T a1, T a2, T a3, T a4) const { return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0;
}
T const_member_func2(T a0, T a1) const
{
return t | a0 | a1;
}
T const_member_func3(T a0, T a1, T a2) const
{
return t | a0 | a1 | a2;
}
T const_member_func4(T a0, T a1, T a2, T a3) const
{
return t | a0 | a1 | a2 | a3;
}
T const_member_func5(T a0, T a1, T a2, T a3, T a4) const
{
return t | a0 | a1 | a2 | a3 | a4;
}
T volatile_member_func0() volatile { return t; } T volatile_member_func0() volatile
T volatile_member_func1(T a0) volatile { return t | a0; } {
T volatile_member_func2(T a0, T a1) volatile { return t | a0 | a1; } return t;
T volatile_member_func3(T a0, T a1, T a2) volatile { return t | a0 | a1 | a2; } }
T volatile_member_func4(T a0, T a1, T a2, T a3) volatile { return t | a0 | a1 | a2 | a3; } T volatile_member_func1(T a0) volatile
T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile { return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0;
}
T volatile_member_func2(T a0, T a1) volatile
{
return t | a0 | a1;
}
T volatile_member_func3(T a0, T a1, T a2) volatile
{
return t | a0 | a1 | a2;
}
T volatile_member_func4(T a0, T a1, T a2, T a3) volatile
{
return t | a0 | a1 | a2 | a3;
}
T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile
{
return t | a0 | a1 | a2 | a3 | a4;
}
T const_volatile_member_func0() const volatile { return t; } T const_volatile_member_func0() const volatile
T const_volatile_member_func1(T a0) const volatile { return t | a0; } {
T const_volatile_member_func2(T a0, T a1) const volatile { return t | a0 | a1; } return t;
T const_volatile_member_func3(T a0, T a1, T a2) const volatile { return t | a0 | a1 | a2; } }
T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile { return t | a0 | a1 | a2 | a3; } T const_volatile_member_func1(T a0) const volatile
T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile { return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0;
}
T const_volatile_member_func2(T a0, T a1) const volatile
{
return t | a0 | a1;
}
T const_volatile_member_func3(T a0, T a1, T a2) const volatile
{
return t | a0 | a1 | a2;
}
T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile
{
return t | a0 | a1 | a2 | a3;
}
T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile
{
return t | a0 | a1 | a2 | a3 | a4;
}
}; };
// bound functions // bound functions
template <typename T> template <typename T>
T bound_func0(Thing<T> *t) { return t->t; } T bound_func0(Thing<T> *t)
{
return t->t;
}
template <typename T> template <typename T>
T bound_func1(Thing<T> *t, T a0) { return t->t | a0; } T bound_func1(Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T> template <typename T>
T bound_func2(Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; } T bound_func2(Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T bound_func3(Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; } T bound_func3(Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; } T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; } T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// const bound functions // const bound functions
template <typename T> template <typename T>
T const_func0(const Thing<T> *t) { return t->t; } T const_func0(const Thing<T> *t)
{
return t->t;
}
template <typename T> template <typename T>
T const_func1(const Thing<T> *t, T a0) { return t->t | a0; } T const_func1(const Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T> template <typename T>
T const_func2(const Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; } T const_func2(const Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T const_func3(const Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; } T const_func3(const Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_func4(const Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; } T const_func4(const Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; } T const_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// volatile bound functions // volatile bound functions
template <typename T> template <typename T>
T volatile_func0(volatile Thing<T> *t) { return t->t; } T volatile_func0(volatile Thing<T> *t)
{
return t->t;
}
template <typename T> template <typename T>
T volatile_func1(volatile Thing<T> *t, T a0) { return t->t | a0; } T volatile_func1(volatile Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T> template <typename T>
T volatile_func2(volatile Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; } T volatile_func2(volatile Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T volatile_func3(volatile Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; } T volatile_func3(volatile Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T volatile_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; } T volatile_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T volatile_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; } T volatile_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// const volatile bound functions // const volatile bound functions
template <typename T> template <typename T>
T const_volatile_func0(const volatile Thing<T> *t) { return t->t; } T const_volatile_func0(const volatile Thing<T> *t)
{
return t->t;
}
template <typename T> template <typename T>
T const_volatile_func1(const volatile Thing<T> *t, T a0) { return t->t | a0; } T const_volatile_func1(const volatile Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T> template <typename T>
T const_volatile_func2(const volatile Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; } T const_volatile_func2(const volatile Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T const_volatile_func3(const volatile Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; } T const_volatile_func3(const volatile Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_volatile_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; } T const_volatile_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_volatile_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; } T const_volatile_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// function call and result verification // function call and result verification
template <typename T> template <typename T>
struct Verifier { struct Verifier {
static void verify0(Callback<T()> func) { static void verify0(Callback<T()> func)
{
T result = func(); T result = func();
TEST_ASSERT_EQUAL(result, 0x00); TEST_ASSERT_EQUAL(result, 0x00);
} }
template <typename O, typename M> template <typename O, typename M>
static void verify0(O *obj, M method) { static void verify0(O *obj, M method)
{
Callback<T()> func(obj, method); Callback<T()> func(obj, method);
T result = func(); T result = func();
TEST_ASSERT_EQUAL(result, 0x80); TEST_ASSERT_EQUAL(result, 0x80);
} }
static void verify1(Callback<T(T)> func) { static void verify1(Callback<T(T)> func)
{
T result = func((1 << 0)); T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify1(O *obj, M method) { static void verify1(O *obj, M method)
{
Callback<T(T)> func(obj, method); Callback<T(T)> func(obj, method);
T result = func((1 << 0)); T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0));
} }
static void verify2(Callback<T(T, T)> func) { static void verify2(Callback<T(T, T)> func)
{
T result = func((1 << 0), (1 << 1)); T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify2(O *obj, M method) { static void verify2(O *obj, M method)
{
Callback<T(T, T)> func(obj, method); Callback<T(T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1)); T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1));
} }
static void verify3(Callback<T(T, T, T)> func) { static void verify3(Callback<T(T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2)); T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify3(O *obj, M method) { static void verify3(O *obj, M method)
{
Callback<T(T, T, T)> func(obj, method); Callback<T(T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2)); T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2));
} }
static void verify4(Callback<T(T, T, T, T)> func) { static void verify4(Callback<T(T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify4(O *obj, M method) { static void verify4(O *obj, M method)
{
Callback<T(T, T, T, T)> func(obj, method); Callback<T(T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
} }
static void verify5(Callback<T(T, T, T, T, T)> func) { static void verify5(Callback<T(T, T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify5(O *obj, M method) { static void verify5(O *obj, M method)
{
Callback<T(T, T, T, T, T)> func(obj, method); Callback<T(T, T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
@ -206,17 +380,18 @@ struct Verifier {
// test dispatch // test dispatch
template <typename T> template <typename T>
void test_dispatch0() { void test_dispatch0()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify0(static_func0<T>); Verifier<T>::verify0(static_func0<T>);
Verifier<T>::verify0(&thing, &Thing<T>::member_func0); Verifier<T>::verify0(&thing, &Thing<T>::member_func0);
Verifier<T>::verify0((const Thing<T>*)&thing, &Thing<T>::const_member_func0); Verifier<T>::verify0((const Thing<T> *)&thing, &Thing<T>::const_member_func0);
Verifier<T>::verify0((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func0); Verifier<T>::verify0((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func0);
Verifier<T>::verify0((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func0); Verifier<T>::verify0((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func0);
Verifier<T>::verify0(&bound_func0<T>, &thing); Verifier<T>::verify0(&bound_func0<T>, &thing);
Verifier<T>::verify0(&const_func0<T>, (const Thing<T>*)&thing); Verifier<T>::verify0(&const_func0<T>, (const Thing<T> *)&thing);
Verifier<T>::verify0(&volatile_func0<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify0(&volatile_func0<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify0(&const_volatile_func0<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify0(&const_volatile_func0<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify0(callback(static_func0<T>)); Verifier<T>::verify0(callback(static_func0<T>));
Callback<T()> cb(static_func0); Callback<T()> cb(static_func0);
@ -225,21 +400,22 @@ void test_dispatch0() {
Verifier<T>::verify0(cb); Verifier<T>::verify0(cb);
cb.attach(&bound_func0<T>, &thing); cb.attach(&bound_func0<T>, &thing);
Verifier<T>::verify0(&cb, &Callback<T()>::call); Verifier<T>::verify0(&cb, &Callback<T()>::call);
Verifier<T>::verify0(&Callback<T()>::thunk, (void*)&cb); Verifier<T>::verify0(&Callback<T()>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch1() { void test_dispatch1()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify1(static_func1<T>); Verifier<T>::verify1(static_func1<T>);
Verifier<T>::verify1(&thing, &Thing<T>::member_func1); Verifier<T>::verify1(&thing, &Thing<T>::member_func1);
Verifier<T>::verify1((const Thing<T>*)&thing, &Thing<T>::const_member_func1); Verifier<T>::verify1((const Thing<T> *)&thing, &Thing<T>::const_member_func1);
Verifier<T>::verify1((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func1); Verifier<T>::verify1((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func1);
Verifier<T>::verify1((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func1); Verifier<T>::verify1((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func1);
Verifier<T>::verify1(&bound_func1<T>, &thing); Verifier<T>::verify1(&bound_func1<T>, &thing);
Verifier<T>::verify1(&const_func1<T>, (const Thing<T>*)&thing); Verifier<T>::verify1(&const_func1<T>, (const Thing<T> *)&thing);
Verifier<T>::verify1(&volatile_func1<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify1(&volatile_func1<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify1(&const_volatile_func1<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify1(&const_volatile_func1<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify1(callback(static_func1<T>)); Verifier<T>::verify1(callback(static_func1<T>));
Callback<T(T)> cb(static_func1); Callback<T(T)> cb(static_func1);
@ -248,21 +424,22 @@ void test_dispatch1() {
Verifier<T>::verify1(cb); Verifier<T>::verify1(cb);
cb.attach(&bound_func1<T>, &thing); cb.attach(&bound_func1<T>, &thing);
Verifier<T>::verify1(&cb, &Callback<T(T)>::call); Verifier<T>::verify1(&cb, &Callback<T(T)>::call);
Verifier<T>::verify1(&Callback<T(T)>::thunk, (void*)&cb); Verifier<T>::verify1(&Callback<T(T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch2() { void test_dispatch2()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify2(static_func2<T>); Verifier<T>::verify2(static_func2<T>);
Verifier<T>::verify2(&thing, &Thing<T>::member_func2); Verifier<T>::verify2(&thing, &Thing<T>::member_func2);
Verifier<T>::verify2((const Thing<T>*)&thing, &Thing<T>::const_member_func2); Verifier<T>::verify2((const Thing<T> *)&thing, &Thing<T>::const_member_func2);
Verifier<T>::verify2((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func2); Verifier<T>::verify2((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func2);
Verifier<T>::verify2((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func2); Verifier<T>::verify2((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func2);
Verifier<T>::verify2(&bound_func2<T>, &thing); Verifier<T>::verify2(&bound_func2<T>, &thing);
Verifier<T>::verify2(&const_func2<T>, (const Thing<T>*)&thing); Verifier<T>::verify2(&const_func2<T>, (const Thing<T> *)&thing);
Verifier<T>::verify2(&volatile_func2<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify2(&volatile_func2<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify2(&const_volatile_func2<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify2(&const_volatile_func2<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify2(callback(static_func2<T>)); Verifier<T>::verify2(callback(static_func2<T>));
Callback<T(T, T)> cb(static_func2); Callback<T(T, T)> cb(static_func2);
@ -271,21 +448,22 @@ void test_dispatch2() {
Verifier<T>::verify2(cb); Verifier<T>::verify2(cb);
cb.attach(&bound_func2<T>, &thing); cb.attach(&bound_func2<T>, &thing);
Verifier<T>::verify2(&cb, &Callback<T(T, T)>::call); Verifier<T>::verify2(&cb, &Callback<T(T, T)>::call);
Verifier<T>::verify2(&Callback<T(T, T)>::thunk, (void*)&cb); Verifier<T>::verify2(&Callback<T(T, T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch3() { void test_dispatch3()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify3(static_func3<T>); Verifier<T>::verify3(static_func3<T>);
Verifier<T>::verify3(&thing, &Thing<T>::member_func3); Verifier<T>::verify3(&thing, &Thing<T>::member_func3);
Verifier<T>::verify3((const Thing<T>*)&thing, &Thing<T>::const_member_func3); Verifier<T>::verify3((const Thing<T> *)&thing, &Thing<T>::const_member_func3);
Verifier<T>::verify3((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func3); Verifier<T>::verify3((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func3);
Verifier<T>::verify3((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func3); Verifier<T>::verify3((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func3);
Verifier<T>::verify3(&bound_func3<T>, &thing); Verifier<T>::verify3(&bound_func3<T>, &thing);
Verifier<T>::verify3(&const_func3<T>, (const Thing<T>*)&thing); Verifier<T>::verify3(&const_func3<T>, (const Thing<T> *)&thing);
Verifier<T>::verify3(&volatile_func3<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify3(&volatile_func3<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify3(&const_volatile_func3<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify3(&const_volatile_func3<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify3(callback(static_func3<T>)); Verifier<T>::verify3(callback(static_func3<T>));
Callback<T(T, T, T)> cb(static_func3); Callback<T(T, T, T)> cb(static_func3);
@ -294,21 +472,22 @@ void test_dispatch3() {
Verifier<T>::verify3(cb); Verifier<T>::verify3(cb);
cb.attach(&bound_func3<T>, &thing); cb.attach(&bound_func3<T>, &thing);
Verifier<T>::verify3(&cb, &Callback<T(T, T, T)>::call); Verifier<T>::verify3(&cb, &Callback<T(T, T, T)>::call);
Verifier<T>::verify3(&Callback<T(T, T, T)>::thunk, (void*)&cb); Verifier<T>::verify3(&Callback<T(T, T, T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch4() { void test_dispatch4()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify4(static_func4<T>); Verifier<T>::verify4(static_func4<T>);
Verifier<T>::verify4(&thing, &Thing<T>::member_func4); Verifier<T>::verify4(&thing, &Thing<T>::member_func4);
Verifier<T>::verify4((const Thing<T>*)&thing, &Thing<T>::const_member_func4); Verifier<T>::verify4((const Thing<T> *)&thing, &Thing<T>::const_member_func4);
Verifier<T>::verify4((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func4); Verifier<T>::verify4((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func4);
Verifier<T>::verify4((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func4); Verifier<T>::verify4((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func4);
Verifier<T>::verify4(&bound_func4<T>, &thing); Verifier<T>::verify4(&bound_func4<T>, &thing);
Verifier<T>::verify4(&const_func4<T>, (const Thing<T>*)&thing); Verifier<T>::verify4(&const_func4<T>, (const Thing<T> *)&thing);
Verifier<T>::verify4(&volatile_func4<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify4(&volatile_func4<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify4(&const_volatile_func4<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify4(&const_volatile_func4<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify4(callback(static_func4<T>)); Verifier<T>::verify4(callback(static_func4<T>));
Callback<T(T, T, T, T)> cb(static_func4); Callback<T(T, T, T, T)> cb(static_func4);
@ -317,21 +496,22 @@ void test_dispatch4() {
Verifier<T>::verify4(cb); Verifier<T>::verify4(cb);
cb.attach(&bound_func4<T>, &thing); cb.attach(&bound_func4<T>, &thing);
Verifier<T>::verify4(&cb, &Callback<T(T, T, T, T)>::call); Verifier<T>::verify4(&cb, &Callback<T(T, T, T, T)>::call);
Verifier<T>::verify4(&Callback<T(T, T, T, T)>::thunk, (void*)&cb); Verifier<T>::verify4(&Callback<T(T, T, T, T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch5() { void test_dispatch5()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify5(static_func5<T>); Verifier<T>::verify5(static_func5<T>);
Verifier<T>::verify5(&thing, &Thing<T>::member_func5); Verifier<T>::verify5(&thing, &Thing<T>::member_func5);
Verifier<T>::verify5((const Thing<T>*)&thing, &Thing<T>::const_member_func5); Verifier<T>::verify5((const Thing<T> *)&thing, &Thing<T>::const_member_func5);
Verifier<T>::verify5((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func5); Verifier<T>::verify5((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func5);
Verifier<T>::verify5((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func5); Verifier<T>::verify5((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func5);
Verifier<T>::verify5(&bound_func5<T>, &thing); Verifier<T>::verify5(&bound_func5<T>, &thing);
Verifier<T>::verify5(&const_func5<T>, (const Thing<T>*)&thing); Verifier<T>::verify5(&const_func5<T>, (const Thing<T> *)&thing);
Verifier<T>::verify5(&volatile_func5<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify5(&volatile_func5<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify5(&const_volatile_func5<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify5(&const_volatile_func5<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify5(callback(static_func5<T>)); Verifier<T>::verify5(callback(static_func5<T>));
Callback<T(T, T, T, T, T)> cb(static_func5); Callback<T(T, T, T, T, T)> cb(static_func5);
@ -340,12 +520,13 @@ void test_dispatch5() {
Verifier<T>::verify5(cb); Verifier<T>::verify5(cb);
cb.attach(&bound_func5<T>, &thing); cb.attach(&bound_func5<T>, &thing);
Verifier<T>::verify5(&cb, &Callback<T(T, T, T, T, T)>::call); Verifier<T>::verify5(&cb, &Callback<T(T, T, T, T, T)>::call);
Verifier<T>::verify5(&Callback<T(T, T, T, T, T)>::thunk, (void*)&cb); Verifier<T>::verify5(&Callback<T(T, T, T, T, T)>::thunk, (void *)&cb);
} }
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto"); GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -361,6 +542,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -23,17 +23,35 @@ using namespace utest::v1;
// static functions // static functions
template <typename T> template <typename T>
T static_func0() { return 0; } T static_func0()
{
return 0;
}
template <typename T> template <typename T>
T static_func1(T a0) { return 0 | a0; } T static_func1(T a0)
{
return 0 | a0;
}
template <typename T> template <typename T>
T static_func2(T a0, T a1) { return 0 | a0 | a1; } T static_func2(T a0, T a1)
{
return 0 | a0 | a1;
}
template <typename T> template <typename T>
T static_func3(T a0, T a1, T a2) { return 0 | a0 | a1 | a2; } T static_func3(T a0, T a1, T a2)
{
return 0 | a0 | a1 | a2;
}
template <typename T> template <typename T>
T static_func4(T a0, T a1, T a2, T a3) { return 0 | a0 | a1 | a2 | a3; } T static_func4(T a0, T a1, T a2, T a3)
{
return 0 | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T static_func5(T a0, T a1, T a2, T a3, T a4) { return 0 | a0 | a1 | a2 | a3 | a4; } T static_func5(T a0, T a1, T a2, T a3, T a4)
{
return 0 | a0 | a1 | a2 | a3 | a4;
}
// class functions // class functions
template <typename T> template <typename T>
@ -41,162 +59,318 @@ struct Thing {
T t; T t;
Thing() : t(0x80) {} Thing() : t(0x80) {}
T member_func0() { return t; } T member_func0()
T member_func1(T a0) { return t | a0; } {
T member_func2(T a0, T a1) { return t | a0 | a1; } return t;
T member_func3(T a0, T a1, T a2) { return t | a0 | a1 | a2; } }
T member_func4(T a0, T a1, T a2, T a3) { return t | a0 | a1 | a2 | a3; } T member_func1(T a0)
T member_func5(T a0, T a1, T a2, T a3, T a4) { return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0;
}
T member_func2(T a0, T a1)
{
return t | a0 | a1;
}
T member_func3(T a0, T a1, T a2)
{
return t | a0 | a1 | a2;
}
T member_func4(T a0, T a1, T a2, T a3)
{
return t | a0 | a1 | a2 | a3;
}
T member_func5(T a0, T a1, T a2, T a3, T a4)
{
return t | a0 | a1 | a2 | a3 | a4;
}
T const_member_func0() const { return t; } T const_member_func0() const
T const_member_func1(T a0) const { return t | a0; } {
T const_member_func2(T a0, T a1) const { return t | a0 | a1; } return t;
T const_member_func3(T a0, T a1, T a2) const { return t | a0 | a1 | a2; } }
T const_member_func4(T a0, T a1, T a2, T a3) const { return t | a0 | a1 | a2 | a3; } T const_member_func1(T a0) const
T const_member_func5(T a0, T a1, T a2, T a3, T a4) const { return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0;
}
T const_member_func2(T a0, T a1) const
{
return t | a0 | a1;
}
T const_member_func3(T a0, T a1, T a2) const
{
return t | a0 | a1 | a2;
}
T const_member_func4(T a0, T a1, T a2, T a3) const
{
return t | a0 | a1 | a2 | a3;
}
T const_member_func5(T a0, T a1, T a2, T a3, T a4) const
{
return t | a0 | a1 | a2 | a3 | a4;
}
T volatile_member_func0() volatile { return t; } T volatile_member_func0() volatile
T volatile_member_func1(T a0) volatile { return t | a0; } {
T volatile_member_func2(T a0, T a1) volatile { return t | a0 | a1; } return t;
T volatile_member_func3(T a0, T a1, T a2) volatile { return t | a0 | a1 | a2; } }
T volatile_member_func4(T a0, T a1, T a2, T a3) volatile { return t | a0 | a1 | a2 | a3; } T volatile_member_func1(T a0) volatile
T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile { return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0;
}
T volatile_member_func2(T a0, T a1) volatile
{
return t | a0 | a1;
}
T volatile_member_func3(T a0, T a1, T a2) volatile
{
return t | a0 | a1 | a2;
}
T volatile_member_func4(T a0, T a1, T a2, T a3) volatile
{
return t | a0 | a1 | a2 | a3;
}
T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile
{
return t | a0 | a1 | a2 | a3 | a4;
}
T const_volatile_member_func0() const volatile { return t; } T const_volatile_member_func0() const volatile
T const_volatile_member_func1(T a0) const volatile { return t | a0; } {
T const_volatile_member_func2(T a0, T a1) const volatile { return t | a0 | a1; } return t;
T const_volatile_member_func3(T a0, T a1, T a2) const volatile { return t | a0 | a1 | a2; } }
T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile { return t | a0 | a1 | a2 | a3; } T const_volatile_member_func1(T a0) const volatile
T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile { return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0;
}
T const_volatile_member_func2(T a0, T a1) const volatile
{
return t | a0 | a1;
}
T const_volatile_member_func3(T a0, T a1, T a2) const volatile
{
return t | a0 | a1 | a2;
}
T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile
{
return t | a0 | a1 | a2 | a3;
}
T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile
{
return t | a0 | a1 | a2 | a3 | a4;
}
}; };
// bound functions // bound functions
template <typename T> template <typename T>
T bound_func0(Thing<T> *t) { return t->t; } T bound_func0(Thing<T> *t)
{
return t->t;
}
template <typename T> template <typename T>
T bound_func1(Thing<T> *t, T a0) { return t->t | a0; } T bound_func1(Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T> template <typename T>
T bound_func2(Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; } T bound_func2(Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T bound_func3(Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; } T bound_func3(Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; } T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; } T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// const bound functions // const bound functions
template <typename T> template <typename T>
T const_func0(const Thing<T> *t) { return t->t; } T const_func0(const Thing<T> *t)
{
return t->t;
}
template <typename T> template <typename T>
T const_func1(const Thing<T> *t, T a0) { return t->t | a0; } T const_func1(const Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T> template <typename T>
T const_func2(const Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; } T const_func2(const Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T const_func3(const Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; } T const_func3(const Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_func4(const Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; } T const_func4(const Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; } T const_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// volatile bound functions // volatile bound functions
template <typename T> template <typename T>
T volatile_func0(volatile Thing<T> *t) { return t->t; } T volatile_func0(volatile Thing<T> *t)
{
return t->t;
}
template <typename T> template <typename T>
T volatile_func1(volatile Thing<T> *t, T a0) { return t->t | a0; } T volatile_func1(volatile Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T> template <typename T>
T volatile_func2(volatile Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; } T volatile_func2(volatile Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T volatile_func3(volatile Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; } T volatile_func3(volatile Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T volatile_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; } T volatile_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T volatile_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; } T volatile_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// const volatile bound functions // const volatile bound functions
template <typename T> template <typename T>
T const_volatile_func0(const volatile Thing<T> *t) { return t->t; } T const_volatile_func0(const volatile Thing<T> *t)
{
return t->t;
}
template <typename T> template <typename T>
T const_volatile_func1(const volatile Thing<T> *t, T a0) { return t->t | a0; } T const_volatile_func1(const volatile Thing<T> *t, T a0)
{
return t->t | a0;
}
template <typename T> template <typename T>
T const_volatile_func2(const volatile Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; } T const_volatile_func2(const volatile Thing<T> *t, T a0, T a1)
{
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T const_volatile_func3(const volatile Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; } T const_volatile_func3(const volatile Thing<T> *t, T a0, T a1, T a2)
{
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_volatile_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; } T const_volatile_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_volatile_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; } T const_volatile_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{
return t->t | a0 | a1 | a2 | a3 | a4;
}
// function call and result verification // function call and result verification
template <typename T> template <typename T>
struct Verifier { struct Verifier {
static void verify0(Callback<T()> func) { static void verify0(Callback<T()> func)
{
T result = func(); T result = func();
TEST_ASSERT_EQUAL(result, 0x00); TEST_ASSERT_EQUAL(result, 0x00);
} }
template <typename O, typename M> template <typename O, typename M>
static void verify0(O *obj, M method) { static void verify0(O *obj, M method)
{
Callback<T()> func(obj, method); Callback<T()> func(obj, method);
T result = func(); T result = func();
TEST_ASSERT_EQUAL(result, 0x80); TEST_ASSERT_EQUAL(result, 0x80);
} }
static void verify1(Callback<T(T)> func) { static void verify1(Callback<T(T)> func)
{
T result = func((1 << 0)); T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify1(O *obj, M method) { static void verify1(O *obj, M method)
{
Callback<T(T)> func(obj, method); Callback<T(T)> func(obj, method);
T result = func((1 << 0)); T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0));
} }
static void verify2(Callback<T(T, T)> func) { static void verify2(Callback<T(T, T)> func)
{
T result = func((1 << 0), (1 << 1)); T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify2(O *obj, M method) { static void verify2(O *obj, M method)
{
Callback<T(T, T)> func(obj, method); Callback<T(T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1)); T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1));
} }
static void verify3(Callback<T(T, T, T)> func) { static void verify3(Callback<T(T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2)); T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify3(O *obj, M method) { static void verify3(O *obj, M method)
{
Callback<T(T, T, T)> func(obj, method); Callback<T(T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2)); T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2));
} }
static void verify4(Callback<T(T, T, T, T)> func) { static void verify4(Callback<T(T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify4(O *obj, M method) { static void verify4(O *obj, M method)
{
Callback<T(T, T, T, T)> func(obj, method); Callback<T(T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
} }
static void verify5(Callback<T(T, T, T, T, T)> func) { static void verify5(Callback<T(T, T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify5(O *obj, M method) { static void verify5(O *obj, M method)
{
Callback<T(T, T, T, T, T)> func(obj, method); Callback<T(T, T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
@ -206,17 +380,18 @@ struct Verifier {
// test dispatch // test dispatch
template <typename T> template <typename T>
void test_dispatch0() { void test_dispatch0()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify0(static_func0<T>); Verifier<T>::verify0(static_func0<T>);
Verifier<T>::verify0(&thing, &Thing<T>::member_func0); Verifier<T>::verify0(&thing, &Thing<T>::member_func0);
Verifier<T>::verify0((const Thing<T>*)&thing, &Thing<T>::const_member_func0); Verifier<T>::verify0((const Thing<T> *)&thing, &Thing<T>::const_member_func0);
Verifier<T>::verify0((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func0); Verifier<T>::verify0((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func0);
Verifier<T>::verify0((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func0); Verifier<T>::verify0((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func0);
Verifier<T>::verify0(&bound_func0<T>, &thing); Verifier<T>::verify0(&bound_func0<T>, &thing);
Verifier<T>::verify0(&const_func0<T>, (const Thing<T>*)&thing); Verifier<T>::verify0(&const_func0<T>, (const Thing<T> *)&thing);
Verifier<T>::verify0(&volatile_func0<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify0(&volatile_func0<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify0(&const_volatile_func0<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify0(&const_volatile_func0<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify0(callback(static_func0<T>)); Verifier<T>::verify0(callback(static_func0<T>));
Callback<T()> cb(static_func0); Callback<T()> cb(static_func0);
@ -225,21 +400,22 @@ void test_dispatch0() {
Verifier<T>::verify0(cb); Verifier<T>::verify0(cb);
cb.attach(&bound_func0<T>, &thing); cb.attach(&bound_func0<T>, &thing);
Verifier<T>::verify0(&cb, &Callback<T()>::call); Verifier<T>::verify0(&cb, &Callback<T()>::call);
Verifier<T>::verify0(&Callback<T()>::thunk, (void*)&cb); Verifier<T>::verify0(&Callback<T()>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch1() { void test_dispatch1()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify1(static_func1<T>); Verifier<T>::verify1(static_func1<T>);
Verifier<T>::verify1(&thing, &Thing<T>::member_func1); Verifier<T>::verify1(&thing, &Thing<T>::member_func1);
Verifier<T>::verify1((const Thing<T>*)&thing, &Thing<T>::const_member_func1); Verifier<T>::verify1((const Thing<T> *)&thing, &Thing<T>::const_member_func1);
Verifier<T>::verify1((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func1); Verifier<T>::verify1((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func1);
Verifier<T>::verify1((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func1); Verifier<T>::verify1((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func1);
Verifier<T>::verify1(&bound_func1<T>, &thing); Verifier<T>::verify1(&bound_func1<T>, &thing);
Verifier<T>::verify1(&const_func1<T>, (const Thing<T>*)&thing); Verifier<T>::verify1(&const_func1<T>, (const Thing<T> *)&thing);
Verifier<T>::verify1(&volatile_func1<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify1(&volatile_func1<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify1(&const_volatile_func1<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify1(&const_volatile_func1<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify1(callback(static_func1<T>)); Verifier<T>::verify1(callback(static_func1<T>));
Callback<T(T)> cb(static_func1); Callback<T(T)> cb(static_func1);
@ -248,21 +424,22 @@ void test_dispatch1() {
Verifier<T>::verify1(cb); Verifier<T>::verify1(cb);
cb.attach(&bound_func1<T>, &thing); cb.attach(&bound_func1<T>, &thing);
Verifier<T>::verify1(&cb, &Callback<T(T)>::call); Verifier<T>::verify1(&cb, &Callback<T(T)>::call);
Verifier<T>::verify1(&Callback<T(T)>::thunk, (void*)&cb); Verifier<T>::verify1(&Callback<T(T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch2() { void test_dispatch2()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify2(static_func2<T>); Verifier<T>::verify2(static_func2<T>);
Verifier<T>::verify2(&thing, &Thing<T>::member_func2); Verifier<T>::verify2(&thing, &Thing<T>::member_func2);
Verifier<T>::verify2((const Thing<T>*)&thing, &Thing<T>::const_member_func2); Verifier<T>::verify2((const Thing<T> *)&thing, &Thing<T>::const_member_func2);
Verifier<T>::verify2((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func2); Verifier<T>::verify2((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func2);
Verifier<T>::verify2((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func2); Verifier<T>::verify2((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func2);
Verifier<T>::verify2(&bound_func2<T>, &thing); Verifier<T>::verify2(&bound_func2<T>, &thing);
Verifier<T>::verify2(&const_func2<T>, (const Thing<T>*)&thing); Verifier<T>::verify2(&const_func2<T>, (const Thing<T> *)&thing);
Verifier<T>::verify2(&volatile_func2<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify2(&volatile_func2<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify2(&const_volatile_func2<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify2(&const_volatile_func2<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify2(callback(static_func2<T>)); Verifier<T>::verify2(callback(static_func2<T>));
Callback<T(T, T)> cb(static_func2); Callback<T(T, T)> cb(static_func2);
@ -271,21 +448,22 @@ void test_dispatch2() {
Verifier<T>::verify2(cb); Verifier<T>::verify2(cb);
cb.attach(&bound_func2<T>, &thing); cb.attach(&bound_func2<T>, &thing);
Verifier<T>::verify2(&cb, &Callback<T(T, T)>::call); Verifier<T>::verify2(&cb, &Callback<T(T, T)>::call);
Verifier<T>::verify2(&Callback<T(T, T)>::thunk, (void*)&cb); Verifier<T>::verify2(&Callback<T(T, T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch3() { void test_dispatch3()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify3(static_func3<T>); Verifier<T>::verify3(static_func3<T>);
Verifier<T>::verify3(&thing, &Thing<T>::member_func3); Verifier<T>::verify3(&thing, &Thing<T>::member_func3);
Verifier<T>::verify3((const Thing<T>*)&thing, &Thing<T>::const_member_func3); Verifier<T>::verify3((const Thing<T> *)&thing, &Thing<T>::const_member_func3);
Verifier<T>::verify3((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func3); Verifier<T>::verify3((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func3);
Verifier<T>::verify3((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func3); Verifier<T>::verify3((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func3);
Verifier<T>::verify3(&bound_func3<T>, &thing); Verifier<T>::verify3(&bound_func3<T>, &thing);
Verifier<T>::verify3(&const_func3<T>, (const Thing<T>*)&thing); Verifier<T>::verify3(&const_func3<T>, (const Thing<T> *)&thing);
Verifier<T>::verify3(&volatile_func3<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify3(&volatile_func3<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify3(&const_volatile_func3<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify3(&const_volatile_func3<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify3(callback(static_func3<T>)); Verifier<T>::verify3(callback(static_func3<T>));
Callback<T(T, T, T)> cb(static_func3); Callback<T(T, T, T)> cb(static_func3);
@ -294,21 +472,22 @@ void test_dispatch3() {
Verifier<T>::verify3(cb); Verifier<T>::verify3(cb);
cb.attach(&bound_func3<T>, &thing); cb.attach(&bound_func3<T>, &thing);
Verifier<T>::verify3(&cb, &Callback<T(T, T, T)>::call); Verifier<T>::verify3(&cb, &Callback<T(T, T, T)>::call);
Verifier<T>::verify3(&Callback<T(T, T, T)>::thunk, (void*)&cb); Verifier<T>::verify3(&Callback<T(T, T, T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch4() { void test_dispatch4()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify4(static_func4<T>); Verifier<T>::verify4(static_func4<T>);
Verifier<T>::verify4(&thing, &Thing<T>::member_func4); Verifier<T>::verify4(&thing, &Thing<T>::member_func4);
Verifier<T>::verify4((const Thing<T>*)&thing, &Thing<T>::const_member_func4); Verifier<T>::verify4((const Thing<T> *)&thing, &Thing<T>::const_member_func4);
Verifier<T>::verify4((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func4); Verifier<T>::verify4((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func4);
Verifier<T>::verify4((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func4); Verifier<T>::verify4((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func4);
Verifier<T>::verify4(&bound_func4<T>, &thing); Verifier<T>::verify4(&bound_func4<T>, &thing);
Verifier<T>::verify4(&const_func4<T>, (const Thing<T>*)&thing); Verifier<T>::verify4(&const_func4<T>, (const Thing<T> *)&thing);
Verifier<T>::verify4(&volatile_func4<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify4(&volatile_func4<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify4(&const_volatile_func4<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify4(&const_volatile_func4<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify4(callback(static_func4<T>)); Verifier<T>::verify4(callback(static_func4<T>));
Callback<T(T, T, T, T)> cb(static_func4); Callback<T(T, T, T, T)> cb(static_func4);
@ -317,21 +496,22 @@ void test_dispatch4() {
Verifier<T>::verify4(cb); Verifier<T>::verify4(cb);
cb.attach(&bound_func4<T>, &thing); cb.attach(&bound_func4<T>, &thing);
Verifier<T>::verify4(&cb, &Callback<T(T, T, T, T)>::call); Verifier<T>::verify4(&cb, &Callback<T(T, T, T, T)>::call);
Verifier<T>::verify4(&Callback<T(T, T, T, T)>::thunk, (void*)&cb); Verifier<T>::verify4(&Callback<T(T, T, T, T)>::thunk, (void *)&cb);
} }
template <typename T> template <typename T>
void test_dispatch5() { void test_dispatch5()
{
Thing<T> thing; Thing<T> thing;
Verifier<T>::verify5(static_func5<T>); Verifier<T>::verify5(static_func5<T>);
Verifier<T>::verify5(&thing, &Thing<T>::member_func5); Verifier<T>::verify5(&thing, &Thing<T>::member_func5);
Verifier<T>::verify5((const Thing<T>*)&thing, &Thing<T>::const_member_func5); Verifier<T>::verify5((const Thing<T> *)&thing, &Thing<T>::const_member_func5);
Verifier<T>::verify5((volatile Thing<T>*)&thing, &Thing<T>::volatile_member_func5); Verifier<T>::verify5((volatile Thing<T> *)&thing, &Thing<T>::volatile_member_func5);
Verifier<T>::verify5((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_member_func5); Verifier<T>::verify5((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func5);
Verifier<T>::verify5(&bound_func5<T>, &thing); Verifier<T>::verify5(&bound_func5<T>, &thing);
Verifier<T>::verify5(&const_func5<T>, (const Thing<T>*)&thing); Verifier<T>::verify5(&const_func5<T>, (const Thing<T> *)&thing);
Verifier<T>::verify5(&volatile_func5<T>, (volatile Thing<T>*)&thing); Verifier<T>::verify5(&volatile_func5<T>, (volatile Thing<T> *)&thing);
Verifier<T>::verify5(&const_volatile_func5<T>, (const volatile Thing<T>*)&thing); Verifier<T>::verify5(&const_volatile_func5<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify5(callback(static_func5<T>)); Verifier<T>::verify5(callback(static_func5<T>));
Callback<T(T, T, T, T, T)> cb(static_func5); Callback<T(T, T, T, T, T)> cb(static_func5);
@ -340,12 +520,13 @@ void test_dispatch5() {
Verifier<T>::verify5(cb); Verifier<T>::verify5(cb);
cb.attach(&bound_func5<T>, &thing); cb.attach(&bound_func5<T>, &thing);
Verifier<T>::verify5(&cb, &Callback<T(T, T, T, T, T)>::call); Verifier<T>::verify5(&cb, &Callback<T(T, T, T, T, T)>::call);
Verifier<T>::verify5(&Callback<T(T, T, T, T, T)>::thunk, (void*)&cb); Verifier<T>::verify5(&Callback<T(T, T, T, T, T)>::thunk, (void *)&cb);
} }
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto"); GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -361,6 +542,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -24,22 +24,34 @@ using namespace utest::v1;
// static functions // static functions
template <typename T> template <typename T>
T static_func0() T static_func0()
{ return 0; } {
return 0;
}
template <typename T> template <typename T>
T static_func1(T a0) T static_func1(T a0)
{ return 0 | a0; } {
return 0 | a0;
}
template <typename T> template <typename T>
T static_func2(T a0, T a1) T static_func2(T a0, T a1)
{ return 0 | a0 | a1; } {
return 0 | a0 | a1;
}
template <typename T> template <typename T>
T static_func3(T a0, T a1, T a2) T static_func3(T a0, T a1, T a2)
{ return 0 | a0 | a1 | a2; } {
return 0 | a0 | a1 | a2;
}
template <typename T> template <typename T>
T static_func4(T a0, T a1, T a2, T a3) T static_func4(T a0, T a1, T a2, T a3)
{ return 0 | a0 | a1 | a2 | a3; } {
return 0 | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T static_func5(T a0, T a1, T a2, T a3, T a4) T static_func5(T a0, T a1, T a2, T a3, T a4)
{ return 0 | a0 | a1 | a2 | a3 | a4; } {
return 0 | a0 | a1 | a2 | a3 | a4;
}
// class functions // class functions
template <typename T> template <typename T>
@ -48,277 +60,433 @@ struct Thing {
Thing() : t(0x80) {} Thing() : t(0x80) {}
T member_func0() T member_func0()
{ return t; } {
return t;
}
T member_func1(T a0) T member_func1(T a0)
{ return t | a0; } {
return t | a0;
}
T member_func2(T a0, T a1) T member_func2(T a0, T a1)
{ return t | a0 | a1; } {
return t | a0 | a1;
}
T member_func3(T a0, T a1, T a2) T member_func3(T a0, T a1, T a2)
{ return t | a0 | a1 | a2; } {
return t | a0 | a1 | a2;
}
T member_func4(T a0, T a1, T a2, T a3) T member_func4(T a0, T a1, T a2, T a3)
{ return t | a0 | a1 | a2 | a3; } {
return t | a0 | a1 | a2 | a3;
}
T member_func5(T a0, T a1, T a2, T a3, T a4) T member_func5(T a0, T a1, T a2, T a3, T a4)
{ return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0 | a1 | a2 | a3 | a4;
}
T const_member_func0() const T const_member_func0() const
{ return t; } {
return t;
}
T const_member_func1(T a0) const T const_member_func1(T a0) const
{ return t | a0; } {
return t | a0;
}
T const_member_func2(T a0, T a1) const T const_member_func2(T a0, T a1) const
{ return t | a0 | a1; } {
return t | a0 | a1;
}
T const_member_func3(T a0, T a1, T a2) const T const_member_func3(T a0, T a1, T a2) const
{ return t | a0 | a1 | a2; } {
return t | a0 | a1 | a2;
}
T const_member_func4(T a0, T a1, T a2, T a3) const T const_member_func4(T a0, T a1, T a2, T a3) const
{ return t | a0 | a1 | a2 | a3; } {
return t | a0 | a1 | a2 | a3;
}
T const_member_func5(T a0, T a1, T a2, T a3, T a4) const T const_member_func5(T a0, T a1, T a2, T a3, T a4) const
{ return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0 | a1 | a2 | a3 | a4;
}
T volatile_member_func0() volatile T volatile_member_func0() volatile
{ return t; } {
return t;
}
T volatile_member_func1(T a0) volatile T volatile_member_func1(T a0) volatile
{ return t | a0; } {
return t | a0;
}
T volatile_member_func2(T a0, T a1) volatile T volatile_member_func2(T a0, T a1) volatile
{ return t | a0 | a1; } {
return t | a0 | a1;
}
T volatile_member_func3(T a0, T a1, T a2) volatile T volatile_member_func3(T a0, T a1, T a2) volatile
{ return t | a0 | a1 | a2; } {
return t | a0 | a1 | a2;
}
T volatile_member_func4(T a0, T a1, T a2, T a3) volatile T volatile_member_func4(T a0, T a1, T a2, T a3) volatile
{ return t | a0 | a1 | a2 | a3; } {
return t | a0 | a1 | a2 | a3;
}
T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile T volatile_member_func5(T a0, T a1, T a2, T a3, T a4) volatile
{ return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0 | a1 | a2 | a3 | a4;
}
T const_volatile_member_func0() const volatile T const_volatile_member_func0() const volatile
{ return t; } {
return t;
}
T const_volatile_member_func1(T a0) const volatile T const_volatile_member_func1(T a0) const volatile
{ return t | a0; } {
return t | a0;
}
T const_volatile_member_func2(T a0, T a1) const volatile T const_volatile_member_func2(T a0, T a1) const volatile
{ return t | a0 | a1; } {
return t | a0 | a1;
}
T const_volatile_member_func3(T a0, T a1, T a2) const volatile T const_volatile_member_func3(T a0, T a1, T a2) const volatile
{ return t | a0 | a1 | a2; } {
return t | a0 | a1 | a2;
}
T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile T const_volatile_member_func4(T a0, T a1, T a2, T a3) const volatile
{ return t | a0 | a1 | a2 | a3; } {
return t | a0 | a1 | a2 | a3;
}
T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile T const_volatile_member_func5(T a0, T a1, T a2, T a3, T a4) const volatile
{ return t | a0 | a1 | a2 | a3 | a4; } {
return t | a0 | a1 | a2 | a3 | a4;
}
}; };
// bound functions // bound functions
template <typename T> template <typename T>
T bound_func0(Thing<T> *t) T bound_func0(Thing<T> *t)
{ return t->t; } {
return t->t;
}
template <typename T> template <typename T>
T bound_func1(Thing<T> *t, T a0) T bound_func1(Thing<T> *t, T a0)
{ return t->t | a0; } {
return t->t | a0;
}
template <typename T> template <typename T>
T bound_func2(Thing<T> *t, T a0, T a1) T bound_func2(Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; } {
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T bound_func3(Thing<T> *t, T a0, T a1, T a2) T bound_func3(Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; } {
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3) T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; } {
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4) T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; } {
return t->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T const_bound_func0(const Thing<T> *t) T const_bound_func0(const Thing<T> *t)
{ return t->t; } {
return t->t;
}
template <typename T> template <typename T>
T const_bound_func1(const Thing<T> *t, T a0) T const_bound_func1(const Thing<T> *t, T a0)
{ return t->t | a0; } {
return t->t | a0;
}
template <typename T> template <typename T>
T const_bound_func2(const Thing<T> *t, T a0, T a1) T const_bound_func2(const Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; } {
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T const_bound_func3(const Thing<T> *t, T a0, T a1, T a2) T const_bound_func3(const Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; } {
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_bound_func4(const Thing<T> *t, T a0, T a1, T a2, T a3) T const_bound_func4(const Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; } {
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_bound_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4) T const_bound_func5(const Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; } {
return t->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T volatile_bound_func0(volatile Thing<T> *t) T volatile_bound_func0(volatile Thing<T> *t)
{ return t->t; } {
return t->t;
}
template <typename T> template <typename T>
T volatile_bound_func1(volatile Thing<T> *t, T a0) T volatile_bound_func1(volatile Thing<T> *t, T a0)
{ return t->t | a0; } {
return t->t | a0;
}
template <typename T> template <typename T>
T volatile_bound_func2(volatile Thing<T> *t, T a0, T a1) T volatile_bound_func2(volatile Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; } {
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T volatile_bound_func3(volatile Thing<T> *t, T a0, T a1, T a2) T volatile_bound_func3(volatile Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; } {
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T volatile_bound_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3) T volatile_bound_func4(volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; } {
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T volatile_bound_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) T volatile_bound_func5(volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; } {
return t->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T const_volatile_bound_func0(const volatile Thing<T> *t) T const_volatile_bound_func0(const volatile Thing<T> *t)
{ return t->t; } {
return t->t;
}
template <typename T> template <typename T>
T const_volatile_bound_func1(const volatile Thing<T> *t, T a0) T const_volatile_bound_func1(const volatile Thing<T> *t, T a0)
{ return t->t | a0; } {
return t->t | a0;
}
template <typename T> template <typename T>
T const_volatile_bound_func2(const volatile Thing<T> *t, T a0, T a1) T const_volatile_bound_func2(const volatile Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; } {
return t->t | a0 | a1;
}
template <typename T> template <typename T>
T const_volatile_bound_func3(const volatile Thing<T> *t, T a0, T a1, T a2) T const_volatile_bound_func3(const volatile Thing<T> *t, T a0, T a1, T a2)
{ return t->t | a0 | a1 | a2; } {
return t->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_volatile_bound_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3) T const_volatile_bound_func4(const volatile Thing<T> *t, T a0, T a1, T a2, T a3)
{ return t->t | a0 | a1 | a2 | a3; } {
return t->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_volatile_bound_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4) T const_volatile_bound_func5(const volatile Thing<T> *t, T a0, T a1, T a2, T a3, T a4)
{ return t->t | a0 | a1 | a2 | a3 | a4; } {
return t->t | a0 | a1 | a2 | a3 | a4;
}
// void functions // void functions
template <typename T> template <typename T>
T void_func0(void *t) T void_func0(void *t)
{ return static_cast<Thing<T>*>(t)->t; } {
return static_cast<Thing<T>*>(t)->t;
}
template <typename T> template <typename T>
T void_func1(void *t, T a0) T void_func1(void *t, T a0)
{ return static_cast<Thing<T>*>(t)->t | a0; } {
return static_cast<Thing<T>*>(t)->t | a0;
}
template <typename T> template <typename T>
T void_func2(void *t, T a0, T a1) T void_func2(void *t, T a0, T a1)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1; } {
return static_cast<Thing<T>*>(t)->t | a0 | a1;
}
template <typename T> template <typename T>
T void_func3(void *t, T a0, T a1, T a2) T void_func3(void *t, T a0, T a1, T a2)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2; } {
return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T void_func4(void *t, T a0, T a1, T a2, T a3) T void_func4(void *t, T a0, T a1, T a2, T a3)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } {
return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T void_func5(void *t, T a0, T a1, T a2, T a3, T a4) T void_func5(void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } {
return static_cast<Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T const_void_func0(const void *t) T const_void_func0(const void *t)
{ return static_cast<const Thing<T>*>(t)->t; } {
return static_cast<const Thing<T>*>(t)->t;
}
template <typename T> template <typename T>
T const_void_func1(const void *t, T a0) T const_void_func1(const void *t, T a0)
{ return static_cast<const Thing<T>*>(t)->t | a0; } {
return static_cast<const Thing<T>*>(t)->t | a0;
}
template <typename T> template <typename T>
T const_void_func2(const void *t, T a0, T a1) T const_void_func2(const void *t, T a0, T a1)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1; } {
return static_cast<const Thing<T>*>(t)->t | a0 | a1;
}
template <typename T> template <typename T>
T const_void_func3(const void *t, T a0, T a1, T a2) T const_void_func3(const void *t, T a0, T a1, T a2)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2; } {
return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_void_func4(const void *t, T a0, T a1, T a2, T a3) T const_void_func4(const void *t, T a0, T a1, T a2, T a3)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } {
return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_void_func5(const void *t, T a0, T a1, T a2, T a3, T a4) T const_void_func5(const void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } {
return static_cast<const Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T volatile_void_func0(volatile void *t) T volatile_void_func0(volatile void *t)
{ return static_cast<volatile Thing<T>*>(t)->t; } {
return static_cast<volatile Thing<T>*>(t)->t;
}
template <typename T> template <typename T>
T volatile_void_func1(volatile void *t, T a0) T volatile_void_func1(volatile void *t, T a0)
{ return static_cast<volatile Thing<T>*>(t)->t | a0; } {
return static_cast<volatile Thing<T>*>(t)->t | a0;
}
template <typename T> template <typename T>
T volatile_void_func2(volatile void *t, T a0, T a1) T volatile_void_func2(volatile void *t, T a0, T a1)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1; } {
return static_cast<volatile Thing<T>*>(t)->t | a0 | a1;
}
template <typename T> template <typename T>
T volatile_void_func3(volatile void *t, T a0, T a1, T a2) T volatile_void_func3(volatile void *t, T a0, T a1, T a2)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2; } {
return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T volatile_void_func4(volatile void *t, T a0, T a1, T a2, T a3) T volatile_void_func4(volatile void *t, T a0, T a1, T a2, T a3)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } {
return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T volatile_void_func5(volatile void *t, T a0, T a1, T a2, T a3, T a4) T volatile_void_func5(volatile void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } {
return static_cast<volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4;
}
template <typename T> template <typename T>
T const_volatile_void_func0(const volatile void *t) T const_volatile_void_func0(const volatile void *t)
{ return static_cast<const volatile Thing<T>*>(t)->t; } {
return static_cast<const volatile Thing<T>*>(t)->t;
}
template <typename T> template <typename T>
T const_volatile_void_func1(const volatile void *t, T a0) T const_volatile_void_func1(const volatile void *t, T a0)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0; } {
return static_cast<const volatile Thing<T>*>(t)->t | a0;
}
template <typename T> template <typename T>
T const_volatile_void_func2(const volatile void *t, T a0, T a1) T const_volatile_void_func2(const volatile void *t, T a0, T a1)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1; } {
return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1;
}
template <typename T> template <typename T>
T const_volatile_void_func3(const volatile void *t, T a0, T a1, T a2) T const_volatile_void_func3(const volatile void *t, T a0, T a1, T a2)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2; } {
return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2;
}
template <typename T> template <typename T>
T const_volatile_void_func4(const volatile void *t, T a0, T a1, T a2, T a3) T const_volatile_void_func4(const volatile void *t, T a0, T a1, T a2, T a3)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3; } {
return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3;
}
template <typename T> template <typename T>
T const_volatile_void_func5(const volatile void *t, T a0, T a1, T a2, T a3, T a4) T const_volatile_void_func5(const volatile void *t, T a0, T a1, T a2, T a3, T a4)
{ return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4; } {
return static_cast<const volatile Thing<T>*>(t)->t | a0 | a1 | a2 | a3 | a4;
}
// function call and result verification // function call and result verification
template <typename T> template <typename T>
struct Verifier { struct Verifier {
static void verify0(Callback<T()> func) { static void verify0(Callback<T()> func)
{
T result = func(); T result = func();
TEST_ASSERT_EQUAL(result, 0x00); TEST_ASSERT_EQUAL(result, 0x00);
} }
template <typename O, typename M> template <typename O, typename M>
static void verify0(O *obj, M method) { static void verify0(O *obj, M method)
{
Callback<T()> func(obj, method); Callback<T()> func(obj, method);
T result = func(); T result = func();
TEST_ASSERT_EQUAL(result, 0x80); TEST_ASSERT_EQUAL(result, 0x80);
} }
static void verify1(Callback<T(T)> func) { static void verify1(Callback<T(T)> func)
{
T result = func((1 << 0)); T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify1(O *obj, M method) { static void verify1(O *obj, M method)
{
Callback<T(T)> func(obj, method); Callback<T(T)> func(obj, method);
T result = func((1 << 0)); T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0));
} }
static void verify2(Callback<T(T, T)> func) { static void verify2(Callback<T(T, T)> func)
{
T result = func((1 << 0), (1 << 1)); T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify2(O *obj, M method) { static void verify2(O *obj, M method)
{
Callback<T(T, T)> func(obj, method); Callback<T(T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1)); T result = func((1 << 0), (1 << 1));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1));
} }
static void verify3(Callback<T(T, T, T)> func) { static void verify3(Callback<T(T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2)); T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify3(O *obj, M method) { static void verify3(O *obj, M method)
{
Callback<T(T, T, T)> func(obj, method); Callback<T(T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2)); T result = func((1 << 0), (1 << 1), (1 << 2));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2));
} }
static void verify4(Callback<T(T, T, T, T)> func) { static void verify4(Callback<T(T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify4(O *obj, M method) { static void verify4(O *obj, M method)
{
Callback<T(T, T, T, T)> func(obj, method); Callback<T(T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
} }
static void verify5(Callback<T(T, T, T, T, T)> func) { static void verify5(Callback<T(T, T, T, T, T)> func)
{
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
} }
template <typename O, typename M> template <typename O, typename M>
static void verify5(O *obj, M method) { static void verify5(O *obj, M method)
{
Callback<T(T, T, T, T, T)> func(obj, method); Callback<T(T, T, T, T, T)> func(obj, method);
T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4)); T result = func((1 << 0), (1 << 1), (1 << 2), (1 << 3), (1 << 4));
TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); TEST_ASSERT_EQUAL(result, 0x80 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
@ -328,24 +496,27 @@ struct Verifier {
// test dispatch // test dispatch
template <typename T> template <typename T>
void test_fparg1() { void test_fparg1()
{
Thing<T> thing; Thing<T> thing;
FunctionPointerArg1<T,T> fp(static_func1<T>); FunctionPointerArg1<T, T> fp(static_func1<T>);
Verifier<T>::verify1(fp); Verifier<T>::verify1(fp);
Verifier<T>::verify1(fp.get_function()); Verifier<T>::verify1(fp.get_function());
} }
template <typename T> template <typename T>
void test_fparg0() { void test_fparg0()
{
Thing<T> thing; Thing<T> thing;
FunctionPointerArg1<T,void> fp(static_func0<T>); FunctionPointerArg1<T, void> fp(static_func0<T>);
Verifier<T>::verify0(fp); Verifier<T>::verify0(fp);
Verifier<T>::verify0(fp.get_function()); Verifier<T>::verify0(fp.get_function());
} }
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto"); GREENTEA_SETUP(10, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -357,6 +528,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -59,7 +59,7 @@ extern "C" {
using namespace utest::v1; using namespace utest::v1;
volatile int intFlag = 0; volatile int intFlag = 0;
const ticker_interface_t* intf; const ticker_interface_t *intf;
ticker_irq_handler_type prev_irq_handler; ticker_irq_handler_type prev_irq_handler;
/* Some targets might fail overflow test uncertainly due to getting trapped in busy /* Some targets might fail overflow test uncertainly due to getting trapped in busy
* intf->read() loop. In the loop, some ticker values wouldn't get caught in time * intf->read() loop. In the loop, some ticker values wouldn't get caught in time
@ -81,7 +81,7 @@ uint32_t count_ticks(uint32_t cycles, uint32_t step)
{ {
register uint32_t reg_cycles = cycles; register uint32_t reg_cycles = cycles;
const ticker_info_t* p_ticker_info = intf->get_info(); const ticker_info_t *p_ticker_info = intf->get_info();
const uint32_t max_count = ((1 << p_ticker_info->bits) - 1); const uint32_t max_count = ((1 << p_ticker_info->bits) - 1);
core_util_critical_section_enter(); core_util_critical_section_enter();
@ -120,7 +120,7 @@ void overflow_protect()
} }
const uint32_t ticks_now = intf->read(); const uint32_t ticks_now = intf->read();
const ticker_info_t* p_ticker_info = intf->get_info(); const ticker_info_t *p_ticker_info = intf->get_info();
const uint32_t max_count = ((1 << p_ticker_info->bits) - 1); const uint32_t max_count = ((1 << p_ticker_info->bits) - 1);
@ -131,7 +131,7 @@ void overflow_protect()
while (intf->read() > ticks_now); while (intf->read() > ticks_now);
} }
void ticker_event_handler_stub(const ticker_data_t * const ticker) void ticker_event_handler_stub(const ticker_data_t *const ticker)
{ {
if (ticker == get_us_ticker_data()) { if (ticker == get_us_ticker_data()) {
us_ticker_clear_interrupt(); us_ticker_clear_interrupt();
@ -156,13 +156,13 @@ void wait_cycles(volatile unsigned int cycles)
* This function returns number of us between <start_ticks> and <stop_ticks> * This function returns number of us between <start_ticks> and <stop_ticks>
* taking into account counter roll-over, counter size and frequency. * taking into account counter roll-over, counter size and frequency.
*/ */
uint32_t diff_us(uint32_t start_ticks, uint32_t stop_ticks, const ticker_info_t * info) uint32_t diff_us(uint32_t start_ticks, uint32_t stop_ticks, const ticker_info_t *info)
{ {
uint32_t counter_mask = ((1 << info->bits) - 1); uint32_t counter_mask = ((1 << info->bits) - 1);
uint32_t diff_ticks = ((stop_ticks - start_ticks) & counter_mask); uint32_t diff_ticks = ((stop_ticks - start_ticks) & counter_mask);
return (uint32_t) ((uint64_t) diff_ticks * US_PER_S / info->frequency); return (uint32_t)((uint64_t) diff_ticks * US_PER_S / info->frequency);
} }
/* Test that ticker_init can be called multiple times and /* Test that ticker_init can be called multiple times and
@ -201,7 +201,7 @@ void ticker_init_test()
/* Test that ticker frequency is non-zero and counter is at least 8 bits */ /* Test that ticker frequency is non-zero and counter is at least 8 bits */
void ticker_info_test(void) void ticker_info_test(void)
{ {
const ticker_info_t* p_ticker_info = intf->get_info(); const ticker_info_t *p_ticker_info = intf->get_info();
TEST_ASSERT(p_ticker_info->frequency != 0); TEST_ASSERT(p_ticker_info->frequency != 0);
TEST_ASSERT(p_ticker_info->bits >= 8); TEST_ASSERT(p_ticker_info->bits >= 8);
@ -313,7 +313,7 @@ void ticker_fire_now_test(void)
/* Test that the ticker correctly handles overflow. */ /* Test that the ticker correctly handles overflow. */
void ticker_overflow_test(void) void ticker_overflow_test(void)
{ {
const ticker_info_t* p_ticker_info = intf->get_info(); const ticker_info_t *p_ticker_info = intf->get_info();
/* We need to check how long it will take to overflow. /* We need to check how long it will take to overflow.
* We will perform this test only if this time is no longer than 30 sec. * We will perform this test only if this time is no longer than 30 sec.
@ -368,7 +368,7 @@ void ticker_overflow_test(void)
/* Test that the ticker increments by one on each tick. */ /* Test that the ticker increments by one on each tick. */
void ticker_increment_test(void) void ticker_increment_test(void)
{ {
const ticker_info_t* p_ticker_info = intf->get_info(); const ticker_info_t *p_ticker_info = intf->get_info();
/* Perform test based on ticker speed. */ /* Perform test based on ticker speed. */
if (p_ticker_info->frequency <= 250000) { // low frequency tickers if (p_ticker_info->frequency <= 250000) { // low frequency tickers
@ -439,13 +439,13 @@ void ticker_speed_test(void)
uint32_t start; uint32_t start;
uint32_t stop; uint32_t stop;
const ticker_info_t * us_ticker_info = get_us_ticker_data()->interface->get_info(); const ticker_info_t *us_ticker_info = get_us_ticker_data()->interface->get_info();
/* Free function will disable the ticker. For time measurement /* Free function will disable the ticker. For time measurement
* we need to use other one if available. * we need to use other one if available.
*/ */
#if DEVICE_LPTICKER #if DEVICE_LPTICKER
const ticker_info_t * lp_ticker_info = get_lp_ticker_data()->interface->get_info(); const ticker_info_t *lp_ticker_info = get_lp_ticker_data()->interface->get_info();
bool us_ticker_test = (intf == get_us_ticker_data()->interface); bool us_ticker_test = (intf == get_us_ticker_data()->interface);
#endif #endif
@ -522,7 +522,7 @@ void ticker_free_interrupt_test(void)
uint32_t cycles_500_ticks = 50; uint32_t cycles_500_ticks = 50;
uint32_t reference_ticks_count = 0; uint32_t reference_ticks_count = 0;
while(reference_ticks_count < TICKER_500_TICKS) { while (reference_ticks_count < TICKER_500_TICKS) {
cycles_500_ticks *= 2; cycles_500_ticks *= 2;
const uint32_t start = intf->read(); const uint32_t start = intf->read();
wait_cycles(cycles_500_ticks); wait_cycles(cycles_500_ticks);
@ -579,7 +579,7 @@ utest::v1::status_t us_ticker_setup(const Case *const source, const size_t index
return greentea_case_setup_handler(source, index_of_case); return greentea_case_setup_handler(source, index_of_case);
} }
utest::v1::status_t us_ticker_teardown(const Case * const source, const size_t passed, const size_t failed, utest::v1::status_t us_ticker_teardown(const Case *const source, const size_t passed, const size_t failed,
const failure_t reason) const failure_t reason)
{ {
set_us_ticker_irq_handler(prev_irq_handler); set_us_ticker_irq_handler(prev_irq_handler);
@ -608,7 +608,7 @@ utest::v1::status_t lp_ticker_setup(const Case *const source, const size_t index
return greentea_case_setup_handler(source, index_of_case); return greentea_case_setup_handler(source, index_of_case);
} }
utest::v1::status_t lp_ticker_teardown(const Case * const source, const size_t passed, const size_t failed, utest::v1::status_t lp_ticker_teardown(const Case *const source, const size_t passed, const size_t failed,
const failure_t reason) const failure_t reason)
{ {
set_lp_ticker_irq_handler(prev_irq_handler); set_lp_ticker_irq_handler(prev_irq_handler);

View File

@ -37,7 +37,7 @@
using namespace utest::v1; using namespace utest::v1;
const ticker_interface_t* intf; const ticker_interface_t *intf;
static volatile unsigned int overflowCounter; static volatile unsigned int overflowCounter;
@ -46,7 +46,7 @@ uint32_t ticks_to_us(uint32_t ticks, uint32_t freq)
return (uint32_t)((uint64_t)ticks * US_PER_S / freq); return (uint32_t)((uint64_t)ticks * US_PER_S / freq);
} }
void ticker_event_handler_stub(const ticker_data_t * const ticker) void ticker_event_handler_stub(const ticker_data_t *const ticker)
{ {
if (ticker == get_us_ticker_data()) { if (ticker == get_us_ticker_data()) {
us_ticker_clear_interrupt(); us_ticker_clear_interrupt();
@ -99,12 +99,12 @@ void ticker_frequency_test()
/* Get the results from host. */ /* Get the results from host. */
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
TEST_ASSERT_EQUAL_STRING_MESSAGE("pass", _key,"Host side script reported a fail..."); TEST_ASSERT_EQUAL_STRING_MESSAGE("pass", _key, "Host side script reported a fail...");
intf->disable_interrupt(); intf->disable_interrupt();
} }
utest::v1::status_t us_ticker_case_setup_handler_t(const Case * const source, const size_t index_of_case) utest::v1::status_t us_ticker_case_setup_handler_t(const Case *const source, const size_t index_of_case)
{ {
intf = get_us_ticker_data()->interface; intf = get_us_ticker_data()->interface;
set_us_ticker_irq_handler(ticker_event_handler_stub); set_us_ticker_irq_handler(ticker_event_handler_stub);
@ -112,7 +112,7 @@ utest::v1::status_t us_ticker_case_setup_handler_t(const Case * const source, co
} }
#if DEVICE_LPTICKER #if DEVICE_LPTICKER
utest::v1::status_t lp_ticker_case_setup_handler_t(const Case * const source, const size_t index_of_case) utest::v1::status_t lp_ticker_case_setup_handler_t(const Case *const source, const size_t index_of_case)
{ {
intf = get_lp_ticker_data()->interface; intf = get_lp_ticker_data()->interface;
set_lp_ticker_irq_handler(ticker_event_handler_stub); set_lp_ticker_irq_handler(ticker_event_handler_stub);
@ -120,7 +120,7 @@ utest::v1::status_t lp_ticker_case_setup_handler_t(const Case * const source, co
} }
#endif #endif
utest::v1::status_t ticker_case_teardown_handler_t(const Case * const source, const size_t passed, const size_t failed, utest::v1::status_t ticker_case_teardown_handler_t(const Case *const source, const size_t passed, const size_t failed,
const failure_t reason) const failure_t reason)
{ {
return greentea_case_teardown_handler(source, passed, failed, reason); return greentea_case_teardown_handler(source, passed, failed, reason);
@ -134,7 +134,7 @@ Case cases[] = {
Case("Low power ticker frequency test", lp_ticker_case_setup_handler_t, ticker_frequency_test, Case("Low power ticker frequency test", lp_ticker_case_setup_handler_t, ticker_frequency_test,
ticker_case_teardown_handler_t), ticker_case_teardown_handler_t),
#endif #endif
}; };
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{ {

View File

@ -35,8 +35,7 @@ using namespace utest::v1;
const uint8_t input_data[] = "123456789"; const uint8_t input_data[] = "123456789";
typedef struct typedef struct {
{
const crc_mbed_config config_data; const crc_mbed_config config_data;
uint32_t expected_result; uint32_t expected_result;
@ -72,7 +71,7 @@ void crc_calc_single_test()
if (hal_crc_is_supported(&test_cases[i].config_data) == true) { if (hal_crc_is_supported(&test_cases[i].config_data) == true) {
hal_crc_compute_partial_start(&test_cases[i].config_data); hal_crc_compute_partial_start(&test_cases[i].config_data);
hal_crc_compute_partial((uint8_t*) input_data, strlen((const char*) input_data)); hal_crc_compute_partial((uint8_t *) input_data, strlen((const char *) input_data));
const uint32_t crc = hal_crc_get_result(); const uint32_t crc = hal_crc_get_result();
TEST_ASSERT_EQUAL(test_cases[i].expected_result, crc); TEST_ASSERT_EQUAL(test_cases[i].expected_result, crc);
@ -89,13 +88,13 @@ void crc_calc_multi_test()
const uint32_t first_part_bytes = 3; const uint32_t first_part_bytes = 3;
const uint32_t second_part_bytes = 1; const uint32_t second_part_bytes = 1;
const uint32_t third_part_bytes = strlen((const char*) input_data) - first_part_bytes const uint32_t third_part_bytes = strlen((const char *) input_data) - first_part_bytes
- second_part_bytes; - second_part_bytes;
hal_crc_compute_partial_start(&test_cases[i].config_data); hal_crc_compute_partial_start(&test_cases[i].config_data);
hal_crc_compute_partial((uint8_t*) input_data, first_part_bytes); hal_crc_compute_partial((uint8_t *) input_data, first_part_bytes);
hal_crc_compute_partial((uint8_t*) (input_data + first_part_bytes), second_part_bytes); hal_crc_compute_partial((uint8_t *)(input_data + first_part_bytes), second_part_bytes);
hal_crc_compute_partial((uint8_t*) (input_data + first_part_bytes + second_part_bytes), hal_crc_compute_partial((uint8_t *)(input_data + first_part_bytes + second_part_bytes),
third_part_bytes); third_part_bytes);
const uint32_t crc = hal_crc_get_result(); const uint32_t crc = hal_crc_get_result();
@ -137,7 +136,7 @@ void crc_reconfigure_test()
/* Init CRC module and provide some data, but do not read the result. */ /* Init CRC module and provide some data, but do not read the result. */
hal_crc_compute_partial_start(&test_cases[pol_idx[pol_cnt]].config_data); hal_crc_compute_partial_start(&test_cases[pol_idx[pol_cnt]].config_data);
hal_crc_compute_partial((uint8_t*) dummy_input_data, strlen((const char*) dummy_input_data)); hal_crc_compute_partial((uint8_t *) dummy_input_data, strlen((const char *) dummy_input_data));
/* Change index only if more than one supported polynomial has been found. */ /* Change index only if more than one supported polynomial has been found. */
if (pol_idx[POL_CNT - 1] != UNSUPPORTED) { if (pol_idx[POL_CNT - 1] != UNSUPPORTED) {
@ -146,7 +145,7 @@ void crc_reconfigure_test()
/* Now re-init CRC module and provide new data and check the result. */ /* Now re-init CRC module and provide new data and check the result. */
hal_crc_compute_partial_start(&test_cases[pol_idx[pol_cnt]].config_data); hal_crc_compute_partial_start(&test_cases[pol_idx[pol_cnt]].config_data);
hal_crc_compute_partial((uint8_t*) input_data, strlen((const char*) input_data)); hal_crc_compute_partial((uint8_t *) input_data, strlen((const char *) input_data));
const uint32_t crc = hal_crc_get_result(); const uint32_t crc = hal_crc_get_result();
TEST_ASSERT_EQUAL(test_cases[pol_idx[pol_cnt]].expected_result, crc); TEST_ASSERT_EQUAL(test_cases[pol_idx[pol_cnt]].expected_result, crc);
@ -165,12 +164,12 @@ void crc_compute_partial_invalid_param_test()
hal_crc_compute_partial_start(&test_cases[i].config_data); hal_crc_compute_partial_start(&test_cases[i].config_data);
/* Call hal_crc_compute_partial() with invalid parameters. */ /* Call hal_crc_compute_partial() with invalid parameters. */
hal_crc_compute_partial((uint8_t*) NULL, strlen((const char*) input_data)); hal_crc_compute_partial((uint8_t *) NULL, strlen((const char *) input_data));
hal_crc_compute_partial((uint8_t*) input_data, 0); hal_crc_compute_partial((uint8_t *) input_data, 0);
/* Now use valid parameters. */ /* Now use valid parameters. */
hal_crc_compute_partial((uint8_t*) input_data, hal_crc_compute_partial((uint8_t *) input_data,
strlen((const char*) input_data)); strlen((const char *) input_data));
crc = hal_crc_get_result(); crc = hal_crc_get_result();
@ -208,70 +207,70 @@ int main()
{ {
TEST_CASE local_test_cases[] = { TEST_CASE local_test_cases[] = {
/* Predefined polynomials. */ /* Predefined polynomials. */
/* 00 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x00000000, false, false}, 0xEA }, /* 00 */{ {POLY_7BIT_SD, 7, 0x00000000, 0x00000000, false, false}, 0xEA },
/* 01 */{ {POLY_7BIT_SD , 7, 0x0000007F, 0x00000000, false, false}, 0xA0 }, /* 01 */{ {POLY_7BIT_SD, 7, 0x0000007F, 0x00000000, false, false}, 0xA0 },
/* 02 */{ {POLY_7BIT_SD , 7, 0x0000002B, 0x00000000, false, false}, 0x74 }, /* 02 */{ {POLY_7BIT_SD, 7, 0x0000002B, 0x00000000, false, false}, 0x74 },
/* 03 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x0000007F, false, false}, 0x95 }, /* 03 */{ {POLY_7BIT_SD, 7, 0x00000000, 0x0000007F, false, false}, 0x95 },
/* 04 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x0000002B, false, false}, 0xC1 }, /* 04 */{ {POLY_7BIT_SD, 7, 0x00000000, 0x0000002B, false, false}, 0xC1 },
/* 05 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x00000000, true , false}, 0xA4 }, /* 05 */{ {POLY_7BIT_SD, 7, 0x00000000, 0x00000000, true, false}, 0xA4 },
/* 06 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x00000000, false, true }, 0x57 }, /* 06 */{ {POLY_7BIT_SD, 7, 0x00000000, 0x00000000, false, true }, 0x57 },
/* 07 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x00000000, false, false}, 0xF4 }, /* 07 */{ {POLY_8BIT_CCITT, 8, 0x00000000, 0x00000000, false, false}, 0xF4 },
/* 08 */{ {POLY_8BIT_CCITT , 8, 0x000000FF, 0x00000000, false, false}, 0xFB }, /* 08 */{ {POLY_8BIT_CCITT, 8, 0x000000FF, 0x00000000, false, false}, 0xFB },
/* 09 */{ {POLY_8BIT_CCITT , 8, 0x000000AB, 0x00000000, false, false}, 0x87 }, /* 09 */{ {POLY_8BIT_CCITT, 8, 0x000000AB, 0x00000000, false, false}, 0x87 },
/* 10 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x000000FF, false, false}, 0x0B }, /* 10 */{ {POLY_8BIT_CCITT, 8, 0x00000000, 0x000000FF, false, false}, 0x0B },
/* 11 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x000000AB, false, false}, 0x5F }, /* 11 */{ {POLY_8BIT_CCITT, 8, 0x00000000, 0x000000AB, false, false}, 0x5F },
/* 12 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x00000000, true , false}, 0x04 }, /* 12 */{ {POLY_8BIT_CCITT, 8, 0x00000000, 0x00000000, true, false}, 0x04 },
/* 13 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x00000000, false, true }, 0x2F }, /* 13 */{ {POLY_8BIT_CCITT, 8, 0x00000000, 0x00000000, false, true }, 0x2F },
/* 14 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x00000000, false, false}, 0x31C3 }, /* 14 */{ {POLY_16BIT_CCITT, 16, 0x00000000, 0x00000000, false, false}, 0x31C3 },
/* 15 */{ {POLY_16BIT_CCITT , 16, 0x0000FFFF, 0x00000000, false, false}, 0x29B1 }, /* 15 */{ {POLY_16BIT_CCITT, 16, 0x0000FFFF, 0x00000000, false, false}, 0x29B1 },
/* 16 */{ {POLY_16BIT_CCITT , 16, 0x0000ABAB, 0x00000000, false, false}, 0x7D70 }, /* 16 */{ {POLY_16BIT_CCITT, 16, 0x0000ABAB, 0x00000000, false, false}, 0x7D70 },
/* 17 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x0000FFFF, false, false}, 0xCE3C }, /* 17 */{ {POLY_16BIT_CCITT, 16, 0x00000000, 0x0000FFFF, false, false}, 0xCE3C },
/* 18 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x0000ABAB, false, false}, 0x9A68 }, /* 18 */{ {POLY_16BIT_CCITT, 16, 0x00000000, 0x0000ABAB, false, false}, 0x9A68 },
/* 19 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x00000000, true , false}, 0x9184 }, /* 19 */{ {POLY_16BIT_CCITT, 16, 0x00000000, 0x00000000, true, false}, 0x9184 },
/* 20 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x00000000, false, true }, 0xC38C }, /* 20 */{ {POLY_16BIT_CCITT, 16, 0x00000000, 0x00000000, false, true }, 0xC38C },
/* 21 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x00000000, false, false}, 0xFEE8 }, /* 21 */{ {POLY_16BIT_IBM, 16, 0x00000000, 0x00000000, false, false}, 0xFEE8 },
/* 22 */{ {POLY_16BIT_IBM , 16, 0x0000FFFF, 0x00000000, false, false}, 0xAEE7 }, /* 22 */{ {POLY_16BIT_IBM, 16, 0x0000FFFF, 0x00000000, false, false}, 0xAEE7 },
/* 23 */{ {POLY_16BIT_IBM , 16, 0x0000ABAB, 0x00000000, false, false}, 0x0887 }, /* 23 */{ {POLY_16BIT_IBM, 16, 0x0000ABAB, 0x00000000, false, false}, 0x0887 },
/* 24 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x0000FFFF, false, false}, 0x0117 }, /* 24 */{ {POLY_16BIT_IBM, 16, 0x00000000, 0x0000FFFF, false, false}, 0x0117 },
/* 25 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x0000ABAB, false, false}, 0x5543 }, /* 25 */{ {POLY_16BIT_IBM, 16, 0x00000000, 0x0000ABAB, false, false}, 0x5543 },
/* 26 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x00000000, true , false}, 0xBCDD }, /* 26 */{ {POLY_16BIT_IBM, 16, 0x00000000, 0x00000000, true, false}, 0xBCDD },
/* 27 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x00000000, false, true }, 0x177F }, /* 27 */{ {POLY_16BIT_IBM, 16, 0x00000000, 0x00000000, false, true }, 0x177F },
/* 28 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0x00000000, false, false}, 0x89A1897F }, /* 28 */{ {POLY_32BIT_ANSI, 32, 0x00000000, 0x00000000, false, false}, 0x89A1897F },
/* 29 */{ {POLY_32BIT_ANSI , 32, 0xFFFFFFFF, 0x00000000, false, false}, 0x0376E6E7 }, /* 29 */{ {POLY_32BIT_ANSI, 32, 0xFFFFFFFF, 0x00000000, false, false}, 0x0376E6E7 },
/* 30 */{ {POLY_32BIT_ANSI , 32, 0xABABABAB, 0x00000000, false, false}, 0x871A2FAA }, /* 30 */{ {POLY_32BIT_ANSI, 32, 0xABABABAB, 0x00000000, false, false}, 0x871A2FAA },
/* 31 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0xFFFFFFFF, false, false}, 0x765E7680 }, /* 31 */{ {POLY_32BIT_ANSI, 32, 0x00000000, 0xFFFFFFFF, false, false}, 0x765E7680 },
/* 32 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0xABABABAB, false, false}, 0x220A22D4 }, /* 32 */{ {POLY_32BIT_ANSI, 32, 0x00000000, 0xABABABAB, false, false}, 0x220A22D4 },
/* 33 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0x00000000, true , false}, 0x11B4BFB4 }, /* 33 */{ {POLY_32BIT_ANSI, 32, 0x00000000, 0x00000000, true, false}, 0x11B4BFB4 },
/* 34 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0x00000000, false, true }, 0xFE918591 }, /* 34 */{ {POLY_32BIT_ANSI, 32, 0x00000000, 0x00000000, false, true }, 0xFE918591 },
/* Not-predefined polynomials. */ /* Not-predefined polynomials. */
/* 35 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x00000000, false, false}, 0xA2 }, /* 35 */{ {POLY_8BIT_MAXIM, 8, 0x00000000, 0x00000000, false, false}, 0xA2 },
/* 36 */{ {POLY_8BIT_MAXIM , 8, 0x000000FF, 0x00000000, false, false}, 0xF7 }, /* 36 */{ {POLY_8BIT_MAXIM, 8, 0x000000FF, 0x00000000, false, false}, 0xF7 },
/* 37 */{ {POLY_8BIT_MAXIM , 8, 0x000000AB, 0x00000000, false, false}, 0x71 }, /* 37 */{ {POLY_8BIT_MAXIM, 8, 0x000000AB, 0x00000000, false, false}, 0x71 },
/* 38 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x000000FF, false, false}, 0x5D }, /* 38 */{ {POLY_8BIT_MAXIM, 8, 0x00000000, 0x000000FF, false, false}, 0x5D },
/* 39 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x000000AB, false, false}, 0x09 }, /* 39 */{ {POLY_8BIT_MAXIM, 8, 0x00000000, 0x000000AB, false, false}, 0x09 },
/* 40 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x00000000, true , false}, 0x85 }, /* 40 */{ {POLY_8BIT_MAXIM, 8, 0x00000000, 0x00000000, true, false}, 0x85 },
/* 41 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x00000000, false, true }, 0x45 }, /* 41 */{ {POLY_8BIT_MAXIM, 8, 0x00000000, 0x00000000, false, true }, 0x45 },
/* 42 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x00000000, false, false}, 0xFEE8 }, /* 42 */{ {POLY_16BIT_MAXIM, 16, 0x00000000, 0x00000000, false, false}, 0xFEE8 },
/* 43 */{ {POLY_16BIT_MAXIM , 16, 0x0000FFFF, 0x00000000, false, false}, 0xAEE7 }, /* 43 */{ {POLY_16BIT_MAXIM, 16, 0x0000FFFF, 0x00000000, false, false}, 0xAEE7 },
/* 44 */{ {POLY_16BIT_MAXIM , 16, 0x0000ABAB, 0x00000000, false, false}, 0x0887 }, /* 44 */{ {POLY_16BIT_MAXIM, 16, 0x0000ABAB, 0x00000000, false, false}, 0x0887 },
/* 45 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x0000FFFF, false, false}, 0x0117 }, /* 45 */{ {POLY_16BIT_MAXIM, 16, 0x00000000, 0x0000FFFF, false, false}, 0x0117 },
/* 46 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x0000ABAB, false, false}, 0x5543 }, /* 46 */{ {POLY_16BIT_MAXIM, 16, 0x00000000, 0x0000ABAB, false, false}, 0x5543 },
/* 47 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x00000000, true , false}, 0xBCDD }, /* 47 */{ {POLY_16BIT_MAXIM, 16, 0x00000000, 0x00000000, true, false}, 0xBCDD },
/* 48 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x00000000, false, true }, 0x177F }, /* 48 */{ {POLY_16BIT_MAXIM, 16, 0x00000000, 0x00000000, false, true }, 0x177F },
/* 49 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0x00000000, false, false}, 0x89A1897F }, /* 49 */{ {POLY_32BIT_POSIX, 32, 0x00000000, 0x00000000, false, false}, 0x89A1897F },
/* 50 */{ {POLY_32BIT_POSIX , 32, 0xFFFFFFFF, 0x00000000, false, false}, 0x0376E6E7 }, /* 50 */{ {POLY_32BIT_POSIX, 32, 0xFFFFFFFF, 0x00000000, false, false}, 0x0376E6E7 },
/* 51 */{ {POLY_32BIT_POSIX , 32, 0xABABABAB, 0x00000000, false, false}, 0x871A2FAA }, /* 51 */{ {POLY_32BIT_POSIX, 32, 0xABABABAB, 0x00000000, false, false}, 0x871A2FAA },
/* 52 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0xFFFFFFFF, false, false}, 0x765E7680 }, /* 52 */{ {POLY_32BIT_POSIX, 32, 0x00000000, 0xFFFFFFFF, false, false}, 0x765E7680 },
/* 53 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0xABABABAB, false, false}, 0x220A22D4 }, /* 53 */{ {POLY_32BIT_POSIX, 32, 0x00000000, 0xABABABAB, false, false}, 0x220A22D4 },
/* 54 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0x00000000, true , false}, 0x11B4BFB4 }, /* 54 */{ {POLY_32BIT_POSIX, 32, 0x00000000, 0x00000000, true, false}, 0x11B4BFB4 },
/* 55 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0x00000000, false, true }, 0xFE918591 }, /* 55 */{ {POLY_32BIT_POSIX, 32, 0x00000000, 0x00000000, false, true }, 0xFE918591 },
}; };
test_cases = local_test_cases; test_cases = local_test_cases;

View File

@ -15,7 +15,7 @@
*/ */
#if !DEVICE_FLASH #if !DEVICE_FLASH
#error [NOT_SUPPORTED] Flash API not supported for this target #error [NOT_SUPPORTED] Flash API not supported for this target
#endif #endif
#include "utest/utest.h" #include "utest/utest.h"
@ -57,10 +57,13 @@ static void erase_range(flash_t *flash, uint32_t addr, uint32_t size)
MBED_NOINLINE MBED_NOINLINE
__asm static void delay_loop(uint32_t count) __asm static void delay_loop(uint32_t count)
{ {
// AStyle should not format inline assembly
// *INDENT-OFF*
1 1
SUBS a1, a1, #1 SUBS a1, a1, #1
BCS %BT1 BCS %BT1
BX lr BX lr
// *INDENT-ON*
} }
#elif defined (__ICCARM__) #elif defined (__ICCARM__)
MBED_NOINLINE MBED_NOINLINE
@ -70,7 +73,7 @@ static void delay_loop(uint32_t count)
"loop: \n" "loop: \n"
" SUBS %0, %0, #1 \n" " SUBS %0, %0, #1 \n"
" BCS.n loop\n" " BCS.n loop\n"
: "+r" (count) : "+r"(count)
: :
: "cc" : "cc"
); );
@ -79,7 +82,7 @@ static void delay_loop(uint32_t count)
MBED_NOINLINE MBED_NOINLINE
static void delay_loop(uint32_t count) static void delay_loop(uint32_t count)
{ {
__asm__ volatile ( __asm__ volatile(
"%=:\n\t" "%=:\n\t"
#if defined(__thumb__) && !defined(__thumb2__) && !defined(__ARMCC_VERSION) #if defined(__thumb__) && !defined(__thumb2__) && !defined(__ARMCC_VERSION)
"SUB %0, #1\n\t" "SUB %0, #1\n\t"
@ -87,7 +90,7 @@ static void delay_loop(uint32_t count)
"SUBS %0, %0, #1\n\t" "SUBS %0, %0, #1\n\t"
#endif #endif
"BCS %=b\n\t" "BCS %=b\n\t"
: "+l" (count) : "+l"(count)
: :
: "cc" : "cc"
); );
@ -193,7 +196,7 @@ void flash_program_page_test()
} }
// the one before the last page in the system // the one before the last page in the system
uint32_t address = flash_get_start_address(&test_flash) + flash_get_size(&test_flash) - (2*test_size); uint32_t address = flash_get_start_address(&test_flash) + flash_get_size(&test_flash) - (2 * test_size);
// sector size might not be same as page size // sector size might not be same as page size
uint32_t erase_sector_boundary = ALIGN_DOWN(address, flash_get_sector_size(&test_flash, address)); uint32_t erase_sector_boundary = ALIGN_DOWN(address, flash_get_sector_size(&test_flash, address));
@ -246,13 +249,15 @@ Case cases[] = {
Case("Flash - clock and cache test", flash_clock_and_cache_test), Case("Flash - clock and cache test", flash_clock_and_cache_test),
}; };
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(20, "default_auto"); GREENTEA_SETUP(20, "default_auto");
return greentea_test_setup_handler(number_of_cases); return greentea_test_setup_handler(number_of_cases);
} }
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
Harness::run(specification); Harness::run(specification);
} }

View File

@ -22,7 +22,7 @@
#include "hal/lp_ticker_api.h" #include "hal/lp_ticker_api.h"
#if !DEVICE_LPTICKER #if !DEVICE_LPTICKER
#error [NOT_SUPPORTED] Low power timer not supported for this target #error [NOT_SUPPORTED] Low power timer not supported for this target
#endif #endif
using namespace utest::v1; using namespace utest::v1;
@ -74,7 +74,7 @@ void overflow_protect()
time_window = LP_TICKER_OV_LIMIT; time_window = LP_TICKER_OV_LIMIT;
const uint32_t ticks_now = lp_ticker_read(); const uint32_t ticks_now = lp_ticker_read();
const ticker_info_t* p_ticker_info = lp_ticker_get_info(); const ticker_info_t *p_ticker_info = lp_ticker_get_info();
const uint32_t max_count = ((1 << p_ticker_info->bits) - 1); const uint32_t max_count = ((1 << p_ticker_info->bits) - 1);
@ -85,7 +85,7 @@ void overflow_protect()
while (lp_ticker_read() > ticks_now); while (lp_ticker_read() > ticks_now);
} }
void ticker_event_handler_stub(const ticker_data_t * const ticker) void ticker_event_handler_stub(const ticker_data_t *const ticker)
{ {
/* Indicate that ISR has been executed in interrupt context. */ /* Indicate that ISR has been executed in interrupt context. */
if (core_util_is_isr_active()) { if (core_util_is_isr_active()) {
@ -100,7 +100,7 @@ void ticker_event_handler_stub(const ticker_data_t * const ticker)
/* Test that the ticker has the correct frequency and number of bits. */ /* Test that the ticker has the correct frequency and number of bits. */
void lp_ticker_info_test() void lp_ticker_info_test()
{ {
const ticker_info_t* p_ticker_info = lp_ticker_get_info(); const ticker_info_t *p_ticker_info = lp_ticker_get_info();
TEST_ASSERT(p_ticker_info->frequency >= 4000); TEST_ASSERT(p_ticker_info->frequency >= 4000);
TEST_ASSERT(p_ticker_info->frequency <= 64000); TEST_ASSERT(p_ticker_info->frequency <= 64000);

View File

@ -15,7 +15,7 @@
*/ */
#if !DEVICE_RTC #if !DEVICE_RTC
#error [NOT_SUPPORTED] RTC API not supported for this target #error [NOT_SUPPORTED] RTC API not supported for this target
#endif #endif
#include "utest/utest.h" #include "utest/utest.h"
@ -37,7 +37,7 @@ static const uint32_t WAIT_TOLERANCE = 1;
static const uint32_t DELAY_4S = 4; static const uint32_t DELAY_4S = 4;
static const uint32_t DELAY_10S = 10; static const uint32_t DELAY_10S = 10;
static const uint32_t RTC_TOLERANCE = 1; static const uint32_t RTC_TOLERANCE = 1;
static const uint32_t TOLERANCE_ACCURACY_US = (DELAY_10S * US_PER_SEC / ACCURACY_FACTOR); static const uint32_t TOLERANCE_ACCURACY_US = (DELAY_10S *US_PER_SEC / ACCURACY_FACTOR);
#if DEVICE_LPTICKER #if DEVICE_LPTICKER
volatile bool expired; volatile bool expired;
@ -49,7 +49,7 @@ void callback(void)
/* Auxiliary function to test if RTC continue counting in /* Auxiliary function to test if RTC continue counting in
* sleep and deep-sleep modes. */ * sleep and deep-sleep modes. */
void rtc_sleep_test_support (bool deepsleep_mode) void rtc_sleep_test_support(bool deepsleep_mode)
{ {
LowPowerTimeout timeout; LowPowerTimeout timeout;
const uint32_t start = 100; const uint32_t start = 100;
@ -66,7 +66,7 @@ void rtc_sleep_test_support (bool deepsleep_mode)
rtc_init(); rtc_init();
if(deepsleep_mode == false) { if (deepsleep_mode == false) {
sleep_manager_lock_deep_sleep(); sleep_manager_lock_deep_sleep();
} }
@ -76,7 +76,9 @@ void rtc_sleep_test_support (bool deepsleep_mode)
TEST_ASSERT(sleep_manager_can_deep_sleep() == deepsleep_mode); TEST_ASSERT(sleep_manager_can_deep_sleep() == deepsleep_mode);
while(!expired) sleep(); while (!expired) {
sleep();
}
const uint32_t stop = rtc_read(); const uint32_t stop = rtc_read();
@ -84,7 +86,7 @@ void rtc_sleep_test_support (bool deepsleep_mode)
timeout.detach(); timeout.detach();
if(deepsleep_mode == false) { if (deepsleep_mode == false) {
sleep_manager_unlock_deep_sleep(); sleep_manager_unlock_deep_sleep();
} }
@ -182,7 +184,7 @@ void rtc_accuracy_test()
rtc_write(start); rtc_write(start);
timer1.start(); timer1.start();
while(rtc_read() < (start + DELAY_10S)) { while (rtc_read() < (start + DELAY_10S)) {
/* Just wait. */ /* Just wait. */
} }
timer1.stop(); timer1.stop();

View File

@ -15,7 +15,7 @@
*/ */
#if !DEVICE_RTC #if !DEVICE_RTC
#error [NOT_SUPPORTED] RTC API not supported for this target #error [NOT_SUPPORTED] RTC API not supported for this target
#endif #endif
#include "utest/utest.h" #include "utest/utest.h"

View File

@ -73,8 +73,7 @@ void test_is_leap_year()
} }
/* Structure to test border values for _rtc_maketime(). */ /* Structure to test border values for _rtc_maketime(). */
typedef struct typedef struct {
{
struct tm timeinfo; struct tm timeinfo;
time_t exp_seconds; // if result is false then exp_seconds is irrelevant time_t exp_seconds; // if result is false then exp_seconds is irrelevant
bool result; bool result;
@ -152,10 +151,10 @@ void test_mk_time_invalid_param()
time_t seconds; time_t seconds;
struct tm timeinfo; struct tm timeinfo;
TEST_ASSERT_EQUAL(false, _rtc_maketime(NULL, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT )); TEST_ASSERT_EQUAL(false, _rtc_maketime(NULL, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT));
TEST_ASSERT_EQUAL(false, _rtc_maketime(NULL, &seconds, RTC_4_YEAR_LEAP_YEAR_SUPPORT )); TEST_ASSERT_EQUAL(false, _rtc_maketime(NULL, &seconds, RTC_4_YEAR_LEAP_YEAR_SUPPORT));
TEST_ASSERT_EQUAL(false, _rtc_maketime(&timeinfo, NULL, RTC_FULL_LEAP_YEAR_SUPPORT )); TEST_ASSERT_EQUAL(false, _rtc_maketime(&timeinfo, NULL, RTC_FULL_LEAP_YEAR_SUPPORT));
TEST_ASSERT_EQUAL(false, _rtc_maketime(&timeinfo, NULL, RTC_4_YEAR_LEAP_YEAR_SUPPORT )); TEST_ASSERT_EQUAL(false, _rtc_maketime(&timeinfo, NULL, RTC_4_YEAR_LEAP_YEAR_SUPPORT));
} }
/* Test _rtc_localtime() function - call with invalid parameters. /* Test _rtc_localtime() function - call with invalid parameters.
@ -166,24 +165,24 @@ void test_mk_time_invalid_param()
*/ */
void test_local_time_invalid_param() void test_local_time_invalid_param()
{ {
TEST_ASSERT_EQUAL(false, _rtc_localtime(1, NULL, RTC_FULL_LEAP_YEAR_SUPPORT )); TEST_ASSERT_EQUAL(false, _rtc_localtime(1, NULL, RTC_FULL_LEAP_YEAR_SUPPORT));
TEST_ASSERT_EQUAL(false, _rtc_localtime(1, NULL, RTC_4_YEAR_LEAP_YEAR_SUPPORT )); TEST_ASSERT_EQUAL(false, _rtc_localtime(1, NULL, RTC_4_YEAR_LEAP_YEAR_SUPPORT));
} }
utest::v1::status_t teardown_handler_t(const Case * const source, const size_t passed, const size_t failed, utest::v1::status_t teardown_handler_t(const Case *const source, const size_t passed, const size_t failed,
const failure_t reason) const failure_t reason)
{ {
return greentea_case_teardown_handler(source, passed, failed, reason); return greentea_case_teardown_handler(source, passed, failed, reason);
} }
utest::v1::status_t full_leap_year_case_setup_handler_t(const Case * const source, const size_t index_of_case) utest::v1::status_t full_leap_year_case_setup_handler_t(const Case *const source, const size_t index_of_case)
{ {
rtc_leap_year_support = RTC_FULL_LEAP_YEAR_SUPPORT; rtc_leap_year_support = RTC_FULL_LEAP_YEAR_SUPPORT;
return greentea_case_setup_handler(source, index_of_case); return greentea_case_setup_handler(source, index_of_case);
} }
utest::v1::status_t partial_leap_year_case_setup_handler_t(const Case * const source, const size_t index_of_case) utest::v1::status_t partial_leap_year_case_setup_handler_t(const Case *const source, const size_t index_of_case)
{ {
rtc_leap_year_support = RTC_4_YEAR_LEAP_YEAR_SUPPORT; rtc_leap_year_support = RTC_4_YEAR_LEAP_YEAR_SUPPORT;

View File

@ -51,8 +51,8 @@ bool is_leap_year(int year)
struct tm make_time_info(int year, int month, int day, int hours, int minutes, int seconds) struct tm make_time_info(int year, int month, int day, int hours, int minutes, int seconds)
{ {
struct tm timeinfo = struct tm timeinfo = {
{ seconds, // tm_sec seconds, // tm_sec
minutes, // tm_min minutes, // tm_min
hours, // tm_hour hours, // tm_hour
day, // tm_mday day, // tm_mday
@ -89,7 +89,7 @@ void test_case_mktime_localtime()
greentea_send_kv("leap_year_setup", rtc_leap_year_support); greentea_send_kv("leap_year_setup", rtc_leap_year_support);
/* Check the first and last last day of each month. */ /* Check the first and last last day of each month. */
for (size_t year_id = 0; year_id < (sizeof(years) /sizeof(size_t)) ; ++year_id) { for (size_t year_id = 0; year_id < (sizeof(years) / sizeof(size_t)) ; ++year_id) {
for (size_t month = 0; month < 12; ++month) { for (size_t month = 0; month < 12; ++month) {
for (size_t dayid = 0; dayid < 2; ++dayid) { for (size_t dayid = 0; dayid < 2; ++dayid) {
@ -100,8 +100,7 @@ void test_case_mktime_localtime()
* day 0 - first, * day 0 - first,
* day 1 - last * day 1 - last
* */ * */
switch (dayid) switch (dayid) {
{
case 0: case 0:
day = 1; day = 1;
break; break;
@ -122,7 +121,7 @@ void test_case_mktime_localtime()
} }
/* Additional conditions for RTCs with partial leap year support. */ /* Additional conditions for RTCs with partial leap year support. */
if(month == 1 && year == 200 && rtc_leap_year_support == RTC_4_YEAR_LEAP_YEAR_SUPPORT) { if (month == 1 && year == 200 && rtc_leap_year_support == RTC_4_YEAR_LEAP_YEAR_SUPPORT) {
day = 29; day = 29;
} }
@ -172,28 +171,28 @@ void test_case_mktime_localtime()
} }
} }
utest::v1::status_t full_leap_year_case_setup_handler_t(const Case * const source, const size_t index_of_case) utest::v1::status_t full_leap_year_case_setup_handler_t(const Case *const source, const size_t index_of_case)
{ {
rtc_leap_year_support = RTC_FULL_LEAP_YEAR_SUPPORT; rtc_leap_year_support = RTC_FULL_LEAP_YEAR_SUPPORT;
return greentea_case_setup_handler(source, index_of_case); return greentea_case_setup_handler(source, index_of_case);
} }
utest::v1::status_t partial_leap_year_case_setup_handler_t(const Case * const source, const size_t index_of_case) utest::v1::status_t partial_leap_year_case_setup_handler_t(const Case *const source, const size_t index_of_case)
{ {
rtc_leap_year_support = RTC_4_YEAR_LEAP_YEAR_SUPPORT; rtc_leap_year_support = RTC_4_YEAR_LEAP_YEAR_SUPPORT;
return greentea_case_setup_handler(source, index_of_case); return greentea_case_setup_handler(source, index_of_case);
} }
utest::v1::status_t teardown_handler_t(const Case * const source, const size_t passed, const size_t failed, utest::v1::status_t teardown_handler_t(const Case *const source, const size_t passed, const size_t failed,
const failure_t reason) const failure_t reason)
{ {
return greentea_case_teardown_handler(source, passed, failed, reason); return greentea_case_teardown_handler(source, passed, failed, reason);
} }
// Test cases // Test cases
Case cases[] ={ Case cases[] = {
Case("test make time and local time - RTC leap years full support", full_leap_year_case_setup_handler_t, test_case_mktime_localtime, teardown_handler_t), Case("test make time and local time - RTC leap years full support", full_leap_year_case_setup_handler_t, test_case_mktime_localtime, teardown_handler_t),
Case("test make time and local time - RTC leap years partial support", partial_leap_year_case_setup_handler_t, test_case_mktime_localtime, teardown_handler_t), Case("test make time and local time - RTC leap years partial support", partial_leap_year_case_setup_handler_t, test_case_mktime_localtime, teardown_handler_t),
}; };

View File

@ -66,12 +66,12 @@ static const uint32_t deepsleep_mode_delta_us = (10000 + 125 + 5);
unsigned int ticks_to_us(unsigned int ticks, unsigned int freq) unsigned int ticks_to_us(unsigned int ticks, unsigned int freq)
{ {
return (unsigned int) ((unsigned long long) ticks * US_PER_S / freq); return (unsigned int)((unsigned long long) ticks * US_PER_S / freq);
} }
unsigned int us_to_ticks(unsigned int us, unsigned int freq) unsigned int us_to_ticks(unsigned int us, unsigned int freq)
{ {
return (unsigned int) ((unsigned long long) us * freq / US_PER_S); return (unsigned int)((unsigned long long) us * freq / US_PER_S);
} }
unsigned int overflow_protect(unsigned int timestamp, unsigned int ticker_width) unsigned int overflow_protect(unsigned int timestamp, unsigned int ticker_width)
@ -103,7 +103,7 @@ bool compare_timestamps(unsigned int delta_ticks, unsigned int ticker_width, uns
} }
} }
void us_ticker_isr(const ticker_data_t * const ticker_data) void us_ticker_isr(const ticker_data_t *const ticker_data)
{ {
us_ticker_clear_interrupt(); us_ticker_clear_interrupt();
} }
@ -119,7 +119,7 @@ void lp_ticker_isr(const ticker_data_t *const ticker_data)
* high frequency ticker interrupt can wake-up target from sleep. */ * high frequency ticker interrupt can wake-up target from sleep. */
void sleep_usticker_test() void sleep_usticker_test()
{ {
const ticker_data_t * ticker = get_us_ticker_data(); const ticker_data_t *ticker = get_us_ticker_data();
const unsigned int ticker_freq = ticker->interface->get_info()->frequency; const unsigned int ticker_freq = ticker->interface->get_info()->frequency;
const unsigned int ticker_width = ticker->interface->get_info()->bits; const unsigned int ticker_width = ticker->interface->get_info()->bits;
@ -169,7 +169,7 @@ void sleep_usticker_test()
* low power ticker interrupt can wake-up target from sleep. */ * low power ticker interrupt can wake-up target from sleep. */
void deepsleep_lpticker_test() void deepsleep_lpticker_test()
{ {
const ticker_data_t * ticker = get_lp_ticker_data(); const ticker_data_t *ticker = get_lp_ticker_data();
const unsigned int ticker_freq = ticker->interface->get_info()->frequency; const unsigned int ticker_freq = ticker->interface->get_info()->frequency;
const unsigned int ticker_width = ticker->interface->get_info()->bits; const unsigned int ticker_width = ticker->interface->get_info()->bits;
@ -207,8 +207,8 @@ void deepsleep_lpticker_test()
void deepsleep_high_speed_clocks_turned_off_test() void deepsleep_high_speed_clocks_turned_off_test()
{ {
const ticker_data_t * us_ticker = get_us_ticker_data(); const ticker_data_t *us_ticker = get_us_ticker_data();
const ticker_data_t * lp_ticker = get_lp_ticker_data(); const ticker_data_t *lp_ticker = get_lp_ticker_data();
const unsigned int us_ticker_freq = us_ticker->interface->get_info()->frequency; const unsigned int us_ticker_freq = us_ticker->interface->get_info()->frequency;
const unsigned int lp_ticker_freq = lp_ticker->interface->get_info()->frequency; const unsigned int lp_ticker_freq = lp_ticker->interface->get_info()->frequency;
const unsigned int us_ticker_width = us_ticker->interface->get_info()->bits; const unsigned int us_ticker_width = us_ticker->interface->get_info()->bits;
@ -247,7 +247,7 @@ void deepsleep_high_speed_clocks_turned_off_test()
#endif #endif
utest::v1::status_t greentea_failure_handler(const Case * const source, const failure_t reason) utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{ {
greentea_case_failure_abort_handler(source, reason); greentea_case_failure_abort_handler(source, reason);
return STATUS_CONTINUE; return STATUS_CONTINUE;
@ -265,13 +265,13 @@ utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
return greentea_test_setup_handler(number_of_cases); return greentea_test_setup_handler(number_of_cases);
} }
Case cases[] = Case cases[] = {
{ Case("sleep - source of wake-up - us ticker", sleep_usticker_test, greentea_failure_handler), Case("sleep - source of wake-up - us ticker", sleep_usticker_test, greentea_failure_handler),
#if DEVICE_LPTICKER #if DEVICE_LPTICKER
Case("deep-sleep - source of wake-up - lp ticker",deepsleep_lpticker_test, greentea_failure_handler), Case("deep-sleep - source of wake-up - lp ticker", deepsleep_lpticker_test, greentea_failure_handler),
Case("deep-sleep - high-speed clocks are turned off",deepsleep_high_speed_clocks_turned_off_test, greentea_failure_handler), Case("deep-sleep - high-speed clocks are turned off", deepsleep_high_speed_clocks_turned_off_test, greentea_failure_handler),
#endif #endif
}; };
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);

View File

@ -55,6 +55,7 @@ Case cases[] = {
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
Harness::run(specification); Harness::run(specification);
} }

View File

@ -23,7 +23,7 @@
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using namespace utest::v1; using namespace utest::v1;
@ -100,6 +100,7 @@ Case cases[] = {
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
Harness::run(specification); Harness::run(specification);
} }

View File

@ -98,7 +98,7 @@ static void reset_ticker_interface_stub()
ticker_interface_stub_disable_interrupt; ticker_interface_stub_disable_interrupt;
interface_stub.interface.clear_interrupt = interface_stub.interface.clear_interrupt =
ticker_interface_stub_clear_interrupt; ticker_interface_stub_clear_interrupt;
interface_stub.interface.set_interrupt =ticker_interface_stub_set_interrupt; interface_stub.interface.set_interrupt = ticker_interface_stub_set_interrupt;
interface_stub.interface.fire_interrupt = ticker_interface_stub_fire_interrupt; interface_stub.interface.fire_interrupt = ticker_interface_stub_fire_interrupt;
interface_stub.interface.get_info = ticker_interface_stub_get_info; interface_stub.interface.get_info = ticker_interface_stub_get_info;
interface_stub.initialized = false; interface_stub.initialized = false;
@ -180,7 +180,8 @@ static void test_over_frequency_and_width(void)
static utest::v1::status_t case_setup_handler( static utest::v1::status_t case_setup_handler(
const Case *const source, const size_t index_of_case const Case *const source, const size_t index_of_case
) { )
{
utest::v1::status_t status = greentea_case_setup_handler(source, index_of_case); utest::v1::status_t status = greentea_case_setup_handler(source, index_of_case);
reset_ticker_stub(); reset_ticker_stub();
return status; return status;
@ -188,7 +189,8 @@ static utest::v1::status_t case_setup_handler(
static utest::v1::status_t case_teardown_handler( static utest::v1::status_t case_teardown_handler(
const Case *const source, const size_t passed, const size_t failed, const failure_t reason const Case *const source, const size_t passed, const size_t failed, const failure_t reason
) { )
{
reset_ticker_stub(); reset_ticker_stub();
utest::v1::status_t status = greentea_case_teardown_handler( utest::v1::status_t status = greentea_case_teardown_handler(
source, passed, failed, reason source, passed, failed, reason
@ -198,7 +200,8 @@ static utest::v1::status_t case_teardown_handler(
static utest::v1::status_t greentea_failure_handler( static utest::v1::status_t greentea_failure_handler(
const Case *const source, const failure_t reason const Case *const source, const failure_t reason
) { )
{
utest::v1::status_t status = greentea_case_failure_abort_handler( utest::v1::status_t status = greentea_case_failure_abort_handler(
source, reason source, reason
); );
@ -493,7 +496,8 @@ static void test_legacy_insert_event_in_overflow_range()
* timestamp state stored in the queue plus one. * timestamp state stored in the queue plus one.
* - The id of the event should be equal to the id passed in parameter. * - The id of the event should be equal to the id passed in parameter.
*/ */
static void test_legacy_insert_event_overflow(){ static void test_legacy_insert_event_overflow()
{
ticker_set_handler(&ticker_stub, NULL); ticker_set_handler(&ticker_stub, NULL);
interface_stub.set_interrupt_call = 0; interface_stub.set_interrupt_call = 0;
@ -580,7 +584,7 @@ static void test_legacy_insert_event_head()
); );
TEST_ASSERT_EQUAL_UINT32(i, events[i].id); TEST_ASSERT_EQUAL_UINT32(i, events[i].id);
ticker_event_t* e = &events[i]; ticker_event_t *e = &events[i];
while (e) { while (e) {
TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp); TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp);
if (e->next) { if (e->next) {
@ -639,7 +643,7 @@ static void test_legacy_insert_event_tail()
TEST_ASSERT_EQUAL_UINT32(timestamps[i], events[i].timestamp); TEST_ASSERT_EQUAL_UINT32(timestamps[i], events[i].timestamp);
TEST_ASSERT_EQUAL_UINT32(i, events[i].id); TEST_ASSERT_EQUAL_UINT32(i, events[i].id);
ticker_event_t* e = queue_stub.head; ticker_event_t *e = queue_stub.head;
while (e) { while (e) {
TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp); TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp);
if (e->next) { if (e->next) {
@ -714,7 +718,7 @@ static void test_legacy_insert_event_multiple_overflow()
TEST_ASSERT_EQUAL_UINT32(timestamps[i], events[i].timestamp); TEST_ASSERT_EQUAL_UINT32(timestamps[i], events[i].timestamp);
TEST_ASSERT_EQUAL_UINT32(i, events[i].id); TEST_ASSERT_EQUAL_UINT32(i, events[i].id);
ticker_event_t* e = queue_stub.head->next; ticker_event_t *e = queue_stub.head->next;
while (e) { while (e) {
TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp); TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp);
if (e->next) { if (e->next) {
@ -1065,7 +1069,7 @@ static void test_insert_event_us_head()
TEST_ASSERT_EQUAL_UINT64(timestamps[i], events[i].timestamp); TEST_ASSERT_EQUAL_UINT64(timestamps[i], events[i].timestamp);
TEST_ASSERT_EQUAL_UINT32(i, events[i].id); TEST_ASSERT_EQUAL_UINT32(i, events[i].id);
ticker_event_t* e = &events[i]; ticker_event_t *e = &events[i];
while (e) { while (e) {
TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp); TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp);
if (e->next) { if (e->next) {
@ -1123,7 +1127,7 @@ static void test_insert_event_us_tail()
TEST_ASSERT_EQUAL_UINT64(timestamps[i], events[i].timestamp); TEST_ASSERT_EQUAL_UINT64(timestamps[i], events[i].timestamp);
TEST_ASSERT_EQUAL_UINT32(i, events[i].id); TEST_ASSERT_EQUAL_UINT32(i, events[i].id);
ticker_event_t* e = queue_stub.head; ticker_event_t *e = queue_stub.head;
while (e) { while (e) {
TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp); TEST_ASSERT_EQUAL_UINT32(timestamps[e->id], e->timestamp);
if (e->next) { if (e->next) {
@ -1273,7 +1277,7 @@ static void test_remove_event_tail()
for (ssize_t i = MBED_ARRAY_SIZE(events) - 1; i >= 0; --i) { for (ssize_t i = MBED_ARRAY_SIZE(events) - 1; i >= 0; --i) {
ticker_remove_event(&ticker_stub, &events[i]); ticker_remove_event(&ticker_stub, &events[i]);
ticker_event_t* e = queue_stub.head; ticker_event_t *e = queue_stub.head;
size_t event_count = 0; size_t event_count = 0;
while (e) { while (e) {
TEST_ASSERT_NOT_EQUAL(e, &events[i]); TEST_ASSERT_NOT_EQUAL(e, &events[i]);
@ -1286,7 +1290,7 @@ static void test_remove_event_tail()
TEST_ASSERT_EQUAL(i, event_count); TEST_ASSERT_EQUAL(i, event_count);
if (i != 0 ) { if (i != 0) {
TEST_ASSERT_EQUAL( TEST_ASSERT_EQUAL(
timestamps[0], timestamps[0],
interface_stub.interrupt_timestamp interface_stub.interrupt_timestamp
@ -1337,7 +1341,7 @@ static void test_remove_event_head()
for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) { for (size_t i = 0; i < MBED_ARRAY_SIZE(events); ++i) {
ticker_remove_event(&ticker_stub, &events[i]); ticker_remove_event(&ticker_stub, &events[i]);
ticker_event_t* e = queue_stub.head; ticker_event_t *e = queue_stub.head;
size_t event_count = 0; size_t event_count = 0;
while (e) { while (e) {
TEST_ASSERT_NOT_EQUAL(e, &events[i]); TEST_ASSERT_NOT_EQUAL(e, &events[i]);
@ -1402,7 +1406,7 @@ static void test_remove_event_invalid()
TEST_ASSERT_EQUAL(&events[0], queue_stub.head); TEST_ASSERT_EQUAL(&events[0], queue_stub.head);
ticker_event_t* e = queue_stub.head; ticker_event_t *e = queue_stub.head;
size_t event_count = 0; size_t event_count = 0;
while (e) { while (e) {
TEST_ASSERT_EQUAL(e, &events[event_count]); TEST_ASSERT_EQUAL(e, &events[event_count]);
@ -1540,7 +1544,8 @@ static void test_overflow_event_update()
{ {
static uint32_t handler_call = 0; static uint32_t handler_call = 0;
struct irq_handler_stub_t { struct irq_handler_stub_t {
static void event_handler(uint32_t id) { static void event_handler(uint32_t id)
{
++handler_call; ++handler_call;
} }
}; };
@ -1582,7 +1587,8 @@ static void test_overflow_event_update_when_spurious_interrupt()
{ {
static uint32_t handler_call = 0; static uint32_t handler_call = 0;
struct irq_handler_stub_t { struct irq_handler_stub_t {
static void event_handler(uint32_t id) { static void event_handler(uint32_t id)
{
++handler_call; ++handler_call;
} }
}; };
@ -1629,8 +1635,9 @@ static void test_irq_handler_single_event()
uint32_t handler_call = 0; uint32_t handler_call = 0;
struct irq_handler_stub_t { struct irq_handler_stub_t {
static void event_handler(uint32_t id) { static void event_handler(uint32_t id)
++ (*((uint32_t*) id)); {
++ (*((uint32_t *) id));
interface_stub.timestamp = interface_timestamp_after_irq; interface_stub.timestamp = interface_timestamp_after_irq;
} }
}; };
@ -1672,7 +1679,8 @@ static void test_irq_handler_single_event()
static void test_irq_handler_single_event_spurious() static void test_irq_handler_single_event_spurious()
{ {
struct irq_handler_stub_t { struct irq_handler_stub_t {
static void event_handler(uint32_t id) { static void event_handler(uint32_t id)
{
TEST_FAIL(); TEST_FAIL();
} }
}; };
@ -1733,9 +1741,10 @@ static void test_irq_handler_multiple_event_multiple_dequeue()
static size_t handler_called = 0; static size_t handler_called = 0;
struct irq_handler_stub_t { struct irq_handler_stub_t {
static void event_handler(uint32_t id) { static void event_handler(uint32_t id)
{
++handler_called; ++handler_called;
ticker_event_t* e = (ticker_event_t*) id; ticker_event_t *e = (ticker_event_t *) id;
if (e->next) { if (e->next) {
interface_stub.timestamp = e->next->timestamp; interface_stub.timestamp = e->next->timestamp;
} }
@ -1793,8 +1802,9 @@ static void test_irq_handler_multiple_event_single_dequeue_overflow()
size_t handler_called = 0; size_t handler_called = 0;
struct irq_handler_stub_t { struct irq_handler_stub_t {
static void event_handler(uint32_t id) { static void event_handler(uint32_t id)
++ (*((size_t*) id)); {
++ (*((size_t *) id));
} }
}; };
@ -1848,8 +1858,9 @@ static void test_irq_handler_multiple_event_single_dequeue()
size_t handler_called = 0; size_t handler_called = 0;
struct irq_handler_stub_t { struct irq_handler_stub_t {
static void event_handler(uint32_t id) { static void event_handler(uint32_t id)
++ (*((size_t*) id)); {
++ (*((size_t *) id));
} }
}; };
@ -1915,8 +1926,9 @@ static void test_irq_handler_insert_immediate_in_irq()
ctrl_block_t ctrl_block = { 0 }; ctrl_block_t ctrl_block = { 0 };
struct irq_handler_stub_t { struct irq_handler_stub_t {
static void event_handler(uint32_t id) { static void event_handler(uint32_t id)
ctrl_block_t* ctrl_block = (ctrl_block_t*) id; {
ctrl_block_t *ctrl_block = (ctrl_block_t *) id;
if (ctrl_block->handler_called == 0) { if (ctrl_block->handler_called == 0) {
ticker_insert_event( ticker_insert_event(
@ -1991,8 +2003,9 @@ static void test_irq_handler_insert_non_immediate_in_irq()
ctrl_block_t ctrl_block = { 0 }; ctrl_block_t ctrl_block = { 0 };
struct irq_handler_stub_t { struct irq_handler_stub_t {
static void event_handler(uint32_t id) { static void event_handler(uint32_t id)
ctrl_block_t* ctrl_block = (ctrl_block_t*) id; {
ctrl_block_t *ctrl_block = (ctrl_block_t *) id;
if (ctrl_block->handler_called == 0) { if (ctrl_block->handler_called == 0) {
ticker_insert_event( ticker_insert_event(

View File

@ -29,7 +29,7 @@ using namespace utest::v1;
/* Test that the ticker has the correct frequency and number of bits. */ /* Test that the ticker has the correct frequency and number of bits. */
void us_ticker_info_test() void us_ticker_info_test()
{ {
const ticker_info_t* p_ticker_info = us_ticker_get_info(); const ticker_info_t *p_ticker_info = us_ticker_get_info();
TEST_ASSERT(p_ticker_info->frequency >= 250000); TEST_ASSERT(p_ticker_info->frequency >= 250000);
TEST_ASSERT(p_ticker_info->frequency <= 8000000); TEST_ASSERT(p_ticker_info->frequency <= 8000000);

View File

@ -39,10 +39,9 @@ public:
ssize_t read; ssize_t read;
_fnCalled = fnRead; _fnCalled = fnRead;
for(read = 0; (size_t)read < size; read++) for (read = 0; (size_t)read < size; read++) {
{ if (POS_IS_VALID(_pos)) {
if(POS_IS_VALID(_pos)) { ((uint8_t *)buffer)[read] = _data[_pos++];
((uint8_t*)buffer)[read] = _data[_pos++];
} else { } else {
break; break;
} }
@ -55,17 +54,16 @@ public:
ssize_t written; ssize_t written;
_fnCalled = fnWrite; _fnCalled = fnWrite;
for(written = 0; (size_t)written < size; written++) for (written = 0; (size_t)written < size; written++) {
{ if (NEW_POS_IS_VALID(_pos)) {
if(NEW_POS_IS_VALID(_pos)) { _data[_pos++] = ((uint8_t *)buffer)[written];
_data[_pos++] = ((uint8_t*)buffer)[written];
} else { } else {
if(0 == written) { if (0 == written) {
return -ENOSPC; return -ENOSPC;
} }
break; break;
} }
if(_end < _pos) { if (_end < _pos) {
_end++; _end++;
} }
} // for } // for
@ -77,8 +75,7 @@ public:
_fnCalled = fnSeek; _fnCalled = fnSeek;
int32_t new_pos = INVALID_POS; int32_t new_pos = INVALID_POS;
switch(whence) switch (whence) {
{
case SEEK_SET: case SEEK_SET:
new_pos = offset; new_pos = offset;
break; break;
@ -96,7 +93,7 @@ public:
break; break;
} }
if(SEEK_POS_IS_VALID(new_pos)) { if (SEEK_POS_IS_VALID(new_pos)) {
_pos = new_pos; _pos = new_pos;
} else { } else {
return -EINVAL; return -EINVAL;

View File

@ -43,7 +43,7 @@ void test_Transaction_init()
const uint8_t word_width = 8; const uint8_t word_width = 8;
unsigned char tx_buffer[tx_buffer_size]; unsigned char tx_buffer[tx_buffer_size];
unsigned char rx_buffer[rx_buffer_size]; unsigned char rx_buffer[rx_buffer_size];
const event_callback_t& callback = dummy_callback; const event_callback_t &callback = dummy_callback;
transaction_t transaction_data = transaction_t transaction_data =
{ tx_buffer, tx_buffer_size, rx_buffer, rx_buffer_size, event_id, callback, word_width }; { tx_buffer, tx_buffer_size, rx_buffer, rx_buffer_size, event_id, callback, word_width };
@ -51,8 +51,8 @@ void test_Transaction_init()
TEST_ASSERT_EQUAL(&object, test_transaction.get_object()); TEST_ASSERT_EQUAL(&object, test_transaction.get_object());
TEST_ASSERT_EQUAL((void*)tx_buffer, test_transaction.get_transaction()->tx_buffer); TEST_ASSERT_EQUAL((void *)tx_buffer, test_transaction.get_transaction()->tx_buffer);
TEST_ASSERT_EQUAL((void*)rx_buffer, test_transaction.get_transaction()->rx_buffer); TEST_ASSERT_EQUAL((void *)rx_buffer, test_transaction.get_transaction()->rx_buffer);
TEST_ASSERT_EQUAL(tx_buffer_size, test_transaction.get_transaction()->tx_length); TEST_ASSERT_EQUAL(tx_buffer_size, test_transaction.get_transaction()->tx_length);
TEST_ASSERT_EQUAL(rx_buffer_size, test_transaction.get_transaction()->rx_length); TEST_ASSERT_EQUAL(rx_buffer_size, test_transaction.get_transaction()->rx_length);
TEST_ASSERT_EQUAL(event_id, test_transaction.get_transaction()->event); TEST_ASSERT_EQUAL(event_id, test_transaction.get_transaction()->event);

View File

@ -38,7 +38,7 @@ void critical_section_raii_recursive(Timeout &timeout)
depth++; depth++;
TEST_ASSERT_TRUE(core_util_in_critical_section()); TEST_ASSERT_TRUE(core_util_in_critical_section());
if(depth < N) { if (depth < N) {
critical_section_raii_recursive<N>(timeout); critical_section_raii_recursive<N>(timeout);
} else { } else {
// max depth reached - do the test // max depth reached - do the test
@ -87,7 +87,7 @@ void test_C_API(void)
wait_us(wait_time_us); wait_us(wait_time_us);
TEST_ASSERT_TRUE(callback_called); TEST_ASSERT_TRUE(callback_called);
for(int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
core_util_critical_section_enter(); core_util_critical_section_enter();
TEST_ASSERT_TRUE(core_util_in_critical_section()); TEST_ASSERT_TRUE(core_util_in_critical_section());
} }
@ -98,7 +98,7 @@ void test_C_API(void)
TEST_ASSERT_FALSE(callback_called); TEST_ASSERT_FALSE(callback_called);
TEST_ASSERT_TRUE(core_util_in_critical_section()); TEST_ASSERT_TRUE(core_util_in_critical_section());
for(int i = 0; i < N - 1; i++) { for (int i = 0; i < N - 1; i++) {
core_util_critical_section_exit(); core_util_critical_section_exit();
TEST_ASSERT_TRUE(core_util_in_critical_section()); TEST_ASSERT_TRUE(core_util_in_critical_section());
TEST_ASSERT_FALSE(callback_called); TEST_ASSERT_FALSE(callback_called);
@ -184,7 +184,7 @@ void test_CPP_API_enable_disable(void)
wait_us(wait_time_us); wait_us(wait_time_us);
TEST_ASSERT_TRUE(callback_called); TEST_ASSERT_TRUE(callback_called);
for(int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
CriticalSectionLock::enable(); CriticalSectionLock::enable();
TEST_ASSERT_TRUE(core_util_in_critical_section()); TEST_ASSERT_TRUE(core_util_in_critical_section());
} }
@ -195,7 +195,7 @@ void test_CPP_API_enable_disable(void)
TEST_ASSERT_FALSE(callback_called); TEST_ASSERT_FALSE(callback_called);
TEST_ASSERT_TRUE(core_util_in_critical_section()); TEST_ASSERT_TRUE(core_util_in_critical_section());
for(int i = 0; i < N - 1; i++) { for (int i = 0; i < N - 1; i++) {
CriticalSectionLock::disable(); CriticalSectionLock::disable();
TEST_ASSERT_TRUE(core_util_in_critical_section()); TEST_ASSERT_TRUE(core_util_in_critical_section());
TEST_ASSERT_FALSE(callback_called); TEST_ASSERT_FALSE(callback_called);

View File

@ -30,7 +30,7 @@ void test_error_count_and_reset()
int count = 7; int count = 7;
//Log multiple errors and get the error count and make sure its 15 //Log multiple errors and get the error count and make sure its 15
for(int i=0; i<count; i++) { for (int i = 0; i < count; i++) {
MBED_WARNING1(MBED_ERROR_OUT_OF_MEMORY, "Out of memory", i); MBED_WARNING1(MBED_ERROR_OUT_OF_MEMORY, "Out of memory", i);
} }
@ -54,23 +54,23 @@ void test_error_capturing()
//first clear all errors and start afresh //first clear all errors and start afresh
MBED_WARNING1(MBED_ERROR_OUT_OF_RESOURCES, "System type error", 0x1100 ); MBED_WARNING1(MBED_ERROR_OUT_OF_RESOURCES, "System type error", 0x1100);
mbed_error_status_t lastError = mbed_get_last_error(); mbed_error_status_t lastError = mbed_get_last_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_SYSTEM, MBED_GET_ERROR_TYPE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_SYSTEM, MBED_GET_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_MODULE_UNKNOWN, MBED_GET_ERROR_MODULE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_MODULE_UNKNOWN, MBED_GET_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_OUT_OF_RESOURCES, MBED_GET_ERROR_CODE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_OUT_OF_RESOURCES, MBED_GET_ERROR_CODE(lastError));
mbed_error_status_t error = MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SERIAL, MBED_ERROR_CODE_OUT_OF_RESOURCES); mbed_error_status_t error = MBED_MAKE_ERROR(MBED_MODULE_DRIVER_SERIAL, MBED_ERROR_CODE_OUT_OF_RESOURCES);
MBED_WARNING1(error, "Error Serial", 0xAA ); MBED_WARNING1(error, "Error Serial", 0xAA);
lastError = mbed_get_last_error(); lastError = mbed_get_last_error();
TEST_ASSERT_EQUAL_UINT(error, lastError); TEST_ASSERT_EQUAL_UINT(error, lastError);
error = MBED_MAKE_CUSTOM_ERROR(MBED_MODULE_APPLICATION, MBED_ERROR_CODE_UNKNOWN); error = MBED_MAKE_CUSTOM_ERROR(MBED_MODULE_APPLICATION, MBED_ERROR_CODE_UNKNOWN);
MBED_WARNING1(error, "Custom Error Unknown", 0x1234 ); MBED_WARNING1(error, "Custom Error Unknown", 0x1234);
lastError = mbed_get_last_error(); lastError = mbed_get_last_error();
TEST_ASSERT_EQUAL_UINT(error, lastError); TEST_ASSERT_EQUAL_UINT(error, lastError);
MBED_WARNING1(MBED_ERROR_EPERM, "Posix Error Eperm", 0x1234 ); MBED_WARNING1(MBED_ERROR_EPERM, "Posix Error Eperm", 0x1234);
lastError = mbed_get_last_error(); lastError = mbed_get_last_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_EPERM, lastError); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_EPERM, lastError);
@ -80,32 +80,32 @@ void test_error_capturing()
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_CUSTOM, MBED_GET_ERROR_TYPE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_CUSTOM, MBED_GET_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_MODULE_PLATFORM, MBED_GET_ERROR_MODULE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_MODULE_PLATFORM, MBED_GET_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_CREATE_FAILED, MBED_GET_ERROR_CODE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_CREATE_FAILED, MBED_GET_ERROR_CODE(lastError));
mbed_error_status_t status = mbed_get_last_error_info( &error_ctx ); mbed_error_status_t status = mbed_get_last_error_info(&error_ctx);
TEST_ASSERT(status == MBED_SUCCESS); TEST_ASSERT(status == MBED_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value); TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
error_value = 0xAABBCC; error_value = 0xAABBCC;
MBED_WARNING1(MBED_ERROR_EACCES, "Posix Error", error_value ); MBED_WARNING1(MBED_ERROR_EACCES, "Posix Error", error_value);
lastError = mbed_get_last_error(); lastError = mbed_get_last_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_POSIX, MBED_GET_ERROR_TYPE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_POSIX, MBED_GET_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_MODULE_UNKNOWN, MBED_GET_ERROR_MODULE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_MODULE_UNKNOWN, MBED_GET_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_EACCES, MBED_GET_ERROR_CODE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_EACCES, MBED_GET_ERROR_CODE(lastError));
status = mbed_get_last_error_info( &error_ctx ); status = mbed_get_last_error_info(&error_ctx);
TEST_ASSERT(status == MBED_SUCCESS); TEST_ASSERT(status == MBED_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value); TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
error_value = 0; error_value = 0;
error = MBED_MAKE_ERROR(MBED_MODULE_HAL, MBED_ERROR_CODE_UNKNOWN); error = MBED_MAKE_ERROR(MBED_MODULE_HAL, MBED_ERROR_CODE_UNKNOWN);
MBED_WARNING1(error, "HAL Entity error", error_value ); MBED_WARNING1(error, "HAL Entity error", error_value);
lastError = mbed_get_last_error(); lastError = mbed_get_last_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_SYSTEM, MBED_GET_ERROR_TYPE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TYPE_SYSTEM, MBED_GET_ERROR_TYPE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_MODULE_HAL, MBED_GET_ERROR_MODULE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_MODULE_HAL, MBED_GET_ERROR_MODULE(lastError));
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_UNKNOWN, MBED_GET_ERROR_CODE(lastError)); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_CODE_UNKNOWN, MBED_GET_ERROR_CODE(lastError));
status = mbed_get_last_error_info( &error_ctx ); status = mbed_get_last_error_info(&error_ctx);
TEST_ASSERT(status == MBED_SUCCESS); TEST_ASSERT(status == MBED_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value); TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
MBED_WARNING1(MBED_ERROR_MUTEX_LOCK_FAILED, "Mutex lock failed", 0x4455 ); MBED_WARNING1(MBED_ERROR_MUTEX_LOCK_FAILED, "Mutex lock failed", 0x4455);
error = mbed_get_last_error(); error = mbed_get_last_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_MUTEX_LOCK_FAILED, error); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_MUTEX_LOCK_FAILED, error);
@ -121,8 +121,8 @@ void test_error_context_capture()
uint32_t error_value = 0xABCD; uint32_t error_value = 0xABCD;
mbed_error_ctx error_ctx = {0}; mbed_error_ctx error_ctx = {0};
MBED_WARNING1(MBED_ERROR_INVALID_ARGUMENT, "System type error", error_value ); MBED_WARNING1(MBED_ERROR_INVALID_ARGUMENT, "System type error", error_value);
mbed_error_status_t status = mbed_get_last_error_info( &error_ctx ); mbed_error_status_t status = mbed_get_last_error_info(&error_ctx);
TEST_ASSERT(status == MBED_SUCCESS); TEST_ASSERT(status == MBED_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value); TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
TEST_ASSERT_EQUAL_UINT((uint32_t)osThreadGetId(), error_ctx.thread_id); TEST_ASSERT_EQUAL_UINT((uint32_t)osThreadGetId(), error_ctx.thread_id);
@ -148,52 +148,52 @@ void test_error_logging()
mbed_clear_all_errors(); mbed_clear_all_errors();
//log 3 errors and retrieve them to ensure they are correct //log 3 errors and retrieve them to ensure they are correct
MBED_WARNING1(MBED_ERROR_INVALID_ARGUMENT, "Invalid argument", 1 ); MBED_WARNING1(MBED_ERROR_INVALID_ARGUMENT, "Invalid argument", 1);
MBED_WARNING1(MBED_ERROR_INVALID_SIZE, "Invalid size", 2 ); MBED_WARNING1(MBED_ERROR_INVALID_SIZE, "Invalid size", 2);
MBED_WARNING1(MBED_ERROR_INVALID_FORMAT, "Invalid format", 3 ); MBED_WARNING1(MBED_ERROR_INVALID_FORMAT, "Invalid format", 3);
mbed_error_status_t status = mbed_get_error_hist_info( 0, &error_ctx ); mbed_error_status_t status = mbed_get_error_hist_info(0, &error_ctx);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_ARGUMENT, error_ctx.error_status); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_ARGUMENT, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(1, error_ctx.error_value); TEST_ASSERT_EQUAL_UINT(1, error_ctx.error_value);
status = mbed_get_error_hist_info( 1, &error_ctx ); status = mbed_get_error_hist_info(1, &error_ctx);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_SIZE, error_ctx.error_status); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_SIZE, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(2, error_ctx.error_value); TEST_ASSERT_EQUAL_UINT(2, error_ctx.error_value);
status = mbed_get_error_hist_info( 2, &error_ctx ); status = mbed_get_error_hist_info(2, &error_ctx);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_FORMAT, error_ctx.error_status); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_FORMAT, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(3, error_ctx.error_value); TEST_ASSERT_EQUAL_UINT(3, error_ctx.error_value);
//Log a bunch of errors to overflow the error log and retrieve them //Log a bunch of errors to overflow the error log and retrieve them
MBED_WARNING1(MBED_ERROR_INVALID_ARGUMENT, "Invalid argument", 6 ); MBED_WARNING1(MBED_ERROR_INVALID_ARGUMENT, "Invalid argument", 6);
MBED_WARNING1(MBED_ERROR_INVALID_SIZE, "Invalid size", 7 ); MBED_WARNING1(MBED_ERROR_INVALID_SIZE, "Invalid size", 7);
MBED_WARNING1(MBED_ERROR_INVALID_FORMAT, "Invalid format", 8 ); MBED_WARNING1(MBED_ERROR_INVALID_FORMAT, "Invalid format", 8);
MBED_WARNING1(MBED_ERROR_NOT_READY, "Not ready error", 9 ); MBED_WARNING1(MBED_ERROR_NOT_READY, "Not ready error", 9);
//Last 4 entries //Last 4 entries
MBED_WARNING1(MBED_ERROR_TIME_OUT, "Timeout error", 10 ); MBED_WARNING1(MBED_ERROR_TIME_OUT, "Timeout error", 10);
MBED_WARNING1(MBED_ERROR_ALREADY_IN_USE, "Already in use error", 11 ); MBED_WARNING1(MBED_ERROR_ALREADY_IN_USE, "Already in use error", 11);
MBED_WARNING1(MBED_ERROR_UNSUPPORTED, "Not supported", 12 ); MBED_WARNING1(MBED_ERROR_UNSUPPORTED, "Not supported", 12);
MBED_WARNING1(MBED_ERROR_ACCESS_DENIED, "Access denied", 13 ); MBED_WARNING1(MBED_ERROR_ACCESS_DENIED, "Access denied", 13);
status = mbed_get_error_hist_info( 0, &error_ctx ); status = mbed_get_error_hist_info(0, &error_ctx);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TIME_OUT, error_ctx.error_status); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_TIME_OUT, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(10, error_ctx.error_value); TEST_ASSERT_EQUAL_UINT(10, error_ctx.error_value);
status = mbed_get_error_hist_info( 1, &error_ctx ); status = mbed_get_error_hist_info(1, &error_ctx);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_ALREADY_IN_USE, error_ctx.error_status); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_ALREADY_IN_USE, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(11, error_ctx.error_value); TEST_ASSERT_EQUAL_UINT(11, error_ctx.error_value);
status = mbed_get_error_hist_info( 2, &error_ctx ); status = mbed_get_error_hist_info(2, &error_ctx);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_UNSUPPORTED, error_ctx.error_status); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_UNSUPPORTED, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(12, error_ctx.error_value); TEST_ASSERT_EQUAL_UINT(12, error_ctx.error_value);
status = mbed_get_error_hist_info( 3, &error_ctx ); status = mbed_get_error_hist_info(3, &error_ctx);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_ACCESS_DENIED, error_ctx.error_status); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_ACCESS_DENIED, error_ctx.error_status);
TEST_ASSERT_EQUAL_UINT(13, error_ctx.error_value); TEST_ASSERT_EQUAL_UINT(13, error_ctx.error_value);
//Try an index which is invalid, we should get ERROR_INVALID_ARGUMENT back //Try an index which is invalid, we should get ERROR_INVALID_ARGUMENT back
status = mbed_get_error_hist_info( 99, &error_ctx ); status = mbed_get_error_hist_info(99, &error_ctx);
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_ARGUMENT, status); TEST_ASSERT_EQUAL_UINT(MBED_ERROR_INVALID_ARGUMENT, status);
} }
@ -204,7 +204,7 @@ void test_error_logging()
//Error logger threads //Error logger threads
void err_thread_func(mbed_error_status_t *error_status) void err_thread_func(mbed_error_status_t *error_status)
{ {
MBED_WARNING1(*error_status, "Error from Multi-Threaded error logging test", *error_status ); MBED_WARNING1(*error_status, "Error from Multi-Threaded error logging test", *error_status);
} }
@ -224,20 +224,20 @@ void test_error_logging_multithread()
}; };
for(i=0; i<NUM_TEST_THREADS; i++) { for (i = 0; i < NUM_TEST_THREADS; i++) {
errThread[i] = new Thread(osPriorityNormal1, THREAD_STACK_SIZE, NULL, NULL); errThread[i] = new Thread(osPriorityNormal1, THREAD_STACK_SIZE, NULL, NULL);
errThread[i]->start(callback(err_thread_func, &error_status[i])); errThread[i]->start(callback(err_thread_func, &error_status[i]));
} }
wait(2.0); wait(2.0);
for(i=0; i<NUM_TEST_THREADS; i++) { for (i = 0; i < NUM_TEST_THREADS; i++) {
errThread[i]->join(); errThread[i]->join();
} }
i = mbed_get_error_hist_count()-1; i = mbed_get_error_hist_count() - 1;
for(;i>=0;--i) { for (; i >= 0; --i) {
mbed_error_status_t status = mbed_get_error_hist_info( i, &error_ctx ); mbed_error_status_t status = mbed_get_error_hist_info(i, &error_ctx);
if(status != MBED_SUCCESS) { if (status != MBED_SUCCESS) {
TEST_FAIL(); TEST_FAIL();
} }
@ -256,7 +256,7 @@ void MyErrorHook(const mbed_error_ctx *error_ctx)
*/ */
void test_error_hook() void test_error_hook()
{ {
if( MBED_SUCCESS != mbed_set_error_hook(MyErrorHook)) { if (MBED_SUCCESS != mbed_set_error_hook(MyErrorHook)) {
TEST_FAIL(); TEST_FAIL();
} }
@ -301,42 +301,42 @@ MBED_TEST_SIM_BLOCKDEVICE_DECL;
void test_save_error_log() void test_save_error_log()
{ {
//Log some errors //Log some errors
MBED_WARNING1(MBED_ERROR_TIME_OUT, "Timeout error", 1 ); MBED_WARNING1(MBED_ERROR_TIME_OUT, "Timeout error", 1);
MBED_WARNING1(MBED_ERROR_ALREADY_IN_USE, "Already in use error", 2 ); MBED_WARNING1(MBED_ERROR_ALREADY_IN_USE, "Already in use error", 2);
MBED_WARNING1(MBED_ERROR_UNSUPPORTED, "Not supported error", 3 ); MBED_WARNING1(MBED_ERROR_UNSUPPORTED, "Not supported error", 3);
MBED_WARNING1(MBED_ERROR_ACCESS_DENIED, "Access denied error", 4 ); MBED_WARNING1(MBED_ERROR_ACCESS_DENIED, "Access denied error", 4);
MBED_WARNING1(MBED_ERROR_ITEM_NOT_FOUND, "Not found error", 5 ); MBED_WARNING1(MBED_ERROR_ITEM_NOT_FOUND, "Not found error", 5);
int error = 0; int error = 0;
error = MBED_TEST_FILESYSTEM::format(&fd); error = MBED_TEST_FILESYSTEM::format(&fd);
if(error < 0) { if (error < 0) {
TEST_FAIL_MESSAGE("Failed formatting"); TEST_FAIL_MESSAGE("Failed formatting");
} }
error = fs.mount(&fd); error = fs.mount(&fd);
if(error < 0) { if (error < 0) {
TEST_FAIL_MESSAGE("Failed mounting fs"); TEST_FAIL_MESSAGE("Failed mounting fs");
} }
if(MBED_SUCCESS != mbed_save_error_hist("/fs/errors.log")) { if (MBED_SUCCESS != mbed_save_error_hist("/fs/errors.log")) {
TEST_FAIL_MESSAGE("Failed saving error log"); TEST_FAIL_MESSAGE("Failed saving error log");
} }
FILE *error_file = fopen("/fs/errors.log", "r"); FILE *error_file = fopen("/fs/errors.log", "r");
if(error_file == NULL) { if (error_file == NULL) {
TEST_FAIL_MESSAGE("Unable to find error log in fs"); TEST_FAIL_MESSAGE("Unable to find error log in fs");
} }
char buff[64] = {0}; char buff[64] = {0};
while (!feof(error_file)){ while (!feof(error_file)) {
int size = fread(&buff[0], 1, 15, error_file); int size = fread(&buff[0], 1, 15, error_file);
fwrite(&buff[0], 1, size, stdout); fwrite(&buff[0], 1, size, stdout);
} }
fclose(error_file); fclose(error_file);
error = fs.unmount(); error = fs.unmount();
if(error < 0) { if (error < 0) {
TEST_FAIL_MESSAGE("Failed unmounting fs"); TEST_FAIL_MESSAGE("Failed unmounting fs");
} }
} }

View File

@ -23,7 +23,7 @@
#include <stdio.h> #include <stdio.h>
#if !defined(MBED_HEAP_STATS_ENABLED) #if !defined(MBED_HEAP_STATS_ENABLED)
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using namespace utest::v1; using namespace utest::v1;
@ -33,12 +33,12 @@ using namespace utest::v1;
#define ALLOCATION_SIZE_LARGE 700 #define ALLOCATION_SIZE_LARGE 700
#define ALLOCATION_SIZE_FAIL (1024 * 1024 *1024) #define ALLOCATION_SIZE_FAIL (1024 * 1024 *1024)
typedef void* (*malloc_cb_t) (uint32_t size); typedef void *(*malloc_cb_t)(uint32_t size);
static void* thunk_malloc(uint32_t size); static void *thunk_malloc(uint32_t size);
static void* thunk_calloc_1(uint32_t size); static void *thunk_calloc_1(uint32_t size);
static void* thunk_calloc_4(uint32_t size); static void *thunk_calloc_4(uint32_t size);
static void* thunk_realloc(uint32_t size); static void *thunk_realloc(uint32_t size);
malloc_cb_t malloc_thunk_array[] = { malloc_cb_t malloc_thunk_array[] = {
thunk_malloc, thunk_malloc,
@ -124,23 +124,23 @@ void test_case_allocate_fail()
} }
} }
static void* thunk_malloc(uint32_t size) static void *thunk_malloc(uint32_t size)
{ {
return malloc(size); return malloc(size);
} }
static void* thunk_calloc_1(uint32_t size) static void *thunk_calloc_1(uint32_t size)
{ {
return calloc(size / 1, 1); return calloc(size / 1, 1);
} }
static void* thunk_calloc_4(uint32_t size) static void *thunk_calloc_4(uint32_t size)
{ {
return calloc(size / 4, 4); return calloc(size / 4, 4);
} }
static void* thunk_realloc(uint32_t size) static void *thunk_realloc(uint32_t size)
{ {
return realloc(NULL, size); return realloc(NULL, size);
} }

View File

@ -101,7 +101,7 @@ void test_case_multi_threads_blocked()
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].stack_size); TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].stack_size);
TEST_ASSERT_EQUAL(osPriorityNormal1, stats[i].priority); TEST_ASSERT_EQUAL(osPriorityNormal1, stats[i].priority);
TEST_ASSERT_EQUAL(osThreadBlocked, stats[i].state); TEST_ASSERT_EQUAL(osThreadBlocked, stats[i].state);
} else if (0 == strcmp (stats[i].name, "Th1")) { } else if (0 == strcmp(stats[i].name, "Th1")) {
TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].stack_size); TEST_ASSERT_EQUAL(TEST_STACK_SIZE, stats[i].stack_size);
TEST_ASSERT_EQUAL(osPriorityNormal, stats[i].priority); TEST_ASSERT_EQUAL(osPriorityNormal, stats[i].priority);
} }

View File

@ -9,12 +9,15 @@ MBED_PACKED(struct) TestAttrPackedStruct1 {
int x; int x;
}; };
typedef MBED_PACKED(struct) { typedef MBED_PACKED(struct)
{
char a; char a;
int x; int x;
} TestAttrPackedStruct2; }
TestAttrPackedStruct2;
int testPacked() { int testPacked()
{
int failed = 0; int failed = 0;
if (sizeof(struct TestAttrPackedStruct1) != sizeof(int) + sizeof(char)) { if (sizeof(struct TestAttrPackedStruct1) != sizeof(int) + sizeof(char)) {
@ -35,22 +38,23 @@ MBED_ALIGN(16) char c;
MBED_ALIGN(8) char d; MBED_ALIGN(8) char d;
MBED_ALIGN(16) char e; MBED_ALIGN(16) char e;
int testAlign() { int testAlign()
{
int failed = 0; int failed = 0;
if(((uintptr_t)&a) & 0x7){ if (((uintptr_t)&a) & 0x7) {
failed++; failed++;
} }
if(((uintptr_t)&b) & 0x7){ if (((uintptr_t)&b) & 0x7) {
failed++; failed++;
} }
if(((uintptr_t)&c) & 0xf){ if (((uintptr_t)&c) & 0xf) {
failed++; failed++;
} }
if(((uintptr_t)&d) & 0x7){ if (((uintptr_t)&d) & 0x7) {
failed++; failed++;
} }
if(((uintptr_t)&e) & 0xf){ if (((uintptr_t)&e) & 0xf) {
failed++; failed++;
} }
@ -58,11 +62,13 @@ int testAlign() {
} }
int testUnused1(MBED_UNUSED int arg) { int testUnused1(MBED_UNUSED int arg)
{
return 0; return 0;
} }
int testUnused() { int testUnused()
{
return testUnused1(0); return testUnused1(0);
} }
@ -70,42 +76,51 @@ int testUnused() {
int testWeak1(); int testWeak1();
int testWeak2(); int testWeak2();
MBED_WEAK int testWeak1() { MBED_WEAK int testWeak1()
{
return 1; return 1;
} }
int testWeak2() { int testWeak2()
{
return 0; return 0;
} }
int testWeak() { int testWeak()
{
return testWeak1() | testWeak2(); return testWeak1() | testWeak2();
} }
MBED_PURE int testPure1() { MBED_PURE int testPure1()
{
return 0; return 0;
} }
int testPure() { int testPure()
{
return testPure1(); return testPure1();
} }
MBED_FORCEINLINE int testForceInline1() { MBED_FORCEINLINE int testForceInline1()
{
return 0; return 0;
} }
int testForceInline() { int testForceInline()
{
return testForceInline1(); return testForceInline1();
} }
MBED_NORETURN int testNoReturn1() { MBED_NORETURN int testNoReturn1()
{
while (1) {} while (1) {}
} }
int testNoReturn() { int testNoReturn()
{
if (0) { if (0) {
testNoReturn1(); testNoReturn1();
} }
@ -113,7 +128,8 @@ int testNoReturn() {
} }
int testUnreachable1(int i) { int testUnreachable1(int i)
{
switch (i) { switch (i) {
case 0: case 0:
return 0; return 0;
@ -122,7 +138,8 @@ int testUnreachable1(int i) {
MBED_UNREACHABLE; MBED_UNREACHABLE;
} }
int testUnreachable() { int testUnreachable()
{
return testUnreachable1(0); return testUnreachable1(0);
} }
@ -133,7 +150,8 @@ void testDeprecatedUnused() { }
MBED_DEPRECATED("this message should be displayed") MBED_DEPRECATED("this message should be displayed")
int testDeprecatedUsed(); int testDeprecatedUsed();
int testDeprecatedUsed() { int testDeprecatedUsed()
{
return 0; return 0;
} }
@ -143,11 +161,13 @@ void testDeprecatedSinceUnused() { }
MBED_DEPRECATED_SINCE("mbed-os-3.14", "this message should be displayed") MBED_DEPRECATED_SINCE("mbed-os-3.14", "this message should be displayed")
int testDeprecatedSinceUsed(); int testDeprecatedSinceUsed();
int testDeprecatedSinceUsed() { int testDeprecatedSinceUsed()
{
return 0; return 0;
} }
int testDeprecated() { int testDeprecated()
{
return testDeprecatedUsed() + testDeprecatedSinceUsed(); return testDeprecatedUsed() + testDeprecatedSinceUsed();
} }

View File

@ -40,11 +40,13 @@ extern "C" {
// Test wrapper and test cases for utest // Test wrapper and test cases for utest
template <int (*F)()> template <int (*F)()>
void test_wrapper() { void test_wrapper()
{
TEST_ASSERT_UNLESS(F()); TEST_ASSERT_UNLESS(F());
} }
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(5, "default_auto"); GREENTEA_SETUP(5, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -63,6 +65,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -1,10 +1,12 @@
#include "mbed_toolchain.h" #include "mbed_toolchain.h"
int testWeak1() { int testWeak1()
{
return 0; return 0;
} }
MBED_WEAK int testWeak2() { MBED_WEAK int testWeak2()
{
return 1; return 1;
} }

View File

@ -16,15 +16,17 @@
#include "greentea-client/test_env.h" #include "greentea-client/test_env.h"
namespace { namespace {
bool mbed_main_called = false; bool mbed_main_called = false;
} }
extern "C" void mbed_main() { extern "C" void mbed_main()
{
printf("MBED: mbed_main() call before main()\r\n"); printf("MBED: mbed_main() call before main()\r\n");
mbed_main_called = true; mbed_main_called = true;
} }
int main() { int main()
{
GREENTEA_SETUP(5, "default_auto"); GREENTEA_SETUP(5, "default_auto");
printf("MBED: main() starts now!\r\n"); printf("MBED: main() starts now!\r\n");
GREENTEA_TESTSUITE_RESULT(mbed_main_called); GREENTEA_TESTSUITE_RESULT(mbed_main_called);

View File

@ -20,37 +20,43 @@
class Test { class Test {
private: private:
const char* name; const char *name;
const int pattern; const int pattern;
public: public:
Test(const char* _name, bool print_message=true) : name(_name), pattern(PATTERN_CHECK_VALUE) { Test(const char *_name, bool print_message = true) : name(_name), pattern(PATTERN_CHECK_VALUE)
{
if (print_message) { if (print_message) {
print("init"); print("init");
} }
} }
void print(const char *message) { void print(const char *message)
{
printf("%s::%s\n", name, message); printf("%s::%s\n", name, message);
} }
bool check_init(void) { bool check_init(void)
{
bool result = (pattern == PATTERN_CHECK_VALUE); bool result = (pattern == PATTERN_CHECK_VALUE);
print(result ? "check_init: OK" : "check_init: ERROR"); print(result ? "check_init: OK" : "check_init: ERROR");
return result; return result;
} }
void stack_test(void) { void stack_test(void)
{
print("stack_test"); print("stack_test");
Test t("Stack"); Test t("Stack");
t.hello(); t.hello();
} }
void hello(void) { void hello(void)
{
print("hello"); print("hello");
} }
~Test() { ~Test()
{
print("destroy"); print("destroy");
} }
}; };
@ -70,17 +76,16 @@ Heap::init
Heap::hello Heap::hello
Heap::destroy Heap::destroy
*******************/ *******************/
int main (void) { int main(void)
{
GREENTEA_SETUP(10, "default_auto"); GREENTEA_SETUP(10, "default_auto");
bool result = true; bool result = true;
for (;;) for (;;) {
{
s.print("init"); s.print("init");
// Global stack object simple test // Global stack object simple test
s.stack_test(); s.stack_test();
if (s.check_init() == false) if (s.check_init() == false) {
{
result = false; result = false;
break; break;
} }
@ -89,8 +94,7 @@ int main (void) {
Test *m = new Test("Heap"); Test *m = new Test("Heap");
m->hello(); m->hello();
if (m->check_init() == false) if (m->check_init() == false) {
{
result = false; result = false;
} }
delete m; delete m;

View File

@ -17,7 +17,8 @@
#include "mbed.h" #include "mbed.h"
#include "greentea-client/test_env.h" #include "greentea-client/test_env.h"
uint32_t test_64(uint64_t ticks) { uint32_t test_64(uint64_t ticks)
{
ticks >>= 3; // divide by 8 ticks >>= 3; // divide by 8
if (ticks > 0xFFFFFFFF) { if (ticks > 0xFFFFFFFF) {
ticks /= 3; ticks /= 3;
@ -27,16 +28,19 @@ uint32_t test_64(uint64_t ticks) {
return (uint32_t)(0xFFFFFFFF & ticks); return (uint32_t)(0xFFFFFFFF & ticks);
} }
const char *result_str(bool result) { const char *result_str(bool result)
{
return result ? "[OK]" : "[FAIL]"; return result ? "[OK]" : "[FAIL]";
} }
int main() { int main()
{
GREENTEA_SETUP(5, "default_auto"); GREENTEA_SETUP(5, "default_auto");
bool result = true; 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; bool test_res = values.first == test_ret;
@ -44,7 +48,8 @@ int main() {
printf("64bit: 0x7FFFFFFF8: expected 0x%lX got 0x%lX ... %s\r\n", values.first, test_ret, result_str(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 {
// 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; bool test_res = values.first == test_ret;

View File

@ -25,7 +25,8 @@ using namespace utest::v1;
void no_test() {} void no_test() {}
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(5, "default_auto"); GREENTEA_SETUP(5, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -36,6 +37,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -27,7 +27,8 @@ struct test {
MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int), MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int),
"Static assertions should not change the size of a struct"); "Static assertions should not change the size of a struct");
void doit_c(void) { void doit_c(void)
{
// Test for static asserts in function context // Test for static asserts in function context
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
"An int must be larger than char"); "An int must be larger than char");

View File

@ -34,7 +34,8 @@ struct test {
MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int), MBED_STATIC_ASSERT(sizeof(struct test) == sizeof(int),
"Static assertions should not change the size of a struct"); "Static assertions should not change the size of a struct");
void doit_c(void) { void doit_c(void)
{
// Test for static asserts in function context // Test for static asserts in function context
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char), MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
"An int must be larger than char"); "An int must be larger than char");

View File

@ -23,8 +23,7 @@
using namespace utest::v1; using namespace utest::v1;
/* Structure for complex type. */ /* Structure for complex type. */
typedef struct typedef struct {
{
int a; int a;
char b; char b;
int c; int c;

View File

@ -21,14 +21,12 @@
using namespace utest::v1; using namespace utest::v1;
/* Enum used to select block allocation method. */ /* Enum used to select block allocation method. */
typedef enum typedef enum {
{
ALLOC, CALLOC ALLOC, CALLOC
} AllocType; } AllocType;
/* Structure for complex block type. */ /* Structure for complex block type. */
typedef struct typedef struct {
{
int a; int a;
char b; char b;
int c; int c;
@ -75,7 +73,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_alloc_success(AllocType atype) void test_mem_pool_alloc_success(AllocType atype)
{ {
MemoryPool<T, numOfEntries> mem_pool; MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries]; T *p_blocks[numOfEntries];
uint32_t i; uint32_t i;
/* Test alloc()/calloc() methods - try to allocate max number of /* Test alloc()/calloc() methods - try to allocate max number of
@ -121,7 +119,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_alloc_success_complex(AllocType atype) void test_mem_pool_alloc_success_complex(AllocType atype)
{ {
MemoryPool<T, numOfEntries> mem_pool; MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries]; T *p_blocks[numOfEntries];
uint32_t i; uint32_t i;
/* Test alloc()/calloc() methods - try to allocate max number of /* Test alloc()/calloc() methods - try to allocate max number of
@ -164,8 +162,8 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_alloc_fail(AllocType atype) void test_mem_pool_alloc_fail(AllocType atype)
{ {
MemoryPool<T, numOfEntries> mem_pool; MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries]; T *p_blocks[numOfEntries];
T * p_extra_block; T *p_extra_block;
uint32_t i; uint32_t i;
/* Allocate all available blocks. */ /* Allocate all available blocks. */
@ -203,7 +201,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_free_success(AllocType atype) void test_mem_pool_free_success(AllocType atype)
{ {
MemoryPool<T, numOfEntries> mem_pool; MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries]; T *p_blocks[numOfEntries];
uint32_t i; uint32_t i;
osStatus status; osStatus status;
@ -243,7 +241,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_free_realloc_last(AllocType atype) void test_mem_pool_free_realloc_last(AllocType atype)
{ {
MemoryPool<T, numOfEntries> mem_pool; MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries]; T *p_blocks[numOfEntries];
uint32_t i; uint32_t i;
osStatus status; osStatus status;
@ -299,7 +297,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_free_realloc_last_complex(AllocType atype) void test_mem_pool_free_realloc_last_complex(AllocType atype)
{ {
MemoryPool<T, numOfEntries> mem_pool; MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries]; T *p_blocks[numOfEntries];
uint32_t i; uint32_t i;
osStatus status; osStatus status;
@ -355,7 +353,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_free_realloc_first(AllocType atype) void test_mem_pool_free_realloc_first(AllocType atype)
{ {
MemoryPool<T, numOfEntries> mem_pool; MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries]; T *p_blocks[numOfEntries];
uint32_t i; uint32_t i;
osStatus status; osStatus status;
@ -411,7 +409,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_free_realloc_first_complex(AllocType atype) void test_mem_pool_free_realloc_first_complex(AllocType atype)
{ {
MemoryPool<T, numOfEntries> mem_pool; MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries]; T *p_blocks[numOfEntries];
uint32_t i; uint32_t i;
osStatus status; osStatus status;
@ -462,7 +460,7 @@ void test_mem_pool_free_realloc_first_complex(AllocType atype)
void test_mem_pool_free_on_freed_block() void test_mem_pool_free_on_freed_block()
{ {
MemoryPool<int, 1> mem_pool; MemoryPool<int, 1> mem_pool;
int * p_block; int *p_block;
osStatus status; osStatus status;
/* Allocate memory block. */ /* Allocate memory block. */
@ -518,7 +516,7 @@ void free_block_invalid_parameter()
osStatus status; osStatus status;
/* Try to free block passing invalid parameter (variable address). */ /* Try to free block passing invalid parameter (variable address). */
status = mem_pool.free(reinterpret_cast<int*>(&status)); status = mem_pool.free(reinterpret_cast<int *>(&status));
/* Check operation status. */ /* Check operation status. */
TEST_ASSERT_EQUAL(osErrorParameter, status); TEST_ASSERT_EQUAL(osErrorParameter, status);

View File

@ -24,7 +24,7 @@
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using utest::v1::Case; using utest::v1::Case;
@ -100,7 +100,7 @@ void test(void)
//get the results from host //get the results from host
greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
TEST_ASSERT_EQUAL_STRING_MESSAGE("pass", _key,"Host side script reported a fail..."); TEST_ASSERT_EQUAL_STRING_MESSAGE("pass", _key, "Host side script reported a fail...");
} }
Case cases[] = { Case cases[] = {

View File

@ -20,11 +20,11 @@
#include "rtos.h" #include "rtos.h"
#if defined(MBED_RTOS_SINGLE_THREAD) #if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using namespace utest::v1; using namespace utest::v1;

View File

@ -23,11 +23,11 @@
using utest::v1::Case; using utest::v1::Case;
#if defined(MBED_RTOS_SINGLE_THREAD) #if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#if defined(__CORTEX_M23) || defined(__CORTEX_M33) #if defined(__CORTEX_M23) || defined(__CORTEX_M33)
@ -56,7 +56,8 @@ Semaphore sync_sem(0, 1);
* which aborts test program. * which aborts test program.
*/ */
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED #if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
void error(const char* format, ...) { void error(const char *format, ...)
{
(void) format; (void) format;
} }
@ -278,7 +279,7 @@ void test_multi_thread_any_timeout(void)
EventFlags ef; EventFlags ef;
uint32_t ret; uint32_t ret;
Thread thread(osPriorityNormal, THREAD_STACK_SIZE); Thread thread(osPriorityNormal, THREAD_STACK_SIZE);
thread.start(callback(send_thread_sync<FLAG01 | FLAG02 | FLAG03, 1>, &ef)); thread.start(callback(send_thread_sync < FLAG01 | FLAG02 | FLAG03, 1 >, &ef));
for (int i = 0; i <= MAX_FLAG_POS; i++) { for (int i = 0; i <= MAX_FLAG_POS; i++) {
uint32_t flag = 1 << i; uint32_t flag = 1 << i;

View File

@ -16,11 +16,11 @@
*/ */
#if defined(TARGET_CORTEX_A) #if defined(TARGET_CORTEX_A)
#error [NOT_SUPPORTED] This function not supported for this target #error [NOT_SUPPORTED] This function not supported for this target
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#include <stdio.h> #include <stdio.h>
@ -50,7 +50,7 @@ extern uint32_t mbed_stack_isr_size;
struct linked_list { struct linked_list {
linked_list * next; linked_list *next;
uint8_t data[MALLOC_TEST_SIZE]; uint8_t data[MALLOC_TEST_SIZE];
}; };
@ -90,7 +90,7 @@ static bool rangeinrange(uint32_t addr, uint32_t size, uint32_t start, uint32_t
/* /*
* Return true if the region is filled only with the specified value * Return true if the region is filled only with the specified value
*/ */
static bool valid_fill(uint8_t * data, uint32_t size, uint8_t fill) static bool valid_fill(uint8_t *data, uint32_t size, uint8_t fill)
{ {
for (uint32_t i = 0; i < size; i++) { for (uint32_t i = 0; i < size; i++) {
if (data[i] != fill) { if (data[i] != fill) {
@ -104,18 +104,18 @@ static void allocate_and_fill_heap(linked_list *&head)
{ {
linked_list *current; linked_list *current;
current = (linked_list*) malloc(sizeof(linked_list)); current = (linked_list *) malloc(sizeof(linked_list));
TEST_ASSERT_NOT_NULL(current); TEST_ASSERT_NOT_NULL(current);
current->next = NULL; current->next = NULL;
memset((void*) current->data, MALLOC_FILL, sizeof(current->data)); memset((void *) current->data, MALLOC_FILL, sizeof(current->data));
// Allocate until malloc returns NULL // Allocate until malloc returns NULL
head = current; head = current;
while (true) { while (true) {
// Allocate // Allocate
linked_list *temp = (linked_list*) malloc(sizeof(linked_list)); linked_list *temp = (linked_list *) malloc(sizeof(linked_list));
if (NULL == temp) { if (NULL == temp) {
break; break;
@ -126,7 +126,7 @@ static void allocate_and_fill_heap(linked_list *&head)
// Init // Init
temp->next = NULL; temp->next = NULL;
memset((void*) temp->data, MALLOC_FILL, sizeof(current->data)); memset((void *) temp->data, MALLOC_FILL, sizeof(current->data));
// Add to list // Add to list
current->next = temp; current->next = temp;
@ -137,7 +137,7 @@ static void allocate_and_fill_heap(linked_list *&head)
static void check_and_free_heap(linked_list *head, uint32_t &max_allocation_size) static void check_and_free_heap(linked_list *head, uint32_t &max_allocation_size)
{ {
uint32_t total_size = 0; uint32_t total_size = 0;
linked_list * current = head; linked_list *current = head;
while (current != NULL) { while (current != NULL) {
total_size += sizeof(linked_list); total_size += sizeof(linked_list);
@ -145,7 +145,7 @@ static void check_and_free_heap(linked_list *head, uint32_t &max_allocation_size
TEST_ASSERT_TRUE_MESSAGE(result, "Memory fill check failed"); TEST_ASSERT_TRUE_MESSAGE(result, "Memory fill check failed");
linked_list * next = current->next; linked_list *next = current->next;
free(current); free(current);
current = next; current = next;
} }
@ -165,7 +165,7 @@ void test_heap_in_range(void)
char *initial_heap; char *initial_heap;
// Sanity check malloc // Sanity check malloc
initial_heap = (char*) malloc(1); initial_heap = (char *) malloc(1);
TEST_ASSERT_NOT_NULL(initial_heap); TEST_ASSERT_NOT_NULL(initial_heap);
bool result = inrange((uint32_t) initial_heap, mbed_heap_start, mbed_heap_size); bool result = inrange((uint32_t) initial_heap, mbed_heap_start, mbed_heap_size);
@ -185,7 +185,7 @@ void test_main_stack_in_range(void)
mbed_rtos_storage_thread_t *thread = (mbed_rtos_storage_thread_t *) osThreadGetId(); mbed_rtos_storage_thread_t *thread = (mbed_rtos_storage_thread_t *) osThreadGetId();
uint32_t psp = __get_PSP(); uint32_t psp = __get_PSP();
uint8_t *stack_mem = (uint8_t*) thread->stack_mem; uint8_t *stack_mem = (uint8_t *) thread->stack_mem;
uint32_t stack_size = thread->stack_size; uint32_t stack_size = thread->stack_size;
// PSP stack should be somewhere in the middle // PSP stack should be somewhere in the middle

View File

@ -20,11 +20,11 @@
#include "rtos.h" #include "rtos.h"
#if defined(MBED_RTOS_SINGLE_THREAD) #if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using namespace utest::v1; using namespace utest::v1;
@ -74,7 +74,7 @@ void receive_thread(Mail<mail_t, queue_size> *m)
for (uint32_t i = 0; i < queue_size; i++) { for (uint32_t i = 0; i < queue_size; i++) {
osEvent evt = m->get(); osEvent evt = m->get();
if (evt.status == osEventMail) { if (evt.status == osEventMail) {
mail_t *mail = (mail_t*)evt.value.p; mail_t *mail = (mail_t *)evt.value.p;
const uint8_t id = mail->thread_id; const uint8_t id = mail->thread_id;
// verify thread id // verify thread id
@ -112,7 +112,7 @@ void test_single_thread_order(void)
// mail receive (main thread) // mail receive (main thread)
osEvent evt = mail_box.get(); osEvent evt = mail_box.get();
if (evt.status == osEventMail) { if (evt.status == osEventMail) {
mail_t *mail = (mail_t*)evt.value.p; mail_t *mail = (mail_t *)evt.value.p;
const uint8_t id = mail->thread_id; const uint8_t id = mail->thread_id;
// verify thread id // verify thread id
@ -154,7 +154,7 @@ void test_multi_thread_order(void)
// mail receive (main thread) // mail receive (main thread)
osEvent evt = mail_box.get(); osEvent evt = mail_box.get();
if (evt.status == osEventMail) { if (evt.status == osEventMail) {
mail_t *mail = (mail_t*)evt.value.p; mail_t *mail = (mail_t *)evt.value.p;
const uint8_t id = mail->thread_id; const uint8_t id = mail->thread_id;
// verify thread id // verify thread id
@ -351,13 +351,13 @@ void test_order(void)
evt = mail_box.get(); evt = mail_box.get();
TEST_ASSERT_EQUAL(evt.status, osEventMail); TEST_ASSERT_EQUAL(evt.status, osEventMail);
mail1 = (int32_t*)evt.value.p; mail1 = (int32_t *)evt.value.p;
TEST_ASSERT_EQUAL(TEST_VAL1, *mail1); TEST_ASSERT_EQUAL(TEST_VAL1, *mail1);
evt = mail_box.get(); evt = mail_box.get();
TEST_ASSERT_EQUAL(evt.status, osEventMail); TEST_ASSERT_EQUAL(evt.status, osEventMail);
mail2 = (int32_t*)evt.value.p; mail2 = (int32_t *)evt.value.p;
TEST_ASSERT_EQUAL(TEST_VAL2, *mail2); TEST_ASSERT_EQUAL(TEST_VAL2, *mail2);
@ -439,7 +439,7 @@ void test_data_type(void)
osEvent evt = mail_box.get(); osEvent evt = mail_box.get();
TEST_ASSERT_EQUAL(evt.status, osEventMail); TEST_ASSERT_EQUAL(evt.status, osEventMail);
mail = (T*)evt.value.p; mail = (T *)evt.value.p;
TEST_ASSERT_EQUAL(TEST_VAL, *mail); TEST_ASSERT_EQUAL(TEST_VAL, *mail);

View File

@ -20,11 +20,11 @@
#if defined(MBED_RTOS_SINGLE_THREAD) #if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using utest::v1::Case; using utest::v1::Case;
@ -138,7 +138,7 @@ void test_zero_allocation(void)
void *data = NULL; void *data = NULL;
data = malloc(0); data = malloc(0);
if(data != NULL) { if (data != NULL) {
free(data); free(data);
} }
TEST_ASSERT_MESSAGE(true, "malloc(0) succeed - no undefined behaviour happens"); TEST_ASSERT_MESSAGE(true, "malloc(0) succeed - no undefined behaviour happens");

View File

@ -20,11 +20,11 @@
#include "rtos.h" #include "rtos.h"
#if defined(MBED_RTOS_SINGLE_THREAD) #if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
using namespace utest::v1; using namespace utest::v1;
@ -204,7 +204,7 @@ void test_dual_thread_lock_lock_thread(Mutex *mutex)
osStatus stat = mutex->lock(TEST_DELAY); osStatus stat = mutex->lock(TEST_DELAY);
TEST_ASSERT_EQUAL(osErrorTimeout, stat); TEST_ASSERT_EQUAL(osErrorTimeout, stat);
TEST_ASSERT_UINT32_WITHIN(5000, TEST_DELAY*1000, timer.read_us()); TEST_ASSERT_UINT32_WITHIN(5000, TEST_DELAY * 1000, timer.read_us());
} }
/** Test dual thread lock /** Test dual thread lock

View File

@ -20,7 +20,7 @@
#include "rtos.h" #include "rtos.h"
#if defined(MBED_RTOS_SINGLE_THREAD) #if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
@ -38,7 +38,7 @@ template <uint32_t ms>
void thread_put_uint_msg(Queue<uint32_t, 1> *q) void thread_put_uint_msg(Queue<uint32_t, 1> *q)
{ {
Thread::wait(ms); Thread::wait(ms);
osStatus stat = q->put((uint32_t*) TEST_UINT_MSG); osStatus stat = q->put((uint32_t *) TEST_UINT_MSG);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
} }
@ -61,7 +61,7 @@ void thread_get_uint_msg(Queue<uint32_t, 1> *q)
void test_pass_uint() void test_pass_uint()
{ {
Queue<uint32_t, 1> q; Queue<uint32_t, 1> q;
osStatus stat = q.put((uint32_t*)TEST_UINT_MSG); osStatus stat = q.put((uint32_t *)TEST_UINT_MSG);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
osEvent evt = q.get(); osEvent evt = q.get();
@ -81,14 +81,14 @@ void test_pass_uint()
void test_pass_uint_twice() void test_pass_uint_twice()
{ {
Queue<uint32_t, 1> q; Queue<uint32_t, 1> q;
osStatus stat = q.put((uint32_t*)TEST_UINT_MSG); osStatus stat = q.put((uint32_t *)TEST_UINT_MSG);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
osEvent evt = q.get(); osEvent evt = q.get();
TEST_ASSERT_EQUAL(osEventMessage, evt.status); TEST_ASSERT_EQUAL(osEventMessage, evt.status);
TEST_ASSERT_EQUAL(TEST_UINT_MSG, evt.value.v); TEST_ASSERT_EQUAL(TEST_UINT_MSG, evt.value.v);
stat = q.put((uint32_t*)TEST_UINT_MSG2); stat = q.put((uint32_t *)TEST_UINT_MSG2);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
evt = q.get(); evt = q.get();
@ -181,10 +181,10 @@ void test_put_full_no_timeout()
{ {
Queue<uint32_t, 1> q; Queue<uint32_t, 1> q;
osStatus stat = q.put((uint32_t*) TEST_UINT_MSG); osStatus stat = q.put((uint32_t *) TEST_UINT_MSG);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
stat = q.put((uint32_t*) TEST_UINT_MSG); stat = q.put((uint32_t *) TEST_UINT_MSG);
TEST_ASSERT_EQUAL(osErrorResource, stat); TEST_ASSERT_EQUAL(osErrorResource, stat);
} }
@ -198,13 +198,13 @@ void test_put_full_timeout()
{ {
Queue<uint32_t, 1> q; Queue<uint32_t, 1> q;
osStatus stat = q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT); osStatus stat = q.put((uint32_t *) TEST_UINT_MSG, TEST_TIMEOUT);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
Timer timer; Timer timer;
timer.start(); timer.start();
stat = q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT); stat = q.put((uint32_t *) TEST_UINT_MSG, TEST_TIMEOUT);
TEST_ASSERT_EQUAL(osErrorTimeout, stat); TEST_ASSERT_EQUAL(osErrorTimeout, stat);
TEST_ASSERT_UINT32_WITHIN(TEST_TIMEOUT * 100, TEST_TIMEOUT * 1000, timer.read_us()); TEST_ASSERT_UINT32_WITHIN(TEST_TIMEOUT * 100, TEST_TIMEOUT * 1000, timer.read_us());
} }
@ -224,12 +224,12 @@ void test_put_full_waitforever()
t.start(callback(thread_get_uint_msg<TEST_TIMEOUT, TEST_UINT_MSG>, &q)); t.start(callback(thread_get_uint_msg<TEST_TIMEOUT, TEST_UINT_MSG>, &q));
osStatus stat = q.put((uint32_t*) TEST_UINT_MSG); osStatus stat = q.put((uint32_t *) TEST_UINT_MSG);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
Timer timer; Timer timer;
timer.start(); timer.start();
stat = q.put((uint32_t*) TEST_UINT_MSG, osWaitForever); stat = q.put((uint32_t *) TEST_UINT_MSG, osWaitForever);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
TEST_ASSERT_UINT32_WITHIN(TEST_TIMEOUT * 100, TEST_TIMEOUT * 1000, timer.read_us()); TEST_ASSERT_UINT32_WITHIN(TEST_TIMEOUT * 100, TEST_TIMEOUT * 1000, timer.read_us());
@ -246,10 +246,10 @@ void test_msg_order()
{ {
Queue<uint32_t, 2> q; Queue<uint32_t, 2> q;
osStatus stat = q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT); osStatus stat = q.put((uint32_t *) TEST_UINT_MSG, TEST_TIMEOUT);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
stat = q.put((uint32_t*) TEST_UINT_MSG2, TEST_TIMEOUT); stat = q.put((uint32_t *) TEST_UINT_MSG2, TEST_TIMEOUT);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
osEvent evt = q.get(); osEvent evt = q.get();
@ -271,10 +271,10 @@ void test_msg_prio()
{ {
Queue<uint32_t, 2> q; Queue<uint32_t, 2> q;
osStatus stat = q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT, 0); osStatus stat = q.put((uint32_t *) TEST_UINT_MSG, TEST_TIMEOUT, 0);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
stat = q.put((uint32_t*) TEST_UINT_MSG2, TEST_TIMEOUT, 1); stat = q.put((uint32_t *) TEST_UINT_MSG2, TEST_TIMEOUT, 1);
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
osEvent evt = q.get(); osEvent evt = q.get();
@ -298,7 +298,7 @@ void test_queue_empty()
TEST_ASSERT_EQUAL(true, q.empty()); TEST_ASSERT_EQUAL(true, q.empty());
q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT, 1); q.put((uint32_t *) TEST_UINT_MSG, TEST_TIMEOUT, 1);
TEST_ASSERT_EQUAL(false, q.empty()); TEST_ASSERT_EQUAL(false, q.empty());
} }
@ -315,7 +315,7 @@ void test_queue_full()
TEST_ASSERT_EQUAL(false, q.full()); TEST_ASSERT_EQUAL(false, q.full());
q.put((uint32_t*) TEST_UINT_MSG, TEST_TIMEOUT, 1); q.put((uint32_t *) TEST_UINT_MSG, TEST_TIMEOUT, 1);
TEST_ASSERT_EQUAL(true, q.full()); TEST_ASSERT_EQUAL(true, q.full());
} }

View File

@ -31,7 +31,7 @@ using namespace utest::v1;
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
class Stopwatch: public Timer { class Stopwatch: public Timer {
@ -85,7 +85,7 @@ void sem_callback(Semaphore *sem)
* which aborts test program. * which aborts test program.
*/ */
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED #if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
void error(const char* format, ...) void error(const char *format, ...)
{ {
(void) format; (void) format;
} }

View File

@ -22,11 +22,11 @@
using namespace utest::v1; using namespace utest::v1;
#if defined(MBED_RTOS_SINGLE_THREAD) #if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#define THREAD_DELAY 30 #define THREAD_DELAY 30
@ -204,7 +204,7 @@ void test_multiple_tokens_wait()
{ {
Semaphore sem(5); Semaphore sem(5);
for(int i = 5; i >= 0; i--) { for (int i = 5; i >= 0; i--) {
int32_t cnt = sem.wait(0); int32_t cnt = sem.wait(0);
TEST_ASSERT_EQUAL(i, cnt); TEST_ASSERT_EQUAL(i, cnt);
} }
@ -220,7 +220,7 @@ void test_multiple_tokens_release()
{ {
Semaphore sem(0, 5); Semaphore sem(0, 5);
for(int i = 5; i > 0; i--) { for (int i = 5; i > 0; i--) {
osStatus stat = sem.release(); osStatus stat = sem.release();
TEST_ASSERT_EQUAL(osOK, stat); TEST_ASSERT_EQUAL(osOK, stat);
} }

View File

@ -21,11 +21,11 @@
using utest::v1::Case; using utest::v1::Case;
#if defined(MBED_RTOS_SINGLE_THREAD) #if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#define TEST_STACK_SIZE 512 #define TEST_STACK_SIZE 512
@ -55,7 +55,8 @@ struct Sync {
* which aborts test program. * which aborts test program.
*/ */
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED #if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
void error(const char* format, ...) { void error(const char *format, ...)
{
(void) format; (void) format;
} }
@ -364,7 +365,7 @@ void test_set_double(void)
Semaphore sem(0, 1); Semaphore sem(0, 1);
Thread t(osPriorityNormal, TEST_STACK_SIZE); Thread t(osPriorityNormal, TEST_STACK_SIZE);
t.start(callback(run_release_signal_wait<SIGNAL1|SIGNAL2|SIGNAL3, osWaitForever, osEventSignal>, &sem)); t.start(callback(run_release_signal_wait < SIGNAL1 | SIGNAL2 | SIGNAL3, osWaitForever, osEventSignal >, &sem));
sem.wait(); sem.wait();
TEST_ASSERT_EQUAL(Thread::WaitingThreadFlag, t.get_state()); TEST_ASSERT_EQUAL(Thread::WaitingThreadFlag, t.get_state());

View File

@ -31,21 +31,23 @@ public:
* Construct a LockGuard instance and ackire ownership of mutex in input. * Construct a LockGuard instance and ackire ownership of mutex in input.
* @param mutex The mutex to ackire ownership of. * @param mutex The mutex to ackire ownership of.
*/ */
LockGuard(rtos::Mutex& mutex) : _mutex(mutex) { LockGuard(rtos::Mutex &mutex) : _mutex(mutex)
{
_mutex.lock(); _mutex.lock();
} }
/** /**
* Destruct the lock and release the inner mutex. * Destruct the lock and release the inner mutex.
*/ */
~LockGuard() { ~LockGuard()
{
_mutex.unlock(); _mutex.unlock();
} }
private: private:
LockGuard(const LockGuard&); LockGuard(const LockGuard &);
LockGuard& operator=(const LockGuard&); LockGuard &operator=(const LockGuard &);
rtos::Mutex& _mutex; rtos::Mutex &_mutex;
}; };
#endif /* MBEDMICRO_RTOS_MBED_THREADS_LOCK_GUARD */ #endif /* MBEDMICRO_RTOS_MBED_THREADS_LOCK_GUARD */

View File

@ -31,37 +31,43 @@ public:
SynchronizedIntegral(T value) : _mutex(), _value(value) { } SynchronizedIntegral(T value) : _mutex(), _value(value) { }
// preincrement operator // preincrement operator
T operator++() { T operator++()
{
LockGuard lock(_mutex); LockGuard lock(_mutex);
return ++_value; return ++_value;
} }
// predecrement operator // predecrement operator
T operator--() { T operator--()
{
LockGuard lock(_mutex); LockGuard lock(_mutex);
return --_value; return --_value;
} }
// post increment operator // post increment operator
T operator++(int) { T operator++(int)
{
LockGuard lock(_mutex); LockGuard lock(_mutex);
return _value++; return _value++;
} }
// post decrement operator // post decrement operator
T operator--(int) { T operator--(int)
{
LockGuard lock(_mutex); LockGuard lock(_mutex);
return _value--; return _value--;
} }
// conversion operator, used also for <,>,<=,>=,== and != // conversion operator, used also for <,>,<=,>=,== and !=
operator T() const { operator T() const
{
LockGuard lock(_mutex); LockGuard lock(_mutex);
return _value; return _value;
} }
// access to the internal mutex // access to the internal mutex
rtos::Mutex& internal_mutex() { rtos::Mutex &internal_mutex()
{
return _mutex; return _mutex;
} }

View File

@ -22,11 +22,11 @@
#include "LockGuard.h" #include "LockGuard.h"
#if defined(MBED_RTOS_SINGLE_THREAD) #if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#if !DEVICE_USTICKER #if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported #error [NOT_SUPPORTED] test not supported
#endif #endif
#define THREAD_STACK_SIZE 512 #define THREAD_STACK_SIZE 512
@ -52,28 +52,33 @@ public:
}; };
// Tasks with different functions to test on threads // Tasks with different functions to test on threads
void increment(counter_t* counter) { void increment(counter_t *counter)
{
(*counter)++; (*counter)++;
} }
void increment_with_yield(counter_t* counter) { void increment_with_yield(counter_t *counter)
{
Thread::yield(); Thread::yield();
(*counter)++; (*counter)++;
} }
void increment_with_wait(counter_t* counter) { void increment_with_wait(counter_t *counter)
{
Thread::wait(100); Thread::wait(100);
(*counter)++; (*counter)++;
} }
void increment_with_child(counter_t* counter) { void increment_with_child(counter_t *counter)
{
Thread *child = new Thread(osPriorityNormal, CHILD_THREAD_STACK_SIZE); Thread *child = new Thread(osPriorityNormal, CHILD_THREAD_STACK_SIZE);
child->start(callback(increment, counter)); child->start(callback(increment, counter));
child->join(); child->join();
delete child; delete child;
} }
void increment_with_murder(counter_t* counter) { void increment_with_murder(counter_t *counter)
{
{ {
// take ownership of the counter mutex so it prevent the child to // take ownership of the counter mutex so it prevent the child to
// modify counter. // modify counter.
@ -87,7 +92,8 @@ void increment_with_murder(counter_t* counter) {
(*counter)++; (*counter)++;
} }
void self_terminate(Thread *self) { void self_terminate(Thread *self)
{
self->terminate(); self->terminate();
// Code should not get here // Code should not get here
TEST_ASSERT(0); TEST_ASSERT(0);
@ -126,7 +132,8 @@ void self_terminate(Thread *self) {
then the final value of the counter is equal to 1 then the final value of the counter is equal to 1
*/ */
template <void (*F)(counter_t *)> template <void (*F)(counter_t *)>
void test_single_thread() { void test_single_thread()
{
counter_t counter(0); counter_t counter(0);
Thread thread(osPriorityNormal, THREAD_STACK_SIZE); Thread thread(osPriorityNormal, THREAD_STACK_SIZE);
thread.start(callback(F, &counter)); thread.start(callback(F, &counter));
@ -165,7 +172,8 @@ void test_single_thread() {
then the final value of the counter is equal to number of parallel threads then the final value of the counter is equal to number of parallel threads
*/ */
template <int N, void (*F)(counter_t *)> template <int N, void (*F)(counter_t *)>
void test_parallel_threads() { void test_parallel_threads()
{
counter_t counter(0); counter_t counter(0);
ParallelThread<osPriorityNormal, PARALLEL_THREAD_STACK_SIZE> threads[N]; ParallelThread<osPriorityNormal, PARALLEL_THREAD_STACK_SIZE> threads[N];
@ -211,7 +219,8 @@ void test_parallel_threads() {
then the final value of the counter is equal to number of serial threads then the final value of the counter is equal to number of serial threads
*/ */
template <int N, void (*F)(counter_t *)> template <int N, void (*F)(counter_t *)>
void test_serial_threads() { void test_serial_threads()
{
counter_t counter(0); counter_t counter(0);
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
@ -229,7 +238,8 @@ void test_serial_threads() {
when the thread calls @a terminate on its self when the thread calls @a terminate on its self
then the thread terminates execution cleanly then the thread terminates execution cleanly
*/ */
void test_self_terminate() { void test_self_terminate()
{
Thread *thread = new Thread(osPriorityNormal, THREAD_STACK_SIZE); Thread *thread = new Thread(osPriorityNormal, THREAD_STACK_SIZE);
thread->start(callback(self_terminate, thread)); thread->start(callback(self_terminate, thread));
thread->join(); thread->join();
@ -336,11 +346,13 @@ void test_thread_signal_clr()
t_wait.join(); t_wait.join();
} }
void thread_wait_signal() { void thread_wait_signal()
{
Thread::signal_wait(0x1); Thread::signal_wait(0x1);
} }
void stack_info() { void stack_info()
{
Thread::signal_wait(0x1); Thread::signal_wait(0x1);
thread_wait_signal(); thread_wait_signal();
@ -360,7 +372,8 @@ void stack_info() {
and the reported stack size is as requested in the constructor and the reported stack size is as requested in the constructor
and the sum of free and used stack sizes is equal to the total stack size and the sum of free and used stack sizes is equal to the total stack size
*/ */
void test_thread_stack_info() { void test_thread_stack_info()
{
Thread t(osPriorityNormal, THREAD_STACK_SIZE); Thread t(osPriorityNormal, THREAD_STACK_SIZE);
t.start(callback(stack_info)); t.start(callback(stack_info));
@ -394,7 +407,8 @@ void test_thread_stack_info() {
when the @a wait function is called when the @a wait function is called
then the thread sleeps for given amount of time then the thread sleeps for given amount of time
*/ */
void test_thread_wait() { void test_thread_wait()
{
Timer timer; Timer timer;
timer.start(); timer.start();
@ -409,7 +423,8 @@ void test_thread_wait() {
when the name is queried using @a get_name when the name is queried using @a get_name
then the returned name is as set then the returned name is as set
*/ */
void test_thread_name() { void test_thread_name()
{
const char tname[] = "Amazing thread"; const char tname[] = "Amazing thread";
Thread t(osPriorityNormal, THREAD_STACK_SIZE, NULL, tname); Thread t(osPriorityNormal, THREAD_STACK_SIZE, NULL, tname);
t.start(callback(thread_wait_signal)); t.start(callback(thread_wait_signal));
@ -627,7 +642,8 @@ void test_msg_put()
} }
/** Utility function that places some date on the stack */ /** Utility function that places some date on the stack */
void use_some_stack () { void use_some_stack()
{
volatile uint32_t stack_filler[10] = {0xDEADBEEF}; volatile uint32_t stack_filler[10] = {0xDEADBEEF};
} }
@ -637,19 +653,21 @@ void use_some_stack () {
when the thread executes when the thread executes
then the supplies buffer is used as a stack then the supplies buffer is used as a stack
*/ */
void test_thread_ext_stack() { void test_thread_ext_stack()
{
char stack[512]; char stack[512];
Thread t(osPriorityNormal, sizeof(stack), (unsigned char*)stack); Thread t(osPriorityNormal, sizeof(stack), (unsigned char *)stack);
memset(&stack, 0, sizeof(stack)); memset(&stack, 0, sizeof(stack));
t.start(callback(use_some_stack)); t.start(callback(use_some_stack));
t.join(); t.join();
/* If buffer was used as a stack it was cleared with pattern and some data were placed in it */ /* If buffer was used as a stack it was cleared with pattern and some data were placed in it */
for(unsigned i = 0; i < sizeof(stack); i++) { for (unsigned i = 0; i < sizeof(stack); i++) {
if (stack[i] != 0) if (stack[i] != 0) {
return; return;
} }
}
TEST_FAIL_MESSAGE("External stack was not used."); TEST_FAIL_MESSAGE("External stack was not used.");
} }
@ -660,7 +678,8 @@ void test_thread_ext_stack() {
when new priority is set using @a set_priority when new priority is set using @a set_priority
then priority is changed and can be retrieved using @a get_priority then priority is changed and can be retrieved using @a get_priority
*/ */
void test_thread_prio() { void test_thread_prio()
{
Thread t(osPriorityNormal, THREAD_STACK_SIZE); Thread t(osPriorityNormal, THREAD_STACK_SIZE);
t.start(callback(thread_wait_signal)); t.start(callback(thread_wait_signal));
@ -674,7 +693,8 @@ void test_thread_prio() {
t.join(); t.join();
} }
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(20, "default_auto"); GREENTEA_SETUP(20, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -685,8 +705,8 @@ utest::v1::status_t test_setup(const size_t number_of_cases) {
// macros don't play nicely with the templates (extra comma). // macros don't play nicely with the templates (extra comma).
static const case_t cases[] = { static const case_t cases[] = {
{"Testing single thread", test_single_thread<increment>, DEFAULT_HANDLERS}, {"Testing single thread", test_single_thread<increment>, DEFAULT_HANDLERS},
{"Testing parallel threads", test_parallel_threads<3, increment> , DEFAULT_HANDLERS}, {"Testing parallel threads", test_parallel_threads<3, increment>, DEFAULT_HANDLERS},
{"Testing serial threads", test_serial_threads<10, increment> , DEFAULT_HANDLERS}, {"Testing serial threads", test_serial_threads<10, increment>, DEFAULT_HANDLERS},
{"Testing single thread with yield", test_single_thread<increment_with_yield>, DEFAULT_HANDLERS}, {"Testing single thread with yield", test_single_thread<increment_with_yield>, DEFAULT_HANDLERS},
{"Testing parallel threads with yield", test_parallel_threads<3, increment_with_yield>, DEFAULT_HANDLERS}, {"Testing parallel threads with yield", test_parallel_threads<3, increment_with_yield>, DEFAULT_HANDLERS},
@ -733,6 +753,7 @@ static const case_t cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -34,65 +34,73 @@ using namespace utest::v1;
#if defined(MBEDTLS_SHA256_C) #if defined(MBEDTLS_SHA256_C)
/* Tests several call to mbedtls_sha256_update function that are not modulo 64 bytes */ /* Tests several call to mbedtls_sha256_update function that are not modulo 64 bytes */
void test_case_sha256_split() { void test_case_sha256_split()
{
const unsigned char test_buf[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"}; const unsigned char test_buf[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"};
// sha256_output_values for 3*abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq // sha256_output_values for 3*abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
const unsigned char test_sum[] = const unsigned char test_sum[] = {
{ 0x50, 0xEA, 0x82, 0x5D, 0x96, 0x84, 0xF4, 0x22, 0x50, 0xEA, 0x82, 0x5D, 0x96, 0x84, 0xF4, 0x22,
0x9C, 0xA2, 0x9F, 0x1F, 0xEC, 0x51, 0x15, 0x93, 0x9C, 0xA2, 0x9F, 0x1F, 0xEC, 0x51, 0x15, 0x93,
0xE2, 0x81, 0xE4, 0x6A, 0x14, 0x0D, 0x81, 0xE0, 0xE2, 0x81, 0xE4, 0x6A, 0x14, 0x0D, 0x81, 0xE0,
0x00, 0x5F, 0x8F, 0x68, 0x86, 0x69, 0xA0, 0x6C}; 0x00, 0x5F, 0x8F, 0x68, 0x86, 0x69, 0xA0, 0x6C
};
unsigned char outsum[32]; unsigned char outsum[32];
int i; int i;
mbedtls_sha256_context ctx; mbedtls_sha256_context ctx;
printf("test sha256\n"); printf("test sha256\n");
mbedtls_sha256_init( &ctx ); mbedtls_sha256_init(&ctx);
mbedtls_sha256_starts( &ctx, 0); mbedtls_sha256_starts(&ctx, 0);
#if 0 #if 0
printf("test not splitted\n"); printf("test not splitted\n");
mbedtls_sha256_update( &ctx, test_buf, 168 ); mbedtls_sha256_update(&ctx, test_buf, 168);
#else #else
printf("test splitted into 3 pieces\n"); printf("test splitted into 3 pieces\n");
mbedtls_sha256_update( &ctx, test_buf, 2 ); mbedtls_sha256_update(&ctx, test_buf, 2);
mbedtls_sha256_update( &ctx, test_buf+2, 66 ); mbedtls_sha256_update(&ctx, test_buf + 2, 66);
mbedtls_sha256_update( &ctx, test_buf+68, 100 ); mbedtls_sha256_update(&ctx, test_buf + 68, 100);
#endif #endif
mbedtls_sha256_finish( &ctx, outsum ); mbedtls_sha256_finish(&ctx, outsum);
mbedtls_sha256_free( &ctx ); mbedtls_sha256_free(&ctx);
printf("\nreceived result : "); printf("\nreceived result : ");
for (i=0;i<32;i++) { printf("%02X",outsum[i]);} for (i = 0; i < 32; i++) {
printf("%02X", outsum[i]);
}
printf("\nawaited result : 50EA825D9684F4229CA29F1FEC511593E281E46A140D81E0005F8F688669A06C\n"); // for abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq printf("\nawaited result : 50EA825D9684F4229CA29F1FEC511593E281E46A140D81E0005F8F688669A06C\n"); // for abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
printf("\nend of test sha256\n"); printf("\nend of test sha256\n");
TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum, test_sum,32); TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum, test_sum, 32);
} }
/* Tests that treating 2 sha256 objects in // does not impact the result */ /* Tests that treating 2 sha256 objects in // does not impact the result */
void test_case_sha256_multi() { void test_case_sha256_multi()
{
const unsigned char test_buf[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"}; const unsigned char test_buf[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"};
const unsigned char test_buf2[] = {"abcdefghijklmnopqrstuvwxyz012345678901234567890123456789"}; const unsigned char test_buf2[] = {"abcdefghijklmnopqrstuvwxyz012345678901234567890123456789"};
// sha256_output_values for abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq // sha256_output_values for abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
const unsigned char test_sum1[] = const unsigned char test_sum1[] = {
{ 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8, 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39, 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67, 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 }; 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1
};
// sha256_output_values for 3*abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq // sha256_output_values for 3*abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
const unsigned char test_sum2[] = const unsigned char test_sum2[] = {
{ 0x50, 0xEA, 0x82, 0x5D, 0x96, 0x84, 0xF4, 0x22, 0x50, 0xEA, 0x82, 0x5D, 0x96, 0x84, 0xF4, 0x22,
0x9C, 0xA2, 0x9F, 0x1F, 0xEC, 0x51, 0x15, 0x93, 0x9C, 0xA2, 0x9F, 0x1F, 0xEC, 0x51, 0x15, 0x93,
0xE2, 0x81, 0xE4, 0x6A, 0x14, 0x0D, 0x81, 0xE0, 0xE2, 0x81, 0xE4, 0x6A, 0x14, 0x0D, 0x81, 0xE0,
0x00, 0x5F, 0x8F, 0x68, 0x86, 0x69, 0xA0, 0x6C}; 0x00, 0x5F, 0x8F, 0x68, 0x86, 0x69, 0xA0, 0x6C
};
// sha256_output_values for abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdefghijklmnopqrstuvwxyz012345678901234567890123456789 // sha256_output_values for abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdefghijklmnopqrstuvwxyz012345678901234567890123456789
const unsigned char test_sum3[] = const unsigned char test_sum3[] = {
{ 0x6D, 0x5D, 0xDB, 0x5F, 0x4A, 0x94, 0xAB, 0x7E, 0x6D, 0x5D, 0xDB, 0x5F, 0x4A, 0x94, 0xAB, 0x7E,
0x5C, 0xF7, 0x9A, 0xD8, 0x3F, 0x58, 0xD3, 0x97, 0x5C, 0xF7, 0x9A, 0xD8, 0x3F, 0x58, 0xD3, 0x97,
0xFE, 0x79, 0xFB, 0x0D, 0x79, 0xB2, 0x0D, 0x22, 0xFE, 0x79, 0xFB, 0x0D, 0x79, 0xB2, 0x0D, 0x22,
0xFF, 0x95, 0x9F, 0x04, 0xA2, 0xE4, 0x6C, 0x68}; 0xFF, 0x95, 0x9F, 0x04, 0xA2, 0xE4, 0x6C, 0x68
};
unsigned char outsum1[32], outsum2[32], outsum3[32]; unsigned char outsum1[32], outsum2[32], outsum3[32];
int i; int i;
@ -101,55 +109,62 @@ void test_case_sha256_multi() {
mbedtls_sha256_context ctx3; mbedtls_sha256_context ctx3;
printf("test sha256_multi\n"); printf("test sha256_multi\n");
//Init both contexts //Init both contexts
mbedtls_sha256_init( &ctx1); mbedtls_sha256_init(&ctx1);
mbedtls_sha256_init( &ctx2); mbedtls_sha256_init(&ctx2);
mbedtls_sha256_init( &ctx3); mbedtls_sha256_init(&ctx3);
//Start both contexts //Start both contexts
mbedtls_sha256_starts( &ctx1, 0); mbedtls_sha256_starts(&ctx1, 0);
mbedtls_sha256_starts( &ctx2, 0); mbedtls_sha256_starts(&ctx2, 0);
printf("upd ctx1\n"); printf("upd ctx1\n");
mbedtls_sha256_update( &ctx1, test_buf, 56 ); mbedtls_sha256_update(&ctx1, test_buf, 56);
printf("upd ctx2\n"); printf("upd ctx2\n");
mbedtls_sha256_update( &ctx2, test_buf, 66 ); mbedtls_sha256_update(&ctx2, test_buf, 66);
printf("finish ctx1\n"); printf("finish ctx1\n");
mbedtls_sha256_finish( &ctx1, outsum1 ); mbedtls_sha256_finish(&ctx1, outsum1);
printf("upd ctx2\n"); printf("upd ctx2\n");
mbedtls_sha256_update( &ctx2, test_buf+66, 46 ); mbedtls_sha256_update(&ctx2, test_buf + 66, 46);
printf("clone ctx2 in ctx3\n"); printf("clone ctx2 in ctx3\n");
mbedtls_sha256_clone(&ctx3, (const mbedtls_sha256_context *)&ctx2); mbedtls_sha256_clone(&ctx3, (const mbedtls_sha256_context *)&ctx2);
printf("free ctx1\n"); printf("free ctx1\n");
mbedtls_sha256_free( &ctx1 ); mbedtls_sha256_free(&ctx1);
printf("upd ctx2\n"); printf("upd ctx2\n");
mbedtls_sha256_update( &ctx2, test_buf+112, 56 ); mbedtls_sha256_update(&ctx2, test_buf + 112, 56);
printf("upd ctx3 with different values than ctx2\n"); printf("upd ctx3 with different values than ctx2\n");
mbedtls_sha256_update( &ctx3, test_buf2, 56 ); mbedtls_sha256_update(&ctx3, test_buf2, 56);
printf("finish ctx2\n"); printf("finish ctx2\n");
mbedtls_sha256_finish( &ctx2, outsum2 ); mbedtls_sha256_finish(&ctx2, outsum2);
printf("finish ctx3\n"); printf("finish ctx3\n");
mbedtls_sha256_finish( &ctx3, outsum3 ); mbedtls_sha256_finish(&ctx3, outsum3);
printf("free ctx2\n"); printf("free ctx2\n");
mbedtls_sha256_free( &ctx2 ); mbedtls_sha256_free(&ctx2);
printf("free ctx3\n"); printf("free ctx3\n");
mbedtls_sha256_free( &ctx3 ); mbedtls_sha256_free(&ctx3);
printf("\nreceived result ctx1 : "); printf("\nreceived result ctx1 : ");
for (i=0;i<32;i++) { printf("%02X",outsum1[i]);} for (i = 0; i < 32; i++) {
printf("%02X", outsum1[i]);
}
printf("\nawaited result : 248D6A61D20638B8E5C026930C3E6039A33CE45964FF216F6ECEDD19DB06C1\n"); // for abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq printf("\nawaited result : 248D6A61D20638B8E5C026930C3E6039A33CE45964FF216F6ECEDD19DB06C1\n"); // for abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
printf("\nreceived result ctx2 : "); printf("\nreceived result ctx2 : ");
for (i=0;i<32;i++) { printf("%02X",outsum2[i]);} for (i = 0; i < 32; i++) {
printf("%02X", outsum2[i]);
}
printf("\nawaited result : 50EA825D9684F4229CA29F1FEC511593E281E46A140D81E0005F8F688669A06C\n"); // for 3*abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq printf("\nawaited result : 50EA825D9684F4229CA29F1FEC511593E281E46A140D81E0005F8F688669A06C\n"); // for 3*abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
printf("\nreceived result ctx3 : "); printf("\nreceived result ctx3 : ");
for (i=0;i<32;i++) { printf("%02X",outsum3[i]);} for (i = 0; i < 32; i++) {
printf("%02X", outsum3[i]);
}
printf("\nawaited result : 6D5DDB5F4A94AB7E5CF79AD83F58D397FE79FB0D79B20D22FF959F04A2E46C68\n"); // for 2*abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq+3*0123456789 printf("\nawaited result : 6D5DDB5F4A94AB7E5CF79AD83F58D397FE79FB0D79B20D22FF959F04A2E46C68\n"); // for 2*abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq+3*0123456789
printf("\nend of test sha256\n"); printf("\nend of test sha256\n");
TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum1, test_sum1,32); TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum1, test_sum1, 32);
TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum2, test_sum2,32); TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum2, test_sum2, 32);
TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum3, test_sum3,32); TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum3, test_sum3, 32);
} }
#endif //MBEDTLS_SHA256_C #endif //MBEDTLS_SHA256_C
utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason)
{
greentea_case_failure_abort_handler(source, reason); greentea_case_failure_abort_handler(source, reason);
return STATUS_CONTINUE; return STATUS_CONTINUE;
} }
@ -161,19 +176,20 @@ Case cases[] = {
#endif #endif
}; };
utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(10, "default_auto"); GREENTEA_SETUP(10, "default_auto");
return greentea_test_setup_handler(number_of_cases); return greentea_test_setup_handler(number_of_cases);
} }
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() { int main()
{
int ret = 0; int ret = 0;
#if defined(MBEDTLS_PLATFORM_C) #if defined(MBEDTLS_PLATFORM_C)
mbedtls_platform_context platform_ctx; mbedtls_platform_context platform_ctx;
if((ret = mbedtls_platform_setup(&platform_ctx))!= 0) if ((ret = mbedtls_platform_setup(&platform_ctx)) != 0) {
{
mbedtls_printf("Mbed TLS multitest failed! mbedtls_platform_setup returned %d\n", ret); mbedtls_printf("Mbed TLS multitest failed! mbedtls_platform_setup returned %d\n", ret);
return 1; return 1;
} }

View File

@ -84,19 +84,20 @@ Case cases[] = {
#endif /* MBEDTLS_SELF_TEST */ #endif /* MBEDTLS_SELF_TEST */
}; };
utest::v1::status_t test_setup(const size_t num_cases) { utest::v1::status_t test_setup(const size_t num_cases)
{
GREENTEA_SETUP(120, "default_auto"); GREENTEA_SETUP(120, "default_auto");
return verbose_test_setup_handler(num_cases); return verbose_test_setup_handler(num_cases);
} }
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
int main() { int main()
{
int ret = 0; int ret = 0;
#if defined(MBEDTLS_PLATFORM_C) #if defined(MBEDTLS_PLATFORM_C)
mbedtls_platform_context platform_ctx; mbedtls_platform_context platform_ctx;
if((ret = mbedtls_platform_setup(&platform_ctx))!= 0) if ((ret = mbedtls_platform_setup(&platform_ctx)) != 0) {
{
mbedtls_printf("Mbed TLS selftest failed! mbedtls_platform_setup returned %d\n", ret); mbedtls_printf("Mbed TLS selftest failed! mbedtls_platform_setup returned %d\n", ret);
return 1; return 1;
} }

View File

@ -29,21 +29,21 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ NetworkInterface *net;
NetworkInterface* net; Timer tc_bucket; // Timer to limit a test cases run time
Timer tc_bucket; // Timer to limit a test cases run time
} }
char tcp_global::rx_buffer[RX_BUFF_SIZE]; char tcp_global::rx_buffer[RX_BUFF_SIZE];
char tcp_global::tx_buffer[TX_BUFF_SIZE]; char tcp_global::tx_buffer[TX_BUFF_SIZE];
NetworkInterface* get_interface() NetworkInterface *get_interface()
{ {
return net; return net;
} }
void drop_bad_packets(TCPSocket& sock, int orig_timeout) { void drop_bad_packets(TCPSocket &sock, int orig_timeout)
{
nsapi_error_t err; nsapi_error_t err;
sock.set_timeout(0); sock.set_timeout(0);
while (true) { while (true) {
@ -55,19 +55,22 @@ void drop_bad_packets(TCPSocket& sock, int orig_timeout) {
sock.set_timeout(orig_timeout); sock.set_timeout(orig_timeout);
} }
static void _ifup() { static void _ifup()
{
net = MBED_CONF_APP_OBJECT_CONSTRUCTION; net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
nsapi_error_t err = MBED_CONF_APP_CONNECT_STATEMENT; nsapi_error_t err = MBED_CONF_APP_CONNECT_STATEMENT;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address()); printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address());
} }
static void _ifdown() { static void _ifdown()
{
net->disconnect(); net->disconnect();
printf("MBED: ifdown\n"); printf("MBED: ifdown\n");
} }
nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket& sock) { nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket &sock)
{
SocketAddress tcp_addr; SocketAddress tcp_addr;
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr); get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
@ -81,7 +84,8 @@ nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket& sock) {
return sock.connect(tcp_addr); return sock.connect(tcp_addr);
} }
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket& sock) { nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock)
{
SocketAddress tcp_addr; SocketAddress tcp_addr;
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr); get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
@ -97,14 +101,14 @@ nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket& sock) {
void fill_tx_buffer_ascii(char *buff, size_t len) void fill_tx_buffer_ascii(char *buff, size_t len)
{ {
for (size_t i = 0; i<len; ++i) { for (size_t i = 0; i < len; ++i) {
buff[i] = (rand() % 43) + '0'; buff[i] = (rand() % 43) + '0';
} }
} }
int split2half_rmng_tcp_test_time() int split2half_rmng_tcp_test_time()
{ {
return (tcp_global::TESTS_TIMEOUT-tc_bucket.read())/2; return (tcp_global::TESTS_TIMEOUT - tc_bucket.read()) / 2;
} }
// Test setup // Test setup

View File

@ -18,19 +18,18 @@
#ifndef TCP_TESTS_H #ifndef TCP_TESTS_H
#define TCP_TESTS_H #define TCP_TESTS_H
NetworkInterface* get_interface(); NetworkInterface *get_interface();
void drop_bad_packets(TCPSocket& sock, int orig_timeout); void drop_bad_packets(TCPSocket &sock, int orig_timeout);
void fill_tx_buffer_ascii(char *buff, size_t len); void fill_tx_buffer_ascii(char *buff, size_t len);
nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket& sock); nsapi_error_t tcpsocket_connect_to_echo_srv(TCPSocket &sock);
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket& sock); nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock);
/** /**
* Single testcase might take only half of the remaining execution time * Single testcase might take only half of the remaining execution time
*/ */
int split2half_rmng_tcp_test_time(); // [s] int split2half_rmng_tcp_test_time(); // [s]
namespace tcp_global namespace tcp_global {
{
static const int TESTS_TIMEOUT = 480; static const int TESTS_TIMEOUT = 480;
static const int TCP_OS_STACK_SIZE = 1024; static const int TCP_OS_STACK_SIZE = 1024;

View File

@ -25,24 +25,25 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ static const int SIGNAL_SIGIO = 0x1;
static const int SIGNAL_SIGIO = 0x1; static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int BUFF_SIZE = 1200; static const int BUFF_SIZE = 1200;
static const int PKTS = 22; static const int PKTS = 22;
static const int pkt_sizes[PKTS] = {1,2,3,4,5,6,7,8,9,10, \ static const int pkt_sizes[PKTS] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, \
100,200,300,400,500,600,700,800,900,1000,\ 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, \
1100,1200}; 1100, 1200
TCPSocket sock; };
Semaphore tx_sem(0, 1); TCPSocket sock;
Semaphore tx_sem(0, 1);
Timer tc_exec_time; Timer tc_exec_time;
int time_allotted; int time_allotted;
} }
static void _sigio_handler(osThreadId id) { static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO); osSignalSet(id, SIGNAL_SIGIO);
} }
@ -69,7 +70,7 @@ void TCPSOCKET_ECHOTEST()
int bytes2recv = sent; int bytes2recv = sent;
while (bytes2recv) { while (bytes2recv) {
recvd = sock.recv(&(tcp_global::rx_buffer[sent-bytes2recv]), bytes2recv); recvd = sock.recv(&(tcp_global::rx_buffer[sent - bytes2recv]), bytes2recv);
if (recvd < 0) { if (recvd < 0) {
printf("[Round#%02d] network error %d\n", x, recvd); printf("[Round#%02d] network error %d\n", x, recvd);
TEST_FAIL(); TEST_FAIL();
@ -85,10 +86,10 @@ void TCPSOCKET_ECHOTEST()
void tcpsocket_echotest_nonblock_receiver(void *receive_bytes) void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
{ {
int bytes2recv = *(int*)receive_bytes; int bytes2recv = *(int *)receive_bytes;
int recvd; int recvd;
while (bytes2recv) { while (bytes2recv) {
recvd = sock.recv(&(tcp_global::rx_buffer[*(int*)receive_bytes-bytes2recv]), bytes2recv); recvd = sock.recv(&(tcp_global::rx_buffer[*(int *)receive_bytes - bytes2recv]), bytes2recv);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) { if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted) { if (tc_exec_time.read() >= time_allotted) {
TEST_FAIL(); TEST_FAIL();
@ -103,10 +104,10 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
bytes2recv -= recvd; bytes2recv -= recvd;
} }
TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, *(int*)receive_bytes)); TEST_ASSERT_EQUAL(0, memcmp(tcp_global::tx_buffer, tcp_global::rx_buffer, *(int *)receive_bytes));
static int round = 0; static int round = 0;
printf("[Recevr#%02d] bytes received: %d\n", round++, *(int*)receive_bytes); printf("[Recevr#%02d] bytes received: %d\n", round++, *(int *)receive_bytes);
tx_sem.release(); tx_sem.release();
@ -140,7 +141,7 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
bytes2send = pkt_s; bytes2send = pkt_s;
while (bytes2send > 0) { while (bytes2send > 0) {
sent = sock.send(&(tcp_global::tx_buffer[pkt_s-bytes2send]), bytes2send); sent = sock.send(&(tcp_global::tx_buffer[pkt_s - bytes2send]), bytes2send);
if (sent == NSAPI_ERROR_WOULD_BLOCK) { if (sent == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted || if (tc_exec_time.read() >= time_allotted ||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) { osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {

View File

@ -25,16 +25,16 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ static const int SIGNAL_SIGIO = 0x1;
static const int SIGNAL_SIGIO = 0x1; static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int BURST_CNT = 100; static const int BURST_CNT = 100;
static const int BURST_SIZE = 1220; static const int BURST_SIZE = 1220;
} }
static void _sigio_handler(osThreadId id) { static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO); osSignalSet(id, SIGNAL_SIGIO);
} }
@ -53,9 +53,9 @@ void TCPSOCKET_ECHOTEST_BURST()
for (int i = 0; i < BURST_CNT; i++) { for (int i = 0; i < BURST_CNT; i++) {
bt_left = BURST_SIZE; bt_left = BURST_SIZE;
while (bt_left > 0) { while (bt_left > 0) {
sent = sock.send(&(tcp_global::tx_buffer[BURST_SIZE-bt_left]), bt_left); sent = sock.send(&(tcp_global::tx_buffer[BURST_SIZE - bt_left]), bt_left);
if (sent == NSAPI_ERROR_WOULD_BLOCK) { if (sent == NSAPI_ERROR_WOULD_BLOCK) {
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) { if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL(); TEST_FAIL();
goto END; goto END;
} }
@ -70,7 +70,7 @@ void TCPSOCKET_ECHOTEST_BURST()
bt_left = BURST_SIZE; bt_left = BURST_SIZE;
while (bt_left > 0) { while (bt_left > 0) {
recvd = sock.recv(&(tcp_global::rx_buffer[BURST_SIZE-bt_left]), BURST_SIZE); recvd = sock.recv(&(tcp_global::rx_buffer[BURST_SIZE - bt_left]), BURST_SIZE);
if (recvd < 0) { if (recvd < 0) {
printf("[%02d] network error %d\n", i, recvd); printf("[%02d] network error %d\n", i, recvd);
break; break;
@ -106,9 +106,9 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
for (int i = 0; i < BURST_CNT; i++) { for (int i = 0; i < BURST_CNT; i++) {
bt_left = BURST_SIZE; bt_left = BURST_SIZE;
while (bt_left > 0) { while (bt_left > 0) {
sent = sock.send(&(tcp_global::tx_buffer[BURST_SIZE-bt_left]), bt_left); sent = sock.send(&(tcp_global::tx_buffer[BURST_SIZE - bt_left]), bt_left);
if (sent == NSAPI_ERROR_WOULD_BLOCK) { if (sent == NSAPI_ERROR_WOULD_BLOCK) {
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) { if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL(); TEST_FAIL();
goto END; goto END;
} }
@ -127,9 +127,9 @@ void TCPSOCKET_ECHOTEST_BURST_NONBLOCK()
bt_left = BURST_SIZE; bt_left = BURST_SIZE;
while (bt_left > 0) { while (bt_left > 0) {
recvd = sock.recv(&(tcp_global::rx_buffer[BURST_SIZE-bt_left]), BURST_SIZE); recvd = sock.recv(&(tcp_global::rx_buffer[BURST_SIZE - bt_left]), BURST_SIZE);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) { if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) { if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
printf("[bt#%02d] packet timeout...", i); printf("[bt#%02d] packet timeout...", i);
break; break;
} }

View File

@ -25,17 +25,18 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ static const int SIGNAL_SIGIO = 0x1;
static const int SIGNAL_SIGIO = 0x1; static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int SIGIO_TIMEOUT = 5000; //[ms]
} }
static void _sigio_handler(osThreadId id) { static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO); osSignalSet(id, SIGNAL_SIGIO);
} }
static nsapi_error_t _tcpsocket_connect_to_daytime_srv(TCPSocket& sock) { static nsapi_error_t _tcpsocket_connect_to_daytime_srv(TCPSocket &sock)
{
SocketAddress tcp_addr; SocketAddress tcp_addr;
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr); get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
@ -75,7 +76,7 @@ void TCPSOCKET_ENDPOINT_CLOSE()
TEST_FAIL(); TEST_FAIL();
break; break;
} else if (recvd == NSAPI_ERROR_WOULD_BLOCK) { } else if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if(tc_exec_time.read() >= time_allotted || if (tc_exec_time.read() >= time_allotted ||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) { osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL(); TEST_FAIL();
break; break;

View File

@ -25,12 +25,11 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ typedef struct TCPSocketItem {
typedef struct TCPSocketItem {
TCPSocket *sock; TCPSocket *sock;
TCPSocketItem *next; TCPSocketItem *next;
} SocketItem; } SocketItem;
} }
void TCPSOCKET_OPEN_LIMIT() void TCPSOCKET_OPEN_LIMIT()
@ -73,7 +72,7 @@ void TCPSOCKET_OPEN_LIMIT()
} }
TCPSocketItem *tmp; TCPSocketItem *tmp;
for(TCPSocketItem *it = socket_list_head; it;) { for (TCPSocketItem *it = socket_list_head; it;) {
++open_sockets[i]; ++open_sockets[i];
tmp = it; tmp = it;
it = it->next; it = it->next;

View File

@ -25,13 +25,12 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ static const int SIGNAL_SIGIO = 0x1;
static const int SIGNAL_SIGIO = 0x1; static const int SIGIO_TIMEOUT = 20000; //[ms]
static const int SIGIO_TIMEOUT = 20000; //[ms]
} }
static nsapi_error_t _tcpsocket_connect_to_chargen_srv(TCPSocket& sock) static nsapi_error_t _tcpsocket_connect_to_chargen_srv(TCPSocket &sock)
{ {
SocketAddress tcp_addr; SocketAddress tcp_addr;
@ -63,12 +62,13 @@ static nsapi_error_t _tcpsocket_connect_to_chargen_srv(TCPSocket& sock)
static void generate_RFC_864_pattern(size_t offset, uint8_t *buf, size_t len) static void generate_RFC_864_pattern(size_t offset, uint8_t *buf, size_t len)
{ {
while (len--) { while (len--) {
if (offset % 74 == 72) if (offset % 74 == 72) {
*buf++ = '\r'; *buf++ = '\r';
else if (offset % 74 == 73) } else if (offset % 74 == 73) {
*buf++ = '\n'; *buf++ = '\n';
else } else {
*buf++ = ' ' + (offset%74 + offset/74) % 95 ; *buf++ = ' ' + (offset % 74 + offset / 74) % 95 ;
}
offset++; offset++;
} }
} }
@ -78,14 +78,15 @@ static void check_RFC_864_pattern(void *rx_buff, const size_t len, const size_t
void *ref_buff = malloc(len); void *ref_buff = malloc(len);
TEST_ASSERT_NOT_NULL(ref_buff); TEST_ASSERT_NOT_NULL(ref_buff);
generate_RFC_864_pattern(offset, (uint8_t*)ref_buff, len); generate_RFC_864_pattern(offset, (uint8_t *)ref_buff, len);
bool match = memcmp(ref_buff, rx_buff, len) == 0; bool match = memcmp(ref_buff, rx_buff, len) == 0;
free(ref_buff); free(ref_buff);
TEST_ASSERT(match); TEST_ASSERT(match);
} }
void rcv_n_chk_against_rfc864_pattern(TCPSocket& sock) { void rcv_n_chk_against_rfc864_pattern(TCPSocket &sock)
{
static const size_t total_size = 1024 * 100; static const size_t total_size = 1024 * 100;
static const size_t buff_size = 1220; static const size_t buff_size = 1220;
uint8_t buff[buff_size]; uint8_t buff[buff_size];
@ -121,7 +122,7 @@ void TCPSOCKET_RECV_100K()
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close()); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
} }
void rcv_n_chk_against_rfc864_pattern_nonblock(TCPSocket& sock) void rcv_n_chk_against_rfc864_pattern_nonblock(TCPSocket &sock)
{ {
static const size_t total_size = 1024 * 100; static const size_t total_size = 1024 * 100;
static const size_t buff_size = 1220; static const size_t buff_size = 1220;
@ -154,7 +155,8 @@ void rcv_n_chk_against_rfc864_pattern_nonblock(TCPSocket& sock)
printf("MBED: Time taken: %fs\n", timer.read()); printf("MBED: Time taken: %fs\n", timer.read());
} }
static void _sigio_handler(osThreadId id) { static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO); osSignalSet(id, SIGNAL_SIGIO);
} }

View File

@ -25,13 +25,13 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ static const int SIGNAL_SIGIO = 0x1;
static const int SIGNAL_SIGIO = 0x1; static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int SIGIO_TIMEOUT = 5000; //[ms]
} }
static void _sigio_handler(osThreadId id) { static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO); osSignalSet(id, SIGNAL_SIGIO);
} }
@ -58,7 +58,7 @@ void TCPSOCKET_RECV_TIMEOUT()
while (pkt_unrecvd) { while (pkt_unrecvd) {
timer.reset(); timer.reset();
timer.start(); timer.start();
recvd = sock.recv(&(buff[DATA_LEN-pkt_unrecvd]), pkt_unrecvd); recvd = sock.recv(&(buff[DATA_LEN - pkt_unrecvd]), pkt_unrecvd);
timer.stop(); timer.stop();
if (recvd == NSAPI_ERROR_WOULD_BLOCK) { if (recvd == NSAPI_ERROR_WOULD_BLOCK) {

View File

@ -32,7 +32,7 @@ void TCPSOCKET_SEND_REPEAT()
int snd; int snd;
Timer timer; Timer timer;
static const char tx_buffer[] = {'h','e','l','l','o'}; static const char tx_buffer[] = {'h', 'e', 'l', 'l', 'o'};
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
snd = sock.send(tx_buffer, sizeof(tx_buffer)); snd = sock.send(tx_buffer, sizeof(tx_buffer));
if (snd != sizeof(tx_buffer)) { if (snd != sizeof(tx_buffer)) {

View File

@ -35,7 +35,7 @@ void TCPSOCKET_SEND_TIMEOUT()
int err; int err;
Timer timer; Timer timer;
static const char tx_buffer[] = {'h','e','l','l','o'}; static const char tx_buffer[] = {'h', 'e', 'l', 'l', 'o'};
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {
timer.reset(); timer.reset();
timer.start(); timer.start();

View File

@ -25,21 +25,22 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ static const int SIGNAL_SIGIO1 = 0x1;
static const int SIGNAL_SIGIO1 = 0x1; static const int SIGNAL_SIGIO2 = 0x2;
static const int SIGNAL_SIGIO2 = 0x2; static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int SIGIO_TIMEOUT = 5000; //[ms]
Thread thread; Thread thread;
volatile bool running = true; volatile bool running = true;
} }
static void _sigio_handler1(osThreadId id) { static void _sigio_handler1(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO1); osSignalSet(id, SIGNAL_SIGIO1);
} }
static void _sigio_handler2(osThreadId id) { static void _sigio_handler2(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO2); osSignalSet(id, SIGNAL_SIGIO2);
} }
@ -61,9 +62,9 @@ static void check_const_len_rand_sequence()
fill_tx_buffer_ascii(tx_buff, BUFF_SIZE); fill_tx_buffer_ascii(tx_buff, BUFF_SIZE);
bytes2process = BUFF_SIZE; bytes2process = BUFF_SIZE;
while (bytes2process > 0) { while (bytes2process > 0) {
sent = sock.send(&(tx_buff[BUFF_SIZE-bytes2process]), bytes2process); sent = sock.send(&(tx_buff[BUFF_SIZE - bytes2process]), bytes2process);
if (sent == NSAPI_ERROR_WOULD_BLOCK) { if (sent == NSAPI_ERROR_WOULD_BLOCK) {
if(osSignalWait(SIGNAL_SIGIO1, SIGIO_TIMEOUT).status == osEventTimeout) { if (osSignalWait(SIGNAL_SIGIO1, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL(); TEST_FAIL();
goto END; goto END;
} }
@ -78,7 +79,7 @@ static void check_const_len_rand_sequence()
bytes2process = BUFF_SIZE; bytes2process = BUFF_SIZE;
while (bytes2process > 0) { while (bytes2process > 0) {
recvd = sock.recv(&(rx_buff[BUFF_SIZE-bytes2process]), bytes2process); recvd = sock.recv(&(rx_buff[BUFF_SIZE - bytes2process]), bytes2process);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) { if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
continue; continue;
} else if (recvd < 0) { } else if (recvd < 0) {
@ -118,9 +119,9 @@ static void check_var_len_rand_sequence()
fill_tx_buffer_ascii(tx_buff, i); fill_tx_buffer_ascii(tx_buff, i);
bytes2process = i; bytes2process = i;
while (bytes2process > 0) { while (bytes2process > 0) {
sent = sock.send(&(tx_buff[i-bytes2process]), bytes2process); sent = sock.send(&(tx_buff[i - bytes2process]), bytes2process);
if (sent == NSAPI_ERROR_WOULD_BLOCK) { if (sent == NSAPI_ERROR_WOULD_BLOCK) {
if(osSignalWait(SIGNAL_SIGIO2, SIGIO_TIMEOUT).status == osEventTimeout) { if (osSignalWait(SIGNAL_SIGIO2, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL(); TEST_FAIL();
goto END; goto END;
} }
@ -135,7 +136,7 @@ static void check_var_len_rand_sequence()
bytes2process = i; bytes2process = i;
while (bytes2process > 0) { while (bytes2process > 0) {
recvd = sock.recv(&(rx_buff[i-bytes2process]), bytes2process); recvd = sock.recv(&(rx_buff[i - bytes2process]), bytes2process);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) { if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
continue; continue;
} else if (recvd < 0) { } else if (recvd < 0) {

View File

@ -29,29 +29,31 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ NetworkInterface *net;
NetworkInterface* net;
} }
NetworkInterface* get_interface() NetworkInterface *get_interface()
{ {
return net; return net;
} }
static void _ifup() { static void _ifup()
{
net = MBED_CONF_APP_OBJECT_CONSTRUCTION; net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
nsapi_error_t err = MBED_CONF_APP_CONNECT_STATEMENT; nsapi_error_t err = MBED_CONF_APP_CONNECT_STATEMENT;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("MBED: UDPClient IP address is '%s'\n", net->get_ip_address()); printf("MBED: UDPClient IP address is '%s'\n", net->get_ip_address());
} }
static void _ifdown() { static void _ifdown()
{
net->disconnect(); net->disconnect();
printf("MBED: ifdown\n"); printf("MBED: ifdown\n");
} }
void drop_bad_packets(UDPSocket& sock, int orig_timeout) { void drop_bad_packets(UDPSocket &sock, int orig_timeout)
{
nsapi_error_t err; nsapi_error_t err;
sock.set_timeout(0); sock.set_timeout(0);
while (true) { while (true) {
@ -65,7 +67,7 @@ void drop_bad_packets(UDPSocket& sock, int orig_timeout) {
void fill_tx_buffer_ascii(char *buff, size_t len) void fill_tx_buffer_ascii(char *buff, size_t len)
{ {
for (size_t i = 0; i<len; ++i) { for (size_t i = 0; i < len; ++i) {
buff[i] = (rand() % 43) + '0'; buff[i] = (rand() % 43) + '0';
} }
} }

View File

@ -18,8 +18,8 @@
#ifndef UDP_TESTS_H #ifndef UDP_TESTS_H
#define UDP_TESTS_H #define UDP_TESTS_H
NetworkInterface* get_interface(); NetworkInterface *get_interface();
void drop_bad_packets(UDPSocket& sock, int orig_timeout); void drop_bad_packets(UDPSocket &sock, int orig_timeout);
void fill_tx_buffer_ascii(char *buff, size_t len); void fill_tx_buffer_ascii(char *buff, size_t len);
/* /*

View File

@ -25,30 +25,31 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ static const int SIGNAL_SIGIO = 0x1;
static const int SIGNAL_SIGIO = 0x1; static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int SIGIO_TIMEOUT = 5000; //[ms] static const int WAIT2RECV_TIMEOUT = 1000; //[ms]
static const int WAIT2RECV_TIMEOUT = 1000; //[ms] static const int RETRIES = 2;
static const int RETRIES = 2;
static const double EXPECTED_LOSS_RATIO = 0.0; static const double EXPECTED_LOSS_RATIO = 0.0;
static const double TOLERATED_LOSS_RATIO = 0.3; static const double TOLERATED_LOSS_RATIO = 0.3;
UDPSocket sock; UDPSocket sock;
Semaphore tx_sem(0, 1); Semaphore tx_sem(0, 1);
static const int BUFF_SIZE = 1200; static const int BUFF_SIZE = 1200;
char rx_buffer[BUFF_SIZE] = {0}; char rx_buffer[BUFF_SIZE] = {0};
char tx_buffer[BUFF_SIZE] = {0}; char tx_buffer[BUFF_SIZE] = {0};
static const int PKTS = 22; static const int PKTS = 22;
static const int pkt_sizes[PKTS] = {1,2,3,4,5,6,7,8,9,10, \ static const int pkt_sizes[PKTS] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, \
100,200,300,400,500,600,700,800,900,1000,\ 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, \
1100,1200}; 1100, 1200
};
} }
static void _sigio_handler(osThreadId id) { static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO); osSignalSet(id, SIGNAL_SIGIO);
} }
@ -101,7 +102,7 @@ void UDPSOCKET_ECHOTEST()
void udpsocket_echotest_nonblock_receiver(void *receive_bytes) void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
{ {
int expt2recv = *(int*)receive_bytes; int expt2recv = *(int *)receive_bytes;
int recvd; int recvd;
for (int retry_cnt = 0; retry_cnt <= RETRIES; retry_cnt++) { for (int retry_cnt = 0; retry_cnt <= RETRIES; retry_cnt++) {
recvd = sock.recvfrom(NULL, rx_buffer, expt2recv); recvd = sock.recvfrom(NULL, rx_buffer, expt2recv);
@ -162,7 +163,7 @@ void UDPSOCKET_ECHOTEST_NONBLOCK()
printf("[Round#%02d - Sender] error, returned %d\n", s_idx, sent); printf("[Round#%02d - Sender] error, returned %d\n", s_idx, sent);
continue; continue;
} }
if (tx_sem.wait(WAIT2RECV_TIMEOUT*2) == 0) { // RX might wait up to WAIT2RECV_TIMEOUT before recvfrom if (tx_sem.wait(WAIT2RECV_TIMEOUT * 2) == 0) { // RX might wait up to WAIT2RECV_TIMEOUT before recvfrom
continue; continue;
} }
break; break;

View File

@ -25,45 +25,47 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ static const int SIGNAL_SIGIO = 0x1;
static const int SIGNAL_SIGIO = 0x1; static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int SIGIO_TIMEOUT = 5000; //[ms] static const int RECV_TIMEOUT = 1; //[s]
static const int RECV_TIMEOUT = 1; //[s]
static const int BURST_CNT = 100; static const int BURST_CNT = 100;
static const int BURST_PKTS = 5; static const int BURST_PKTS = 5;
static const int PKG_SIZES[BURST_PKTS] = {100, 200, 300, 120, 500}; static const int PKG_SIZES[BURST_PKTS] = {100, 200, 300, 120, 500};
static const int RECV_TOTAL = 1220; static const int RECV_TOTAL = 1220;
static const double EXPECTED_LOSS_RATIO = 0.0; static const double EXPECTED_LOSS_RATIO = 0.0;
static const double TOLERATED_LOSS_RATIO = 0.3; static const double TOLERATED_LOSS_RATIO = 0.3;
typedef struct pkg { typedef struct pkg {
int len; int len;
char *payload; char *payload;
} pkg_t; } pkg_t;
pkg_t tx_buffers[BURST_PKTS]; pkg_t tx_buffers[BURST_PKTS];
char rx_buffer[500] = {0}; char rx_buffer[500] = {0};
} }
void prepare_tx_buffers() { void prepare_tx_buffers()
{
// TX buffers to be preserved for comparison // TX buffers to be preserved for comparison
for (int x = 0; x < BURST_PKTS; x++) { for (int x = 0; x < BURST_PKTS; x++) {
tx_buffers[x].len = PKG_SIZES[x]; tx_buffers[x].len = PKG_SIZES[x];
tx_buffers[x].payload = (char*) (malloc(PKG_SIZES[x])); tx_buffers[x].payload = (char *)(malloc(PKG_SIZES[x]));
TEST_ASSERT_NOT_NULL(tx_buffers[x].payload); TEST_ASSERT_NOT_NULL(tx_buffers[x].payload);
fill_tx_buffer_ascii(tx_buffers[x].payload, tx_buffers[x].len); fill_tx_buffer_ascii(tx_buffers[x].payload, tx_buffers[x].len);
} }
} }
void free_tx_buffers() { void free_tx_buffers()
{
for (int x = 0; x < BURST_PKTS; x++) { for (int x = 0; x < BURST_PKTS; x++) {
free(tx_buffers[x].payload); free(tx_buffers[x].payload);
} }
} }
static void _sigio_handler(osThreadId id) { static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO); osSignalSet(id, SIGNAL_SIGIO);
} }
@ -98,12 +100,12 @@ void UDPSOCKET_ECHOTEST_BURST()
for (int j = 0; j < BURST_PKTS; j++) { for (int j = 0; j < BURST_PKTS; j++) {
recvd = sock.recvfrom(&temp_addr, rx_buffer, 500); recvd = sock.recvfrom(&temp_addr, rx_buffer, 500);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) { if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) { if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
pkg_fail += BURST_PKTS-j; pkg_fail += BURST_PKTS - j;
break; break;
} }
} else if (recvd < 0) { } else if (recvd < 0) {
pkg_fail += BURST_PKTS-j; // Assume all the following packets of the burst to be lost pkg_fail += BURST_PKTS - j; // Assume all the following packets of the burst to be lost
printf("[%02d] network error %d\n", i, recvd); printf("[%02d] network error %d\n", i, recvd);
wait(recv_timeout); wait(recv_timeout);
recv_timeout *= 2; // Back off, recv_timeout *= 2; // Back off,
@ -114,7 +116,7 @@ void UDPSOCKET_ECHOTEST_BURST()
continue; continue;
} }
recv_timeout = recv_timeout > RECV_TIMEOUT ? recv_timeout/2 : RECV_TIMEOUT; recv_timeout = recv_timeout > RECV_TIMEOUT ? recv_timeout / 2 : RECV_TIMEOUT;
// Packets might arrive unordered // Packets might arrive unordered
for (int k = 0; k < BURST_PKTS; k++) { for (int k = 0; k < BURST_PKTS; k++) {
@ -135,13 +137,13 @@ void UDPSOCKET_ECHOTEST_BURST()
free_tx_buffers(); free_tx_buffers();
double loss_ratio = 1 - ((double)(BURST_CNT*BURST_PKTS-pkg_fail) / (double)(BURST_CNT*BURST_PKTS)); double loss_ratio = 1 - ((double)(BURST_CNT * BURST_PKTS - pkg_fail) / (double)(BURST_CNT * BURST_PKTS));
printf("Packets sent: %d, packets received %d, loss ratio %.2lf\r\n", printf("Packets sent: %d, packets received %d, loss ratio %.2lf\r\n",
BURST_CNT*BURST_PKTS, BURST_CNT*BURST_PKTS-pkg_fail, loss_ratio); BURST_CNT * BURST_PKTS, BURST_CNT * BURST_PKTS - pkg_fail, loss_ratio);
// Packet loss up to 30% tolerated // Packet loss up to 30% tolerated
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio); TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio);
// 70% of the bursts need to be successful // 70% of the bursts need to be successful
TEST_ASSERT_INT_WITHIN(3*(BURST_CNT/10), BURST_CNT, ok_bursts); TEST_ASSERT_INT_WITHIN(3 * (BURST_CNT / 10), BURST_CNT, ok_bursts);
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close()); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
} }
@ -175,8 +177,8 @@ void UDPSOCKET_ECHOTEST_BURST_NONBLOCK()
for (int j = 0; j < BURST_PKTS; j++) { for (int j = 0; j < BURST_PKTS; j++) {
recvd = sock.recvfrom(&temp_addr, rx_buffer, 500); recvd = sock.recvfrom(&temp_addr, rx_buffer, 500);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) { if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) { if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
pkg_fail += BURST_PKTS-j; pkg_fail += BURST_PKTS - j;
break; break;
} }
--j; --j;
@ -213,13 +215,13 @@ PKT_OK:
free_tx_buffers(); free_tx_buffers();
double loss_ratio = 1 - ((double)(BURST_CNT*BURST_PKTS-pkg_fail) / (double)(BURST_CNT*BURST_PKTS)); double loss_ratio = 1 - ((double)(BURST_CNT * BURST_PKTS - pkg_fail) / (double)(BURST_CNT * BURST_PKTS));
printf("Packets sent: %d, packets received %d, loss ratio %.2lf\r\n", printf("Packets sent: %d, packets received %d, loss ratio %.2lf\r\n",
BURST_CNT*BURST_PKTS, BURST_CNT*BURST_PKTS-pkg_fail, loss_ratio); BURST_CNT * BURST_PKTS, BURST_CNT * BURST_PKTS - pkg_fail, loss_ratio);
// Packet loss up to 30% tolerated // Packet loss up to 30% tolerated
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio); TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio);
// 70% of the bursts need to be successful // 70% of the bursts need to be successful
TEST_ASSERT_INT_WITHIN(3*(BURST_CNT/10), BURST_CNT, ok_bursts); TEST_ASSERT_INT_WITHIN(3 * (BURST_CNT / 10), BURST_CNT, ok_bursts);
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close()); TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
} }

View File

@ -25,12 +25,11 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ typedef struct UDPSocketItem {
typedef struct UDPSocketItem {
UDPSocket *sock; UDPSocket *sock;
UDPSocketItem *next; UDPSocketItem *next;
} SocketItem; } SocketItem;
} }
void UDPSOCKET_OPEN_LIMIT() void UDPSOCKET_OPEN_LIMIT()
@ -73,7 +72,7 @@ void UDPSOCKET_OPEN_LIMIT()
} }
UDPSocketItem *tmp; UDPSocketItem *tmp;
for(UDPSocketItem *it = socket_list_head; it;) { for (UDPSocketItem *it = socket_list_head; it;) {
++open_sockets[i]; ++open_sockets[i];
tmp = it; tmp = it;
it = it->next; it = it->next;

View File

@ -25,13 +25,13 @@
using namespace utest::v1; using namespace utest::v1;
namespace namespace {
{ static const int SIGNAL_SIGIO = 0x1;
static const int SIGNAL_SIGIO = 0x1; static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int SIGIO_TIMEOUT = 5000; //[ms]
} }
static void _sigio_handler(osThreadId id) { static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO); osSignalSet(id, SIGNAL_SIGIO);
} }

View File

@ -37,7 +37,7 @@ void UDPSOCKET_SENDTO_REPEAT()
int sent; int sent;
Timer timer; Timer timer;
int i; int i;
static const char tx_buffer[] = {'h','e','l','l','o'}; static const char tx_buffer[] = {'h', 'e', 'l', 'l', 'o'};
bool oom_earlier = false; // 2 times in a row -> time to give up bool oom_earlier = false; // 2 times in a row -> time to give up
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
sent = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer)); sent = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));

View File

@ -550,7 +550,8 @@ void EmacTestMemoryManager::validate_list() const
m_mem_mutex.unlock(); m_mem_mutex.unlock();
} }
EmacTestMemoryManager &EmacTestMemoryManager::get_instance() { EmacTestMemoryManager &EmacTestMemoryManager::get_instance()
{
static EmacTestMemoryManager test_memory_manager; static EmacTestMemoryManager test_memory_manager;
return test_memory_manager; return test_memory_manager;
} }

View File

@ -236,7 +236,7 @@ protected:
* @return 0 on success, negative error code on failure * @return 0 on success, negative error code on failure
*/ */
virtual nsapi_error_t socket_accept(nsapi_socket_t server, virtual nsapi_error_t socket_accept(nsapi_socket_t server,
nsapi_socket_t *handle, SocketAddress *address=0); nsapi_socket_t *handle, SocketAddress *address = 0);
/** Send data over a TCP socket /** Send data over a TCP socket
* *

View File

@ -83,7 +83,7 @@ void test_emac_initialize()
int size = network_interface->scan(ap, 30); int size = network_interface->scan(ap, 30);
for (int i=0; i<size; i++) { for (int i = 0; i < size; i++) {
const char *ssid = ap[i].get_ssid(); const char *ssid = ap[i].get_ssid();
nsapi_security_t security = ap[i].get_security(); nsapi_security_t security = ap[i].get_security();
int8_t rssi = ap[i].get_rssi(); int8_t rssi = ap[i].get_rssi();
@ -142,7 +142,7 @@ bool emac_if_init(EMAC *emac)
mbed_mac_address(reinterpret_cast<char *>(&eth_mac_addr[0])); mbed_mac_address(reinterpret_cast<char *>(&eth_mac_addr[0]));
emac->get_hwaddr(eth_mac_addr); emac->get_hwaddr(eth_mac_addr);
emac->set_hwaddr(eth_mac_addr); emac->set_hwaddr(eth_mac_addr);
printf("emac hwaddr %x:%x:%x:%x:%x:%x\r\n\r\n", eth_mac_addr[0],eth_mac_addr[1],eth_mac_addr[2],eth_mac_addr[3],eth_mac_addr[4],eth_mac_addr[5]); printf("emac hwaddr %x:%x:%x:%x:%x:%x\r\n\r\n", eth_mac_addr[0], eth_mac_addr[1], eth_mac_addr[2], eth_mac_addr[3], eth_mac_addr[4], eth_mac_addr[5]);
int mtu_size = emac->get_mtu_size(); int mtu_size = emac->get_mtu_size();
printf("emac mtu %i\r\n\r\n", mtu_size); printf("emac mtu %i\r\n\r\n", mtu_size);

View File

@ -81,7 +81,7 @@ typedef struct {
extern struct netif *netif_list; extern struct netif *netif_list;
// Broadcast address // Broadcast address
const unsigned char eth_mac_broadcast_addr[ETH_MAC_ADDR_LEN] = {0xff,0xff,0xff,0xff,0xff,0xff}; const unsigned char eth_mac_broadcast_addr[ETH_MAC_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
// MTU size // MTU size
static int eth_mtu_size = 0; static int eth_mtu_size = 0;
@ -348,12 +348,12 @@ void emac_if_print_error_flags(void)
} }
printf("test result: %s%s%s%s%s%s\r\n\r\n", printf("test result: %s%s%s%s%s%s\r\n\r\n",
error_flags_value ? "Test FAILED, reason: ": "PASS", error_flags_value ? "Test FAILED, reason: " : "PASS",
error_flags_value & TEST_FAILED ? "test failed ": "", error_flags_value & TEST_FAILED ? "test failed " : "",
error_flags_value & MSG_VALID_ERROR ? "message content validation error ": "", error_flags_value & MSG_VALID_ERROR ? "message content validation error " : "",
error_flags_value & OUT_OF_MSG_DATA ? "out of message validation data storage ": "", error_flags_value & OUT_OF_MSG_DATA ? "out of message validation data storage " : "",
error_flags_value & NO_FREE_MEM_BUF ? "no free memory buffers ": "", error_flags_value & NO_FREE_MEM_BUF ? "no free memory buffers " : "",
error_flags_value & NO_RESPONSE ? no_resp_message: ""); error_flags_value & NO_RESPONSE ? no_resp_message : "");
} }
void emac_if_set_trace_level(char trace_level_value) void emac_if_set_trace_level(char trace_level_value)
@ -417,7 +417,7 @@ void emac_if_check_memory(bool output)
void emac_if_set_memory(bool memory) void emac_if_set_memory(bool memory)
{ {
static bool memory_value = true; static bool memory_value = true;
if (memory_value != memory ) { if (memory_value != memory) {
memory_value = memory; memory_value = memory;
EmacTestMemoryManager *mem_mngr = emac_m_mngr_get(); EmacTestMemoryManager *mem_mngr = emac_m_mngr_get();
mem_mngr->set_memory_available(memory); mem_mngr->set_memory_available(memory);

View File

@ -53,7 +53,8 @@
using namespace utest::v1; using namespace utest::v1;
// Test setup // Test setup
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
#if !MBED_CONF_APP_ECHO_SERVER #if !MBED_CONF_APP_ECHO_SERVER
GREENTEA_SETUP(600, "default_auto"); GREENTEA_SETUP(600, "default_auto");
#endif #endif

View File

@ -16,11 +16,11 @@
*/ */
#ifndef MBED_CONF_APP_OBJECT_CONSTRUCTION #ifndef MBED_CONF_APP_OBJECT_CONSTRUCTION
#error [NOT_SUPPORTED] No network interface found for this target. #error [NOT_SUPPORTED] No network interface found for this target.
#endif #endif
#if !defined(MBED_CONF_APP_WIFI_SECURE_SSID) && !defined(MBED_CONF_APP_WIFI_UNSECURE_SSID) #if !defined(MBED_CONF_APP_WIFI_SECURE_SSID) && !defined(MBED_CONF_APP_WIFI_UNSECURE_SSID)
#error [NOT_SUPPORTED] Requires parameters from mbed_app.json #error [NOT_SUPPORTED] Requires parameters from mbed_app.json
#endif #endif
#include "mbed.h" #include "mbed.h"

View File

@ -16,7 +16,7 @@
*/ */
#ifndef MBED_CONF_APP_OBJECT_CONSTRUCTION #ifndef MBED_CONF_APP_OBJECT_CONSTRUCTION
#error [NOT_SUPPORTED] No network interface found for this target. #error [NOT_SUPPORTED] No network interface found for this target.
#endif #endif
#include "mbed.h" #include "mbed.h"
@ -48,7 +48,8 @@
using namespace utest::v1; using namespace utest::v1;
utest::v1::status_t test_setup(const size_t number_of_cases) { utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(240, "default_auto"); GREENTEA_SETUP(240, "default_auto");
return verbose_test_setup_handler(number_of_cases); return verbose_test_setup_handler(number_of_cases);
} }
@ -90,6 +91,7 @@ Case cases[] = {
Specification specification(test_setup, cases); Specification specification(test_setup, cases);
// Entry point into the tests // Entry point into the tests
int main() { int main()
{
return !Harness::run(specification); return !Harness::run(specification);
} }

View File

@ -23,7 +23,8 @@
using namespace utest::v1; using namespace utest::v1;
void wifi_constructor() { void wifi_constructor()
{
WiFiInterface *wifi = get_interface(); WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi); TEST_ASSERT(wifi);
} }

View File

@ -33,7 +33,7 @@ void wifi_connect_disconnect_repeat(void)
error = wifi->set_credentials(MBED_CONF_APP_WIFI_UNSECURE_SSID, NULL); error = wifi->set_credentials(MBED_CONF_APP_WIFI_UNSECURE_SSID, NULL);
TEST_ASSERT(error == NSAPI_ERROR_OK); TEST_ASSERT(error == NSAPI_ERROR_OK);
for(int i=0; i<10; i++) { for (int i = 0; i < 10; i++) {
error = wifi->connect(); error = wifi->connect();
TEST_ASSERT(error == NSAPI_ERROR_OK); TEST_ASSERT(error == NSAPI_ERROR_OK);
error = wifi->disconnect(); error = wifi->disconnect();

Some files were not shown because too many files have changed in this diff Show More