Skip to content

Commit

Permalink
Merge pull request ARMmbed#7605 from 0xc0170/fix_astyle_tests
Browse files Browse the repository at this point in the history
tests: astyle fix
  • Loading branch information
Cruz Monrreal authored Aug 6, 2018
2 parents 6cce3d2 + 98b4570 commit cdcc550
Show file tree
Hide file tree
Showing 110 changed files with 2,984 additions and 2,049 deletions.
96 changes: 61 additions & 35 deletions TESTS/events/queue/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;

Expand All @@ -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];
Expand All @@ -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]);
}

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -327,7 +352,8 @@ const Case cases[] = {

Specification specification(test_setup, cases);

int main() {
int main()
{
return !Harness::run(specification);
}

41 changes: 24 additions & 17 deletions TESTS/events/timing/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

Expand All @@ -62,40 +64,43 @@ 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;
}
}

// equeue tick timing test
void tick_timing_test() {
void tick_timing_test()
{
unsigned start = equeue_tick();
int prev = 0;

while (prev < TEST_EVENTS_TIMING_TIME) {
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;
}
}

// equeue semaphore timing test
void semaphore_timing_test() {
void semaphore_timing_test()
{
srand(0);
timer.reset();
timer.start();
Expand Down Expand Up @@ -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);
}

Expand All @@ -137,7 +143,8 @@ const Case cases[] = {

Specification specification(test_setup, cases);

int main() {
int main()
{
return !Harness::run(specification);
}

3 changes: 2 additions & 1 deletion TESTS/integration/basic/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
*/
#include "test_env.h"

int main() {
int main()
{
GREENTEA_SETUP(15, "default_auto");
GREENTEA_TESTSUITE_RESULT(true);
}
Loading

0 comments on commit cdcc550

Please sign in to comment.