]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - resources/item/tests/test_item.c
Updated ITEM test
[frescor/frsh.git] / resources / item / tests / test_item.c
1 #include <frsh.h>
2 #include <error.h>
3 #include <item.h>
4 #include <fres_contract.h>
5
6 #define N 3
7
8 int contract_deadline_sec[N] = { 8, 8, 4 };
9 int contract_nodes[N] = { 0x01, 0x03, 0x02 };
10
11 int main(int argc, char *argv[])
12 {
13         int ret;
14         frsh_contract_t contract[N];
15         frsh_vres_id_t vres[N];
16         int i;
17
18         ret = frsh_init();
19         if (ret) PERROR_AND_EXIT(ret, "frsh_init");
20
21         /* Negotiate N contracts */
22         for (i=0; i<N; i++) {
23                 frsh_rel_time_t deadline;
24                 frsh_signal_info_t si;
25                 fres_block_item_nodes *nodes;
26                 ret = frsh_contract_init(&contract[i]);
27                 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
28
29                 /* Set resource */
30                 ret = frsh_contract_set_resource_and_label(
31                         &contract[i], FRSH_RT_NETWORK, FRSH_NETPF_ITEM, NULL);
32                 if (ret) PERROR_AND_EXIT(ret, "Cannot set resource\n");
33
34                 /* Set nodes we want to receive data from */
35                 nodes = malloc(sizeof(*nodes));
36                 if (!nodes) PERROR_AND_EXIT(errno, "malloc");
37                 nodes->mask = contract_nodes[i];
38                 ret = fres_contract_add_block(contract[i], FRES_BLOCK_ITEM_NODES,
39                                               nodes);
40                 if (ret) PERROR_AND_EXIT(ret, "Cannot add item_nodes block\n");
41
42                 /* Set deadline */
43                 deadline = fosa_msec_to_rel_time(contract_deadline_sec[i]*1000);
44                 ret = frsh_contract_set_timing_reqs(&contract[i],
45                                                     false, &deadline,
46                                             0, si, 0, si);
47                 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_timing_reqs");
48
49                 /* Negotiate the contract */
50                 ret = frsh_contract_negotiate(&contract[i], &vres[i]);
51                 if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
52         }
53         printf("Contracts negotiated\n");
54
55         for (i=0; i<10; i++) {
56                 int j;
57                 printf("Reading data\n");
58                 for (j=0; j<N; j++) {
59                         unsigned *data;
60                         ret = frs_item_receive(vres[j], &data);
61                         if (ret == -1) PERROR_AND_EXIT(errno, "frs_item_receive");
62                         
63                         /* TODO: Do something with the received data */
64
65                         forb_free(data);
66                 }
67                 sleep(1);
68         }
69
70 /*      for (i=0; i<N; i++) { */
71 /*              frsh_cancel_contract(vres[i]); */
72 /*      }        */
73         return 0;
74 }