You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/11/01 17:16:50 UTC
[07/11] incubator-mynewt-core git commit: OS unit tests: Event codes
-> callbacks
OS unit tests: Event codes -> callbacks
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/d6f98b44
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/d6f98b44
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/d6f98b44
Branch: refs/heads/develop
Commit: d6f98b4406db88691b86bb1379c0a9f5efb9a301
Parents: cf38f1f
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Oct 31 18:52:29 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Tue Nov 1 10:08:16 2016 -0700
----------------------------------------------------------------------
kernel/os/test/src/callout_test.c | 78 ++++++++++----------
kernel/os/test/src/callout_test.h | 14 ++--
kernel/os/test/src/eventq_test.c | 18 ++---
kernel/os/test/src/os_test.c | 1 +
.../test/src/testcases/event_test_poll_0timo.c | 1 -
.../src/testcases/event_test_poll_single_sr.c | 3 +-
.../src/testcases/event_test_poll_timeout_sr.c | 1 -
kernel/os/test/src/testcases/os_callout_test.c | 3 +-
.../test/src/testcases/os_callout_test_speak.c | 12 +--
.../test/src/testcases/os_callout_test_stop.c | 13 ++--
10 files changed, 69 insertions(+), 75 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/callout_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/callout_test.c b/kernel/os/test/src/callout_test.c
index 8ad3dc0..ff15357 100644
--- a/kernel/os/test/src/callout_test.c
+++ b/kernel/os/test/src/callout_test.c
@@ -28,8 +28,8 @@ os_stack_t callout_task_stack_send[CALLOUT_STACK_SIZE];
struct os_task callout_task_struct_receive;
os_stack_t callout_task_stack_receive[CALLOUT_STACK_SIZE];
-/* Delearing variables for callout_func */
-struct os_callout_func callout_func_test;
+/* Declaring variables for callout */
+struct os_callout callout_test_c;
/* The event to be sent*/
struct os_eventq callout_evq;
@@ -43,7 +43,7 @@ struct os_task callout_task_struct_stop_receive;
os_stack_t callout_task_stack_stop_receive[CALLOUT_STACK_SIZE];
/* Delearing variables for callout_stop_func */
-struct os_callout_func callout_func_stop_test[MULTI_SIZE];
+struct os_callout callout_stop_test[MULTI_SIZE];
/* The event to be sent*/
struct os_eventq callout_stop_evq[MULTI_SIZE];
@@ -57,7 +57,7 @@ os_stack_t callout_task_stack_speak[CALLOUT_STACK_SIZE];
struct os_task callout_task_struct_listen;
os_stack_t callout_task_stack_listen[CALLOUT_STACK_SIZE];
-struct os_callout_func callout_func_speak;
+struct os_callout callout_speak;
/* Global variables to be used by the callout functions */
int p;
@@ -66,39 +66,39 @@ int t;
/* This is the function for callout_init*/
void
-my_callout_func(void *arg)
+my_callout(struct os_event *ev)
{
p = 4;
}
/* This is the function for callout_init of stop test_case*/
void
-my_callout_stop_func(void *arg)
+my_callout_stop_func(struct os_event *ev)
{
q = 1;
}
/* This is the function for callout_init for speak test_case*/
void
-my_callout_speak_func(void *arg)
+my_callout_speak_func(struct os_event *ev)
{
t = 2;
}
/* This is a callout task to send data */
void
-callout_task_send(void *arg )
+callout_task_send(void *arg)
{
int i;
/* Should say whether callout is armed or not */
- i= os_callout_queued(&callout_func_test.cf_c);
+ i= os_callout_queued(&callout_test_c);
TEST_ASSERT(i == 0);
/* Arm the callout */
- i = os_callout_reset(&callout_func_test.cf_c, OS_TICKS_PER_SEC/ 50);
+ i = os_callout_reset(&callout_test_c, OS_TICKS_PER_SEC/ 50);
TEST_ASSERT_FATAL(i == 0);
/* Should say whether callout is armed or not */
- i = os_callout_queued(&callout_func_test.cf_c);
+ i = os_callout_queued(&callout_test_c);
TEST_ASSERT(i == 1);
/* Send the callout */
@@ -107,23 +107,23 @@ callout_task_send(void *arg )
/* This is the callout to receive data */
void
-callout_task_receive( void *arg)
+callout_task_receive(void *arg)
{
int i;
struct os_event *event;
- struct os_callout_func *callout;
+ struct os_callout *callout;
os_time_t now;
os_time_t tm;
os_sr_t sr;
+
/* Recieve using the os_eventq_poll */
- event = os_eventq_poll(&callout_func_test.cf_c.c_evq, 1, OS_WAIT_FOREVER);
- TEST_ASSERT(event->ev_type == OS_EVENT_T_TIMER);
+ event = os_eventq_poll(&callout_test_c.c_evq, 1, OS_WAIT_FOREVER);
TEST_ASSERT(event->ev_arg == NULL);
- callout = (struct os_callout_func *)event;
- TEST_ASSERT(callout->cf_func == my_callout_func);
+ callout = (struct os_callout *)event;
+ TEST_ASSERT(callout->c_ev.ev_cb == my_callout);
/* Should say whether callout is armed or not */
- i = os_callout_queued(&callout_func_test.cf_c);
+ i = os_callout_queued(&callout_test_c);
TEST_ASSERT(i == 0);
OS_ENTER_CRITICAL(sr);
@@ -139,26 +139,26 @@ callout_task_receive( void *arg)
/* This is callout to send the stop_callout */
void
-callout_task_stop_send( void *arg)
+callout_task_stop_send(void *arg)
{
int k;
int j;
/* Should say whether callout is armed or not */
for(k = 0; k<MULTI_SIZE; k++){
- j = os_callout_queued(&callout_func_stop_test[k].cf_c);
+ j = os_callout_queued(&callout_stop_test[k]);
TEST_ASSERT(j == 0);
}
/* Show that callout is not armed after calling callout_stop */
for(k = 0; k<MULTI_SIZE; k++){
- os_callout_stop(&callout_func_stop_test[k].cf_c);
- j = os_callout_queued(&callout_func_stop_test[k].cf_c);
+ os_callout_stop(&callout_stop_test[k]);
+ j = os_callout_queued(&callout_stop_test[k]);
TEST_ASSERT(j == 0);
}
/* Arm the callout */
for(k = 0; k<MULTI_SIZE; k++){
- j = os_callout_reset(&callout_func_stop_test[k].cf_c, OS_TICKS_PER_SEC/ 50);
+ j = os_callout_reset(&callout_stop_test[k], OS_TICKS_PER_SEC/ 50);
TEST_ASSERT_FATAL(j == 0);
}
os_time_delay( OS_TICKS_PER_SEC );
@@ -166,26 +166,25 @@ callout_task_stop_send( void *arg)
/* This is the callout to receive stop_callout data */
void
-callout_task_stop_receive( void *arg )
+callout_task_stop_receive(void *arg)
{
int k;
struct os_event *event;
- struct os_callout_func *callout;
+ struct os_callout *callout;
/* Recieving using the os_eventq_poll */
for(k=0; k<MULTI_SIZE; k++){
- event = os_eventq_poll(&callout_func_stop_test[k].cf_c.c_evq, 1,
+ event = os_eventq_poll(&callout_stop_test[k].c_evq, 1,
OS_WAIT_FOREVER);
- TEST_ASSERT(event->ev_type == OS_EVENT_T_TIMER);
TEST_ASSERT(event->ev_arg == NULL);
- callout = (struct os_callout_func *)event;
- TEST_ASSERT(callout->cf_func == my_callout_stop_func);
+ callout = (struct os_callout *)event;
+ TEST_ASSERT(callout->c_ev.ev_cb == my_callout_stop_func);
}
/* Show that event is removed from the queued after calling callout_stop */
for(k=0; k<MULTI_SIZE; k++){
- os_callout_stop(&callout_func_stop_test[k].cf_c);
+ os_callout_stop(&callout_stop_test[k]);
/* Testing that the event has been removed from queue */
TEST_ASSERT_FATAL(1);
}
@@ -196,18 +195,18 @@ callout_task_stop_receive( void *arg )
/* This is a callout task to send data */
void
-callout_task_stop_speak( void *arg )
+callout_task_stop_speak(void *arg)
{
int i;
/* Arm the callout */
- i = os_callout_reset(&callout_func_speak.cf_c, OS_TICKS_PER_SEC/ 50);
+ i = os_callout_reset(&callout_speak, OS_TICKS_PER_SEC/ 50);
TEST_ASSERT_FATAL(i == 0);
/* should say whether callout is armed or not */
- i = os_callout_queued(&callout_func_speak.cf_c);
+ i = os_callout_queued(&callout_speak);
TEST_ASSERT(i == 1);
- os_callout_stop(&callout_func_speak.cf_c);
+ os_callout_stop(&callout_speak);
/* Send the callout */
os_time_delay(OS_TICKS_PER_SEC/ 100 );
@@ -216,14 +215,15 @@ callout_task_stop_speak( void *arg )
}
void
-callout_task_stop_listen( void *arg )
+callout_task_stop_listen(void *arg)
{
struct os_event *event;
- struct os_callout_func *callout;
- event = os_eventq_get(callout_func_speak.cf_c.c_evq);
+ struct os_callout *callout;
+
+ event = os_eventq_get(callout_speak.c_evq);
TEST_ASSERT_FATAL(0);
- callout = (struct os_callout_func *)event;
- TEST_ASSERT(callout->cf_func == my_callout_speak_func);
+ callout = (struct os_callout *)event;
+ TEST_ASSERT(callout->c_ev.ev_cb == my_callout_speak_func);
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/callout_test.h
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/callout_test.h b/kernel/os/test/src/callout_test.h
index ea85962..494251d 100644
--- a/kernel/os/test/src/callout_test.h
+++ b/kernel/os/test/src/callout_test.h
@@ -38,9 +38,6 @@ extern os_stack_t callout_task_stack_send[CALLOUT_STACK_SIZE];
extern struct os_task callout_task_struct_receive;
extern os_stack_t callout_task_stack_receive[CALLOUT_STACK_SIZE];
-/* Delearing variables for callout_func */
-extern struct os_callout_func callout_func_test;
-
/* The event to be sent*/
extern struct os_eventq callout_evq;
extern struct os_event callout_ev;
@@ -56,7 +53,7 @@ extern os_stack_t callout_task_stack_stop_receive[CALLOUT_STACK_SIZE];
/* Delearing variables for callout_stop_func */
#define MULTI_SIZE (2)
-extern struct os_callout_func callout_func_stop_test[MULTI_SIZE];
+extern struct os_callout callout_stop_test[MULTI_SIZE];
/* The event to be sent*/
extern struct os_eventq callout_stop_evq[MULTI_SIZE];
@@ -72,16 +69,17 @@ extern os_stack_t callout_task_stack_speak[CALLOUT_STACK_SIZE];
extern struct os_task callout_task_struct_listen;
extern os_stack_t callout_task_stack_listen[CALLOUT_STACK_SIZE];
-extern struct os_callout_func callout_func_speak;
+extern struct os_callout callout_speak;
+extern struct os_callout callout_test_c;
/* Global variables to be used by the callout functions */
extern int p;
extern int q;
extern int t;
-void my_callout_func(void *arg);
-void my_callout_stop_func(void *arg);
-void my_callout_speak_func(void *arg);
+void my_callout(struct os_event *ev);
+void my_callout_stop_func(struct os_event *ev);
+void my_callout_speak_func(struct os_event *ev);
void callout_task_send(void *arg);
void callout_task_receive(void *arg);
void callout_task_stop_send(void *arg);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/eventq_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/eventq_test.c b/kernel/os/test/src/eventq_test.c
index f741613..5696645 100644
--- a/kernel/os/test/src/eventq_test.c
+++ b/kernel/os/test/src/eventq_test.c
@@ -47,6 +47,7 @@ struct os_event g_event;
struct os_event m_event[SIZE_MULTI_EVENT];
/* Setting the event to send and receive multiple data */
+
uint8_t my_event_type = 1;
/* Setting up data for the poll */
@@ -95,16 +96,14 @@ eventq_task_send(void *arg)
int i;
g_event.ev_queued = 0;
- g_event.ev_type = my_event_type;
- g_event.ev_arg = NULL;
+ g_event.ev_arg = (void *)(intptr_t)my_event_type;
os_eventq_put(&my_eventq, &g_event);
os_time_delay(OS_TICKS_PER_SEC / 2);
for (i = 0; i < SIZE_MULTI_EVENT; i++){
- m_event[i].ev_type = i + 2;
- m_event[i].ev_arg = NULL;
+ m_event[i].ev_arg = (void *)(intptr_t)(i + 2);
/* Put and send */
os_eventq_put(&multi_eventq[i], &m_event[i]);
@@ -123,12 +122,12 @@ eventq_task_receive(void *arg)
int i;
event = os_eventq_get(&my_eventq);
- TEST_ASSERT(event->ev_type == my_event_type);
+ TEST_ASSERT((intptr_t)event->ev_arg == my_event_type);
/* Receiving multi event from the send task */
for (i = 0; i < SIZE_MULTI_EVENT; i++) {
event = os_eventq_get(&multi_eventq[i]);
- TEST_ASSERT(event->ev_type == i + 2);
+ TEST_ASSERT((intptr_t)event->ev_arg == i + 2);
}
/* Finishes the test when OS has been started */
@@ -146,8 +145,7 @@ eventq_task_poll_send(void *arg)
}
for (i = 0; i < SIZE_MULTI_EVENT; i++){
- m_event[i].ev_type = i + 10;
- m_event[i].ev_arg = NULL;
+ m_event[i].ev_arg = (void *)(intptr_t)(i + 10);
/* Put and send */
os_eventq_put(eventqs[i], &m_event[i]);
@@ -172,7 +170,7 @@ eventq_task_poll_receive(void *arg)
/* Recieving using the os_eventq_poll*/
for (i = 0; i < SIZE_MULTI_EVENT; i++) {
event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
- TEST_ASSERT(event->ev_type == i +10);
+ TEST_ASSERT((intptr_t)event->ev_arg == i +10);
}
/* Finishes the test when OS has been started */
@@ -261,7 +259,7 @@ eventq_task_poll_single_receive(void *arg)
/* Recieving using the os_eventq_poll*/
event = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, OS_WAIT_FOREVER);
- TEST_ASSERT(event->ev_type == 20);
+ TEST_ASSERT((intptr_t)event->ev_arg == 20);
/* Finishes the test when OS has been started */
os_test_restart();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/os_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/os_test.c b/kernel/os/test/src/os_test.c
index eaf1535..1e817a7 100644
--- a/kernel/os/test/src/os_test.c
+++ b/kernel/os/test/src/os_test.c
@@ -76,6 +76,7 @@ int
main(int argc, char **argv)
{
ts_config.ts_print_results = 1;
+ tu_parse_args(argc, argv);
tu_init();
os_test_all();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/event_test_poll_0timo.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/event_test_poll_0timo.c b/kernel/os/test/src/testcases/event_test_poll_0timo.c
index a1b52bb..5e86395 100644
--- a/kernel/os/test/src/testcases/event_test_poll_0timo.c
+++ b/kernel/os/test/src/testcases/event_test_poll_0timo.c
@@ -44,7 +44,6 @@ TEST_CASE(event_test_poll_0timo)
/* Put an event on one of the queues. */
memset(&ev, 0, sizeof ev);
- ev.ev_type = 1;
os_eventq_put(eventqs[3], &ev);
evp = os_eventq_poll(eventqs, SIZE_MULTI_EVENT, 0);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/event_test_poll_single_sr.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/event_test_poll_single_sr.c b/kernel/os/test/src/testcases/event_test_poll_single_sr.c
index 92c0677..8abf755 100644
--- a/kernel/os/test/src/testcases/event_test_poll_single_sr.c
+++ b/kernel/os/test/src/testcases/event_test_poll_single_sr.c
@@ -39,8 +39,7 @@ TEST_CASE(event_test_poll_single_sr)
for (i = 0; i < SIZE_MULTI_EVENT; i++){
os_eventq_init(&multi_eventq[i]);
- m_event[i].ev_type = 10 * i;
- m_event[i].ev_arg = NULL;
+ m_event[i].ev_arg = (void *)(intptr_t)(10 * i);
}
/* Does not return until OS_restart is called */
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c b/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c
index 958c69f..9ce3481 100644
--- a/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c
+++ b/kernel/os/test/src/testcases/event_test_poll_timeout_sr.c
@@ -39,7 +39,6 @@ TEST_CASE(event_test_poll_timeout_sr)
for (i = 0; i < SIZE_MULTI_EVENT; i++){
os_eventq_init(&multi_eventq[i]);
- m_event[i].ev_type = i + 10;
m_event[i].ev_arg = NULL;
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/os_callout_test.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_callout_test.c b/kernel/os/test/src/testcases/os_callout_test.c
index 8d6739d..6fc01c7 100644
--- a/kernel/os/test/src/testcases/os_callout_test.c
+++ b/kernel/os/test/src/testcases/os_callout_test.c
@@ -38,8 +38,7 @@ TEST_CASE(callout_test)
os_eventq_init(&callout_evq);
/* Initialize the callout function */
- os_callout_func_init(&callout_func_test, &callout_evq,
- my_callout_func, NULL);
+ os_callout_init(&callout_test_c, &callout_evq, my_callout, NULL);
/* Does not return until OS_restart is called */
os_start();
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/os_callout_test_speak.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_callout_test_speak.c b/kernel/os/test/src/testcases/os_callout_test_speak.c
index dda02e7..11dd3d2 100644
--- a/kernel/os/test/src/testcases/os_callout_test_speak.c
+++ b/kernel/os/test/src/testcases/os_callout_test_speak.c
@@ -26,20 +26,20 @@ TEST_CASE(callout_test_speak)
/* Initialize the sending task */
os_task_init(&callout_task_struct_speak, "callout_task_speak",
- callout_task_stop_speak, NULL, SPEAK_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
- callout_task_stack_speak, CALLOUT_STACK_SIZE);
+ callout_task_stop_speak, NULL, SPEAK_CALLOUT_TASK_PRIO,
+ OS_WAIT_FOREVER, callout_task_stack_speak, CALLOUT_STACK_SIZE);
/* Initialize the receive task */
os_task_init(&callout_task_struct_listen, "callout_task_listen",
- callout_task_stop_listen, NULL, LISTEN_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
- callout_task_stack_listen, CALLOUT_STACK_SIZE);
+ callout_task_stop_listen, NULL, LISTEN_CALLOUT_TASK_PRIO,
+ OS_WAIT_FOREVER, callout_task_stack_listen, CALLOUT_STACK_SIZE);
os_eventq_init(&callout_evq);
/* Initialize the callout function */
- os_callout_func_init(&callout_func_speak, &callout_evq,
+ os_callout_init(&callout_speak, &callout_evq,
my_callout_speak_func, NULL);
+
/* Does not return until OS_restart is called */
os_start();
-
}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/d6f98b44/kernel/os/test/src/testcases/os_callout_test_stop.c
----------------------------------------------------------------------
diff --git a/kernel/os/test/src/testcases/os_callout_test_stop.c b/kernel/os/test/src/testcases/os_callout_test_stop.c
index b4e92b4..da7674d 100644
--- a/kernel/os/test/src/testcases/os_callout_test_stop.c
+++ b/kernel/os/test/src/testcases/os_callout_test_stop.c
@@ -27,13 +27,14 @@ TEST_CASE(callout_test_stop)
/* Initialize the sending task */
os_task_init(&callout_task_struct_stop_send, "callout_task_stop_send",
- callout_task_stop_send, NULL, SEND_STOP_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
- callout_task_stack_stop_send, CALLOUT_STACK_SIZE);
+ callout_task_stop_send, NULL, SEND_STOP_CALLOUT_TASK_PRIO,
+ OS_WAIT_FOREVER, callout_task_stack_stop_send, CALLOUT_STACK_SIZE);
/* Initialize the receiving task */
- os_task_init(&callout_task_struct_stop_receive, "callout_task_stop_receive",
- callout_task_stop_receive, NULL, RECEIVE_STOP_CALLOUT_TASK_PRIO,
- OS_WAIT_FOREVER, callout_task_stack_stop_receive, CALLOUT_STACK_SIZE);
+ os_task_init(&callout_task_struct_stop_receive,
+ "callout_task_stop_receive", callout_task_stop_receive, NULL,
+ RECEIVE_STOP_CALLOUT_TASK_PRIO, OS_WAIT_FOREVER,
+ callout_task_stack_stop_receive, CALLOUT_STACK_SIZE);
for(k = 0; k< MULTI_SIZE; k++){
os_eventq_init(&callout_stop_evq[k]);
@@ -41,7 +42,7 @@ TEST_CASE(callout_test_stop)
/* Initialize the callout function */
for(k = 0; k<MULTI_SIZE; k++){
- os_callout_func_init(&callout_func_stop_test[k], &callout_stop_evq[k],
+ os_callout_init(&callout_stop_test[k], &callout_stop_evq[k],
my_callout_stop_func, NULL);
}