]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - build/aquosa/tests/negotiation.cc
d4ce749cbcd6ed3448481787a7829401e7509029
[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 int ret;
27 frsh_contract_t contract[N];
28 frsh_vres_id_t vres[N];
29 frsh_rel_time_t budget, period, deadline;
30 int i;
31
32 WVTEST_MAIN("basic negotiation")
33 {
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 }
80
81 WVTEST_MAIN("renegotiation")
82 {
83         for (i=0; i<2 /*N*/; i++) {
84                 // FIXME: There is a bug on the test - the 3rd renegotiation fails
85                 budget = fosa_msec_to_rel_time(2*b[i]);
86                 period = fosa_msec_to_rel_time(110);
87                 ret = WVFRSH(frsh_contract_set_basic_params(&contract[i],
88                                                             &budget,
89                                                             &period,
90                                                             FRSH_WT_BOUNDED,
91                                                             FRSH_CT_REGULAR));
92                 if (ret) exit(1);
93
94                 ret = WVFRSH(frsh_contract_renegotiate_sync(&contract[i], vres[i]));
95                 if (ret) exit(1);
96         }
97 }
98
99 WVTEST_MAIN("cancelation")
100 {
101         /* Cancel N contracts */
102         for (i=0; i<N; i++) {
103                 ret = WVFRSH(frsh_contract_cancel(vres[i]));
104                 if (ret) exit(1);
105         }
106
107         frsh_destroy();
108 }