]> rtime.felk.cvut.cz Git - frescor/fna.git/blob - tests/tests_frescan/test_frescan_bwres_negotiate_in_master_not_accepted.c
add test used to detect bug when a contract was non schedulable in the master
[frescor/fna.git] / tests / tests_frescan / test_frescan_bwres_negotiate_in_master_not_accepted.c
1 #include <stdio.h>  // perror
2 #include <stdlib.h> // exit
3 #include <unistd.h>   // sleep
4 #include <assert.h>
5
6 #include "frsh.h"
7
8 #include "frescan.h"
9 #include "frescan_bwres.h"
10 #include "frescan_servers.h"
11
12 #define PUT_ERROR(s) {perror (s); exit (-1);}
13
14 #define NETWORK 0
15 #define LOCAL_NODE 0
16
17 // #define ENABLE_LOGGING
18 #ifdef ENABLE_LOGGING
19 #include <drivers/console_switcher.h>
20 #include <misc/logger.h>
21 #include <assert.h>
22 #define LOG_DEVICE LOG_ETHERNET
23 #endif
24
25 extern int frescan_fna_network_bytes_to_budget
26                                     (const frsh_resource_id_t resource_id,
27                                     const size_t nbytes,
28                                     frsh_rel_time_t *budget);
29
30 int main ()
31 {
32         int ret;
33         frescan_init_params_t init_params;
34         frescan_ss_t ss;
35         frsh_contract_t contract;
36         frescan_server_params_t server_params;
37         bool accepted;
38         frsh_rel_time_t budget_min, period_max;
39
40 #ifdef ENABLE_LOGGING
41         ret = logger_init(LOG_DEVICE);
42         assert(ret == 0);
43
44         printf("Changing to membuffer console\n");
45         MEMBUFFER_CONSOLE_INIT();
46 #endif
47
48         init_params.net = NETWORK;
49         init_params.node = LOCAL_NODE;
50         init_params.tx_fp_max_prio = 10;
51         init_params.rx_num_of_channels = 10;
52         init_params.rx_channel_max_prio = NULL;
53
54         printf("Initializing FRESCAN\n");
55         ret = frescan_init(&init_params);
56         if (ret != 0) PUT_ERROR ("could not init FRESCAN");
57
58         printf("Initializing BWRES\n");
59         ret = frescan_bwres_init(NETWORK);
60         if (ret != 0) PUT_ERROR ("could not init BWRES");
61
62
63         ret = frsh_contract_init(&contract);
64         assert(ret == 0);
65
66         ret = frsh_network_bytes_to_budget(FRSH_NETWORK_ID_DEFAULT,
67                                            8*10,
68                                            &budget_min);
69         assert(ret == 0);
70
71         period_max.tv_sec = 1; period_max.tv_nsec = 0;
72
73         ret = frsh_contract_set_basic_params(&contract,
74                                              &budget_min,
75                                              &period_max,
76                                              FRSH_WT_INDETERMINATE,
77                                              FRSH_CT_REGULAR);
78         assert(ret == 0);
79
80         ret = frsh_contract_set_preemption_level(&contract, 5);
81         assert(ret == 0);
82
83         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
84         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
85
86         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
87         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
88
89
90         ret = frsh_contract_init(&contract);
91         if (ret != 0) PUT_ERROR ("could not init contract");
92
93         ret = frescan_fna_network_bytes_to_budget (NETWORK, 8*1, &budget_min);
94         if (ret != 0) PUT_ERROR ("could not transform bytes to budget");
95
96         period_max = frsh_msec_to_rel_time(2);
97
98         ret = frsh_contract_set_basic_params
99                         (&contract,
100                          &budget_min,
101                          &period_max,
102                          FRSH_WT_INDETERMINATE,
103                          FRSH_CT_REGULAR);
104         if (ret != 0) PUT_ERROR ("could not set basic params");
105
106         ret = frsh_contract_set_preemption_level(&contract, 8);
107         if (ret != 0) PUT_ERROR ("could not set preemption level");
108
109         printf("Negotiating a contract\n");
110         ret = frescan_bwres_negotiate(NETWORK, &contract, &ss, &accepted);
111         if (ret != 0) PUT_ERROR ("could not negotiate succesfully");
112
113         if (accepted) {
114                 printf("The contract was accepted, ss:%u\n", ss);
115                 ret = frescan_servers_get_data(NETWORK, &server_params, ss);
116                 if (ret != 0) PUT_ERROR ("could not get servers data");
117
118                 printf("B:%u, T=(%u,%u), P:%u\n",
119                        server_params.budget,
120                        server_params.period.tv_sec,
121                        server_params.period.tv_nsec,
122                        server_params.prio);
123         } else {
124                 printf("The contract was not accepted\n");
125         }
126
127         printf("MAIN DONE\n");
128
129 #ifdef ENABLE_LOGGING
130         while (logger_manual_call() > 0);
131 #endif
132
133         while (1) sleep(1);
134         return 0;
135 }
136
137