]> rtime.felk.cvut.cz Git - frescor/frsh-forb.git/blob - src/frsh/frsh_api/tests/dummy_spare_capacity.c
Get rid of the most of other warnings
[frescor/frsh-forb.git] / src / frsh / frsh_api / tests / dummy_spare_capacity.c
1 #include <frsh.h>
2 #include <error.h>
3 #include <signal.h>
4 #include <getopt.h>
5 #include <ul_logreg.h>
6 #include <res_dummy.h>
7 #include <semaphore.h>
8 #include <wvtest.h>
9
10 #define MSEC(x) { x/1000, (x%1000) * 1000000 }
11 frsh_utilization_set_t utilization_set = {
12         .size = 2,
13         .utilizations = {
14                 { .budget = MSEC(20),  .period = MSEC(100),  .deadline = MSEC(100) },
15                 { .budget = MSEC(50),  .period = MSEC(100),  .deadline = MSEC(100) },
16         },
17 };
18
19 frsh_vres_id_t vres[5];
20
21 void
22 get_min_max_budget(int count, int *min, int*max)
23 {
24         frsh_contract_t c;
25         fosa_rel_time_t budget;
26         int i, b;
27
28         *max = 0;
29         *min = 10000;
30         
31         for (i=0; i<count; i++) {
32                 WVFRSH(frsh_vres_get_contract(vres[i], &c));
33                 WVPASS(fres_contract_get_budget(&c, &budget));
34                 b = fosa_rel_time_to_msec(budget);
35                 if (b < *min)
36                         *min = b;
37                 if (b > *max)
38                         *max = b;
39         }
40 }
41
42 WVTEST_MAIN("spare capacity")
43 {
44         frsh_contract_t contract;
45         frsh_rel_time_t zero = fosa_msec_to_rel_time(0);
46         int min, max;
47
48 /*      ul_log_domain_arg2levels(optarg); */
49
50         setenv("WVTEST_DIE_FAST", "", 1);
51         WVFRSH(frsh_init());
52         
53         /* Contract negotiation for CPU */
54         WVFRSH(frsh_contract_init(&contract));
55                 
56         WVFRSH(frsh_contract_set_basic_params(&contract,
57                                              &utilization_set.utilizations[0].budget,
58                                              &utilization_set.utilizations[0].period,
59                                              FRSH_WT_BOUNDED,
60                                                     FRSH_CT_REGULAR));
61
62         WVFRSH(frsh_contract_set_resource_and_label(&contract ,
63                                                    DUMMY_RESOURCE_TYPE, DUMMY_RESOURCE_ID,
64                                                           "spare cap test"));
65
66         WVFRSH(frsh_contract_set_reclamation_params(&contract,
67                                                    &zero,
68                                                    &utilization_set.utilizations[utilization_set.size-1].budget,
69                                                    &utilization_set.utilizations[utilization_set.size-1].period,
70                                                    FRSH_GR_DISCRETE,
71                                                    &utilization_set,
72                                                    0,
73                                                           0));
74
75         WVFRSH(frsh_contract_negotiate(&contract, &vres[0]));
76         get_min_max_budget(1, &min, &max);
77         WVPASS(min == 50 && max == 50);
78         
79         WVFRSH(frsh_contract_negotiate(&contract, &vres[1]));
80         get_min_max_budget(2, &min, &max);
81         WVPASS(min == 20 && max == 50);
82         
83         WVFRSH(frsh_contract_negotiate(&contract, &vres[2]));
84         get_min_max_budget(3, &min, &max);
85         WVPASS(min == 20 && max == 50);
86         
87         WVFRSH(frsh_contract_negotiate(&contract, &vres[3]));
88         get_min_max_budget(4, &min, &max);
89         WVPASS(min == 20 && max == 20);
90         
91
92         WVFRSH(frsh_contract_cancel(vres[0]));
93         WVFRSH(frsh_contract_cancel(vres[1]));
94         WVFRSH(frsh_contract_cancel(vres[2]));
95         WVFRSH(frsh_contract_cancel(vres[3]));
96         frsh_destroy();
97 }
98