]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - resources/acpi_battery/tests/acpi_battery_test.c
Added speed reading functions.
[frescor/frsh.git] / resources / acpi_battery / tests / acpi_battery_test.c
1 #include <frsh.h>
2
3 int main()
4 {
5         int terror;
6         frsh_vres_id_t vres;
7         frsh_contract_t contract;
8         frsh_rel_time_t budget, period;
9         frsh_rel_time_t current, duration, expiration;
10         unsigned long duration_msec, duration_step;
11
12         PXW(frsh_init());
13         
14         PXW(frsh_contract_init(&contract));
15
16         duration_msec = duration_step = 1000UL * 60UL * 10UL;
17         
18         budget = fosa_msec_to_rel_time(10);
19         period = fosa_msec_to_rel_time(100);
20         PXW(frsh_contract_set_basic_params(&contract,
21                                            &budget,
22                                            &period,
23                                            FRSH_WT_BOUNDED,
24                                            FRSH_CT_REGULAR));
25
26         PXW(frsh_contract_set_resource_and_label(&contract, FRSH_RT_PROCESSOR, 0,"TEST_VRES"));
27
28         PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_HIGH, &budget));
29
30         PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_MEDIUM, &budget));
31
32         PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_LOW, &budget));
33
34         terror = frsh_battery_get_expiration(&expiration);
35         if (terror == EAGAIN)
36                 PERROR_AND_EXIT(terror, "frsh_battery_get_expiration: system running on AC");
37         if (terror)
38                 PERROR_AND_EXIT(terror, "frsh_battery_get_expiration");
39
40         fosa_clock_get_time(FOSA_CLOCK_REALTIME, &current);
41         printf("System battery wil expire in %lu seconds\n",
42                fosa_rel_time_to_msec(fosa_abs_time_decr(expiration, current)) / 1000UL);
43
44         printf("Starting with minumum diration = %lu seconds\n"
45                " ans stepping by %lu seconds.\n",
46                duration_msec / 1000UL,
47                duration_step / 1000UL);
48
49         duration = fosa_msec_to_rel_time(duration_msec);
50         PXW(frsh_contract_set_min_expiration(&contract, duration));
51
52         PXW(frsh_contract_get_min_expiration(&contract, &duration));
53
54         PXW(frsh_contract_negotiate(&contract, &vres));
55         printf("Aqcpu vres negotiated, vres-ID: %d\n", (int) vres);
56
57         while (1) {
58                 duration_msec += duration_step;
59                 duration = fosa_msec_to_rel_time(duration_msec);
60
61                 fosa_clock_get_time(FOSA_CLOCK_REALTIME, &current);
62                 printf(" Renegotiating the contract with minimum expiration %lu sec.\n"
63                        " System expiration time: %lu seconds\n",
64                        fosa_rel_time_to_msec(duration) / 1000UL,
65                        fosa_rel_time_to_msec(fosa_abs_time_decr(expiration, current)) / 1000UL);
66
67                 PXW(frsh_contract_set_min_expiration(&contract, duration));
68
69                 PXW(frsh_battery_get_expiration(&expiration));
70                 terror = frsh_contract_renegotiate_sync(&contract, vres);
71                 if (terror == FRSH_ERR_CONTRACT_REJECTED) {
72                         PERROR_FRESCOR(terror, "frsh_contract_renegotiate_sync");
73                         goto out;
74                 }
75                 if (terror) PERROR_AND_EXIT(terror, "frsh_contract_renegotiate_sync");
76
77                 sleep(3);
78         }
79
80 out:
81         PXW(frsh_contract_cancel(vres));
82
83         printf("Test PASSED!\n");
84                 
85         return 0;       
86 }
87