#include <semaphore.h>
#include <wvtest.h>
-/* static struct option long_opts[] = { */
-/* { "loglevel", 1, 0, 'l' }, */
-/* { 0, 0, 0, 0} */
-/* }; */
-
-/* static void */
-/* usage(void) */
-/* { */
-/* printf("usage: cpu_spare_capacity [ options ]\n"); */
-/* printf(" -l, --loglevel <number>|<domain>=<number>,...\n"); */
-/* } */
-
-
#define MSEC(x) { x/1000, (x%1000) * 1000000 }
frsh_utilization_set_t utilization_set = {
.size = 2,
},
};
+frsh_vres_id_t vres[5];
+
+void
+get_min_max_budget(int count, int *min, int*max)
+{
+ frsh_contract_t c;
+ fosa_rel_time_t budget;
+ int i, b;
+
+ *max = 0;
+ *min = 10000;
+
+ for (i=0; i<count; i++) {
+ WVFRSH(frsh_vres_get_contract(vres[i], &c));
+ WVPASS(fres_contract_get_budget(&c, &budget));
+ b = fosa_rel_time_to_msec(budget);
+ if (b < *min)
+ *min = b;
+ if (b > *max)
+ *max = b;
+ }
+}
+
WVTEST_MAIN("spare capacity")
{
- frsh_vres_id_t vres;
frsh_contract_t contract;
frsh_rel_time_t zero = fosa_msec_to_rel_time(0);
int ret;
-/* char opt; */
+ int min, max;
-/* while ((opt = getopt_long(argc, argv, "l:", &long_opts[0], NULL)) != EOF) { */
-/* switch (opt) { */
-/* case 'l': */
-/* ul_log_domain_arg2levels(optarg); */
-/* break; */
-/* case 'h': */
-/* /\*default:*\/ */
-/* usage(); */
-/* exit(opt == 'h' ? 0 : 1); */
-/* } */
-/* } */
+/* ul_log_domain_arg2levels(optarg); */
setenv("WVTEST_DIE_FAST", "", 1);
WVFRSH(frsh_init());
0,
0));
- ret = WVFRSH(frsh_contract_negotiate(&contract, &vres));
+ WVFRSH(frsh_contract_negotiate(&contract, &vres[0]));
+ get_min_max_budget(1, &min, &max);
+ WVPASS(min == 50 && max == 50);
+
+ WVFRSH(frsh_contract_negotiate(&contract, &vres[1]));
+ get_min_max_budget(2, &min, &max);
+ WVPASS(min == 20 && max == 50);
+
+ WVFRSH(frsh_contract_negotiate(&contract, &vres[2]));
+ get_min_max_budget(3, &min, &max);
+ WVPASS(min == 20 && max == 50);
+
+ WVFRSH(frsh_contract_negotiate(&contract, &vres[3]));
+ get_min_max_budget(4, &min, &max);
+ WVPASS(min == 20 && max == 20);
+
- ret = WVFRSH(frsh_contract_cancel(vres));
+ ret = WVFRSH(frsh_contract_cancel(vres[0]));
+ ret = WVFRSH(frsh_contract_cancel(vres[1]));
+ ret = WVFRSH(frsh_contract_cancel(vres[2]));
+ ret = WVFRSH(frsh_contract_cancel(vres[3]));
frsh_destroy();
}