]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
frsh: Simplify negotiation test and rename the full test as renegotiation
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Feb 2011 07:14:31 +0000 (08:14 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Feb 2011 07:14:31 +0000 (08:14 +0100)
It was daunting to look for bugs in the large test, so now, negotiation
program performs only a single negotiation and cancelation.

frsh_api/tests/Makefile.omk
frsh_api/tests/negotiation.c
frsh_api/tests/negotiation.sh
frsh_api/tests/renegotiation.c [new file with mode: 0644]
frsh_api/tests/renegotiation.sh [new file with mode: 0755]

index 5949f61d57d3c239c3bfbbd92e0218a057bd8f6b..833f73b5ecc0d4a43601c05f12c20bac2e382357 100644 (file)
@@ -5,6 +5,11 @@ test_PROGRAMS += negotiation
 negotiation_SOURCES = negotiation.c
 negotiation_LIBS = wvtest
 
+wvtest_SCRIPTS += renegotiation.sh
+test_PROGRAMS += renegotiation
+renegotiation_SOURCES = renegotiation.c
+renegotiation_LIBS = wvtest
+
 test_PROGRAMS += spare_capacity
 spare_capacity_SOURCES = spare_capacity.c
 
index 8d45b9d441974d5f10f1ce4df23150c3490ea571..cfdd0b773a6113ae957de0b57403dfeb5c4ccfec 100644 (file)
 #include <ul_logreg.h>
 #include <wvtest.h>
 
-#define N 3
-
-int b[N] = { 10, 20, 30 };
-
-// TODO: Allow specifying loglevel in evironment
-
-// static struct option long_opts[] = {
-//     { "loglevel", 1, 0, 'l' },
-//     { 0, 0, 0, 0}
-// };
-
-// static void
-// usage(void)
-// {
-//     printf("usage: negotiation [ options ]\n");
-//     printf("  -l, --loglevel <number>|<domain>=<number>,...\n");
-// }
-
-int ret;
-frsh_contract_t contract[N], c;
-frsh_vres_id_t vres[N];
-frsh_rel_time_t budget, period, deadline;
-int i;
-
-WVTEST_MAIN("basic negotiation")
+WVTEST_MAIN("single negotiation and cancelation")
 {
-//     char opt;
+       int ret;
 
-//     while ((opt = getopt_long(argc, argv, "l:", &long_opts[0], NULL)) != EOF) {
-//             switch (opt) {
-//                     case 'l':
-//                             break;
-//                     case 'h':
-//                     /\*default:*\/
-//                             usage();
-//                             exit(opt == 'h' ? 0 : 1);
-//             }
-//     }
+       frsh_contract_t contract, c;
+       frsh_vres_id_t vres;
+       frsh_rel_time_t budget, period, deadline;
 
        setenv("WVTEST_DIE_FAST", "", 1);
        ret = WVFRSH(frsh_init());
 
-       /* Negotiate N contracts */
-       for (i=0; i<N; i++) {
-               ret = WVFRSH(frsh_contract_init(&contract[i]));
-
-               ret = WVFRSH(frsh_contract_set_resource_and_label(
-                       &contract[i],
-                       DUMMY_RESOURCE_TYPE, DUMMY_RESOURCE_ID,
-                       NULL));
-
-               budget = fosa_msec_to_rel_time(b[i]);
-               period = fosa_msec_to_rel_time(100);
-               deadline = fosa_msec_to_rel_time(50);
-               ret = WVFRSH(frsh_contract_set_basic_params(&contract[i],
-                                                           &budget,
-                                                           &period,
-                                                           FRSH_WT_BOUNDED,
-                                                           FRSH_CT_REGULAR));
-               
-               ret = WVFRSH(frsh_contract_set_timing_reqs(&contract[i],
-                                                          false, &deadline));
-               
-               ret = WVFRSH(frsh_contract_negotiate(&contract[i], &vres[i]));
-               WVFRSH(frsh_vres_get_contract(vres[i], &c));
-               WVPASS(fres_contract_get_budget(&c, &budget));
-               WVPASS(fosa_rel_time_to_msec(budget) == b[i]);
-       }
-
-       /* Renegotiate the first two contracts */
-       for (i=0; i<2; i++) {
-               budget = fosa_msec_to_rel_time(2*b[i]);
-               period = fosa_msec_to_rel_time(110);
-               ret = WVFRSH(frsh_contract_set_basic_params(&contract[i],
-                                                           &budget,
-                                                           &period,
-                                                           FRSH_WT_BOUNDED,
-                                                           FRSH_CT_REGULAR));
-
-               ret = WVFRSH(frsh_contract_renegotiate_sync(&contract[i], vres[i]));
-               WVFRSH(frsh_vres_get_contract(vres[i], &c));
-               WVPASS(fres_contract_get_budget(&c, &budget));
-               WVPASS(fosa_rel_time_to_msec(budget) == 2*b[i]);
-       }
-
-       /* Try to renegotiate the third contract - it will be rejected */
-       budget = fosa_msec_to_rel_time(2*b[2]);
-       period = fosa_msec_to_rel_time(110);
-       ret = WVFRSH(frsh_contract_set_basic_params(&contract[2],
+       /* Negotiate the contract */
+       ret = WVFRSH(frsh_contract_init(&contract));
+       
+       ret = WVFRSH(frsh_contract_set_resource_and_label(
+                            &contract,
+                            DUMMY_RESOURCE_TYPE, DUMMY_RESOURCE_ID,
+                            NULL));
+       
+       budget = fosa_msec_to_rel_time(10);
+       period = fosa_msec_to_rel_time(100);
+       deadline = fosa_msec_to_rel_time(50);
+       ret = WVFRSH(frsh_contract_set_basic_params(&contract,
                                                    &budget,
                                                    &period,
                                                    FRSH_WT_BOUNDED,
                                                    FRSH_CT_REGULAR));
-
-       WVPASS(frsh_contract_renegotiate_sync(&contract[2], vres[2]) == FRSH_ERR_CONTRACT_REJECTED);
-       WVFRSH(frsh_vres_get_contract(vres[2], &c));
+       
+       ret = WVFRSH(frsh_contract_set_timing_reqs(&contract,
+                                                  false, &deadline));
+       
+       ret = WVFRSH(frsh_contract_negotiate(&contract, &vres));
+       WVFRSH(frsh_vres_get_contract(vres, &c));
        WVPASS(fres_contract_get_budget(&c, &budget));
-       WVPASSEQ(fosa_rel_time_to_msec(budget), b[2]);
+       WVPASS(fosa_rel_time_to_msec(budget) == 10);
 
-       /* Cancel N contracts */
-       for (i=0; i<N; i++) {
-               ret = WVFRSH(frsh_contract_cancel(vres[i]));
-       }
+       /* Cancel the contract */
+       ret = WVFRSH(frsh_contract_cancel(vres));
 
        frsh_destroy();
 }
index 1962317fc19b7d5c7483469ef2725415a29bcd1b..5b31203b437777c4a699e64c9b3793ce760ceb08 100755 (executable)
@@ -13,6 +13,27 @@ WVSTART Setup
 WVPASS fcb -dfcb.pid
 WVPASS frm_dummy -dfrm.pid
 
+# cat > .gdbinit <<EOF
+# break main
+# run
 
-WVPASS negotiation
+# break forb_peer_get
+# commands
+# printf "serverid=%llx  refcount=%d\n", *(int64_t*)&peer->server_id, peer->ref.refcount+1
+# bt
+# cont
+# end
+
+# break forb_peer_put
+# commands
+# printf "serverid=%llx  refcount=%d\n", *(int64_t*)&peer->server_id, peer->ref.refcount
+# bt
+# cont
+# end
 
+# break forb_destroy
+# cont
+# layout src
+# EOF
+
+WVPASS negotiation
diff --git a/frsh_api/tests/renegotiation.c b/frsh_api/tests/renegotiation.c
new file mode 100644 (file)
index 0000000..8d45b9d
--- /dev/null
@@ -0,0 +1,113 @@
+#include <frsh.h>
+#include <error.h>
+#include <res_dummy.h>
+#include <getopt.h>
+#include <ul_logreg.h>
+#include <wvtest.h>
+
+#define N 3
+
+int b[N] = { 10, 20, 30 };
+
+// TODO: Allow specifying loglevel in evironment
+
+// static struct option long_opts[] = {
+//     { "loglevel", 1, 0, 'l' },
+//     { 0, 0, 0, 0}
+// };
+
+// static void
+// usage(void)
+// {
+//     printf("usage: negotiation [ options ]\n");
+//     printf("  -l, --loglevel <number>|<domain>=<number>,...\n");
+// }
+
+int ret;
+frsh_contract_t contract[N], c;
+frsh_vres_id_t vres[N];
+frsh_rel_time_t budget, period, deadline;
+int i;
+
+WVTEST_MAIN("basic negotiation")
+{
+//     char opt;
+
+//     while ((opt = getopt_long(argc, argv, "l:", &long_opts[0], NULL)) != EOF) {
+//             switch (opt) {
+//                     case 'l':
+//                             break;
+//                     case 'h':
+//                     /\*default:*\/
+//                             usage();
+//                             exit(opt == 'h' ? 0 : 1);
+//             }
+//     }
+
+       setenv("WVTEST_DIE_FAST", "", 1);
+       ret = WVFRSH(frsh_init());
+
+       /* Negotiate N contracts */
+       for (i=0; i<N; i++) {
+               ret = WVFRSH(frsh_contract_init(&contract[i]));
+
+               ret = WVFRSH(frsh_contract_set_resource_and_label(
+                       &contract[i],
+                       DUMMY_RESOURCE_TYPE, DUMMY_RESOURCE_ID,
+                       NULL));
+
+               budget = fosa_msec_to_rel_time(b[i]);
+               period = fosa_msec_to_rel_time(100);
+               deadline = fosa_msec_to_rel_time(50);
+               ret = WVFRSH(frsh_contract_set_basic_params(&contract[i],
+                                                           &budget,
+                                                           &period,
+                                                           FRSH_WT_BOUNDED,
+                                                           FRSH_CT_REGULAR));
+               
+               ret = WVFRSH(frsh_contract_set_timing_reqs(&contract[i],
+                                                          false, &deadline));
+               
+               ret = WVFRSH(frsh_contract_negotiate(&contract[i], &vres[i]));
+               WVFRSH(frsh_vres_get_contract(vres[i], &c));
+               WVPASS(fres_contract_get_budget(&c, &budget));
+               WVPASS(fosa_rel_time_to_msec(budget) == b[i]);
+       }
+
+       /* Renegotiate the first two contracts */
+       for (i=0; i<2; i++) {
+               budget = fosa_msec_to_rel_time(2*b[i]);
+               period = fosa_msec_to_rel_time(110);
+               ret = WVFRSH(frsh_contract_set_basic_params(&contract[i],
+                                                           &budget,
+                                                           &period,
+                                                           FRSH_WT_BOUNDED,
+                                                           FRSH_CT_REGULAR));
+
+               ret = WVFRSH(frsh_contract_renegotiate_sync(&contract[i], vres[i]));
+               WVFRSH(frsh_vres_get_contract(vres[i], &c));
+               WVPASS(fres_contract_get_budget(&c, &budget));
+               WVPASS(fosa_rel_time_to_msec(budget) == 2*b[i]);
+       }
+
+       /* Try to renegotiate the third contract - it will be rejected */
+       budget = fosa_msec_to_rel_time(2*b[2]);
+       period = fosa_msec_to_rel_time(110);
+       ret = WVFRSH(frsh_contract_set_basic_params(&contract[2],
+                                                   &budget,
+                                                   &period,
+                                                   FRSH_WT_BOUNDED,
+                                                   FRSH_CT_REGULAR));
+
+       WVPASS(frsh_contract_renegotiate_sync(&contract[2], vres[2]) == FRSH_ERR_CONTRACT_REJECTED);
+       WVFRSH(frsh_vres_get_contract(vres[2], &c));
+       WVPASS(fres_contract_get_budget(&c, &budget));
+       WVPASSEQ(fosa_rel_time_to_msec(budget), b[2]);
+
+       /* Cancel N contracts */
+       for (i=0; i<N; i++) {
+               ret = WVFRSH(frsh_contract_cancel(vres[i]));
+       }
+
+       frsh_destroy();
+}
diff --git a/frsh_api/tests/renegotiation.sh b/frsh_api/tests/renegotiation.sh
new file mode 100755 (executable)
index 0000000..cc0f6af
--- /dev/null
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+. $(dirname $0)/wvtest.sh
+
+wvtest_cleanup() {
+    WVPASS kill `cat fcb.pid`
+    WVPASS rm fcb.pid
+    WVPASS kill `cat frm.pid`
+    WVPASS rm frm.pid
+}
+
+WVSTART Setup
+WVPASS fcb -dfcb.pid
+WVPASS frm_dummy -dfrm.pid
+
+WVPASS renegotiation