Merge pull request #7605 from 0xc0170/fix_astyle_tests

tests: astyle fix
pull/7402/head
Cruz Monrreal 2018-08-06 10:07:59 -05:00 committed by GitHub
commit 1e676f6eda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
110 changed files with 2961 additions and 2026 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -33,68 +33,76 @@ static char buffer[256] = {0};
using namespace utest::v1;
void test_case_c_string_i_d() {
void test_case_c_string_i_d()
{
CLEAN_BUFFER;
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);
}
void test_case_c_string_u_d() {
void test_case_c_string_u_d()
{
CLEAN_BUFFER;
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);
}
void test_case_c_string_x_E() {
void test_case_c_string_x_E()
{
CLEAN_BUFFER;
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);
}
void test_case_c_string_f_f() {
void test_case_c_string_f_f()
{
CLEAN_BUFFER;
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);
}
void test_case_c_string_g_g() {
void test_case_c_string_g_g()
{
CLEAN_BUFFER;
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);
}
void test_case_c_string_e_E() {
void test_case_c_string_e_E()
{
CLEAN_BUFFER;
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);
}
void test_case_c_string_strtok() {
void test_case_c_string_strtok()
{
CLEAN_BUFFER;
char str[] ="- This, a sample string.";
char * pch = strtok (str," ,.-");
char str[] = "- This, a sample string.";
char *pch = strtok(str, " ,.-");
while (pch != NULL) {
strcat(buffer, pch);
pch = strtok (NULL, " ,.-");
pch = strtok(NULL, " ,.-");
}
TEST_ASSERT_EQUAL_STRING("Thisasamplestring", buffer);
}
void test_case_c_string_strpbrk() {
void test_case_c_string_strpbrk()
{
CLEAN_BUFFER;
char str[] = "This is a sample string";
char key[] = "aeiou";
char *pch = strpbrk(str, key);
while (pch != NULL)
{
while (pch != NULL) {
char buf[2] = {*pch, '\0'};
strcat(buffer, buf);
pch = strpbrk(pch + 1,key);
pch = strpbrk(pch + 1, key);
}
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);
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),
};
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");
return greentea_test_setup_handler(number_of_cases);
}
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
Harness::run(specification);
}

View File

@ -30,27 +30,27 @@ void test_supported_polynomials()
{
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);
}
{
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);
}
{
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);
}
{
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);
}
{
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);
}
}
@ -82,7 +82,7 @@ void test_sd_crc()
test[3] = 0x00;
test[4] = 0x00;
TEST_ASSERT_EQUAL(0, crc7.compute((void *)test, 5, &crc));
crc = (crc | 0x1 ) & 0xFF;
crc = (crc | 0x1) & 0xFF;
TEST_ASSERT_EQUAL(0x95, crc);
test[0] = 0x48;
@ -91,7 +91,7 @@ void test_sd_crc()
test[3] = 0x01;
test[4] = 0xAA;
TEST_ASSERT_EQUAL(0, crc7.compute((void *)test, 5, &crc));
crc = (crc | 0x1 ) & 0xFF;
crc = (crc | 0x1) & 0xFF;
TEST_ASSERT_EQUAL(0x87, crc);
test[0] = 0x51;
@ -100,7 +100,7 @@ void test_sd_crc()
test[3] = 0x00;
test[4] = 0x00;
TEST_ASSERT_EQUAL(0, crc7.compute((void *)test, 5, &crc));
crc = (crc | 0x1 ) & 0xFF;
crc = (crc | 0x1) & 0xFF;
TEST_ASSERT_EQUAL(0x55, crc);
MbedCRC<POLY_16BIT_CCITT, 16> crc16(0, 0, false, false);
@ -115,12 +115,12 @@ void test_any_polynomial()
uint32_t crc;
{
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);
}
{
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);
}
}
@ -132,13 +132,15 @@ Case cases[] = {
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");
return greentea_test_setup_handler(number_of_cases);
}
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
Harness::run(specification);
}

View File

@ -22,17 +22,20 @@ public:
DevNull(const char *name = NULL) : Stream(name) {}
protected:
virtual int _getc() {
virtual int _getc()
{
return 0;
}
virtual int _putc(int c) {
virtual int _putc(int c)
{
return c;
}
};
DevNull null("null");
int main() {
int main()
{
GREENTEA_SETUP(2, "dev_null_auto");
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");
}
while(1) {
// Success is determined by the host test at this point, so busy wait
while (1) {
// Success is determined by the host test at this point, so busy wait
}
}

View File

@ -26,7 +26,8 @@
using namespace utest::v1;
// 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;
for (int i = 0; i < length - 1; i++) {
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)
template<int N>
void test_case_echo_server_x() {
void test_case_echo_server_x()
{
char _key[11] = {};
char _tx_value[PAYLOAD_LENGTH + 1] = {};
char _rx_value[PAYLOAD_LENGTH + 1] = {};
@ -55,7 +57,7 @@ void test_case_echo_server_x() {
} while (expected_key);
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);
greentea_send_kv(_echo_key_const, _tx_value);
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);
return STATUS_CONTINUE;
}
@ -76,13 +79,15 @@ Case cases[] = {
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");
return greentea_test_setup_handler(number_of_cases);
}
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
Harness::run(specification);
}

View File

@ -16,7 +16,7 @@
*/
#if !DEVICE_FLASH
#error [NOT_SUPPORTED] Flash API not supported for this target
#error [NOT_SUPPORTED] Flash API not supported for this target
#endif
#include "utest/utest.h"
@ -239,7 +239,7 @@ void flashiap_timing_test()
delete[] buf;
avg_write_time /= num_writes;
utest_printf("Write size %6u bytes: avg %10u, min %10u, max %10u (usec)\n",
write_size, avg_write_time, min_write_time, max_write_time);
write_size, avg_write_time, min_write_time, max_write_time);
byte_usec_ratio = write_size / avg_write_time;
TEST_ASSERT(byte_usec_ratio < max_byte_usec_ratio);
write_size *= 4;
@ -248,7 +248,7 @@ void flashiap_timing_test()
if (num_write_sizes) {
avg_erase_time /= num_write_sizes;
utest_printf("\nErase size %6u bytes: avg %10u, min %10u, max %10u (usec)\n\n",
sector_size, avg_erase_time, min_erase_time, max_erase_time);
sector_size, avg_erase_time, min_erase_time, max_erase_time);
byte_usec_ratio = sector_size / avg_erase_time;
TEST_ASSERT(byte_usec_ratio < max_byte_usec_ratio);
}
@ -266,13 +266,15 @@ Case cases[] = {
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");
return greentea_test_setup_handler(number_of_cases);
}
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
Harness::run(specification);
}

View File

@ -28,48 +28,56 @@ using namespace utest::v1;
class CppTestCaseHelperClass {
private:
const char* name;
const char *name;
const unsigned pattern;
public:
CppTestCaseHelperClass(const char* _name) : name(_name), pattern(PATTERN_CHECK_VALUE) {
CppTestCaseHelperClass(const char *_name) : name(_name), pattern(PATTERN_CHECK_VALUE)
{
print("init");
}
void print(const char *message) {
void print(const char *message)
{
printf("%s::%s\n", name, message);
}
bool check_init(void) {
bool check_init(void)
{
bool result = (pattern == PATTERN_CHECK_VALUE);
print(result ? "check_init: OK" : "check_init: ERROR");
return result;
}
void stack_test(void) {
void stack_test(void)
{
print("stack_test");
CppTestCaseHelperClass t("Stack");
t.hello();
}
void hello(void) {
void hello(void)
{
print("hello");
}
~CppTestCaseHelperClass() {
~CppTestCaseHelperClass()
{
print("destroy");
}
};
void test_case_basic() {
void test_case_basic()
{
TEST_ASSERT_TRUE(true);
TEST_ASSERT_FALSE(false);
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);
const int cnt_max = 1024;
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
CppTestCaseHelperClass s("Static");
@ -86,7 +95,8 @@ void test_case_cpp_stack() {
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
CppTestCaseHelperClass *m = new CppTestCaseHelperClass("Heap");
m->hello();
@ -94,7 +104,8 @@ void test_case_cpp_heap() {
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);
return STATUS_CONTINUE;
}
@ -107,13 +118,15 @@ Case cases[] = {
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");
return greentea_test_setup_handler(number_of_cases);
}
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
Harness::run(specification);
}

View File

@ -20,7 +20,7 @@
#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
using utest::v1::Case;
@ -53,12 +53,12 @@ void sem_release(Semaphore *sem)
void stop_gtimer_set_flag(void)
{
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)
{
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
@ -83,7 +83,7 @@ void test_multi_ticker(void)
TEST_ASSERT_EQUAL(TICKER_COUNT, multi_counter);
for (int i = 0; i < TICKER_COUNT; i++) {
ticker[i].detach();
ticker[i].detach();
}
// Because detach calls schedule_interrupt in some circumstances
// (e.g. when head event is removed), it's good to check if
@ -125,7 +125,7 @@ void test_multi_call_time(void)
gtimer.start();
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();
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.start();
ticker.attach(callback(stop_gtimer_set_flag), ((float)DELAY_US) / 1000000.0f);
while(!ticker_callback_flag);
while (!ticker_callback_flag);
ticker.detach();
const int time_diff = gtimer.read_us();
@ -196,7 +196,7 @@ void test_attach_us_time(void)
gtimer.reset();
gtimer.start();
ticker.attach_us(callback(stop_gtimer_set_flag), DELAY_US);
while(!ticker_callback_flag);
while (!ticker_callback_flag);
ticker.detach();
const int time_diff = gtimer.read_us();

View File

@ -15,7 +15,7 @@
*/
#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
#include "mbed.h"
@ -26,7 +26,7 @@
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);
return STATUS_CONTINUE;
@ -49,30 +49,30 @@ Case cases[] = {
Case("Zero delay (attach_us)", test_no_wait<AttachUSTester<LowPowerTimeout> >),
Case("10 ms delay accuracy (attach)", test_delay_accuracy<AttachTester<LowPowerTimeout>, 10000, SHORT_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("10 ms delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<LowPowerTimeout>, 10000, SHORT_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("1 s delay accuracy (attach)", test_delay_accuracy<AttachTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("1 s delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("5 s delay accuracy (attach)", test_delay_accuracy<AttachTester<LowPowerTimeout>, 5000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("5 s delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<LowPowerTimeout>, 5000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
#if DEVICE_SLEEP
Case("1 s delay during sleep (attach)", test_sleep<AttachTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("1 s delay during sleep (attach_us)", test_sleep<AttachUSTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("1 s delay during deepsleep (attach)", test_deepsleep<AttachTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("1 s delay during deepsleep (attach_us)", test_deepsleep<AttachUSTester<LowPowerTimeout>, 1000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
#endif
Case("Timing drift (attach)", test_drift<AttachTester<LowPowerTimeout> >),

View File

@ -35,17 +35,17 @@ extern uint32_t SystemCoreClock;
* timer we need to adjust delta.
*/
/*
* Define tolerance as follows:
* tolerance = 500 us + 5% of measured time
*
* e.g.
* 1 ms delay: tolerance = 550 us
* 10 ms delay: tolerance = 1000 us
* 100 ms delay: tolerance = 5500 us
* 1000 ms delay: tolerance = 50500 us
*
* */
/*
* Define tolerance as follows:
* tolerance = 500 us + 5% of measured time
*
* e.g.
* 1 ms delay: tolerance = 550 us
* 10 ms delay: tolerance = 1000 us
* 100 ms delay: tolerance = 5500 us
* 1000 ms delay: tolerance = 50500 us
*
* */
#define US_PER_SEC 1000000
#define US_PER_MSEC 1000
@ -292,7 +292,7 @@ void test_lptimer_float_operator()
lp_timer.stop();
/* 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
@ -320,7 +320,7 @@ void test_lptimer_time_measurement()
lp_timer.stop();
/* 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_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());

View File

@ -25,7 +25,7 @@
#include <stdarg.h>
#ifndef MBED_MEM_TRACING_ENABLED
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
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);
pmem->op = op;
pmem->res = res;
switch(op) {
switch (op) {
case MBED_MEM_TRACE_MALLOC:
pmem->malloc_info.arg_size = va_arg(va, size_t);
break;
@ -180,7 +180,7 @@ void malloc_free(volatile bool *thread_continue)
{
const size_t block_size = 126;
while(*thread_continue) {
while (*thread_continue) {
void *p = malloc(block_size);
TEST_ASSERT_NOT_EQUAL(p, NULL);
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 all memory operations trace", test_case_all_memory_ops),
Case("Test trace off", test_case_trace_off),

View File

@ -23,7 +23,7 @@
#include <stdio.h>
#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
#if !DEVICE_USTICKER
@ -37,21 +37,24 @@ static uint32_t instance_count = 0;
class TestClass {
public:
TestClass() {
TestClass()
{
Thread::wait(500);
instance_count++;
}
void do_something() {
void do_something()
{
Thread::wait(100);
}
~TestClass() {
~TestClass()
{
instance_count--;
}
};
static TestClass* get_test_class()
static TestClass *get_test_class()
{
static TestClass tc;
return &tc;

View File

@ -56,9 +56,9 @@ static time_t read_rtc_stub(void)
/* Stub of RTC write function. */
static void write_rtc_stub(time_t t)
{
rtc_write_called = true;
rtc_write_called = true;
rtc_time_val = t;
rtc_time_val = t;
}
/* Stub of RTC init function. */
@ -294,7 +294,7 @@ void test_time_read_RTC_func_undefined()
seconds = time(NULL);
/* 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
@ -490,6 +490,7 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -16,7 +16,7 @@
*/
#if !DEVICE_SLEEP
#error [NOT_SUPPORTED] Sleep not supported for this target
#error [NOT_SUPPORTED] Sleep not supported for this target
#endif
#include "utest/utest.h"
@ -120,13 +120,15 @@ Case cases[] = {
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");
return greentea_test_setup_handler(number_of_cases);
}
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
Harness::run(specification);
}

View File

@ -39,16 +39,17 @@ using namespace utest::v1;
namespace {
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;
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;
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];
_array[j] = _array[j + 1];
_array[j+1] = temp;
_array[j + 1] = temp;
flag = true;
}
}
@ -56,27 +57,33 @@ void BubbleSort(T& _array, size_t array_size, F functor) {
}
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
void test_case_stl_equal() {
void test_case_stl_equal()
{
const int n_integers[] = {NEGATIVE_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));
}
void test_case_stl_transform() {
void test_case_stl_transform()
{
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};
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));
}
void test_case_stl_sort_greater() {
void test_case_stl_sort_greater()
{
int n_integers[] = {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_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);
return STATUS_CONTINUE;
}
@ -110,13 +119,15 @@ Case cases[] = {
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");
return greentea_test_setup_handler(number_of_cases);
}
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
Harness::run(specification);
}

View File

@ -19,7 +19,7 @@
#include "unity/unity.h"
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
using utest::v1::Case;
@ -48,7 +48,7 @@ volatile int ticker_count = 0;
void switch_led1_state(void)
{
// blink 3 times per second
if((callback_trigger_count % 333) == 0) {
if ((callback_trigger_count % 333) == 0) {
led1 = !led1;
}
}
@ -57,7 +57,7 @@ void switch_led2_state(void)
{
// blink 3 times per second
// 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;
}
}
@ -84,12 +84,12 @@ void sem_release(Semaphore *sem)
void stop_gtimer_set_flag(void)
{
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)
{
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
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
@ -174,7 +174,7 @@ void test_case_2x_ticker()
//get the results from host
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
@ -199,7 +199,7 @@ void test_multi_ticker(void)
TEST_ASSERT_EQUAL(TICKER_COUNT, multi_counter);
for (int i = 0; i < TICKER_COUNT; i++) {
ticker[i].detach();
ticker[i].detach();
}
// Because detach calls schedule_interrupt in some circumstances
// (e.g. when head event is removed), it's good to check if
@ -241,7 +241,7 @@ void test_multi_call_time(void)
gtimer.start();
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();
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.start();
ticker.attach(callback(stop_gtimer_set_flag), ((float)DELAY_US) / 1000000.0f);
while(!ticker_callback_flag);
while (!ticker_callback_flag);
ticker.detach();
const int time_diff = gtimer.read_us();
@ -312,7 +312,7 @@ void test_attach_us_time(void)
gtimer.reset();
gtimer.start();
ticker.attach_us(callback(stop_gtimer_set_flag), DELAY_US);
while(!ticker_callback_flag);
while (!ticker_callback_flag);
ticker.detach();
const int time_diff = gtimer.read_us();

View File

@ -25,7 +25,7 @@
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);
return STATUS_CONTINUE;
@ -48,25 +48,25 @@ Case cases[] = {
Case("Zero delay (attach_us)", test_no_wait<AttachUSTester<Timeout> >),
Case("10 ms delay accuracy (attach)", test_delay_accuracy<AttachTester<Timeout>, 10000, SHORT_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("10 ms delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<Timeout>, 10000, SHORT_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("1 s delay accuracy (attach)", test_delay_accuracy<AttachTester<Timeout>, 1000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("1 s delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<Timeout>, 1000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("5 s delay accuracy (attach)", test_delay_accuracy<AttachTester<Timeout>, 5000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("5 s delay accuracy (attach_us)", test_delay_accuracy<AttachUSTester<Timeout>, 5000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
#if DEVICE_SLEEP
Case("1 s delay during sleep (attach)", test_sleep<AttachTester<Timeout>, 1000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
Case("1 s delay during sleep (attach_us)", test_sleep<AttachUSTester<Timeout>, 1000000, LONG_DELTA_US>,
greentea_failure_handler),
greentea_failure_handler),
#endif
Case("Timing drift (attach)", test_drift<AttachTester<Timeout> >),

View File

@ -340,7 +340,7 @@ template<typename TimeoutTesterType>
class TimeoutDriftTester {
public:
TimeoutDriftTester(us_timestamp_t period = 1000) :
_callback_count(0), _period(period), _timeout()
_callback_count(0), _period(period), _timeout()
{
}

View File

@ -23,7 +23,7 @@
#include "hal/us_ticker_api.h"
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
using namespace utest::v1;
@ -34,17 +34,17 @@ extern uint32_t SystemCoreClock;
#define US_PER_MSEC 1000
#define MSEC_PER_SEC 1000
/*
* Define tolerance as follows:
* tolerance = 500 us + 2% of measured time
*
* e.g.
* 1 ms delay: tolerance = 520 us
* 10 ms delay: tolerance = 700 us
* 100 ms delay: tolerance = 2500 us
* 1000 ms delay: tolerance = 20500 us
*
* */
/*
* Define tolerance as follows:
* tolerance = 500 us + 2% of measured time
*
* e.g.
* 1 ms delay: tolerance = 520 us
* 10 ms delay: tolerance = 700 us
* 100 ms delay: tolerance = 2500 us
* 1000 ms delay: tolerance = 20500 us
*
* */
#ifdef NO_SYSTICK
#define TOLERANCE 5
#else
@ -112,7 +112,7 @@ static void stub_free(void)
ticker_info_t info =
{ TICKER_FREQ_1MHZ, TICKER_BITS };
const ticker_info_t * stub_get_info(void)
const ticker_info_t *stub_get_info(void)
{
return &info;
}
@ -139,7 +139,7 @@ static const ticker_data_t us_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;
}
@ -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());
}
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");
return verbose_test_setup_handler(number_of_cases);
}
@ -769,7 +770,8 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -28,7 +28,7 @@
using namespace utest::v1;
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
#define TEST_DELAY_US 50000ULL
@ -37,22 +37,26 @@ using namespace utest::v1;
class TestTimerEvent: public TimerEvent {
private:
Semaphore sem;
virtual void handler() {
virtual void handler()
{
sem.release();
}
public:
TestTimerEvent() :
TimerEvent(), sem(0, 1) {
TimerEvent(), sem(0, 1)
{
sleep_manager_lock_deep_sleep();
}
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();
}
@ -61,7 +65,8 @@ public:
using TimerEvent::insert_absolute;
using TimerEvent::remove;
int32_t sem_wait(uint32_t millisec) {
int32_t sem_wait(uint32_t millisec)
{
return sem.wait(millisec);
}
};
@ -70,19 +75,23 @@ class TestTimerEventRelative: public TestTimerEvent {
public:
static const int32_t SEM_SLOTS_AFTER_PAST_TS_INSERTED = 0;
TestTimerEventRelative() :
TestTimerEvent() {
TestTimerEvent()
{
}
TestTimerEventRelative(const ticker_data_t *data) :
TestTimerEvent(data) {
TestTimerEvent(data)
{
}
// 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);
}
void set_past_timestamp(void) {
void set_past_timestamp(void)
{
insert(::ticker_read(_ticker_data) - 1UL);
}
};
@ -91,19 +100,23 @@ class TestTimerEventAbsolute: public TestTimerEvent {
public:
static const int32_t SEM_SLOTS_AFTER_PAST_TS_INSERTED = 1;
TestTimerEventAbsolute() :
TestTimerEvent() {
TestTimerEvent()
{
}
TestTimerEventAbsolute(const ticker_data_t *data) :
TestTimerEvent(data) {
TestTimerEvent(data)
{
}
// 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);
}
void set_past_timestamp(void) {
void set_past_timestamp(void)
{
insert_absolute(::ticker_read_us(_ticker_data) - 1ULL);
}
};
@ -123,7 +136,8 @@ public:
* Then an event handler is called
*/
template<typename T>
void test_insert(void) {
void test_insert(void)
{
T tte;
tte.set_future_timestamp(TEST_DELAY_US);
@ -151,7 +165,8 @@ void test_insert(void) {
* Then the event handler is never called
*/
template<typename T>
void test_remove(void) {
void test_remove(void)
{
T tte;
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()
* Then an event handler is called instantly
*/
void test_insert_zero(void) {
void test_insert_zero(void)
{
TestTimerEvent tte;
tte.insert_absolute(0ULL);
@ -194,7 +210,8 @@ void test_insert_zero(void) {
* Then an event handler is called instantly
*/
template<typename T>
void test_insert_past(void) {
void test_insert_past(void)
{
T tte;
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)
{
{
GREENTEA_SETUP(5, "default_auto");
return verbose_test_setup_handler(number_of_cases);
}

View File

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

View File

@ -23,17 +23,35 @@ using namespace utest::v1;
// static functions
template <typename T>
T static_func0() { return 0; }
T static_func0()
{
return 0;
}
template <typename T>
T static_func1(T a0) { return 0 | a0; }
T static_func1(T a0)
{
return 0 | a0;
}
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>
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>
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>
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
template <typename T>
@ -41,162 +59,318 @@ struct Thing {
T t;
Thing() : t(0x80) {}
T member_func0() { return t; }
T member_func1(T a0) { 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 member_func0()
{
return t;
}
T member_func1(T a0)
{
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_func1(T a0) const { 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 const_member_func0() const
{
return t;
}
T const_member_func1(T a0) const
{
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_func1(T a0) volatile { 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 volatile_member_func0() volatile
{
return t;
}
T volatile_member_func1(T a0) volatile
{
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_func1(T a0) const volatile { 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; }
T const_volatile_member_func0() const volatile
{
return t;
}
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;
}
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
template <typename T>
T bound_func0(Thing<T> *t) { return t->t; }
T bound_func0(Thing<T> *t)
{
return t->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>
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>
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>
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>
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
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>
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>
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>
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>
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>
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
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>
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>
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>
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>
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>
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
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>
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>
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>
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>
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>
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
template <typename T>
struct Verifier {
static void verify0(Callback<T()> func) {
static void verify0(Callback<T()> func)
{
T result = func();
TEST_ASSERT_EQUAL(result, 0x00);
}
template <typename O, typename M>
static void verify0(O *obj, M method) {
static void verify0(O *obj, M method)
{
Callback<T()> func(obj, method);
T result = func();
TEST_ASSERT_EQUAL(result, 0x80);
}
static void verify1(Callback<T(T)> func) {
static void verify1(Callback<T(T)> func)
{
T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
}
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);
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));
@ -206,17 +380,18 @@ struct Verifier {
// test dispatch
template <typename T>
void test_dispatch0() {
void test_dispatch0()
{
Thing<T> thing;
Verifier<T>::verify0(static_func0<T>);
Verifier<T>::verify0(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func0);
Verifier<T>::verify0(&bound_func0<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(&const_volatile_func0<T>, (const volatile 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(&const_volatile_func0<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify0(callback(static_func0<T>));
Callback<T()> cb(static_func0);
@ -225,21 +400,22 @@ void test_dispatch0() {
Verifier<T>::verify0(cb);
cb.attach(&bound_func0<T>, &thing);
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>
void test_dispatch1() {
void test_dispatch1()
{
Thing<T> thing;
Verifier<T>::verify1(static_func1<T>);
Verifier<T>::verify1(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func1);
Verifier<T>::verify1(&bound_func1<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(&const_volatile_func1<T>, (const volatile 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(&const_volatile_func1<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify1(callback(static_func1<T>));
Callback<T(T)> cb(static_func1);
@ -248,21 +424,22 @@ void test_dispatch1() {
Verifier<T>::verify1(cb);
cb.attach(&bound_func1<T>, &thing);
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>
void test_dispatch2() {
void test_dispatch2()
{
Thing<T> thing;
Verifier<T>::verify2(static_func2<T>);
Verifier<T>::verify2(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func2);
Verifier<T>::verify2(&bound_func2<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(&const_volatile_func2<T>, (const volatile 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(&const_volatile_func2<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify2(callback(static_func2<T>));
Callback<T(T, T)> cb(static_func2);
@ -271,21 +448,22 @@ void test_dispatch2() {
Verifier<T>::verify2(cb);
cb.attach(&bound_func2<T>, &thing);
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>
void test_dispatch3() {
void test_dispatch3()
{
Thing<T> thing;
Verifier<T>::verify3(static_func3<T>);
Verifier<T>::verify3(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func3);
Verifier<T>::verify3(&bound_func3<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(&const_volatile_func3<T>, (const volatile 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(&const_volatile_func3<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify3(callback(static_func3<T>));
Callback<T(T, T, T)> cb(static_func3);
@ -294,21 +472,22 @@ void test_dispatch3() {
Verifier<T>::verify3(cb);
cb.attach(&bound_func3<T>, &thing);
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>
void test_dispatch4() {
void test_dispatch4()
{
Thing<T> thing;
Verifier<T>::verify4(static_func4<T>);
Verifier<T>::verify4(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func4);
Verifier<T>::verify4(&bound_func4<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(&const_volatile_func4<T>, (const volatile 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(&const_volatile_func4<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify4(callback(static_func4<T>));
Callback<T(T, T, T, T)> cb(static_func4);
@ -317,21 +496,22 @@ void test_dispatch4() {
Verifier<T>::verify4(cb);
cb.attach(&bound_func4<T>, &thing);
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>
void test_dispatch5() {
void test_dispatch5()
{
Thing<T> thing;
Verifier<T>::verify5(static_func5<T>);
Verifier<T>::verify5(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func5);
Verifier<T>::verify5(&bound_func5<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(&const_volatile_func5<T>, (const volatile 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(&const_volatile_func5<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify5(callback(static_func5<T>));
Callback<T(T, T, T, T, T)> cb(static_func5);
@ -340,12 +520,13 @@ void test_dispatch5() {
Verifier<T>::verify5(cb);
cb.attach(&bound_func5<T>, &thing);
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
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");
return verbose_test_setup_handler(number_of_cases);
}
@ -361,6 +542,7 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -23,17 +23,35 @@ using namespace utest::v1;
// static functions
template <typename T>
T static_func0() { return 0; }
T static_func0()
{
return 0;
}
template <typename T>
T static_func1(T a0) { return 0 | a0; }
T static_func1(T a0)
{
return 0 | a0;
}
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>
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>
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>
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
template <typename T>
@ -41,162 +59,318 @@ struct Thing {
T t;
Thing() : t(0x80) {}
T member_func0() { return t; }
T member_func1(T a0) { 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 member_func0()
{
return t;
}
T member_func1(T a0)
{
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_func1(T a0) const { 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 const_member_func0() const
{
return t;
}
T const_member_func1(T a0) const
{
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_func1(T a0) volatile { 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 volatile_member_func0() volatile
{
return t;
}
T volatile_member_func1(T a0) volatile
{
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_func1(T a0) const volatile { 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; }
T const_volatile_member_func0() const volatile
{
return t;
}
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;
}
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
template <typename T>
T bound_func0(Thing<T> *t) { return t->t; }
T bound_func0(Thing<T> *t)
{
return t->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>
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>
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>
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>
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
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>
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>
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>
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>
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>
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
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>
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>
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>
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>
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>
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
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>
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>
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>
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>
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>
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
template <typename T>
struct Verifier {
static void verify0(Callback<T()> func) {
static void verify0(Callback<T()> func)
{
T result = func();
TEST_ASSERT_EQUAL(result, 0x00);
}
template <typename O, typename M>
static void verify0(O *obj, M method) {
static void verify0(O *obj, M method)
{
Callback<T()> func(obj, method);
T result = func();
TEST_ASSERT_EQUAL(result, 0x80);
}
static void verify1(Callback<T(T)> func) {
static void verify1(Callback<T(T)> func)
{
T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
}
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);
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));
@ -206,17 +380,18 @@ struct Verifier {
// test dispatch
template <typename T>
void test_dispatch0() {
void test_dispatch0()
{
Thing<T> thing;
Verifier<T>::verify0(static_func0<T>);
Verifier<T>::verify0(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func0);
Verifier<T>::verify0(&bound_func0<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(&const_volatile_func0<T>, (const volatile 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(&const_volatile_func0<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify0(callback(static_func0<T>));
Callback<T()> cb(static_func0);
@ -225,21 +400,22 @@ void test_dispatch0() {
Verifier<T>::verify0(cb);
cb.attach(&bound_func0<T>, &thing);
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>
void test_dispatch1() {
void test_dispatch1()
{
Thing<T> thing;
Verifier<T>::verify1(static_func1<T>);
Verifier<T>::verify1(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func1);
Verifier<T>::verify1(&bound_func1<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(&const_volatile_func1<T>, (const volatile 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(&const_volatile_func1<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify1(callback(static_func1<T>));
Callback<T(T)> cb(static_func1);
@ -248,21 +424,22 @@ void test_dispatch1() {
Verifier<T>::verify1(cb);
cb.attach(&bound_func1<T>, &thing);
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>
void test_dispatch2() {
void test_dispatch2()
{
Thing<T> thing;
Verifier<T>::verify2(static_func2<T>);
Verifier<T>::verify2(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func2);
Verifier<T>::verify2(&bound_func2<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(&const_volatile_func2<T>, (const volatile 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(&const_volatile_func2<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify2(callback(static_func2<T>));
Callback<T(T, T)> cb(static_func2);
@ -271,21 +448,22 @@ void test_dispatch2() {
Verifier<T>::verify2(cb);
cb.attach(&bound_func2<T>, &thing);
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>
void test_dispatch3() {
void test_dispatch3()
{
Thing<T> thing;
Verifier<T>::verify3(static_func3<T>);
Verifier<T>::verify3(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func3);
Verifier<T>::verify3(&bound_func3<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(&const_volatile_func3<T>, (const volatile 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(&const_volatile_func3<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify3(callback(static_func3<T>));
Callback<T(T, T, T)> cb(static_func3);
@ -294,21 +472,22 @@ void test_dispatch3() {
Verifier<T>::verify3(cb);
cb.attach(&bound_func3<T>, &thing);
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>
void test_dispatch4() {
void test_dispatch4()
{
Thing<T> thing;
Verifier<T>::verify4(static_func4<T>);
Verifier<T>::verify4(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func4);
Verifier<T>::verify4(&bound_func4<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(&const_volatile_func4<T>, (const volatile 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(&const_volatile_func4<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify4(callback(static_func4<T>));
Callback<T(T, T, T, T)> cb(static_func4);
@ -317,21 +496,22 @@ void test_dispatch4() {
Verifier<T>::verify4(cb);
cb.attach(&bound_func4<T>, &thing);
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>
void test_dispatch5() {
void test_dispatch5()
{
Thing<T> thing;
Verifier<T>::verify5(static_func5<T>);
Verifier<T>::verify5(&thing, &Thing<T>::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((const volatile Thing<T>*)&thing, &Thing<T>::const_volatile_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((const volatile Thing<T> *)&thing, &Thing<T>::const_volatile_member_func5);
Verifier<T>::verify5(&bound_func5<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(&const_volatile_func5<T>, (const volatile 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(&const_volatile_func5<T>, (const volatile Thing<T> *)&thing);
Verifier<T>::verify5(callback(static_func5<T>));
Callback<T(T, T, T, T, T)> cb(static_func5);
@ -340,12 +520,13 @@ void test_dispatch5() {
Verifier<T>::verify5(cb);
cb.attach(&bound_func5<T>, &thing);
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
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");
return verbose_test_setup_handler(number_of_cases);
}
@ -361,6 +542,7 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -24,22 +24,34 @@ using namespace utest::v1;
// static functions
template <typename T>
T static_func0()
{ return 0; }
{
return 0;
}
template <typename T>
T static_func1(T a0)
{ return 0 | a0; }
{
return 0 | a0;
}
template <typename T>
T static_func2(T a0, T a1)
{ return 0 | a0 | a1; }
{
return 0 | a0 | a1;
}
template <typename T>
T static_func3(T a0, T a1, T a2)
{ return 0 | a0 | a1 | a2; }
{
return 0 | a0 | a1 | a2;
}
template <typename T>
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>
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
template <typename T>
@ -48,277 +60,433 @@ struct Thing {
Thing() : t(0x80) {}
T member_func0()
{ return t; }
{
return t;
}
T member_func1(T a0)
{ return t | a0; }
{
return t | a0;
}
T member_func2(T a0, T a1)
{ return t | a0 | a1; }
{
return t | a0 | a1;
}
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)
{ 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)
{ return t | a0 | a1 | a2 | a3 | a4; }
{
return t | a0 | a1 | a2 | a3 | a4;
}
T const_member_func0() const
{ return t; }
{
return t;
}
T const_member_func1(T a0) const
{ return t | a0; }
{
return t | a0;
}
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
{ return t | a0 | a1 | a2; }
{
return t | a0 | a1 | a2;
}
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
{ return t | a0 | a1 | a2 | a3 | a4; }
{
return t | a0 | a1 | a2 | a3 | a4;
}
T volatile_member_func0() volatile
{ return t; }
{
return t;
}
T volatile_member_func1(T a0) volatile
{ return t | a0; }
{
return t | a0;
}
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
{ return t | a0 | a1 | a2; }
{
return t | a0 | a1 | a2;
}
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
{ return t | a0 | a1 | a2 | a3 | a4; }
{
return t | a0 | a1 | a2 | a3 | a4;
}
T const_volatile_member_func0() const volatile
{ return t; }
{
return t;
}
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
{ return t | a0 | a1; }
{
return t | a0 | a1;
}
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
{ 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
{ return t | a0 | a1 | a2 | a3 | a4; }
{
return t | a0 | a1 | a2 | a3 | a4;
}
};
// bound functions
template <typename T>
T bound_func0(Thing<T> *t)
{ return t->t; }
{
return t->t;
}
template <typename T>
T bound_func1(Thing<T> *t, T a0)
{ return t->t | a0; }
{
return t->t | a0;
}
template <typename T>
T bound_func2(Thing<T> *t, T a0, T a1)
{ return t->t | a0 | a1; }
{
return t->t | a0 | a1;
}
template <typename T>
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>
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>
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>
T const_bound_func0(const Thing<T> *t)
{ return t->t; }
{
return t->t;
}
template <typename T>
T const_bound_func1(const Thing<T> *t, T a0)
{ return t->t | a0; }
{
return t->t | a0;
}
template <typename T>
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>
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>
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>
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>
T volatile_bound_func0(volatile Thing<T> *t)
{ return t->t; }
{
return t->t;
}
template <typename T>
T volatile_bound_func1(volatile Thing<T> *t, T a0)
{ return t->t | a0; }
{
return t->t | a0;
}
template <typename T>
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>
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>
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>
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>
T const_volatile_bound_func0(const volatile Thing<T> *t)
{ return t->t; }
{
return t->t;
}
template <typename T>
T const_volatile_bound_func1(const volatile Thing<T> *t, T a0)
{ return t->t | a0; }
{
return t->t | a0;
}
template <typename T>
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>
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>
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>
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
template <typename T>
T void_func0(void *t)
{ return static_cast<Thing<T>*>(t)->t; }
{
return static_cast<Thing<T>*>(t)->t;
}
template <typename T>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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
template <typename T>
struct Verifier {
static void verify0(Callback<T()> func) {
static void verify0(Callback<T()> func)
{
T result = func();
TEST_ASSERT_EQUAL(result, 0x00);
}
template <typename O, typename M>
static void verify0(O *obj, M method) {
static void verify0(O *obj, M method)
{
Callback<T()> func(obj, method);
T result = func();
TEST_ASSERT_EQUAL(result, 0x80);
}
static void verify1(Callback<T(T)> func) {
static void verify1(Callback<T(T)> func)
{
T result = func((1 << 0));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3));
}
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);
T result = func((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));
TEST_ASSERT_EQUAL(result, 0x00 | (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4));
}
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);
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));
@ -328,24 +496,27 @@ struct Verifier {
// test dispatch
template <typename T>
void test_fparg1() {
void test_fparg1()
{
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.get_function());
}
template <typename T>
void test_fparg0() {
void test_fparg0()
{
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.get_function());
}
// 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");
return verbose_test_setup_handler(number_of_cases);
}
@ -357,6 +528,7 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -59,7 +59,7 @@ extern "C" {
using namespace utest::v1;
volatile int intFlag = 0;
const ticker_interface_t* intf;
const ticker_interface_t *intf;
ticker_irq_handler_type prev_irq_handler;
/* 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
@ -67,7 +67,7 @@ ticker_irq_handler_type prev_irq_handler;
* 1. Lower CPU clock
* 2. Compiled code with worse performance
* 3. Interrupt at that time
*
*
* We fix it by checking small ticker value range rather than one exact ticker point
* in near overflow check.
*/
@ -81,7 +81,7 @@ uint32_t count_ticks(uint32_t cycles, uint32_t step)
{
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);
core_util_critical_section_enter();
@ -120,7 +120,7 @@ void overflow_protect()
}
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);
@ -131,7 +131,7 @@ void overflow_protect()
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()) {
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>
* 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 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
@ -201,7 +201,7 @@ void ticker_init_test()
/* Test that ticker frequency is non-zero and counter is at least 8 bits */
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->bits >= 8);
@ -313,7 +313,7 @@ void ticker_fire_now_test(void)
/* Test that the ticker correctly handles overflow. */
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 will perform this test only if this time is no longer than 30 sec.
@ -331,7 +331,7 @@ void ticker_overflow_test(void)
/* Wait for max count. */
while (intf->read() >= (max_count - ticker_overflow_delta2) &&
intf->read() <= (max_count - ticker_overflow_delta1)) {
intf->read() <= (max_count - ticker_overflow_delta1)) {
/* Just wait. */
}
@ -368,7 +368,7 @@ void ticker_overflow_test(void)
/* Test that the ticker increments by one on each tick. */
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. */
if (p_ticker_info->frequency <= 250000) { // low frequency tickers
@ -408,7 +408,7 @@ void ticker_increment_test(void)
} else {
/* Check if we got 1 tick diff. */
if (next_tick_count - base_tick_count == 1 ||
base_tick_count - next_tick_count == 1) {
base_tick_count - next_tick_count == 1) {
break;
}
@ -439,13 +439,13 @@ void ticker_speed_test(void)
uint32_t start;
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
* we need to use other one if available.
*/
#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);
#endif
@ -522,7 +522,7 @@ void ticker_free_interrupt_test(void)
uint32_t cycles_500_ticks = 50;
uint32_t reference_ticks_count = 0;
while(reference_ticks_count < TICKER_500_TICKS) {
while (reference_ticks_count < TICKER_500_TICKS) {
cycles_500_ticks *= 2;
const uint32_t start = intf->read();
wait_cycles(cycles_500_ticks);
@ -579,8 +579,8 @@ utest::v1::status_t us_ticker_setup(const Case *const source, const size_t index
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,
const failure_t reason)
utest::v1::status_t us_ticker_teardown(const Case *const source, const size_t passed, const size_t failed,
const failure_t reason)
{
set_us_ticker_irq_handler(prev_irq_handler);
@ -608,8 +608,8 @@ utest::v1::status_t lp_ticker_setup(const Case *const source, const size_t index
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,
const failure_t reason)
utest::v1::status_t lp_ticker_teardown(const Case *const source, const size_t passed, const size_t failed,
const failure_t reason)
{
set_lp_ticker_irq_handler(prev_irq_handler);

View File

@ -37,7 +37,7 @@
using namespace utest::v1;
const ticker_interface_t* intf;
const ticker_interface_t *intf;
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);
}
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()) {
us_ticker_clear_interrupt();
@ -99,12 +99,12 @@ void ticker_frequency_test()
/* Get the results from host. */
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();
}
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;
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
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;
set_lp_ticker_irq_handler(ticker_event_handler_stub);
@ -120,8 +120,8 @@ utest::v1::status_t lp_ticker_case_setup_handler_t(const Case * const source, co
}
#endif
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)
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)
{
return greentea_case_teardown_handler(source, passed, failed, reason);
}
@ -129,12 +129,12 @@ utest::v1::status_t ticker_case_teardown_handler_t(const Case * const source, co
// Test cases
Case cases[] = {
Case("Microsecond ticker frequency test", us_ticker_case_setup_handler_t, ticker_frequency_test,
ticker_case_teardown_handler_t),
ticker_case_teardown_handler_t),
#if DEVICE_LPTICKER
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
};
};
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";
typedef struct
{
typedef struct {
const crc_mbed_config config_data;
uint32_t expected_result;
@ -72,7 +71,7 @@ void crc_calc_single_test()
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((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();
TEST_ASSERT_EQUAL(test_cases[i].expected_result, crc);
@ -89,14 +88,14 @@ void crc_calc_multi_test()
const uint32_t first_part_bytes = 3;
const uint32_t second_part_bytes = 1;
const uint32_t third_part_bytes = strlen((const char*) input_data) - first_part_bytes
- second_part_bytes;
const uint32_t third_part_bytes = strlen((const char *) input_data) - first_part_bytes
- second_part_bytes;
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), second_part_bytes);
hal_crc_compute_partial((uint8_t*) (input_data + first_part_bytes + second_part_bytes),
third_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),
third_part_bytes);
const uint32_t crc = hal_crc_get_result();
TEST_ASSERT_EQUAL(test_cases[i].expected_result, crc);
@ -137,7 +136,7 @@ void crc_reconfigure_test()
/* 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((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. */
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. */
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();
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);
/* 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*) input_data, 0);
hal_crc_compute_partial((uint8_t *) NULL, strlen((const char *) input_data));
hal_crc_compute_partial((uint8_t *) input_data, 0);
/* Now use valid parameters. */
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));
crc = hal_crc_get_result();
@ -206,73 +205,75 @@ Specification specification(greentea_test_setup, cases, greentea_test_teardown_h
int main()
{
// *INDENT-OFF*
TEST_CASE local_test_cases[] = {
/* Predefined polynomials. */
/* 00 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x00000000, false, false}, 0xEA },
/* 01 */{ {POLY_7BIT_SD , 7, 0x0000007F, 0x00000000, false, false}, 0xA0 },
/* 02 */{ {POLY_7BIT_SD , 7, 0x0000002B, 0x00000000, false, false}, 0x74 },
/* 03 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x0000007F, false, false}, 0x95 },
/* 04 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x0000002B, false, false}, 0xC1 },
/* 05 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x00000000, true , false}, 0xA4 },
/* 06 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x00000000, false, true }, 0x57 },
/* 00 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x00000000, false, false}, 0xEA },
/* 01 */{ {POLY_7BIT_SD , 7, 0x0000007F, 0x00000000, false, false}, 0xA0 },
/* 02 */{ {POLY_7BIT_SD , 7, 0x0000002B, 0x00000000, false, false}, 0x74 },
/* 03 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x0000007F, false, false}, 0x95 },
/* 04 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x0000002B, false, false}, 0xC1 },
/* 05 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x00000000, true , false}, 0xA4 },
/* 06 */{ {POLY_7BIT_SD , 7, 0x00000000, 0x00000000, false, true }, 0x57 },
/* 07 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x00000000, false, false}, 0xF4 },
/* 08 */{ {POLY_8BIT_CCITT , 8, 0x000000FF, 0x00000000, false, false}, 0xFB },
/* 09 */{ {POLY_8BIT_CCITT , 8, 0x000000AB, 0x00000000, false, false}, 0x87 },
/* 10 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x000000FF, false, false}, 0x0B },
/* 11 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x000000AB, false, false}, 0x5F },
/* 12 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x00000000, true , false}, 0x04 },
/* 13 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x00000000, false, true }, 0x2F },
/* 07 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x00000000, false, false}, 0xF4 },
/* 08 */{ {POLY_8BIT_CCITT , 8, 0x000000FF, 0x00000000, false, false}, 0xFB },
/* 09 */{ {POLY_8BIT_CCITT , 8, 0x000000AB, 0x00000000, false, false}, 0x87 },
/* 10 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x000000FF, false, false}, 0x0B },
/* 11 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x000000AB, false, false}, 0x5F },
/* 12 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x00000000, true , false}, 0x04 },
/* 13 */{ {POLY_8BIT_CCITT , 8, 0x00000000, 0x00000000, false, true }, 0x2F },
/* 14 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x00000000, false, false}, 0x31C3 },
/* 15 */{ {POLY_16BIT_CCITT , 16, 0x0000FFFF, 0x00000000, false, false}, 0x29B1 },
/* 16 */{ {POLY_16BIT_CCITT , 16, 0x0000ABAB, 0x00000000, false, false}, 0x7D70 },
/* 17 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x0000FFFF, false, false}, 0xCE3C },
/* 18 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x0000ABAB, false, false}, 0x9A68 },
/* 19 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x00000000, true , false}, 0x9184 },
/* 20 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x00000000, false, true }, 0xC38C },
/* 14 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x00000000, false, false}, 0x31C3 },
/* 15 */{ {POLY_16BIT_CCITT , 16, 0x0000FFFF, 0x00000000, false, false}, 0x29B1 },
/* 16 */{ {POLY_16BIT_CCITT , 16, 0x0000ABAB, 0x00000000, false, false}, 0x7D70 },
/* 17 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x0000FFFF, false, false}, 0xCE3C },
/* 18 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x0000ABAB, false, false}, 0x9A68 },
/* 19 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x00000000, true , false}, 0x9184 },
/* 20 */{ {POLY_16BIT_CCITT , 16, 0x00000000, 0x00000000, false, true }, 0xC38C },
/* 21 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x00000000, false, false}, 0xFEE8 },
/* 22 */{ {POLY_16BIT_IBM , 16, 0x0000FFFF, 0x00000000, false, false}, 0xAEE7 },
/* 23 */{ {POLY_16BIT_IBM , 16, 0x0000ABAB, 0x00000000, false, false}, 0x0887 },
/* 24 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x0000FFFF, false, false}, 0x0117 },
/* 25 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x0000ABAB, false, false}, 0x5543 },
/* 26 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x00000000, true , false}, 0xBCDD },
/* 27 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x00000000, false, true }, 0x177F },
/* 21 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x00000000, false, false}, 0xFEE8 },
/* 22 */{ {POLY_16BIT_IBM , 16, 0x0000FFFF, 0x00000000, false, false}, 0xAEE7 },
/* 23 */{ {POLY_16BIT_IBM , 16, 0x0000ABAB, 0x00000000, false, false}, 0x0887 },
/* 24 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x0000FFFF, false, false}, 0x0117 },
/* 25 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x0000ABAB, false, false}, 0x5543 },
/* 26 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x00000000, true , false}, 0xBCDD },
/* 27 */{ {POLY_16BIT_IBM , 16, 0x00000000, 0x00000000, false, true }, 0x177F },
/* 28 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0x00000000, false, false}, 0x89A1897F },
/* 29 */{ {POLY_32BIT_ANSI , 32, 0xFFFFFFFF, 0x00000000, false, false}, 0x0376E6E7 },
/* 30 */{ {POLY_32BIT_ANSI , 32, 0xABABABAB, 0x00000000, false, false}, 0x871A2FAA },
/* 31 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0xFFFFFFFF, false, false}, 0x765E7680 },
/* 32 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0xABABABAB, false, false}, 0x220A22D4 },
/* 33 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0x00000000, true , false}, 0x11B4BFB4 },
/* 34 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0x00000000, false, true }, 0xFE918591 },
/* 28 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0x00000000, false, false}, 0x89A1897F },
/* 29 */{ {POLY_32BIT_ANSI , 32, 0xFFFFFFFF, 0x00000000, false, false}, 0x0376E6E7 },
/* 30 */{ {POLY_32BIT_ANSI , 32, 0xABABABAB, 0x00000000, false, false}, 0x871A2FAA },
/* 31 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0xFFFFFFFF, false, false}, 0x765E7680 },
/* 32 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0xABABABAB, false, false}, 0x220A22D4 },
/* 33 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0x00000000, true , false}, 0x11B4BFB4 },
/* 34 */{ {POLY_32BIT_ANSI , 32, 0x00000000, 0x00000000, false, true }, 0xFE918591 },
/* Not-predefined polynomials. */
/* 35 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x00000000, false, false}, 0xA2 },
/* 36 */{ {POLY_8BIT_MAXIM , 8, 0x000000FF, 0x00000000, false, false}, 0xF7 },
/* 37 */{ {POLY_8BIT_MAXIM , 8, 0x000000AB, 0x00000000, false, false}, 0x71 },
/* 38 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x000000FF, false, false}, 0x5D },
/* 39 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x000000AB, false, false}, 0x09 },
/* 40 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x00000000, true , false}, 0x85 },
/* 41 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x00000000, false, true }, 0x45 },
/* Not-predefined polynomials. */
/* 35 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x00000000, false, false}, 0xA2 },
/* 36 */{ {POLY_8BIT_MAXIM , 8, 0x000000FF, 0x00000000, false, false}, 0xF7 },
/* 37 */{ {POLY_8BIT_MAXIM , 8, 0x000000AB, 0x00000000, false, false}, 0x71 },
/* 38 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x000000FF, false, false}, 0x5D },
/* 39 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x000000AB, false, false}, 0x09 },
/* 40 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x00000000, true , false}, 0x85 },
/* 41 */{ {POLY_8BIT_MAXIM , 8, 0x00000000, 0x00000000, false, true }, 0x45 },
/* 42 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x00000000, false, false}, 0xFEE8 },
/* 43 */{ {POLY_16BIT_MAXIM , 16, 0x0000FFFF, 0x00000000, false, false}, 0xAEE7 },
/* 44 */{ {POLY_16BIT_MAXIM , 16, 0x0000ABAB, 0x00000000, false, false}, 0x0887 },
/* 45 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x0000FFFF, false, false}, 0x0117 },
/* 46 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x0000ABAB, false, false}, 0x5543 },
/* 47 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x00000000, true , false}, 0xBCDD },
/* 48 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x00000000, false, true }, 0x177F },
/* 42 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x00000000, false, false}, 0xFEE8 },
/* 43 */{ {POLY_16BIT_MAXIM , 16, 0x0000FFFF, 0x00000000, false, false}, 0xAEE7 },
/* 44 */{ {POLY_16BIT_MAXIM , 16, 0x0000ABAB, 0x00000000, false, false}, 0x0887 },
/* 45 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x0000FFFF, false, false}, 0x0117 },
/* 46 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x0000ABAB, false, false}, 0x5543 },
/* 47 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x00000000, true , false}, 0xBCDD },
/* 48 */{ {POLY_16BIT_MAXIM , 16, 0x00000000, 0x00000000, false, true }, 0x177F },
/* 49 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0x00000000, false, false}, 0x89A1897F },
/* 50 */{ {POLY_32BIT_POSIX , 32, 0xFFFFFFFF, 0x00000000, false, false}, 0x0376E6E7 },
/* 51 */{ {POLY_32BIT_POSIX , 32, 0xABABABAB, 0x00000000, false, false}, 0x871A2FAA },
/* 52 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0xFFFFFFFF, false, false}, 0x765E7680 },
/* 53 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0xABABABAB, false, false}, 0x220A22D4 },
/* 54 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0x00000000, true , false}, 0x11B4BFB4 },
/* 55 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0x00000000, false, true }, 0xFE918591 },
/* 49 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0x00000000, false, false}, 0x89A1897F },
/* 50 */{ {POLY_32BIT_POSIX , 32, 0xFFFFFFFF, 0x00000000, false, false}, 0x0376E6E7 },
/* 51 */{ {POLY_32BIT_POSIX , 32, 0xABABABAB, 0x00000000, false, false}, 0x871A2FAA },
/* 52 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0xFFFFFFFF, false, false}, 0x765E7680 },
/* 53 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0xABABABAB, false, false}, 0x220A22D4 },
/* 54 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0x00000000, true , false}, 0x11B4BFB4 },
/* 55 */{ {POLY_32BIT_POSIX , 32, 0x00000000, 0x00000000, false, true }, 0xFE918591 },
};
// *INDENT-ON*
test_cases = local_test_cases;
test_cases_size = sizeof(local_test_cases);

View File

@ -31,11 +31,11 @@ bool test_are_interrupts_enabled(void)
// NRF5x targets don't disable interrupts when in critical section, instead they mask application interrupts this is due to BLE stack
// (BLE to be operational requires some interrupts to be always enabled)
#if defined(TARGET_NRF52)
// check if APP interrupts are masked for NRF52 boards
return (((NVIC->ISER[0] & __NRF_NVIC_APP_IRQS_0) != 0) || ((NVIC->ISER[1] & __NRF_NVIC_APP_IRQS_1) != 0));
// check if APP interrupts are masked for NRF52 boards
return (((NVIC->ISER[0] & __NRF_NVIC_APP_IRQS_0) != 0) || ((NVIC->ISER[1] & __NRF_NVIC_APP_IRQS_1) != 0));
#elif defined(TARGET_NRF51)
// check if APP interrupts are masked for other NRF51 boards
return ((NVIC->ISER[0] & __NRF_NVIC_APP_IRQS_0) != 0);
// check if APP interrupts are masked for other NRF51 boards
return ((NVIC->ISER[0] & __NRF_NVIC_APP_IRQS_0) != 0);
#else
#if defined(__CORTEX_A9)
return ((__get_CPSR() & 0x80) == 0);

View File

@ -15,7 +15,7 @@
*/
#if !DEVICE_FLASH
#error [NOT_SUPPORTED] Flash API not supported for this target
#error [NOT_SUPPORTED] Flash API not supported for this target
#endif
#include "utest/utest.h"
@ -57,40 +57,43 @@ static void erase_range(flash_t *flash, uint32_t addr, uint32_t size)
MBED_NOINLINE
__asm static void delay_loop(uint32_t count)
{
// AStyle should not format inline assembly
// *INDENT-OFF*
1
SUBS a1, a1, #1
BCS %BT1
BX lr
// *INDENT-ON*
}
#elif defined (__ICCARM__)
MBED_NOINLINE
static void delay_loop(uint32_t count)
{
__asm volatile(
"loop: \n"
" SUBS %0, %0, #1 \n"
" BCS.n loop\n"
: "+r" (count)
:
: "cc"
);
__asm volatile(
"loop: \n"
" SUBS %0, %0, #1 \n"
" BCS.n loop\n"
: "+r"(count)
:
: "cc"
);
}
#elif defined ( __GNUC__ ) || (defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050))
MBED_NOINLINE
static void delay_loop(uint32_t count)
{
__asm__ volatile (
"%=:\n\t"
__asm__ volatile(
"%=:\n\t"
#if defined(__thumb__) && !defined(__thumb2__) && !defined(__ARMCC_VERSION)
"SUB %0, #1\n\t"
"SUB %0, #1\n\t"
#else
"SUBS %0, %0, #1\n\t"
"SUBS %0, %0, #1\n\t"
#endif
"BCS %=b\n\t"
: "+l" (count)
:
: "cc"
);
"BCS %=b\n\t"
: "+l"(count)
:
: "cc"
);
}
#endif
@ -193,7 +196,7 @@ void flash_program_page_test()
}
// 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
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),
};
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");
return greentea_test_setup_handler(number_of_cases);
}
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
Harness::run(specification);
}

View File

@ -22,7 +22,7 @@
#include "hal/lp_ticker_api.h"
#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
using namespace utest::v1;
@ -74,7 +74,7 @@ void overflow_protect()
time_window = LP_TICKER_OV_LIMIT;
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);
@ -85,7 +85,7 @@ void overflow_protect()
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. */
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. */
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 <= 64000);

View File

@ -15,7 +15,7 @@
*/
#if !DEVICE_RTC
#error [NOT_SUPPORTED] RTC API not supported for this target
#error [NOT_SUPPORTED] RTC API not supported for this target
#endif
#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_10S = 10;
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
volatile bool expired;
@ -49,7 +49,7 @@ void callback(void)
/* Auxiliary function to test if RTC continue counting in
* sleep and deep-sleep modes. */
void rtc_sleep_test_support (bool deepsleep_mode)
void rtc_sleep_test_support(bool deepsleep_mode)
{
LowPowerTimeout timeout;
const uint32_t start = 100;
@ -66,7 +66,7 @@ void rtc_sleep_test_support (bool deepsleep_mode)
rtc_init();
if(deepsleep_mode == false) {
if (deepsleep_mode == false) {
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);
while(!expired) sleep();
while (!expired) {
sleep();
}
const uint32_t stop = rtc_read();
@ -84,7 +86,7 @@ void rtc_sleep_test_support (bool deepsleep_mode)
timeout.detach();
if(deepsleep_mode == false) {
if (deepsleep_mode == false) {
sleep_manager_unlock_deep_sleep();
}
@ -155,10 +157,10 @@ void rtc_glitch_test()
void rtc_range_test()
{
static const uint32_t starts[] = {
0x00000000,
0xEFFFFFFF,
0x00001000,
0x00010000,
0x00000000,
0xEFFFFFFF,
0x00001000,
0x00010000,
};
rtc_init();
@ -182,7 +184,7 @@ void rtc_accuracy_test()
rtc_write(start);
timer1.start();
while(rtc_read() < (start + DELAY_10S)) {
while (rtc_read() < (start + DELAY_10S)) {
/* Just wait. */
}
timer1.stop();

View File

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

View File

@ -73,8 +73,7 @@ void test_is_leap_year()
}
/* Structure to test border values for _rtc_maketime(). */
typedef struct
{
typedef struct {
struct tm timeinfo;
time_t exp_seconds; // if result is false then exp_seconds is irrelevant
bool result;
@ -85,7 +84,7 @@ typedef struct
* Expected range: the 1st of January 1970 at 00:00:00 (seconds: 0) to the 7th of February 2106 at 06:28:15 (seconds: UINT_MAX).
*/
test_mk_time_struct test_mk_time_arr_full[] = {
{{ 0, 0, 0, 1, 0, 70, 0, 0, 0 }, (time_t) 0, true}, // valid lower bound - the 1st of January 1970 at 00:00:00
{{ 0, 0, 0, 1, 0, 70, 0, 0, 0 }, (time_t) 0, true}, // valid lower bound - the 1st of January 1970 at 00:00:00
{{ 59, 59, 23, 31, 11, 59, 0, 0, 0 }, (time_t) 0, false }, // invalid lower bound - the 31st of December 1969 at 23:59:59
{{ 15, 28, 6, 7, 1, 206, 0, 0, 0 }, (time_t)(UINT_MAX), true }, // valid upper bound - the 7th of February 2106 at 06:28:15
@ -98,7 +97,7 @@ test_mk_time_struct test_mk_time_arr_full[] = {
* Expected range: the 1st of January 1970 at 00:00:00 (seconds: 0) to the 6th of February 2106 at 06:28:15 (seconds: UINT_MAX).
*/
test_mk_time_struct test_mk_time_arr_partial[] = {
{{ 0, 0, 0, 1, 0, 70, 0, 0, 0 }, (time_t) 0, true}, // valid lower bound - the 1st of January 1970 at 00:00:00
{{ 0, 0, 0, 1, 0, 70, 0, 0, 0 }, (time_t) 0, true}, // valid lower bound - the 1st of January 1970 at 00:00:00
{{ 59, 59, 23, 31, 11, 59, 0, 0, 0 }, (time_t) 0, false }, // invalid lower bound - the 31st of December 1969 at 23:59:59
{{ 15, 28, 6, 6, 1, 206, 0, 0, 0 }, (time_t)(UINT_MAX), true }, // valid upper bound - the 6th of February 2106 at 06:28:15
@ -152,10 +151,10 @@ void test_mk_time_invalid_param()
time_t seconds;
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_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_4_YEAR_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(&timeinfo, NULL, RTC_FULL_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.
@ -166,24 +165,24 @@ void test_mk_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_4_YEAR_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));
}
utest::v1::status_t teardown_handler_t(const Case * const source, const size_t passed, const size_t failed,
const failure_t reason)
utest::v1::status_t teardown_handler_t(const Case *const source, const size_t passed, const size_t failed,
const failure_t 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;
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;
@ -191,12 +190,12 @@ utest::v1::status_t partial_leap_year_case_setup_handler_t(const Case * const so
}
Case cases[] = {
Case("test is leap year - RTC leap years full support", full_leap_year_case_setup_handler_t, test_is_leap_year, teardown_handler_t),
Case("test is leap year - RTC leap years partial support", partial_leap_year_case_setup_handler_t, test_is_leap_year, teardown_handler_t),
Case("test make time boundary values - RTC leap years full support", full_leap_year_case_setup_handler_t, test_mk_time_boundary, teardown_handler_t),
Case("test make time boundary values - RTC leap years partial support", partial_leap_year_case_setup_handler_t, test_mk_time_boundary, teardown_handler_t),
Case("test make time - invalid param", test_mk_time_invalid_param, teardown_handler_t),
Case("test local time - invalid param", test_local_time_invalid_param, teardown_handler_t),
Case("test is leap year - RTC leap years full support", full_leap_year_case_setup_handler_t, test_is_leap_year, teardown_handler_t),
Case("test is leap year - RTC leap years partial support", partial_leap_year_case_setup_handler_t, test_is_leap_year, teardown_handler_t),
Case("test make time boundary values - RTC leap years full support", full_leap_year_case_setup_handler_t, test_mk_time_boundary, teardown_handler_t),
Case("test make time boundary values - RTC leap years partial support", partial_leap_year_case_setup_handler_t, test_mk_time_boundary, teardown_handler_t),
Case("test make time - invalid param", test_mk_time_invalid_param, teardown_handler_t),
Case("test local time - invalid param", test_local_time_invalid_param, teardown_handler_t),
};
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)

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 timeinfo =
{ seconds, // tm_sec
struct tm timeinfo = {
seconds, // tm_sec
minutes, // tm_min
hours, // tm_hour
day, // tm_mday
@ -61,7 +61,7 @@ struct tm make_time_info(int year, int month, int day, int hours, int minutes, i
0, // tm_wday
0, // tm_yday
0, // tm_isdst
};
};
return timeinfo;
}
@ -79,9 +79,9 @@ struct tm make_time_info(int year, int month, int day, int hours, int minutes, i
void test_case_mktime_localtime()
{
char _key[11] =
{ };
{ };
char _value[128] =
{ };
{ };
size_t years[] = {70, 71, 100, 196, 200, 205};
@ -89,7 +89,7 @@ void test_case_mktime_localtime()
greentea_send_kv("leap_year_setup", rtc_leap_year_support);
/* 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 dayid = 0; dayid < 2; ++dayid) {
@ -100,8 +100,7 @@ void test_case_mktime_localtime()
* day 0 - first,
* day 1 - last
* */
switch (dayid)
{
switch (dayid) {
case 0:
day = 1;
break;
@ -122,7 +121,7 @@ void test_case_mktime_localtime()
}
/* 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;
}
@ -172,30 +171,30 @@ 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;
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;
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,
const failure_t reason)
utest::v1::status_t teardown_handler_t(const Case *const source, const size_t passed, const size_t failed,
const failure_t reason)
{
return greentea_case_teardown_handler(source, passed, failed, reason);
}
// Test 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 partial support", partial_leap_year_case_setup_handler_t, test_case_mktime_localtime, teardown_handler_t),
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 partial support", partial_leap_year_case_setup_handler_t, test_case_mktime_localtime, teardown_handler_t),
};
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)

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)
{
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)
{
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)
@ -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();
}
@ -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. */
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_width = ticker->interface->get_info()->bits;
@ -144,7 +144,7 @@ void sleep_usticker_test()
for (timestamp_t i = 100; i < 1000; i += 100) {
/* note: us_ticker_read() operates on ticks. */
const timestamp_t next_match_timestamp = overflow_protect(us_ticker_read() + us_to_ticks(i, ticker_freq),
ticker_width);
ticker_width);
us_ticker_set_interrupt(next_match_timestamp);
@ -153,8 +153,8 @@ void sleep_usticker_test()
const unsigned int wakeup_timestamp = us_ticker_read();
TEST_ASSERT(
compare_timestamps(us_to_ticks(sleep_mode_delta_us, ticker_freq), ticker_width, next_match_timestamp,
wakeup_timestamp));
compare_timestamps(us_to_ticks(sleep_mode_delta_us, ticker_freq), ticker_width, next_match_timestamp,
wakeup_timestamp));
}
set_us_ticker_irq_handler(us_ticker_irq_handler_org);
@ -169,7 +169,7 @@ void sleep_usticker_test()
* low power ticker interrupt can wake-up target from sleep. */
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_width = ticker->interface->get_info()->bits;
@ -207,8 +207,8 @@ void deepsleep_lpticker_test()
void deepsleep_high_speed_clocks_turned_off_test()
{
const ticker_data_t * us_ticker = get_us_ticker_data();
const ticker_data_t * lp_ticker = get_lp_ticker_data();
const ticker_data_t *us_ticker = get_us_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 lp_ticker_freq = lp_ticker->interface->get_info()->frequency;
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
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);
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);
}
Case cases[] =
{ Case("sleep - source of wake-up - us ticker", sleep_usticker_test, greentea_failure_handler),
Case cases[] = {
Case("sleep - source of wake-up - us ticker", sleep_usticker_test, greentea_failure_handler),
#if DEVICE_LPTICKER
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 - 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),
#endif
};
};
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);

View File

@ -27,7 +27,7 @@ void sleep_manager_deepsleep_counter_test()
{
bool deep_sleep_allowed = sleep_manager_can_deep_sleep();
TEST_ASSERT_TRUE(deep_sleep_allowed);
sleep_manager_lock_deep_sleep();
deep_sleep_allowed = sleep_manager_can_deep_sleep();
TEST_ASSERT_FALSE(deep_sleep_allowed);
@ -37,13 +37,13 @@ void sleep_manager_deepsleep_counter_test()
TEST_ASSERT_TRUE(deep_sleep_allowed);
}
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);
return STATUS_CONTINUE;
}
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");
return greentea_test_setup_handler(number_of_cases);
@ -55,6 +55,7 @@ Case cases[] = {
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
Harness::run(specification);
}

View File

@ -23,7 +23,7 @@
#endif
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
using namespace utest::v1;
@ -87,7 +87,7 @@ void sleep_manager_irq_test()
TEST_ASSERT_TRUE_MESSAGE(deep_sleep_allowed, "Deep sleep should be allowed");
}
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, "default_auto");
return greentea_test_setup_handler(number_of_cases);
@ -100,6 +100,7 @@ Case cases[] = {
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
Harness::run(specification);
}

File diff suppressed because it is too large Load Diff

View File

@ -29,7 +29,7 @@ using namespace utest::v1;
/* Test that the ticker has the correct frequency and number of bits. */
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 <= 8000000);

View File

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

View File

@ -23,7 +23,7 @@ using utest::v1::Case;
static void dummy_callback(int)
{
/* do nothing. */
/* do nothing. */
}
/** Test Transaction class - creation with initialisation
@ -43,7 +43,7 @@ void test_Transaction_init()
const uint8_t word_width = 8;
unsigned char tx_buffer[tx_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 =
{ 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((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 *)tx_buffer, test_transaction.get_transaction()->tx_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(rx_buffer_size, test_transaction.get_transaction()->rx_length);
TEST_ASSERT_EQUAL(event_id, test_transaction.get_transaction()->event);

View File

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

View File

@ -28,20 +28,20 @@ using utest::v1::Case;
void test_error_count_and_reset()
{
int count = 7;
//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);
}
TEST_ASSERT_EQUAL_INT(count, mbed_get_error_count());
//clear the errors and error count to 0
mbed_clear_all_errors();
//Now the error count should be 0
TEST_ASSERT_EQUAL_INT(0, mbed_get_error_count());
}
/** Test error type encoding and test capturing of system, custom, posix errors
@ -51,67 +51,67 @@ void test_error_capturing()
{
uint32_t error_value = 0xAA11BB22;
mbed_error_ctx error_ctx = {0};
//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();
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_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_WARNING1(error, "Error Serial", 0xAA );
MBED_WARNING1(error, "Error Serial", 0xAA);
lastError = mbed_get_last_error();
TEST_ASSERT_EQUAL_UINT(error, lastError);
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();
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();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_EPERM, lastError);
error = MBED_MAKE_CUSTOM_ERROR(MBED_MODULE_PLATFORM, MBED_ERROR_CODE_CREATE_FAILED);
MBED_WARNING1(error, "Custom Error Type", error_value);
lastError = mbed_get_last_error();
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_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_EQUAL_UINT(error_value, error_ctx.error_value);
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();
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_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_EQUAL_UINT(error_value, error_ctx.error_value);
error_value = 0;
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();
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_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_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();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_MUTEX_LOCK_FAILED, error);
error = mbed_get_first_error();
TEST_ASSERT_EQUAL_UINT(MBED_ERROR_OUT_OF_RESOURCES, error);
}
/** Test error context capture
@ -120,13 +120,13 @@ void test_error_context_capture()
{
uint32_t error_value = 0xABCD;
mbed_error_ctx error_ctx = {0};
MBED_WARNING1(MBED_ERROR_INVALID_ARGUMENT, "System type error", error_value );
mbed_error_status_t status = mbed_get_last_error_info( &error_ctx );
MBED_WARNING1(MBED_ERROR_INVALID_ARGUMENT, "System type error", error_value);
mbed_error_status_t status = mbed_get_last_error_info(&error_ctx);
TEST_ASSERT(status == MBED_SUCCESS);
TEST_ASSERT_EQUAL_UINT(error_value, error_ctx.error_value);
TEST_ASSERT_EQUAL_UINT((uint32_t)osThreadGetId(), error_ctx.thread_id);
//Capture thread info and compare
osRtxThread_t *current_thread = osRtxInfo.thread.run.curr;
TEST_ASSERT_EQUAL_UINT((uint32_t)current_thread->thread_addr, error_ctx.thread_entry_address);
@ -134,7 +134,7 @@ void test_error_context_capture()
TEST_ASSERT_EQUAL_UINT((uint32_t)current_thread->stack_mem, error_ctx.thread_stack_mem);
#if MBED_CONF_PLATFORM_ERROR_FILENAME_CAPTURE_ENABLED
TEST_ASSERT_EQUAL_STRING(MBED_FILENAME, error_ctx.error_filename);
#endif
#endif
}
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED
@ -143,59 +143,59 @@ void test_error_context_capture()
void test_error_logging()
{
mbed_error_ctx error_ctx = {0};
//clear the current errors first
mbed_clear_all_errors();
//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_SIZE, "Invalid size", 2 );
MBED_WARNING1(MBED_ERROR_INVALID_FORMAT, "Invalid format", 3 );
mbed_error_status_t status = mbed_get_error_hist_info( 0, &error_ctx );
MBED_WARNING1(MBED_ERROR_INVALID_ARGUMENT, "Invalid argument", 1);
MBED_WARNING1(MBED_ERROR_INVALID_SIZE, "Invalid size", 2);
MBED_WARNING1(MBED_ERROR_INVALID_FORMAT, "Invalid format", 3);
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(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(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(3, error_ctx.error_value);
//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_SIZE, "Invalid size", 7 );
MBED_WARNING1(MBED_ERROR_INVALID_FORMAT, "Invalid format", 8 );
MBED_WARNING1(MBED_ERROR_NOT_READY, "Not ready error", 9 );
MBED_WARNING1(MBED_ERROR_INVALID_ARGUMENT, "Invalid argument", 6);
MBED_WARNING1(MBED_ERROR_INVALID_SIZE, "Invalid size", 7);
MBED_WARNING1(MBED_ERROR_INVALID_FORMAT, "Invalid format", 8);
MBED_WARNING1(MBED_ERROR_NOT_READY, "Not ready error", 9);
//Last 4 entries
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_UNSUPPORTED, "Not supported", 12 );
MBED_WARNING1(MBED_ERROR_ACCESS_DENIED, "Access denied", 13 );
status = mbed_get_error_hist_info( 0, &error_ctx );
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_UNSUPPORTED, "Not supported", 12);
MBED_WARNING1(MBED_ERROR_ACCESS_DENIED, "Access denied", 13);
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(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(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(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(13, error_ctx.error_value);
//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);
}
#define NUM_TEST_THREADS 5
@ -204,7 +204,7 @@ void test_error_logging()
//Error logger threads
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);
}
@ -219,28 +219,28 @@ void test_error_logging_multithread()
mbed_error_ctx error_ctx = {0};
int i;
Thread *errThread[NUM_TEST_THREADS];
mbed_error_status_t error_status[NUM_TEST_THREADS] = {
MBED_ERROR_INVALID_ARGUMENT, MBED_ERROR_INVALID_DATA_DETECTED, MBED_ERROR_INVALID_FORMAT, MBED_ERROR_INVALID_SIZE, MBED_ERROR_INVALID_OPERATION
mbed_error_status_t error_status[NUM_TEST_THREADS] = {
MBED_ERROR_INVALID_ARGUMENT, MBED_ERROR_INVALID_DATA_DETECTED, MBED_ERROR_INVALID_FORMAT, MBED_ERROR_INVALID_SIZE, MBED_ERROR_INVALID_OPERATION
};
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]->start(callback(err_thread_func, &error_status[i]));
}
wait(2.0);
for(i=0; i<NUM_TEST_THREADS; i++) {
for (i = 0; i < NUM_TEST_THREADS; i++) {
errThread[i]->join();
}
i = mbed_get_error_hist_count()-1;
for(;i>=0;--i) {
mbed_error_status_t status = mbed_get_error_hist_info( i, &error_ctx );
if(status != MBED_SUCCESS) {
i = mbed_get_error_hist_count() - 1;
for (; i >= 0; --i) {
mbed_error_status_t status = mbed_get_error_hist_info(i, &error_ctx);
if (status != MBED_SUCCESS) {
TEST_FAIL();
}
TEST_ASSERT_EQUAL_UINT((unsigned int)error_ctx.error_value, (unsigned int)error_ctx.error_status);
}
}
@ -256,13 +256,13 @@ void MyErrorHook(const mbed_error_ctx *error_ctx)
*/
void test_error_hook()
{
if( MBED_SUCCESS != mbed_set_error_hook(MyErrorHook)) {
if (MBED_SUCCESS != mbed_set_error_hook(MyErrorHook)) {
TEST_FAIL();
}
MBED_WARNING1(MBED_ERROR_INVALID_ARGUMENT, "Test for error hook", 1234);
int32_t sem_status = callback_sem.wait(5000);
TEST_ASSERT(sem_status > 0);
}
@ -301,42 +301,42 @@ MBED_TEST_SIM_BLOCKDEVICE_DECL;
void test_save_error_log()
{
//Log some errors
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_UNSUPPORTED, "Not supported error", 3 );
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_TIME_OUT, "Timeout error", 1);
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_ACCESS_DENIED, "Access denied error", 4);
MBED_WARNING1(MBED_ERROR_ITEM_NOT_FOUND, "Not found error", 5);
int error = 0;
error = MBED_TEST_FILESYSTEM::format(&fd);
if(error < 0) {
if (error < 0) {
TEST_FAIL_MESSAGE("Failed formatting");
}
error = fs.mount(&fd);
if(error < 0) {
if (error < 0) {
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");
}
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");
}
char buff[64] = {0};
while (!feof(error_file)){
int size = fread(&buff[0], 1, 15, error_file);
fwrite(&buff[0], 1, size, stdout);
while (!feof(error_file)) {
int size = fread(&buff[0], 1, 15, error_file);
fwrite(&buff[0], 1, size, stdout);
}
fclose(error_file);
error = fs.unmount();
if(error < 0) {
if (error < 0) {
TEST_FAIL_MESSAGE("Failed unmounting fs");
}
}
@ -356,7 +356,7 @@ Case cases[] = {
Case("Test error context capture", test_error_context_capture),
#endif //MBED_CONF_RTOS_PRESENT
Case("Test error hook", test_error_hook),
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED
#if MBED_CONF_PLATFORM_ERROR_HIST_ENABLED
Case("Test error logging", test_error_logging),
#if MBED_CONF_RTOS_PRESENT
Case("Test error handling multi-threaded", test_error_logging_multithread),

View File

@ -38,7 +38,7 @@ static int32_t wait_time = 5000;
static void busy_thread()
{
volatile uint64_t i = ~0;
while (i--) {
led1 = !led1;
wait_us(wait_time);

View File

@ -23,7 +23,7 @@
#include <stdio.h>
#if !defined(MBED_HEAP_STATS_ENABLED)
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
using namespace utest::v1;
@ -33,12 +33,12 @@ using namespace utest::v1;
#define ALLOCATION_SIZE_LARGE 700
#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_calloc_1(uint32_t size);
static void* thunk_calloc_4(uint32_t size);
static void* thunk_realloc(uint32_t size);
static void *thunk_malloc(uint32_t size);
static void *thunk_calloc_1(uint32_t size);
static void *thunk_calloc_4(uint32_t size);
static void *thunk_realloc(uint32_t size);
malloc_cb_t malloc_thunk_array[] = {
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);
}
static void* thunk_calloc_1(uint32_t size)
static void *thunk_calloc_1(uint32_t size)
{
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);
}
static void* thunk_realloc(uint32_t size)
static void *thunk_realloc(uint32_t 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(osPriorityNormal1, stats[i].priority);
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(osPriorityNormal, stats[i].priority);
}

View File

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

View File

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

View File

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

View File

@ -16,15 +16,17 @@
#include "greentea-client/test_env.h"
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");
mbed_main_called = true;
}
int main() {
int main()
{
GREENTEA_SETUP(5, "default_auto");
printf("MBED: main() starts now!\r\n");
GREENTEA_TESTSUITE_RESULT(mbed_main_called);

View File

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

View File

@ -17,7 +17,8 @@
#include "mbed.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
if (ticks > 0xFFFFFFFF) {
ticks /= 3;
@ -27,16 +28,19 @@ uint32_t test_64(uint64_t ticks) {
return (uint32_t)(0xFFFFFFFF & ticks);
}
const char *result_str(bool result) {
const char *result_str(bool result)
{
return result ? "[OK]" : "[FAIL]";
}
int main() {
int main()
{
GREENTEA_SETUP(5, "default_auto");
bool result = true;
{ // 0xFFFFFFFF * 8 = 0x7fffffff8
{
// 0xFFFFFFFF * 8 = 0x7fffffff8
std::pair<uint32_t, uint64_t> values = std::make_pair(0x55555555, 0x7FFFFFFF8);
uint32_t test_ret = test_64(values.second);
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));
}
{ // 0xFFFFFFFF * 24 = 0x17ffffffe8
{
// 0xFFFFFFFF * 24 = 0x17ffffffe8
std::pair<uint32_t, uint64_t> values = std::make_pair(0xFFFFFFFF, 0x17FFFFFFE8);
uint32_t test_ret = test_64(values.second);
bool test_res = values.first == test_ret;

View File

@ -25,7 +25,8 @@ using namespace utest::v1;
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");
return verbose_test_setup_handler(number_of_cases);
}
@ -36,6 +37,7 @@ Case cases[] = {
Specification specification(test_setup, cases);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -6,34 +6,35 @@
// Test for static asserts in global context
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
"An int must be larger than char");
"An int must be larger than char");
MBED_STATIC_ASSERT(2 + 2 == 4,
"Hopefully the universe is mathematically consistent");
"Hopefully the universe is mathematically consistent");
MBED_STATIC_ASSERT(THE_ANSWER == 42,
"Said Deep Thought, with infinite majesty and calm");
"Said Deep Thought, with infinite majesty and calm");
struct test {
int dummy;
// Test for static asserts in struct context
MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char),
"An int must be larger than char");
"An int must be larger than char");
MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4,
"Hopefully the universe is mathematically consistent");
"Hopefully the universe is mathematically consistent");
MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42,
"Said Deep Thought, with infinite majesty and calm");
"Said Deep Thought, with infinite majesty and calm");
};
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
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
"An int must be larger than char");
"An int must be larger than char");
MBED_STATIC_ASSERT(2 + 2 == 4,
"Hopefully the universe is mathematically consistent");
"Hopefully the universe is mathematically consistent");
MBED_STATIC_ASSERT(THE_ANSWER == 42,
"Said Deep Thought, with infinite majesty and calm");
"Said Deep Thought, with infinite majesty and calm");
}

View File

@ -6,41 +6,42 @@
// Test for static asserts in global context
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
"An int must be larger than char");
"An int must be larger than char");
MBED_STATIC_ASSERT(2 + 2 == 4,
"Hopefully the universe is mathematically consistent");
"Hopefully the universe is mathematically consistent");
MBED_STATIC_ASSERT(THE_ANSWER == 42,
"Said Deep Thought, with infinite majesty and calm");
"Said Deep Thought, with infinite majesty and calm");
struct test {
int dummy;
// Test for static asserts in struct context
MBED_STRUCT_STATIC_ASSERT(sizeof(int) >= sizeof(char),
"An int must be larger than char");
"An int must be larger than char");
MBED_STRUCT_STATIC_ASSERT(2 + 2 == 4,
"Hopefully the universe is mathematically consistent");
"Hopefully the universe is mathematically consistent");
MBED_STRUCT_STATIC_ASSERT(THE_ANSWER == 42,
"Said Deep Thought, with infinite majesty and calm");
"Said Deep Thought, with infinite majesty and calm");
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
"An int must be larger than char");
"An int must be larger than char");
MBED_STATIC_ASSERT(2 + 2 == 4,
"Hopefully the universe is mathematically consistent");
"Hopefully the universe is mathematically consistent");
MBED_STATIC_ASSERT(THE_ANSWER == 42,
"Said Deep Thought, with infinite majesty and calm");
"Said Deep Thought, with infinite majesty and calm");
};
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
MBED_STATIC_ASSERT(sizeof(int) >= sizeof(char),
"An int must be larger than char");
"An int must be larger than char");
MBED_STATIC_ASSERT(2 + 2 == 4,
"Hopefully the universe is mathematically consistent");
"Hopefully the universe is mathematically consistent");
MBED_STATIC_ASSERT(THE_ANSWER == 42,
"Said Deep Thought, with infinite majesty and calm");
"Said Deep Thought, with infinite majesty and calm");
}

View File

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

View File

@ -21,14 +21,12 @@
using namespace utest::v1;
/* Enum used to select block allocation method. */
typedef enum
{
typedef enum {
ALLOC, CALLOC
} AllocType;
/* Structure for complex block type. */
typedef struct
{
typedef struct {
int a;
char b;
int c;
@ -75,7 +73,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_alloc_success(AllocType atype)
{
MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries];
T *p_blocks[numOfEntries];
uint32_t i;
/* 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)
{
MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries];
T *p_blocks[numOfEntries];
uint32_t i;
/* 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)
{
MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries];
T * p_extra_block;
T *p_blocks[numOfEntries];
T *p_extra_block;
uint32_t i;
/* Allocate all available blocks. */
@ -203,7 +201,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_free_success(AllocType atype)
{
MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries];
T *p_blocks[numOfEntries];
uint32_t i;
osStatus status;
@ -243,7 +241,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_free_realloc_last(AllocType atype)
{
MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries];
T *p_blocks[numOfEntries];
uint32_t i;
osStatus status;
@ -299,7 +297,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_free_realloc_last_complex(AllocType atype)
{
MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries];
T *p_blocks[numOfEntries];
uint32_t i;
osStatus status;
@ -355,7 +353,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_free_realloc_first(AllocType atype)
{
MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries];
T *p_blocks[numOfEntries];
uint32_t i;
osStatus status;
@ -411,7 +409,7 @@ template<typename T, const uint32_t numOfEntries>
void test_mem_pool_free_realloc_first_complex(AllocType atype)
{
MemoryPool<T, numOfEntries> mem_pool;
T * p_blocks[numOfEntries];
T *p_blocks[numOfEntries];
uint32_t i;
osStatus status;
@ -462,7 +460,7 @@ void test_mem_pool_free_realloc_first_complex(AllocType atype)
void test_mem_pool_free_on_freed_block()
{
MemoryPool<int, 1> mem_pool;
int * p_block;
int *p_block;
osStatus status;
/* Allocate memory block. */
@ -518,7 +516,7 @@ void free_block_invalid_parameter()
osStatus status;
/* 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. */
TEST_ASSERT_EQUAL(osErrorParameter, status);

View File

@ -24,7 +24,7 @@
#endif
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
using utest::v1::Case;
@ -100,7 +100,7 @@ void test(void)
//get the results from host
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[] = {

View File

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

View File

@ -23,11 +23,11 @@
using utest::v1::Case;
#if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
#if defined(__CORTEX_M23) || defined(__CORTEX_M33)
@ -56,12 +56,13 @@ Semaphore sync_sem(0, 1);
* which aborts test program.
*/
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
void error(const char* format, ...) {
void error(const char *format, ...)
{
(void) format;
}
//Override the set_error function to trap the errors
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
//Override the set_error function to trap the errors
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
return MBED_SUCCESS;
}
@ -278,7 +279,7 @@ void test_multi_thread_any_timeout(void)
EventFlags ef;
uint32_t ret;
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++) {
uint32_t flag = 1 << i;

View File

@ -16,11 +16,11 @@
*/
#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
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
#include <stdio.h>
@ -50,7 +50,7 @@ extern uint32_t mbed_stack_isr_size;
struct linked_list {
linked_list * next;
linked_list *next;
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
*/
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++) {
if (data[i] != fill) {
@ -104,18 +104,18 @@ static void allocate_and_fill_heap(linked_list *&head)
{
linked_list *current;
current = (linked_list*) malloc(sizeof(linked_list));
current = (linked_list *) malloc(sizeof(linked_list));
TEST_ASSERT_NOT_NULL(current);
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
head = current;
while (true) {
// Allocate
linked_list *temp = (linked_list*) malloc(sizeof(linked_list));
linked_list *temp = (linked_list *) malloc(sizeof(linked_list));
if (NULL == temp) {
break;
@ -126,7 +126,7 @@ static void allocate_and_fill_heap(linked_list *&head)
// Init
temp->next = NULL;
memset((void*) temp->data, MALLOC_FILL, sizeof(current->data));
memset((void *) temp->data, MALLOC_FILL, sizeof(current->data));
// Add to list
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)
{
uint32_t total_size = 0;
linked_list * current = head;
linked_list *current = head;
while (current != NULL) {
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");
linked_list * next = current->next;
linked_list *next = current->next;
free(current);
current = next;
}
@ -165,7 +165,7 @@ void test_heap_in_range(void)
char *initial_heap;
// Sanity check malloc
initial_heap = (char*) malloc(1);
initial_heap = (char *) malloc(1);
TEST_ASSERT_NOT_NULL(initial_heap);
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();
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;
// PSP stack should be somewhere in the middle

View File

@ -20,11 +20,11 @@
#include "rtos.h"
#if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
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++) {
osEvent evt = m->get();
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;
// verify thread id
@ -112,7 +112,7 @@ void test_single_thread_order(void)
// mail receive (main thread)
osEvent evt = mail_box.get();
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;
// verify thread id
@ -154,7 +154,7 @@ void test_multi_thread_order(void)
// mail receive (main thread)
osEvent evt = mail_box.get();
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;
// verify thread id
@ -351,13 +351,13 @@ void test_order(void)
evt = mail_box.get();
TEST_ASSERT_EQUAL(evt.status, osEventMail);
mail1 = (int32_t*)evt.value.p;
mail1 = (int32_t *)evt.value.p;
TEST_ASSERT_EQUAL(TEST_VAL1, *mail1);
evt = mail_box.get();
TEST_ASSERT_EQUAL(evt.status, osEventMail);
mail2 = (int32_t*)evt.value.p;
mail2 = (int32_t *)evt.value.p;
TEST_ASSERT_EQUAL(TEST_VAL2, *mail2);
@ -439,7 +439,7 @@ void test_data_type(void)
osEvent evt = mail_box.get();
TEST_ASSERT_EQUAL(evt.status, osEventMail);
mail = (T*)evt.value.p;
mail = (T *)evt.value.p;
TEST_ASSERT_EQUAL(TEST_VAL, *mail);

View File

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

View File

@ -20,11 +20,11 @@
#include "rtos.h"
#if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
using namespace utest::v1;
@ -204,7 +204,7 @@ void test_dual_thread_lock_lock_thread(Mutex *mutex)
osStatus stat = mutex->lock(TEST_DELAY);
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

View File

@ -20,7 +20,7 @@
#include "rtos.h"
#if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
#if !DEVICE_USTICKER
@ -38,7 +38,7 @@ template <uint32_t ms>
void thread_put_uint_msg(Queue<uint32_t, 1> *q)
{
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);
}
@ -61,7 +61,7 @@ void thread_get_uint_msg(Queue<uint32_t, 1> *q)
void test_pass_uint()
{
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);
osEvent evt = q.get();
@ -81,14 +81,14 @@ void test_pass_uint()
void test_pass_uint_twice()
{
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);
osEvent evt = q.get();
TEST_ASSERT_EQUAL(osEventMessage, evt.status);
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);
evt = q.get();
@ -181,10 +181,10 @@ void test_put_full_no_timeout()
{
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);
stat = q.put((uint32_t*) TEST_UINT_MSG);
stat = q.put((uint32_t *) TEST_UINT_MSG);
TEST_ASSERT_EQUAL(osErrorResource, stat);
}
@ -198,13 +198,13 @@ void test_put_full_timeout()
{
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);
Timer timer;
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_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));
osStatus stat = q.put((uint32_t*) TEST_UINT_MSG);
osStatus stat = q.put((uint32_t *) TEST_UINT_MSG);
TEST_ASSERT_EQUAL(osOK, stat);
Timer timer;
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_UINT32_WITHIN(TEST_TIMEOUT * 100, TEST_TIMEOUT * 1000, timer.read_us());
@ -246,10 +246,10 @@ void test_msg_order()
{
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);
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);
osEvent evt = q.get();
@ -271,10 +271,10 @@ void test_msg_prio()
{
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);
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);
osEvent evt = q.get();
@ -298,7 +298,7 @@ void test_queue_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());
}
@ -315,7 +315,7 @@ void test_queue_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());
}

View File

@ -31,7 +31,7 @@ using namespace utest::v1;
#endif
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
class Stopwatch: public Timer {
@ -40,7 +40,7 @@ private:
public:
Stopwatch() :
Timer(), _sem(1)
Timer(), _sem(1)
{
}
@ -85,12 +85,12 @@ void sem_callback(Semaphore *sem)
* which aborts test program.
*/
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
void error(const char* format, ...)
void error(const char *format, ...)
{
(void) format;
}
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
return MBED_SUCCESS;
}

View File

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

View File

@ -21,11 +21,11 @@
using utest::v1::Case;
#if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
#define TEST_STACK_SIZE 512
@ -55,11 +55,12 @@ struct Sync {
* which aborts test program.
*/
#if defined(MBED_TRAP_ERRORS_ENABLED) && MBED_TRAP_ERRORS_ENABLED
void error(const char* format, ...) {
void error(const char *format, ...)
{
(void) format;
}
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
mbed_error_status_t mbed_error(mbed_error_status_t error_status, const char *error_msg, unsigned int error_value, const char *filename, int line_number)
{
return MBED_SUCCESS;
}
@ -364,7 +365,7 @@ void test_set_double(void)
Semaphore sem(0, 1);
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();
TEST_ASSERT_EQUAL(Thread::WaitingThreadFlag, t.get_state());

View File

@ -53,12 +53,12 @@ private:
public:
SysTimerTest() :
SysTimer(), _sem(0, 1)
SysTimer(), _sem(0, 1)
{
}
SysTimerTest(const ticker_data_t *data) :
SysTimer(data), _sem(0, 1)
SysTimer(data), _sem(0, 1)
{
}

View File

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

View File

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

View File

@ -22,11 +22,11 @@
#include "LockGuard.h"
#if defined(MBED_RTOS_SINGLE_THREAD)
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
#if !DEVICE_USTICKER
#error [NOT_SUPPORTED] test not supported
#error [NOT_SUPPORTED] test not supported
#endif
#define THREAD_STACK_SIZE 512
@ -52,28 +52,33 @@ public:
};
// Tasks with different functions to test on threads
void increment(counter_t* counter) {
void increment(counter_t *counter)
{
(*counter)++;
}
void increment_with_yield(counter_t* counter) {
void increment_with_yield(counter_t *counter)
{
Thread::yield();
(*counter)++;
}
void increment_with_wait(counter_t* counter) {
void increment_with_wait(counter_t *counter)
{
Thread::wait(100);
(*counter)++;
}
void increment_with_child(counter_t* counter) {
void increment_with_child(counter_t *counter)
{
Thread *child = new Thread(osPriorityNormal, CHILD_THREAD_STACK_SIZE);
child->start(callback(increment, counter));
child->join();
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
// modify counter.
@ -87,7 +92,8 @@ void increment_with_murder(counter_t* counter) {
(*counter)++;
}
void self_terminate(Thread *self) {
void self_terminate(Thread *self)
{
self->terminate();
// Code should not get here
TEST_ASSERT(0);
@ -126,7 +132,8 @@ void self_terminate(Thread *self) {
then the final value of the counter is equal to 1
*/
template <void (*F)(counter_t *)>
void test_single_thread() {
void test_single_thread()
{
counter_t counter(0);
Thread thread(osPriorityNormal, THREAD_STACK_SIZE);
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
*/
template <int N, void (*F)(counter_t *)>
void test_parallel_threads() {
void test_parallel_threads()
{
counter_t counter(0);
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
*/
template <int N, void (*F)(counter_t *)>
void test_serial_threads() {
void test_serial_threads()
{
counter_t counter(0);
for (int i = 0; i < N; i++) {
@ -229,7 +238,8 @@ void test_serial_threads() {
when the thread calls @a terminate on its self
then the thread terminates execution cleanly
*/
void test_self_terminate() {
void test_self_terminate()
{
Thread *thread = new Thread(osPriorityNormal, THREAD_STACK_SIZE);
thread->start(callback(self_terminate, thread));
thread->join();
@ -336,11 +346,13 @@ void test_thread_signal_clr()
t_wait.join();
}
void thread_wait_signal() {
void thread_wait_signal()
{
Thread::signal_wait(0x1);
}
void stack_info() {
void stack_info()
{
Thread::signal_wait(0x1);
thread_wait_signal();
@ -360,7 +372,8 @@ void stack_info() {
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
*/
void test_thread_stack_info() {
void test_thread_stack_info()
{
Thread t(osPriorityNormal, THREAD_STACK_SIZE);
t.start(callback(stack_info));
@ -394,7 +407,8 @@ void test_thread_stack_info() {
when the @a wait function is called
then the thread sleeps for given amount of time
*/
void test_thread_wait() {
void test_thread_wait()
{
Timer timer;
timer.start();
@ -409,7 +423,8 @@ void test_thread_wait() {
when the name is queried using @a get_name
then the returned name is as set
*/
void test_thread_name() {
void test_thread_name()
{
const char tname[] = "Amazing thread";
Thread t(osPriorityNormal, THREAD_STACK_SIZE, NULL, tname);
t.start(callback(thread_wait_signal));
@ -627,7 +642,8 @@ void test_msg_put()
}
/** Utility function that places some date on the stack */
void use_some_stack () {
void use_some_stack()
{
volatile uint32_t stack_filler[10] = {0xDEADBEEF};
}
@ -637,18 +653,20 @@ void use_some_stack () {
when the thread executes
then the supplies buffer is used as a stack
*/
void test_thread_ext_stack() {
void test_thread_ext_stack()
{
char stack[512];
Thread t(osPriorityNormal, sizeof(stack), (unsigned char*)stack);
Thread t(osPriorityNormal, sizeof(stack), (unsigned char *)stack);
memset(&stack, 0, sizeof(stack));
t.start(callback(use_some_stack));
t.join();
/* 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++) {
if (stack[i] != 0)
for (unsigned i = 0; i < sizeof(stack); i++) {
if (stack[i] != 0) {
return;
}
}
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
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);
t.start(callback(thread_wait_signal));
@ -674,7 +693,8 @@ void test_thread_prio() {
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");
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).
static const case_t cases[] = {
{"Testing single thread", test_single_thread<increment>, DEFAULT_HANDLERS},
{"Testing parallel threads", test_parallel_threads<3, increment> , DEFAULT_HANDLERS},
{"Testing serial threads", test_serial_threads<10, increment> , DEFAULT_HANDLERS},
{"Testing parallel threads", test_parallel_threads<3, 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 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);
int main() {
int main()
{
return !Harness::run(specification);
}

View File

@ -34,65 +34,73 @@ using namespace utest::v1;
#if defined(MBEDTLS_SHA256_C)
/* Tests several call to mbedtls_sha256_update function that are not modulo 64 bytes */
void test_case_sha256_split() {
const unsigned char test_buf[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"};
// sha256_output_values for 3*abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
const unsigned char test_sum[] =
{ 0x50, 0xEA, 0x82, 0x5D, 0x96, 0x84, 0xF4, 0x22,
0x9C, 0xA2, 0x9F, 0x1F, 0xEC, 0x51, 0x15, 0x93,
0xE2, 0x81, 0xE4, 0x6A, 0x14, 0x0D, 0x81, 0xE0,
0x00, 0x5F, 0x8F, 0x68, 0x86, 0x69, 0xA0, 0x6C};
unsigned char outsum[32];
int i;
void test_case_sha256_split()
{
const unsigned char test_buf[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"};
// sha256_output_values for 3*abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
const unsigned char test_sum[] = {
0x50, 0xEA, 0x82, 0x5D, 0x96, 0x84, 0xF4, 0x22,
0x9C, 0xA2, 0x9F, 0x1F, 0xEC, 0x51, 0x15, 0x93,
0xE2, 0x81, 0xE4, 0x6A, 0x14, 0x0D, 0x81, 0xE0,
0x00, 0x5F, 0x8F, 0x68, 0x86, 0x69, 0xA0, 0x6C
};
unsigned char outsum[32];
int i;
mbedtls_sha256_context ctx;
printf("test sha256\n");
mbedtls_sha256_init( &ctx );
mbedtls_sha256_starts( &ctx, 0);
#if 0
mbedtls_sha256_context ctx;
printf("test sha256\n");
mbedtls_sha256_init(&ctx);
mbedtls_sha256_starts(&ctx, 0);
#if 0
printf("test not splitted\n");
mbedtls_sha256_update( &ctx, test_buf, 168 );
#else
mbedtls_sha256_update(&ctx, test_buf, 168);
#else
printf("test splitted into 3 pieces\n");
mbedtls_sha256_update( &ctx, test_buf, 2 );
mbedtls_sha256_update( &ctx, test_buf+2, 66 );
mbedtls_sha256_update( &ctx, test_buf+68, 100 );
#endif
mbedtls_sha256_finish( &ctx, outsum );
mbedtls_sha256_free( &ctx );
mbedtls_sha256_update(&ctx, test_buf, 2);
mbedtls_sha256_update(&ctx, test_buf + 2, 66);
mbedtls_sha256_update(&ctx, test_buf + 68, 100);
#endif
mbedtls_sha256_finish(&ctx, outsum);
mbedtls_sha256_free(&ctx);
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("\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 */
void test_case_sha256_multi() {
void test_case_sha256_multi()
{
const unsigned char test_buf[] = {"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"};
const unsigned char test_buf2[] = {"abcdefghijklmnopqrstuvwxyz012345678901234567890123456789"};
// sha256_output_values for abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
const unsigned char test_sum1[] =
{ 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 };
const unsigned char test_sum1[] = {
0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8,
0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39,
0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67,
0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1
};
// sha256_output_values for 3*abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq
const unsigned char test_sum2[] =
{ 0x50, 0xEA, 0x82, 0x5D, 0x96, 0x84, 0xF4, 0x22,
0x9C, 0xA2, 0x9F, 0x1F, 0xEC, 0x51, 0x15, 0x93,
0xE2, 0x81, 0xE4, 0x6A, 0x14, 0x0D, 0x81, 0xE0,
0x00, 0x5F, 0x8F, 0x68, 0x86, 0x69, 0xA0, 0x6C};
const unsigned char test_sum2[] = {
0x50, 0xEA, 0x82, 0x5D, 0x96, 0x84, 0xF4, 0x22,
0x9C, 0xA2, 0x9F, 0x1F, 0xEC, 0x51, 0x15, 0x93,
0xE2, 0x81, 0xE4, 0x6A, 0x14, 0x0D, 0x81, 0xE0,
0x00, 0x5F, 0x8F, 0x68, 0x86, 0x69, 0xA0, 0x6C
};
// sha256_output_values for abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopqabcdefghijklmnopqrstuvwxyz012345678901234567890123456789
const unsigned char test_sum3[] =
{ 0x6D, 0x5D, 0xDB, 0x5F, 0x4A, 0x94, 0xAB, 0x7E,
0x5C, 0xF7, 0x9A, 0xD8, 0x3F, 0x58, 0xD3, 0x97,
0xFE, 0x79, 0xFB, 0x0D, 0x79, 0xB2, 0x0D, 0x22,
0xFF, 0x95, 0x9F, 0x04, 0xA2, 0xE4, 0x6C, 0x68};
const unsigned char test_sum3[] = {
0x6D, 0x5D, 0xDB, 0x5F, 0x4A, 0x94, 0xAB, 0x7E,
0x5C, 0xF7, 0x9A, 0xD8, 0x3F, 0x58, 0xD3, 0x97,
0xFE, 0x79, 0xFB, 0x0D, 0x79, 0xB2, 0x0D, 0x22,
0xFF, 0x95, 0x9F, 0x04, 0xA2, 0xE4, 0x6C, 0x68
};
unsigned char outsum1[32], outsum2[32], outsum3[32];
int i;
@ -101,55 +109,62 @@ void test_case_sha256_multi() {
mbedtls_sha256_context ctx3;
printf("test sha256_multi\n");
//Init both contexts
mbedtls_sha256_init( &ctx1);
mbedtls_sha256_init( &ctx2);
mbedtls_sha256_init( &ctx3);
mbedtls_sha256_init(&ctx1);
mbedtls_sha256_init(&ctx2);
mbedtls_sha256_init(&ctx3);
//Start both contexts
mbedtls_sha256_starts( &ctx1, 0);
mbedtls_sha256_starts( &ctx2, 0);
mbedtls_sha256_starts(&ctx1, 0);
mbedtls_sha256_starts(&ctx2, 0);
printf("upd ctx1\n");
mbedtls_sha256_update( &ctx1, test_buf, 56 );
mbedtls_sha256_update(&ctx1, test_buf, 56);
printf("upd ctx2\n");
mbedtls_sha256_update( &ctx2, test_buf, 66 );
mbedtls_sha256_update(&ctx2, test_buf, 66);
printf("finish ctx1\n");
mbedtls_sha256_finish( &ctx1, outsum1 );
mbedtls_sha256_finish(&ctx1, outsum1);
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");
mbedtls_sha256_clone(&ctx3, (const mbedtls_sha256_context *)&ctx2);
printf("free ctx1\n");
mbedtls_sha256_free( &ctx1 );
mbedtls_sha256_free(&ctx1);
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");
mbedtls_sha256_update( &ctx3, test_buf2, 56 );
mbedtls_sha256_update(&ctx3, test_buf2, 56);
printf("finish ctx2\n");
mbedtls_sha256_finish( &ctx2, outsum2 );
mbedtls_sha256_finish(&ctx2, outsum2);
printf("finish ctx3\n");
mbedtls_sha256_finish( &ctx3, outsum3 );
mbedtls_sha256_finish(&ctx3, outsum3);
printf("free ctx2\n");
mbedtls_sha256_free( &ctx2 );
mbedtls_sha256_free(&ctx2);
printf("free ctx3\n");
mbedtls_sha256_free( &ctx3 );
mbedtls_sha256_free(&ctx3);
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("\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("\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("\nend of test sha256\n");
TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum1, test_sum1,32);
TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum2, test_sum2,32);
TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum3, test_sum3,32);
TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum1, test_sum1, 32);
TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum2, test_sum2, 32);
TEST_ASSERT_EQUAL_UINT8_ARRAY(outsum3, test_sum3, 32);
}
#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);
return STATUS_CONTINUE;
}
@ -161,19 +176,20 @@ Case cases[] = {
#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");
return greentea_test_setup_handler(number_of_cases);
}
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
int main() {
int main()
{
int ret = 0;
#if defined(MBEDTLS_PLATFORM_C)
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);
return 1;
}

View File

@ -84,19 +84,20 @@ Case cases[] = {
#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");
return verbose_test_setup_handler(num_cases);
}
Specification specification(test_setup, cases);
int main() {
int main()
{
int ret = 0;
#if defined(MBEDTLS_PLATFORM_C)
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);
return 1;
}

View File

@ -29,21 +29,21 @@
using namespace utest::v1;
namespace
{
NetworkInterface* net;
Timer tc_bucket; // Timer to limit a test cases run time
namespace {
NetworkInterface *net;
Timer tc_bucket; // Timer to limit a test cases run time
}
char tcp_global::rx_buffer[RX_BUFF_SIZE];
char tcp_global::tx_buffer[TX_BUFF_SIZE];
NetworkInterface* get_interface()
NetworkInterface *get_interface()
{
return net;
}
void drop_bad_packets(TCPSocket& sock, int orig_timeout) {
void drop_bad_packets(TCPSocket &sock, int orig_timeout)
{
nsapi_error_t err;
sock.set_timeout(0);
while (true) {
@ -55,19 +55,22 @@ void drop_bad_packets(TCPSocket& sock, int orig_timeout) {
sock.set_timeout(orig_timeout);
}
static void _ifup() {
static void _ifup()
{
net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
nsapi_error_t err = MBED_CONF_APP_CONNECT_STATEMENT;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("MBED: TCPClient IP address is '%s'\n", net->get_ip_address());
}
static void _ifdown() {
static void _ifdown()
{
net->disconnect();
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;
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);
}
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket& sock) {
nsapi_error_t tcpsocket_connect_to_discard_srv(TCPSocket &sock)
{
SocketAddress 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)
{
for (size_t i = 0; i<len; ++i) {
for (size_t i = 0; i < len; ++i) {
buff[i] = (rand() % 43) + '0';
}
}
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

View File

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

View File

@ -25,24 +25,25 @@
using namespace utest::v1;
namespace
{
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int BUFF_SIZE = 1200;
static const int PKTS = 22;
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,\
1100,1200};
TCPSocket sock;
Semaphore tx_sem(0, 1);
static const int BUFF_SIZE = 1200;
static const int PKTS = 22;
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, \
1100, 1200
};
TCPSocket sock;
Semaphore tx_sem(0, 1);
Timer tc_exec_time;
int time_allotted;
Timer tc_exec_time;
int time_allotted;
}
static void _sigio_handler(osThreadId id) {
static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO);
}
@ -69,8 +70,8 @@ void TCPSOCKET_ECHOTEST()
int bytes2recv = sent;
while (bytes2recv) {
recvd = sock.recv(&(tcp_global::rx_buffer[sent-bytes2recv]), bytes2recv);
if (recvd < 0) {
recvd = sock.recv(&(tcp_global::rx_buffer[sent - bytes2recv]), bytes2recv);
if (recvd < 0) {
printf("[Round#%02d] network error %d\n", x, recvd);
TEST_FAIL();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());
@ -85,10 +86,10 @@ void TCPSOCKET_ECHOTEST()
void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
{
int bytes2recv = *(int*)receive_bytes;
int bytes2recv = *(int *)receive_bytes;
int recvd;
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 (tc_exec_time.read() >= time_allotted) {
TEST_FAIL();
@ -103,10 +104,10 @@ void tcpsocket_echotest_nonblock_receiver(void *receive_bytes)
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;
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();
@ -140,10 +141,10 @@ void TCPSOCKET_ECHOTEST_NONBLOCK()
bytes2send = pkt_s;
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 (tc_exec_time.read() >= time_allotted ||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
thread->terminate();
delete thread;
TEST_FAIL();

View File

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

View File

@ -25,17 +25,18 @@
using namespace utest::v1;
namespace
{
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
}
static void _sigio_handler(osThreadId id) {
static void _sigio_handler(osThreadId id)
{
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;
get_interface()->gethostbyname(MBED_CONF_APP_ECHO_SERVER_ADDR, &tcp_addr);
@ -68,22 +69,22 @@ void TCPSOCKET_ENDPOINT_CLOSE()
int recvd = 0;
int recvd_total = 0;
while (true) {
recvd = sock.recv(&(buff[recvd_total]), MORE_THAN_AVAILABLE);
if (recvd_total > 0 && recvd == 0) {
break; // Endpoint closed socket, success
} else if (recvd <= 0) {
recvd = sock.recv(&(buff[recvd_total]), MORE_THAN_AVAILABLE);
if (recvd_total > 0 && recvd == 0) {
break; // Endpoint closed socket, success
} else if (recvd <= 0) {
TEST_FAIL();
break;
} else if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if(tc_exec_time.read() >= time_allotted ||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL();
break;
}
continue;
}
recvd_total += recvd;
TEST_ASSERT(recvd_total < MORE_THAN_AVAILABLE);
} else if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted ||
osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
TEST_FAIL();
break;
}
continue;
}
recvd_total += recvd;
TEST_ASSERT(recvd_total < MORE_THAN_AVAILABLE);
}
tc_exec_time.stop();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, sock.close());

View File

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

View File

@ -25,13 +25,12 @@
using namespace utest::v1;
namespace
{
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 20000; //[ms]
namespace {
static const int SIGNAL_SIGIO = 0x1;
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;
@ -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)
{
while (len--) {
if (offset % 74 == 72)
if (offset % 74 == 72) {
*buf++ = '\r';
else if (offset % 74 == 73)
} else if (offset % 74 == 73) {
*buf++ = '\n';
else
*buf++ = ' ' + (offset%74 + offset/74) % 95 ;
} else {
*buf++ = ' ' + (offset % 74 + offset / 74) % 95 ;
}
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);
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;
free(ref_buff);
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 buff_size = 1220;
uint8_t buff[buff_size];
@ -121,7 +122,7 @@ void TCPSOCKET_RECV_100K()
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 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());
}
static void _sigio_handler(osThreadId id) {
static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO);
}

View File

@ -25,13 +25,13 @@
using namespace utest::v1;
namespace
{
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
}
static void _sigio_handler(osThreadId id) {
static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO);
}
@ -58,12 +58,12 @@ void TCPSOCKET_RECV_TIMEOUT()
while (pkt_unrecvd) {
timer.reset();
timer.start();
recvd = sock.recv(&(buff[DATA_LEN-pkt_unrecvd]), pkt_unrecvd);
recvd = sock.recv(&(buff[DATA_LEN - pkt_unrecvd]), pkt_unrecvd);
timer.stop();
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if (tc_exec_time.read() >= time_allotted ||
(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout)) {
(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout)) {
TEST_FAIL();
goto CLEANUP;
}

View File

@ -32,7 +32,7 @@ void TCPSOCKET_SEND_REPEAT()
int snd;
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++) {
snd = sock.send(tx_buffer, sizeof(tx_buffer));
if (snd != sizeof(tx_buffer)) {

View File

@ -35,14 +35,14 @@ void TCPSOCKET_SEND_TIMEOUT()
int err;
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++) {
timer.reset();
timer.start();
err = sock.send(tx_buffer, sizeof(tx_buffer));
timer.stop();
if ((err == sizeof(tx_buffer)) &&
(timer.read_ms() <= 800)) {
(timer.read_ms() <= 800)) {
continue;
}
TEST_FAIL();

View File

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

View File

@ -29,29 +29,31 @@
using namespace utest::v1;
namespace
{
NetworkInterface* net;
namespace {
NetworkInterface *net;
}
NetworkInterface* get_interface()
NetworkInterface *get_interface()
{
return net;
}
static void _ifup() {
static void _ifup()
{
net = MBED_CONF_APP_OBJECT_CONSTRUCTION;
nsapi_error_t err = MBED_CONF_APP_CONNECT_STATEMENT;
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
printf("MBED: UDPClient IP address is '%s'\n", net->get_ip_address());
}
static void _ifdown() {
static void _ifdown()
{
net->disconnect();
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;
sock.set_timeout(0);
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)
{
for (size_t i = 0; i<len; ++i) {
for (size_t i = 0; i < len; ++i) {
buff[i] = (rand() % 43) + '0';
}
}
@ -85,16 +87,16 @@ void greentea_teardown(const size_t passed, const size_t failed, const failure_t
}
Case cases[] = {
Case("UDPSOCKET_ECHOTEST_NONBLOCK", UDPSOCKET_ECHOTEST_NONBLOCK),
Case("UDPSOCKET_OPEN_CLOSE_REPEAT", UDPSOCKET_OPEN_CLOSE_REPEAT),
Case("UDPSOCKET_OPEN_LIMIT", UDPSOCKET_OPEN_LIMIT),
Case("UDPSOCKET_SENDTO_TIMEOUT", UDPSOCKET_SENDTO_TIMEOUT),
Case("UDPSOCKET_ECHOTEST_NONBLOCK", UDPSOCKET_ECHOTEST_NONBLOCK),
Case("UDPSOCKET_OPEN_CLOSE_REPEAT", UDPSOCKET_OPEN_CLOSE_REPEAT),
Case("UDPSOCKET_OPEN_LIMIT", UDPSOCKET_OPEN_LIMIT),
Case("UDPSOCKET_SENDTO_TIMEOUT", UDPSOCKET_SENDTO_TIMEOUT),
#ifdef MBED_EXTENDED_TESTS
Case("UDPSOCKET_SENDTO_INVALID", UDPSOCKET_SENDTO_INVALID),
Case("UDPSOCKET_ECHOTEST", UDPSOCKET_ECHOTEST),
Case("UDPSOCKET_ECHOTEST_BURST", UDPSOCKET_ECHOTEST_BURST),
Case("UDPSOCKET_ECHOTEST_BURST_NONBLOCK", UDPSOCKET_ECHOTEST_BURST_NONBLOCK),
Case("UDPSOCKET_SENDTO_REPEAT", UDPSOCKET_SENDTO_REPEAT),
Case("UDPSOCKET_SENDTO_INVALID", UDPSOCKET_SENDTO_INVALID),
Case("UDPSOCKET_ECHOTEST", UDPSOCKET_ECHOTEST),
Case("UDPSOCKET_ECHOTEST_BURST", UDPSOCKET_ECHOTEST_BURST),
Case("UDPSOCKET_ECHOTEST_BURST_NONBLOCK", UDPSOCKET_ECHOTEST_BURST_NONBLOCK),
Case("UDPSOCKET_SENDTO_REPEAT", UDPSOCKET_SENDTO_REPEAT),
#endif
};

View File

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

View File

@ -25,30 +25,31 @@
using namespace utest::v1;
namespace
{
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int WAIT2RECV_TIMEOUT = 1000; //[ms]
static const int RETRIES = 2;
namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int WAIT2RECV_TIMEOUT = 1000; //[ms]
static const int RETRIES = 2;
static const double EXPECTED_LOSS_RATIO = 0.0;
static const double TOLERATED_LOSS_RATIO = 0.3;
static const double EXPECTED_LOSS_RATIO = 0.0;
static const double TOLERATED_LOSS_RATIO = 0.3;
UDPSocket sock;
Semaphore tx_sem(0, 1);
UDPSocket sock;
Semaphore tx_sem(0, 1);
static const int BUFF_SIZE = 1200;
char rx_buffer[BUFF_SIZE] = {0};
char tx_buffer[BUFF_SIZE] = {0};
static const int BUFF_SIZE = 1200;
char rx_buffer[BUFF_SIZE] = {0};
char tx_buffer[BUFF_SIZE] = {0};
static const int PKTS = 22;
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,\
1100,1200};
static const int PKTS = 22;
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, \
1100, 1200
};
}
static void _sigio_handler(osThreadId id) {
static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO);
}
@ -101,7 +102,7 @@ void UDPSOCKET_ECHOTEST()
void udpsocket_echotest_nonblock_receiver(void *receive_bytes)
{
int expt2recv = *(int*)receive_bytes;
int expt2recv = *(int *)receive_bytes;
int recvd;
for (int retry_cnt = 0; retry_cnt <= RETRIES; retry_cnt++) {
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);
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;
}
break;

View File

@ -25,45 +25,47 @@
using namespace utest::v1;
namespace
{
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int RECV_TIMEOUT = 1; //[s]
namespace {
static const int SIGNAL_SIGIO = 0x1;
static const int SIGIO_TIMEOUT = 5000; //[ms]
static const int RECV_TIMEOUT = 1; //[s]
static const int BURST_CNT = 100;
static const int BURST_PKTS = 5;
static const int PKG_SIZES[BURST_PKTS] = {100, 200, 300, 120, 500};
static const int RECV_TOTAL = 1220;
static const int BURST_CNT = 100;
static const int BURST_PKTS = 5;
static const int PKG_SIZES[BURST_PKTS] = {100, 200, 300, 120, 500};
static const int RECV_TOTAL = 1220;
static const double EXPECTED_LOSS_RATIO = 0.0;
static const double TOLERATED_LOSS_RATIO = 0.3;
static const double EXPECTED_LOSS_RATIO = 0.0;
static const double TOLERATED_LOSS_RATIO = 0.3;
typedef struct pkg {
int len;
char *payload;
} pkg_t;
pkg_t tx_buffers[BURST_PKTS];
char rx_buffer[500] = {0};
typedef struct pkg {
int len;
char *payload;
} pkg_t;
pkg_t tx_buffers[BURST_PKTS];
char rx_buffer[500] = {0};
}
void prepare_tx_buffers() {
void prepare_tx_buffers()
{
// TX buffers to be preserved for comparison
for (int x = 0; x < BURST_PKTS; 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);
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++) {
free(tx_buffers[x].payload);
}
}
static void _sigio_handler(osThreadId id) {
static void _sigio_handler(osThreadId id)
{
osSignalSet(id, SIGNAL_SIGIO);
}
@ -98,12 +100,12 @@ void UDPSOCKET_ECHOTEST_BURST()
for (int j = 0; j < BURST_PKTS; j++) {
recvd = sock.recvfrom(&temp_addr, rx_buffer, 500);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
pkg_fail += BURST_PKTS-j;
if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
pkg_fail += BURST_PKTS - j;
break;
}
} 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);
wait(recv_timeout);
recv_timeout *= 2; // Back off,
@ -114,12 +116,12 @@ void UDPSOCKET_ECHOTEST_BURST()
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
for (int k = 0; k < BURST_PKTS; k++) {
if (tx_buffers[k].len == recvd &&
(memcmp(tx_buffers[k].payload, rx_buffer, recvd) == 0)) {
(memcmp(tx_buffers[k].payload, rx_buffer, recvd) == 0)) {
bt_total += recvd;
}
}
@ -135,13 +137,13 @@ void UDPSOCKET_ECHOTEST_BURST()
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",
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
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio);
// 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());
}
@ -175,8 +177,8 @@ void UDPSOCKET_ECHOTEST_BURST_NONBLOCK()
for (int j = 0; j < BURST_PKTS; j++) {
recvd = sock.recvfrom(&temp_addr, rx_buffer, 500);
if (recvd == NSAPI_ERROR_WOULD_BLOCK) {
if(osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
pkg_fail += BURST_PKTS-j;
if (osSignalWait(SIGNAL_SIGIO, SIGIO_TIMEOUT).status == osEventTimeout) {
pkg_fail += BURST_PKTS - j;
break;
}
--j;
@ -191,7 +193,7 @@ void UDPSOCKET_ECHOTEST_BURST_NONBLOCK()
// Packets might arrive unordered
for (int k = 0; k < BURST_PKTS; k++) {
if (tx_buffers[k].len == recvd &&
(memcmp(tx_buffers[k].payload, rx_buffer, recvd) == 0)) {
(memcmp(tx_buffers[k].payload, rx_buffer, recvd) == 0)) {
bt_total += recvd;
goto PKT_OK;
}
@ -213,13 +215,13 @@ PKT_OK:
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",
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
TEST_ASSERT_DOUBLE_WITHIN(TOLERATED_LOSS_RATIO, EXPECTED_LOSS_RATIO, loss_ratio);
// 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());
}

View File

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

View File

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

View File

@ -37,7 +37,7 @@ void UDPSOCKET_SENDTO_REPEAT()
int sent;
Timer timer;
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
for (i = 0; i < 100; i++) {
sent = sock.sendto(udp_addr, tx_buffer, sizeof(tx_buffer));

View File

@ -203,7 +203,7 @@ emac_mem_buf_t *EmacTestMemoryManager::alloc_pool(uint32_t size, uint32_t align,
if (size_left > pool_buffer_max_size) {
size_left = size_left - pool_buffer_max_size;
alloc_size = pool_buffer_max_size;
// New smaller than alloc size buffer needed
// New smaller than alloc size buffer needed
} else {
alloc_size = size_left;
size_left = 0;
@ -550,7 +550,8 @@ void EmacTestMemoryManager::validate_list() const
m_mem_mutex.unlock();
}
EmacTestMemoryManager &EmacTestMemoryManager::get_instance() {
EmacTestMemoryManager &EmacTestMemoryManager::get_instance()
{
static EmacTestMemoryManager test_memory_manager;
return test_memory_manager;
}

View File

@ -56,7 +56,7 @@ public:
const char *netmask, const char *gw,
nsapi_ip_stack_t stack = DEFAULT_STACK,
bool blocking = true
);
);
/** Disconnect interface from the network
*
@ -148,7 +148,7 @@ public:
* @return 0 on success, negative error code on failure
*/
virtual nsapi_error_t gethostbyname(const char *host,
SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC);
SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC);
/** Add a domain name server to list of servers to query
*
@ -236,7 +236,7 @@ protected:
* @return 0 on success, negative error code on failure
*/
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
*

View File

@ -90,7 +90,7 @@ ctp_function emac_if_ctp_header_handle(unsigned char *eth_input_frame, unsigned
// Copy own address to origin
memcpy(&eth_output_frame[6], origin_addr, 6);
return CTP_FORWARD;
// reply
// reply
} else if (function == 0x0001) {
*receipt_number = ethernet_ptr[1] << 8 | ethernet_ptr[0];
return CTP_REPLY;

View File

@ -83,7 +83,7 @@ void test_emac_initialize()
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();
nsapi_security_t security = ap[i].get_security();
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]));
emac->get_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();
printf("emac mtu %i\r\n\r\n", mtu_size);

View File

@ -86,19 +86,19 @@ void test_emac_memory_cb(int opt)
break;
case 6:
printf("STEP 6: memory available\r\n\r\n");
emac_if_set_output_memory(true);
emac_if_set_input_memory(true);
memory = true;
break;
printf("STEP 6: memory available\r\n\r\n");
emac_if_set_output_memory(true);
emac_if_set_input_memory(true);
memory = true;
break;
case 7:
printf("STEP 7: memory available, alloc from heap\r\n\r\n");
emac_if_set_output_memory(true);
emac_if_set_input_memory(true);
options |= CTP_OPT_HEAP;
memory = true;
break;
printf("STEP 7: memory available, alloc from heap\r\n\r\n");
emac_if_set_output_memory(true);
emac_if_set_input_memory(true);
options |= CTP_OPT_HEAP;
memory = true;
break;
case 8:
// Test ended
@ -121,7 +121,7 @@ void test_emac_memory_cb(int opt)
printf("too many retries\r\n\r\n");
SET_ERROR_FLAGS(TEST_FAILED);
END_TEST_LOOP;
// Otherwise continues test
// Otherwise continues test
} else {
RESET_OUTGOING_MSG_DATA;
next_len = true;

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