]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Finish testing of spare capacity
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 20 Jun 2010 15:05:24 +0000 (17:05 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 20 Jun 2010 15:05:24 +0000 (17:05 +0200)
frsh_api/tests/dummy_spare_capacity.c

index 8157f61edeac60735e6ee63eee0b1d823e01e15f..aef63858c28380cdbdade06d395ced700729e255 100644 (file)
@@ -7,19 +7,6 @@
 #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,
@@ -29,25 +16,37 @@ frsh_utilization_set_t utilization_set = {
        },
 };
 
+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());
@@ -74,9 +73,27 @@ WVTEST_MAIN("spare capacity")
                                                   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();
 }