]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - frsh_api/tests/dummy_spare_capacity.c
Remove "Setup" header from tests
[frescor/frsh.git] / 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 ret;
47         int min, max;
48
49 /*      ul_log_domain_arg2levels(optarg); */
50
51         setenv("WVTEST_DIE_FAST", "", 1);
52         WVFRSH(frsh_init());
53         
54         /* Contract negotiation for CPU */
55         ret = WVFRSH(frsh_contract_init(&contract));
56                 
57         ret = WVFRSH(frsh_contract_set_basic_params(&contract,
58                                              &utilization_set.utilizations[0].budget,
59                                              &utilization_set.utilizations[0].period,
60                                              FRSH_WT_BOUNDED,
61                                                     FRSH_CT_REGULAR));
62
63         ret = WVFRSH(frsh_contract_set_resource_and_label(&contract ,
64                                                    DUMMY_RESOURCE_TYPE, DUMMY_RESOURCE_ID,
65                                                           "spare cap test"));
66
67         ret = WVFRSH(frsh_contract_set_reclamation_params(&contract,
68                                                    &zero,
69                                                    &utilization_set.utilizations[utilization_set.size-1].budget,
70                                                    &utilization_set.utilizations[utilization_set.size-1].period,
71                                                    FRSH_GR_DISCRETE,
72                                                    &utilization_set,
73                                                    0,
74                                                           0));
75
76         WVFRSH(frsh_contract_negotiate(&contract, &vres[0]));
77         get_min_max_budget(1, &min, &max);
78         WVPASS(min == 50 && max == 50);
79         
80         WVFRSH(frsh_contract_negotiate(&contract, &vres[1]));
81         get_min_max_budget(2, &min, &max);
82         WVPASS(min == 20 && max == 50);
83         
84         WVFRSH(frsh_contract_negotiate(&contract, &vres[2]));
85         get_min_max_budget(3, &min, &max);
86         WVPASS(min == 20 && max == 50);
87         
88         WVFRSH(frsh_contract_negotiate(&contract, &vres[3]));
89         get_min_max_budget(4, &min, &max);
90         WVPASS(min == 20 && max == 20);
91         
92
93         ret = WVFRSH(frsh_contract_cancel(vres[0]));
94         ret = WVFRSH(frsh_contract_cancel(vres[1]));
95         ret = WVFRSH(frsh_contract_cancel(vres[2]));
96         ret = WVFRSH(frsh_contract_cancel(vres[3]));
97         frsh_destroy();
98 }
99