]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Start of transaction implementation and tests
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 23 Jun 2010 15:37:49 +0000 (17:37 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 23 Jun 2010 15:37:49 +0000 (17:37 +0200)
fres/contract/fres_error.c
fres/contract/fres_error.h
frsh_api/frsh_transaction.c
frsh_api/tests/Makefile.omk
frsh_api/tests/trans_nego.c
frsh_api/tests/trans_nego.h [new file with mode: 0644]
frsh_api/tests/trans_nego.sh
frsh_api/tests/trans_nego2.c [new file with mode: 0644]

index bfcf30f2e9ea4ac122ae7c76e7502b6228ae4ce8..ec331b761d21c183376089e4dac9c20d7804155c 100644 (file)
@@ -124,6 +124,8 @@ int fres_strerror (int error, char *message, size_t size)
                MSG(FORB_EX_APPLICATION);
                MSG(NO_RESOURCE_MANAGER);
                MSG(ALLOCATOR_ALREADY_REGISTERED);
+               MSG(VRES_ALREADY_ALLOCATED);
+               MSG(VRES_PART_OF_TRANSACTION);
        }
 
        if (s == NULL) return FRSH_ERR_BAD_ARGUMENT;
index 8864b457ccc2b9a231a4435069e013cf9a22882e..9c7b23470ffdaa52280d272dc732c7a3e7f1f86b 100644 (file)
@@ -93,6 +93,8 @@ enum fres_error {
        FRES_ERR_FORB_EX_APPLICATION,
        FRES_ERR_NO_RESOURCE_MANAGER,
        FRES_ERR_ALLOCATOR_ALREADY_REGISTERED,
+       FRES_ERR_VRES_ALREADY_ALLOCATED,
+       FRES_ERR_VRES_PART_OF_TRANSACTION,
 };
 
 int fres_strerror (int error, char *message, size_t size);
index 6909d837dc85f1954e149c90d23c108149561727..fd7fb797e42ca87f75703bf6320fca5f75d6532b 100644 (file)
 
 #include <frsh.h>
 #include <frsh_transaction.h>
+#include <fres_transaction.h>
+#include <fcb.h>
+#include "frsh_forb.h"
 
+int
+frsh_transaction_init(frsh_transaction_t *transaction,
+                     char *name)
+{
+       int ret = 0;
+       if (!transaction) {
+               ret = FRSH_ERR_BAD_ARGUMENT;
+               goto err;
+       }
+       *transaction = fres_transaction_new();
+       (*transaction)->name = name;
+err:
+       return ret;
+}
+
+void
+frsh_transaction_destroy(frsh_transaction_t *transaction)
+{
+       fres_transaction_destroy(*transaction);
+}
+
+int
+frsh_transaction_add_contract(frsh_transaction_t *transaction,
+                             frsh_contract_t *contract,
+                             int id)
+{
+       int ret;
+       if (!transaction || !*transaction ||
+           !contract || !*contract ||
+           id < 0) {
+               ret = FRSH_ERR_BAD_ARGUMENT;
+               goto err;
+       }
+       
+       ret = fres_transaction_add_contract(*transaction, *contract);
+       if (ret == -1)
+               ret = FRSH_ERR_INTERNAL_ERROR;
+       else
+               ret = 0;
+err:   
+       return ret;
+}
 
 int
 frsh_transaction_negotiate(frsh_transaction_t *trans)
+{
+       int ret;
+       struct forb_env env;
+       if (!trans || !*trans) {
+               ret = FRSH_ERR_BAD_ARGUMENT;
+               goto err;
+       }
+       ret = fres_contract_broker_negotiate_transaction(
+               frsh_forb_global.fcb, *trans, &env);
+       if (forb_exception_occurred(&env)) {
+               ret = fres_forbex2err(&env);
+               goto err;
+       }
+err:
+       return ret;
+}
+
+int
+frsh_transaction_cancel(frsh_transaction_t *trans)
 {
        return FRSH_ERR_NOT_IMPLEMENTED;
 }
 
+int
+frsh_transaction_wait_for_name(frsh_transaction_t *transaction,
+                              const char *name)
+{
+       return FRSH_ERR_NOT_IMPLEMENTED;
+}
+
+int
+frsh_transaction_alloc_vres(frsh_transaction_t *t,
+                           int id,
+                           frsh_vres_id_t *vres)
+{
+       return FRSH_ERR_NOT_IMPLEMENTED;
+}
index 6eb7237e602c08134911a98a270a17c69dc523f0..5949f61d57d3c239c3bfbbd92e0218a057bd8f6b 100644 (file)
@@ -28,6 +28,9 @@ wvtest_SCRIPTS += trans_nego.sh
 test_PROGRAMS += trans_nego
 trans_nego_SOURCES = trans_nego.c
 trans_nego_LIBS = wvtest
+test_PROGRAMS += trans_nego2
+trans_nego2_SOURCES = trans_nego2.c
+trans_nego2_LIBS = wvtest
 
 test_PROGRAMS += negobench
 negobench_SOURCES = negobench.c
index 5b74f782a01d599577793fbeeded783513a4d323..1f8d85c9ee3c7fdce7adf615b3b8c7d4fb4e21eb 100644 (file)
@@ -1,23 +1,24 @@
 #include <frsh.h>
 #include <wvtest.h>
 #include <res_dummy.h>
+#include "trans_nego.h"
 
 WVTEST_MAIN("transaction negotiation")
 {
        frsh_contract_t contract[3];
-       const frsh_resource_id_t id[3] = { 255, 0, 1 };
+       const frsh_resource_id_t id[3] = { 0, 1, 255 };
        frsh_contract_label_t label[3];
        frsh_rel_time_t budget, period;
        int i;
-       fres_transaction_t *t;
+       frsh_transaction_t t;
+       frsh_vres_id_t vres1, vres2;
        
        WVFRSH(frsh_init());
-       WVFRSH(fra_dummy_init_and_activate_id(0));
        WVFRSH(fra_dummy_init_and_activate_id(1));
 
-       WVPASS(t = fres_transaction_new());
+       WVFRSH(frsh_transaction_init(&t, "test"));
 
-       for (i = 0; i < 3; i++) {
+       for (i = TEST_CONTRACT_1; i <= TEST_CONTRACT_3; i++) {
                WVFRSH(frsh_contract_init(&contract[i]));
                sprintf(label[i], "contract%d", i);
                WVFRSH(frsh_contract_set_resource_and_label(
@@ -33,9 +34,15 @@ WVTEST_MAIN("transaction negotiation")
                                                      FRSH_WT_BOUNDED,
                                                      FRSH_CT_REGULAR));
 
-               WVPASS(fres_transaction_add_contract(t, contract[i]) > 0);
+               WVFRSH(frsh_transaction_add_contract(&t, &contract[i], i));
        }
-       WVFRSH(frsh_transaction_negotiate(t));
+       WVFRSH(frsh_transaction_negotiate(&t));
+
+       WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_1, &vres1));
+       WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_2, &vres2));
+       /* TEST_CONTRACT_3 is allocated in trans_nego2.c */
+
+       WVPASS(frsh_contract_cancel(vres2) == FRES_ERR_VRES_PART_OF_TRANSACTION);
        
        frsh_destroy();
 }
diff --git a/frsh_api/tests/trans_nego.h b/frsh_api/tests/trans_nego.h
new file mode 100644 (file)
index 0000000..6875903
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef TRANS_NEGO_H
+#define TRANS_NEGO_H
+
+enum {
+       TEST_CONTRACT_1 = 0,
+       TEST_CONTRACT_2 = 1,
+       TEST_CONTRACT_3 = 2,
+};
+
+#endif
index 42d774185b1f5dbf9567bf7a75d7ae6ccbc8a80e..a37cfc0a46247daa4dafd4341c4664b05c7e117b 100755 (executable)
@@ -21,3 +21,4 @@ WVPASS rm frm1.pid
 ' 0
 
 WVPASS trans_nego
+WVPASS trans_nego2
diff --git a/frsh_api/tests/trans_nego2.c b/frsh_api/tests/trans_nego2.c
new file mode 100644 (file)
index 0000000..1dfd8fb
--- /dev/null
@@ -0,0 +1,19 @@
+#include <frsh.h>
+#include <wvtest.h>
+#include <res_dummy.h>
+#include "trans_nego.h"
+
+WVTEST_MAIN("transaction negotiation - remote part")
+{
+       frsh_transaction_t t;
+       frsh_vres_id_t vres3;
+       
+       WVFRSH(frsh_init());
+       WVFRSH(fra_dummy_init_and_activate_id(1));
+       WVFRSH(frsh_transaction_wait_for_name(&t, "test"));
+       WVPASS(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_2, &vres3) ==
+              FRES_ERR_VRES_ALREADY_ALLOCATED);
+       WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_3, &vres3));
+       
+       frsh_destroy();
+}