]> rtime.felk.cvut.cz Git - frescor/frsh.git/blob - frsh_api/tests/trans_nego.c
fcb: Reject direct contract manipulation in transactions
[frescor/frsh.git] / frsh_api / tests / trans_nego.c
1 #include <frsh.h>
2 #include <wvtest.h>
3 #include <res_dummy.h>
4 #include "trans_nego.h"
5
6 WVTEST_MAIN("transaction negotiation")
7 {
8         frsh_contract_t contract[3];
9         frsh_contract_label_t label[3];
10         frsh_rel_time_t budget, period;
11         int i;
12         frsh_transaction_t t;
13         frsh_vres_id_t vres0, vres1;
14         
15         WVFRSH(frsh_init());
16
17         WVFRSH(frsh_transaction_init(&t, "test"));
18
19         for (i = TEST_CONTRACT_0; i <= TEST_CONTRACT_2; i++) {
20                 WVFRSH(frsh_contract_init(&contract[i]));
21                 sprintf(label[i], "contract%d", i);
22                 WVFRSH(frsh_contract_set_resource_and_label(
23                                &contract[i],
24                                DUMMY_RESOURCE_TYPE, i,
25                                label[i]));
26
27                 budget = fosa_msec_to_rel_time(10);
28                 period = fosa_msec_to_rel_time(100);
29                 WVFRSH(frsh_contract_set_basic_params(&contract[i],
30                                                       &budget,
31                                                       &period,
32                                                       FRSH_WT_BOUNDED,
33                                                       FRSH_CT_REGULAR));
34
35                 WVFRSH(frsh_transaction_add_contract(&t, &contract[i], i));
36         }
37         WVPASS(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_0, &vres0) == FRES_ERR_TRANSACTION_NOT_FOUND);
38         WVFRSH(frsh_transaction_negotiate(&t));
39
40         WVFRSH(fra_dummy_init_and_activate_id(0));
41         WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_0, &vres0));
42         
43         WVPASS(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_1, &vres1) == FRES_ERR_NO_RESOURCE_ALLOCATOR);
44         WVFRSH(fra_dummy_init_and_activate_id(1));
45         WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_1, &vres1));
46         WVPASS(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_2+1, &vres1) == FRSH_ERR_TOO_LARGE);
47         /* TEST_CONTRACT_2 is allocated in trans_nego2.c */
48
49         WVPASS(frsh_contract_cancel(vres1) == FRES_ERR_VRES_PART_OF_TRANSACTION);
50
51         frsh_destroy();
52 }