]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - src_rtep/tests/test_c_rtep_frsh_fna.c
big commint with a lot of changes, see files
[frescor/fna.git] / src_rtep / tests / test_c_rtep_frsh_fna.c
1 /*
2  * test_c_rtep_frsh_fna.c
3  *
4  * Goal:
5  *
6  * The goal of this program is to test the RTEP functions defined at frsh_fna.h
7  * which is the public part of frsh_fna.h. The interface of this public part
8  * is dependent of the underlying network protocol. We are not trying here to
9  * make a very intense test but a simple and basic one to check the correct
10  * behaviour of the functions.
11  *
12  * Algorithm:
13  *
14  * First we check the conversions between frsh and rtep addresses and streams.
15  * Then, we check the renegotiation functions for the period of the internal
16  * negotiation messages. And finally, we check the renegotiation functions for
17  * the internal service thread.
18  *
19  */
20
21 #include <assert.h> // for assert
22 #include <stdio.h> // for printf
23 #include <stdbool.h> // for bool
24
25 #include "frsh_core_types.h" // for FRSH_RESOURCE_ID_DEFAULT
26 #include "frsh_distributed_types.h" // frsh_network_address_t, frsh_stream_id_t
27
28 #include "rtep_fna.h" // for rtep_fna_operations.fna_init
29 #include "rtep.h" // for rtep_station_id_t, rtep_channel_t
30
31 #include "frsh_fna.h" // for frsh_rtep_*
32
33 int main ()
34 {
35     int err;
36     rtep_station_id_t rtep_station = 3;
37     frsh_network_address_t frsh_address;
38     rtep_channel_t in_stream = 7;
39     frsh_stream_id_t out_stream;
40     struct timespec neg_period = {2,0};
41     struct timespec get_period = {0,0};
42     struct timespec rtep_serv_thread_budget = {1,0};
43     struct timespec rtep_serv_thread_period = {5,0};
44     bool serv_thread_renegotiation_accepted = false;
45     struct timespec current_serv_thread_budget = {0,0};
46     struct timespec current_serv_thread_period = {0,0};
47
48     printf("1.- fna_init\n");
49     err=rtep_fna_operations.fna_init(FRSH_RESOURCE_ID_DEFAULT);
50     assert(err == 0);
51
52     printf("2.- frsh_rtep_map_network_address\n");
53     err=frsh_rtep_map_network_address
54             (FRSH_RESOURCE_ID_DEFAULT, rtep_station, &frsh_address);
55     assert(err == 0);
56     printf("rtep_address:%d -> frsh_address:%d\n", rtep_station, frsh_address);
57     assert(rtep_station == frsh_address);
58
59     printf("3.- frsh_rtep_map_stream_id\n");
60     err=frsh_rtep_map_stream_id
61             (FRSH_RESOURCE_ID_DEFAULT, in_stream, &out_stream);
62     assert(err == 0);
63     printf("rtep_channel:%d -> frsh_stream:%d\n", in_stream, out_stream);
64     assert(in_stream == out_stream);
65
66     printf("4.- frsh_rtep_negotiation_messages_vres_renegotiate period\n");
67     err=frsh_rtep_negotiation_messages_vres_get_period
68             (FRSH_RESOURCE_ID_DEFAULT, &get_period);
69     assert(err == 0);
70     printf("period before renegotiation: sec=%d nsec=%d\n",
71             get_period.tv_sec, get_period.tv_nsec);
72
73     err=frsh_rtep_negotiation_messages_vres_renegotiate
74             (FRSH_RESOURCE_ID_DEFAULT, &neg_period);
75     if (err == 0) {
76         printf("renegotiation accepted (period negotiated: sec=%d nsec=%d)\n",
77                neg_period.tv_sec, neg_period.tv_nsec);
78     } else {
79         printf("renegotiation not accepted\n");
80     }
81     assert (err == 0);
82
83     err=frsh_rtep_negotiation_messages_vres_get_period
84             (FRSH_RESOURCE_ID_DEFAULT, &get_period);
85     assert(err == 0);
86     printf("period after renegotiation: sec=%d nsec=%d\n",
87            get_period.tv_sec, get_period.tv_nsec);
88
89 // TODO: uncomment step 5 when internal thread has a frescor contract
90 // printf("5.- frsh_rtep_service_thread_vres_renegotiate\n");
91 //
92 // err=frsh_rtep_service_thread_vres_get_budget_and_period
93 //         (FRSH_RESOURCE_ID_DEFAULT,
94 //             &current_serv_thread_budget,
95 //             &current_serv_thread_period);
96 // assert(err == 0);
97 // printf("service thread budget (before renegotiation): sec=%d nsec=%d\n",
98 //         current_serv_thread_budget.tv_sec,
99 //         current_serv_thread_budget.tv_nsec);
100 // printf("service thread period (before renegotiation): sec=%d nsec=%d\n",
101 //         current_serv_thread_period.tv_sec,
102 //         current_serv_thread_period.tv_nsec);
103 //
104 // err=frsh_rtep_service_thread_vres_renegotiate
105 //         (FRSH_RESOURCE_ID_DEFAULT,
106 //             &rtep_serv_thread_budget,
107 //             &rtep_serv_thread_period,
108 //             &serv_thread_renegotiation_accepted);
109 // assert(err == 0);
110 //
111 // if (serv_thread_renegotiation_accepted) {
112 //     printf("service_thread renegotiation accepted\n");
113 // } else {
114 //     printf("service_thread renegotiation not accepted\n");
115 // }
116 // assert (err == 0);
117 //
118 // err=frsh_rtep_service_thread_vres_get_budget_and_period
119 //         (FRSH_RESOURCE_ID_DEFAULT,
120 //             &current_serv_thread_budget,
121 //             &current_serv_thread_period);
122 // assert(err == 0);
123 // printf("service thread budget (after renegotiation): sec=%d nsec=%d\n",
124 //         current_serv_thread_budget.tv_sec,
125 //         current_serv_thread_budget.tv_nsec);
126 // printf("service thread period (after renegotiation): sec=%d nsec=%d\n",
127 //         current_serv_thread_period.tv_sec,
128 //         current_serv_thread_period.tv_nsec);
129
130     printf("\nEND of the TEST\n");
131     return 0;
132 }