]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - build/aquosa/tests/negotiation.cc
f4cc5bfdba42dfd3bcfc0d0eb8dd49ef49f1427c
[frescor/frsh-forb.git] / build / aquosa / tests / negotiation.cc
1 #include <frsh.h>
2 #include <error.h>
3 #include <res_dummy.h>
4 #include <getopt.h>
5 #include <ul_logreg.h>
6 #include <wvtest.h>
7
8 #define N 3
9
10 int b[N] = { 10, 20, 30 };
11
12 // TODO: Allow specifying loglevel in evironment
13
14 // static struct option long_opts[] = {
15 //     { "loglevel", 1, 0, 'l' },
16 //     { 0, 0, 0, 0}
17 // };
18
19 // static void
20 // usage(void)
21 // {
22 //      printf("usage: negotiation [ options ]\n");
23 //      printf("  -l, --loglevel <number>|<domain>=<number>,...\n");
24 // }
25
26
27 WVTEST_MAIN("basic negotiation")
28 {
29         int ret;
30         frsh_contract_t contract[N];
31         frsh_vres_id_t vres[N];
32         frsh_rel_time_t budget, period, deadline;
33         int i;
34 //      char opt;
35
36 //      while ((opt = getopt_long(argc, argv, "l:", &long_opts[0], NULL)) != EOF) {
37 //              switch (opt) {
38 //                      case 'l':
39         ul_log_domain_arg2levels("forb_proto_inet=6");
40 //                              break;
41 //                      case 'h':
42 //                      /\*default:*\/
43 //                              usage();
44 //                              exit(opt == 'h' ? 0 : 1);
45 //              }
46 //      }
47
48         ret = WVFRSH(frsh_init());
49         if (ret) exit(1);
50
51         /* Negotiate N contracts */
52         for (i=0; i<N; i++) {
53                 ret = WVFRSH(frsh_contract_init(&contract[i]));
54                 if (ret) exit(1);
55
56                 ret = WVFRSH(frsh_contract_set_resource_and_label(
57                         &contract[i],
58                         DUMMY_RESOURCE_TYPE, DUMMY_RESOURCE_ID,
59                         NULL));
60                 if (ret) exit(1);
61
62                 budget = fosa_msec_to_rel_time(b[i]);
63                 period = fosa_msec_to_rel_time(100);
64                 deadline = fosa_msec_to_rel_time(50);
65                 ret = WVFRSH(frsh_contract_set_basic_params(&contract[i],
66                                                             &budget,
67                                                             &period,
68                                                             FRSH_WT_BOUNDED,
69                                                             FRSH_CT_REGULAR));
70                 if (ret) exit(1);
71                 
72                 ret = WVFRSH(frsh_contract_set_timing_reqs(&contract[i],
73                                                            false, &deadline));
74                 if (ret) exit(1);
75                 
76                 ret = WVFRSH(frsh_contract_negotiate(&contract[i], &vres[i]));
77                 if (ret) exit(1);
78         }
79         for (i=0; i<2 /*N*/; i++) {
80                 // FIXME: There is a bug on the test - the 3rd renegotiation fails
81                 budget = fosa_msec_to_rel_time(2*b[i]);
82                 period = fosa_msec_to_rel_time(110);
83                 ret = WVFRSH(frsh_contract_set_basic_params(&contract[i],
84                                                             &budget,
85                                                             &period,
86                                                             FRSH_WT_BOUNDED,
87                                                             FRSH_CT_REGULAR));
88                 if (ret) exit(1);
89
90                 ret = WVFRSH(frsh_contract_renegotiate_sync(&contract[i], vres[i]));
91                 if (ret) exit(1);
92         }
93
94         /* Cancel N contracts */
95         for (i=0; i<N; i++) {
96                 ret = WVFRSH(frsh_contract_cancel(vres[i]));
97                 if (ret) exit(1);
98         }
99
100         frsh_destroy();
101 }