#include <frsh.h>
-#include <aqcpu_res.h>
-#include <error.h>
int main()
{
- int ret;
+ int terror;
frsh_vres_id_t vres;
frsh_contract_t contract;
frsh_rel_time_t budget, period;
- frsh_rel_time_t duration, expiration;
- unsigned long long duration_msec = 10000;
+ frsh_rel_time_t current, duration, expiration;
+ unsigned long duration_msec, duration_step;
- if (frsh_init())
- error(1, 0, "FRSH initialization failed\n");
+ PXW(frsh_init());
+
+ PXW(frsh_contract_init(&contract));
+
+ duration_msec = duration_step = 1000UL * 60UL * 10UL;
- /* Contract negotiation for CPU */
- ret = frsh_contract_init(&contract);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_init");
-
budget = fosa_msec_to_rel_time(10);
period = fosa_msec_to_rel_time(100);
- ret = frsh_contract_set_basic_params(&contract,
- &budget,
- &period,
- FRSH_WT_BOUNDED,
- FRSH_CT_REGULAR);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_basic_params");
+ PXW(frsh_contract_set_basic_params(&contract,
+ &budget,
+ &period,
+ FRSH_WT_BOUNDED,
+ FRSH_CT_REGULAR));
+
+ PXW(frsh_contract_set_resource_and_label(&contract, FRSH_RT_PROCESSOR, 0,"TEST_VRES"));
+
+ PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_HIGH, &budget));
- ret = frsh_contract_set_resource_and_label(&contract, FRSH_RT_PROCESSOR,
- 0,"TEST_VRES");
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_resource_and_label");
+ PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_MEDIUM, &budget));
- ret = frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_HIGH, &budget);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_budget_pow (FRSH_PLT_HIGH)");
+ PXW(frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_LOW, &budget));
- ret = frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_MEDIUM, &budget);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_budget_pow (FRSH_PLT_MEDIUM)");
+ terror = frsh_battery_get_expiration(&expiration);
+ if (terror == EAGAIN)
+ PERROR_AND_EXIT(terror, "frsh_battery_get_expiration: system running on AC");
+ if (terror)
+ PERROR_AND_EXIT(terror, "frsh_battery_get_expiration");
- ret = frsh_contract_set_min_budget_pow(&contract, FRSH_PLT_LOW, &budget);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_budget_pow (FRSH_PLT_LOW)");
+ fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t);
+ printf("System battery wil expire in %lu seconds\n",
+ fosa_rel_time_to_msec(fosa_abs_time_decr(expiration, current)) / 1000UL);
+
+ printf("Starting with minumum diration = %lu seconds\n"
+ " ans stepping by %lu seconds.\n",
+ duration_msec / 1000UL,
+ duration_step / 1000UL);
duration = fosa_msec_to_rel_time(duration_msec);
- ret = frsh_contract_set_min_expiration(&contract, duration);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_expiration");
+ PXW(frsh_contract_set_min_expiration(&contract, duration));
- ret = frsh_contract_get_min_expiration(&contract, &duration);
- if (ret || fosa_rel_time_to_msec(duration) != duration_msec)
- PERROR_AND_EXIT(ret, "frsh_contract_get_min_expiration");
- printf("Minimum duration correctly set to: %lu\n", fosa_rel_time_to_msec(duration));
+ PXW(frsh_contract_get_min_expiration(&contract, &duration));
- ret = frsh_contract_negotiate(&contract, &vres);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_negotiate");
+ PXW(frsh_contract_negotiate(&contract, &vres));
printf("Aqcpu vres negotiated, vres-ID: %d\n", (int) vres);
while (1) {
- duration_msec += duration_msec;
+ duration_msec += duration_step;
duration = fosa_msec_to_rel_time(duration_msec);
- ret = frsh_contract_set_min_expiration(&contract, duration);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_set_min_expiration");
-
- ret = frsh_contract_get_min_expiration(&contract, &duration);
- if (ret || fosa_rel_time_to_msec(duration) != duration_msec) {
- //PERROR_AND_EXIT(ret, "frsh_contract_get_duration");
- printf("%lu %lu\n", fosa_rel_time_to_msec(duration), duration_msec);
- break;
- }
- printf("Minimum duration correctly set to: %lu\n",
- fosa_rel_time_to_msec(duration));
+ fosa_clock_get_time(FOSA_CLOCK_REALTIME, ¤t);
+ printf(" Renegotiating the contract with minimum expiration %lu sec.\n"
+ " System expiration time: %lu seconds\n",
+ fosa_rel_time_to_msec(duration) / 1000UL,
+ fosa_rel_time_to_msec(fosa_abs_time_decr(expiration, current)) / 1000UL);
- ret = frsh_battery_get_expiration(&expiration);
- if (ret) PERROR_AND_EXIT(ret, "frsh_battery_get_expiration");
+ PXW(frsh_contract_set_min_expiration(&contract, duration));
- ret = frsh_contract_renegotiate_sync(&contract, vres);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_renegotiate_sync");
-
- printf("Contract with minimum expiration %lu renegotiated."
- "System expiration time: %lu\n",
- fosa_rel_time_to_msec(duration),
- fosa_abs_time_to_msec(expiration));
+ PXW(frsh_battery_get_expiration(&expiration));
+ terror = frsh_contract_renegotiate_sync(&contract, vres);
+ if (terror == FRSH_ERR_CONTRACT_REJECTED) {
+ PERROR_FRESCOR(terror, "frsh_contract_renegotiate_sync");
+ goto out;
+ }
+ if (terror) PERROR_AND_EXIT(terror, "frsh_contract_renegotiate_sync");
sleep(3);
}
- ret = frsh_contract_cancel(vres);
- if (ret) PERROR_AND_EXIT(ret, "frsh_contract_cancel");
+out:
+ PXW(frsh_contract_cancel(vres));
printf("Test PASSED!\n");