]> rtime.felk.cvut.cz Git - frescor/fosa.git/blobdiff - src_marte/test_fosa_ads.c
updated error callback
[frescor/fosa.git] / src_marte / test_fosa_ads.c
index d55b7566a23ec706e45a028626379389fb2deaa0..92cf84e0b071d93cd37299958211a5bb4fadbfab 100644 (file)
@@ -129,7 +129,8 @@ typedef struct {
 
 typedef enum {
     ACTIVATE,
-    SUSPEND
+    SUSPEND,
+    CAUSE_ERROR
 } command_t;
 
 typedef struct {
@@ -156,6 +157,10 @@ int main () {
 
     adjust(); // for function eat
 
+    // err = fosa_thread_set_prio (fosa_thread_self(), MX_PRIO + 1);
+    // printf("set main to highest priority, err=%d\n", err);
+    // assert(err == 0);
+
     err = fosa_mutex_init(&lock, MX_PRIO);
     printf("mutex initialized with ceiling %d. err=%d\n", MX_PRIO, err);
     assert(err == 0);
@@ -288,15 +293,24 @@ int main () {
 
     sleep (3);
 
-    fosa_timer_delete(timerid);
+    //////////////////////////////////////////////////////////////
+    //  2e) Cause error
+    //////////////////////////////////////////////////////////////
+    printf("--------------------------------------------------\n");
+    printf("2e) Cause error\n");
 
-    sleep (5);
+    signal_action.command = CAUSE_ERROR;
+    err=fosa_timer_arm(timerid, false, &timerval);
+    printf("causing an ERROR callback in 0.5 secs, err=%d\n", err);
+    assert(err == 0);
+
+    sleep (3);
 
     //////////////////////////////////////////////////////////////
-    //  2e) Dettach from application scheduler
+    //  2f) Dettach from application scheduler
     //////////////////////////////////////////////////////////////
     printf("--------------------------------------------------\n");
-    printf("2e) Dettach from application scheduler\n");
+    printf("2f) Dettach from application scheduler\n");
 
     err = fosa_ads_set_appscheduled (tid1, false);
     printf("dettach thread 1, err=%d\n", err);
@@ -310,6 +324,8 @@ int main () {
     printf("thread 2 is dettached? %d, err=%d\n", !is_appsched, err);
     assert(err == 0);
 
+    fosa_timer_delete(timerid);
+
     sleep(1000);
     return 0;
 }
@@ -326,28 +342,28 @@ static void *thread_code (void * arg)
     int reply;
     size_t reply_size;
 
-    printf("Thread %d starts\n", (int)arg);
+    printf("Thread %d starts\n", (int)arg);
     for (i=1;i<50;i++) {
         nanosleep (&ts, NULL);
 
-        eat (2.0);
-
         err=fosa_mutex_lock(&lock);
-        printf("mutex locked by %d. err=%d\n", (int)arg, err);
+        printf("Thread %d - mutex locked, err=%d\n", (int)arg, err);
         assert(err == 0);
 
         eat (1.0);
 
         err=fosa_mutex_unlock(&lock);
-        printf("mutex unlocked %d. err=%d\n", (int)arg, err);
+        printf("Thread %d - mutex unlocked, err=%d\n", (int)arg, err);
         assert(err == 0);
 
         err = fosa_ads_invoke_withdata
                 (whoami, sizeof(whoami), (void *)&reply, &reply_size);
-        printf("who am I, correct?: %d, err=%d\n", reply == (int)arg, err);
-        assert(err == 0);
+        printf("Thread %d - who am I, correct?: %d, err=%d\n", (int)arg,
+               reply == (int)fosa_thread_self(), err);
+        if (err != 0) {
+            pthread_exit (NULL);
+        }
 
-        eat (1.0);
     }
     return NULL;
 }
@@ -481,8 +497,9 @@ static void frsh_callback_explicit_call_with_data
          struct timespec *current_time)
 {
     printf ("CALLBACK: %s \n", __func__);
-    printf ("received command: %s \n", (char *)msg);
     *((int *)reply) = (int)thread;
+    printf ("received command: %s , answer %d \n", (char *)msg,
+      *((int *)reply));
 }
 
 static void frsh_callback_notification_for_thread
@@ -518,15 +535,25 @@ static void frsh_callback_signal
 
     printf ("CALLBACK: %s \n", __func__);
 
-    if (signal_action->command == SUSPEND) {
-        err = fosa_adsactions_add_suspend(actions, signal_action->thread_id);
-        printf("suspending thread 1 , err=%d\n", err);
-        assert(err == 0);
-    } else {
-        err = fosa_adsactions_add_activate
-                (actions, signal_action->thread_id, frsh->array_prio[0]);
-        printf("activating thread 1, err=%d\n", err);
-        assert(err == 0);
+    switch (signal_action->command) {
+        case SUSPEND:
+            err=fosa_adsactions_add_suspend(actions, signal_action->thread_id);
+            printf("suspending thread 1 , err=%d\n", err);
+            assert(err == 0);
+            break;
+        case ACTIVATE:
+            err = fosa_adsactions_add_activate
+                    (actions, signal_action->thread_id, frsh->array_prio[0]);
+            printf("activating thread 1, err=%d\n", err);
+            assert(err == 0);
+            break;
+        case CAUSE_ERROR:
+            // cause an error by using a wrong thread id: 666 ;D
+            err = fosa_adsactions_add_activate
+                    (actions, (frsh_thread_id_t)666, frsh->array_prio[0]);
+            printf("causing an error, err=%d\n", err);
+            assert(err == 0);
+            break;
     }
 }