From: Michal Sojka Date: Wed, 23 Jun 2010 15:37:49 +0000 (+0200) Subject: Start of transaction implementation and tests X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/frsh.git/commitdiff_plain/cd50efb70d107923064dca31c0d99a377b5f63a8 Start of transaction implementation and tests --- diff --git a/fres/contract/fres_error.c b/fres/contract/fres_error.c index bfcf30f..ec331b7 100644 --- a/fres/contract/fres_error.c +++ b/fres/contract/fres_error.c @@ -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; diff --git a/fres/contract/fres_error.h b/fres/contract/fres_error.h index 8864b45..9c7b234 100644 --- a/fres/contract/fres_error.h +++ b/fres/contract/fres_error.h @@ -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); diff --git a/frsh_api/frsh_transaction.c b/frsh_api/frsh_transaction.c index 6909d83..fd7fb79 100644 --- a/frsh_api/frsh_transaction.c +++ b/frsh_api/frsh_transaction.c @@ -32,11 +32,89 @@ #include #include +#include +#include +#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; +} diff --git a/frsh_api/tests/Makefile.omk b/frsh_api/tests/Makefile.omk index 6eb7237..5949f61 100644 --- a/frsh_api/tests/Makefile.omk +++ b/frsh_api/tests/Makefile.omk @@ -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 diff --git a/frsh_api/tests/trans_nego.c b/frsh_api/tests/trans_nego.c index 5b74f78..1f8d85c 100644 --- a/frsh_api/tests/trans_nego.c +++ b/frsh_api/tests/trans_nego.c @@ -1,23 +1,24 @@ #include #include #include +#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 index 0000000..6875903 --- /dev/null +++ b/frsh_api/tests/trans_nego.h @@ -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 diff --git a/frsh_api/tests/trans_nego.sh b/frsh_api/tests/trans_nego.sh index 42d7741..a37cfc0 100755 --- a/frsh_api/tests/trans_nego.sh +++ b/frsh_api/tests/trans_nego.sh @@ -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 index 0000000..1dfd8fb --- /dev/null +++ b/frsh_api/tests/trans_nego2.c @@ -0,0 +1,19 @@ +#include +#include +#include +#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(); +}