]> rtime.felk.cvut.cz Git - frescor/fosa.git/blob - src_marte/tests/test_queue_signal_fosa/test_queue_signal_fosa.c
Time abstraction added to FOSA to replace timespec_operations
[frescor/fosa.git] / src_marte / tests / test_queue_signal_fosa / test_queue_signal_fosa.c
1 /*
2 ** test_queue_signal.c
3 ** 
4 ** Made by (Miguel marciano)
5 ** Login   <miguel@namir.ctr.unican.es>
6 ** 
7 ** Started on  Thu Nov  8 16:22:18 2007 Miguel marciano
8 ** Last update Sun May 12 01:17:25 2002 Speed Blue
9 */
10
11 #include <stdio.h>
12 #include <string.h>
13 #include <stdlib.h>
14
15 #include "fosa.h"
16
17 #define TEST_SIGNAL (SIGRTMIN + 6)
18
19 int main()
20 {
21     int terror = -1;
22
23     fosa_abs_time_t past_time;
24     fosa_abs_time_t current_time;
25     fosa_timer_id_t timer;
26
27     fosa_signal_t signal_set[1];
28     fosa_signal_info_t signal_info;
29     fosa_signal_t signal_received;
30
31     int my_test_value = 42;
32     fosa_rel_time_t eat_time = fosa_msec_to_rel_time(2000);
33
34
35
36     /* We block the signals that we are going to process */
37     /*****************************************************/
38     signal_set[0] = TEST_SIGNAL;
39     terror = fosa_set_accepted_signals(signal_set, 1);
40     if (terror != 0) exit(1);
41
42     
43
44     /* We create a timer based on the FOSA_CLOCK_REALTIME */
45     /******************************************************/
46     signal_info.sival_int = my_test_value;
47     terror = fosa_timer_create(FOSA_CLOCK_REALTIME, TEST_SIGNAL, signal_info, &timer);
48     if (terror != 0) exit(1);
49
50     /* I get the time BEFORE doing the eat */
51     /***************************************/
52     terror = fosa_clock_get_time(FOSA_CLOCK_REALTIME, &past_time);
53     if (terror != 0) exit(1);
54     printf("Current time:  %ld msec\n", fosa_abs_time_to_msec(past_time) );
55
56     /* Now I do some work for some secs */
57     /************************************/
58     fosa_eat(&eat_time);
59
60     /* I read the time again */
61     /*************************/
62     terror = fosa_clock_get_time(FOSA_CLOCK_REALTIME, &current_time);
63     if (terror != 0) exit(1);
64     printf("Current time:  %ld msec\n", fosa_abs_time_to_msec(current_time) );
65     
66     /* I arm the timer to the past                                    */
67     /* Since we have blocked this signal, the signal should be stored */
68     /******************************************************************/
69     printf("Arming the timer\n");
70     terror = fosa_abs_timer_arm(timer, &past_time);
71
72
73     /* Now I do the sigwait */
74     /************************/
75     printf("Waiting for the signal\n");
76     terror = fosa_signal_wait(signal_set, 1, &signal_received, &signal_info);
77     if (terror != 0) exit(1);
78
79     printf("Signal accepted!!!\n");
80
81     return 0;
82 }