Motr  M0
udb_ut.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
22 #include "lib/types.h"
23 #include "ut/ut.h"
24 #include "lib/misc.h" /* M0_SET0() */
25 
26 #include "udb/udb.h"
27 
28 static void cred_init(struct m0_udb_cred *cred,
30  struct m0_udb_domain *dom)
31 {
32  cred->uc_type = type;
33  cred->uc_domain = dom;
34 }
35 
36 static void cred_fini(struct m0_udb_cred *cred)
37 {
38 }
39 
40 /* uncomment when realization ready */
41 #if 0
42 static bool cred_cmp(struct m0_udb_cred *left,
43  struct m0_udb_cred *right)
44 {
45  return
46  left->uc_type == right->uc_type &&
47  left->uc_domain == right->uc_domain;
48 }
49 #endif
50 
51 static void udb_test(void)
52 {
53  int ret;
54  struct m0_udb_domain dom;
55  struct m0_udb_ctxt ctx;
56  struct m0_udb_cred external;
57  struct m0_udb_cred internal;
58  struct m0_udb_cred testcred;
59 
60  cred_init(&external, M0_UDB_CRED_EXTERNAL, &dom);
61  cred_init(&internal, M0_UDB_CRED_INTERNAL, &dom);
62 
63  ret = m0_udb_ctxt_init(&ctx);
64  M0_UT_ASSERT(ret == 0);
65 
66  /* add mapping */
67  ret = m0_udb_add(&ctx, &dom, &external, &internal);
68  M0_UT_ASSERT(ret == 0);
69 
70  M0_SET0(&testcred);
71  ret = m0_udb_e2i(&ctx, &external, &testcred);
72  /* means that mapping exists */
73  M0_UT_ASSERT(ret == 0);
74 /* uncomment when realization ready */
75 #if 0
76  /* successfully mapped */
77  M0_UT_ASSERT(cred_cmp(&internal, &testcred));
78 #endif
79  M0_SET0(&testcred);
80  ret = m0_udb_i2e(&ctx, &internal, &testcred);
81  /* means that mapping exists */
82  M0_UT_ASSERT(ret == 0);
83 /* uncomment when realization ready */
84 #if 0
85  /* successfully mapped */
86  M0_UT_ASSERT(cred_cmp(&external, &testcred));
87 #endif
88  /* delete mapping */
89  ret = m0_udb_del(&ctx, &dom, &external, &internal);
90  M0_UT_ASSERT(ret == 0);
91 
92 /* uncomment when realization ready */
93 #if 0
94  /* check that mapping does not exist */
95  M0_SET0(&testcred);
96  ret = m0_udb_e2i(&ctx, &external, &testcred);
97  M0_UT_ASSERT(ret != 0);
98 
99  /* check that mapping does not exist */
100  M0_SET0(&testcred);
101  ret = m0_udb_i2e(&ctx, &internal, &testcred);
102  M0_UT_ASSERT(ret != 0);
103 #endif
104  cred_fini(&internal);
105  cred_fini(&external);
107 }
108 
109 struct m0_ut_suite udb_ut = {
110  .ts_name = "udb-ut",
111  .ts_init = NULL,
112  .ts_fini = NULL,
113  .ts_tests = {
114  { "udb", udb_test },
115  { NULL, NULL }
116  }
117 };
118 
119 /*
120  * Local variables:
121  * c-indentation-style: "K&R"
122  * c-basic-offset: 8
123  * tab-width: 8
124  * fill-column: 80
125  * scroll-step: 1
126  * End:
127  */
M0_INTERNAL int m0_udb_add(struct m0_udb_ctxt *ctxt, const struct m0_udb_domain *edomain, const struct m0_udb_cred *external, const struct m0_udb_cred *internal)
Definition: udb.c:43
#define NULL
Definition: misc.h:38
M0_INTERNAL int m0_udb_ctxt_init(struct m0_udb_ctxt *ctxt)
Definition: udb.c:30
M0_INTERNAL int m0_udb_del(struct m0_udb_ctxt *ctxt, const struct m0_udb_domain *edomain, const struct m0_udb_cred *external, const struct m0_udb_cred *internal)
Definition: udb.c:52
static void udb_test(void)
Definition: udb_ut.c:51
static int left
Definition: locality.c:280
#define M0_SET0(obj)
Definition: misc.h:64
Definition: ut.h:77
enum m0_udb_cred_type uc_type
Definition: udb.h:69
static struct m0_stob_domain * dom
Definition: storage.c:38
struct m0_ut_suite udb_ut
Definition: udb_ut.c:109
const char * ts_name
Definition: ut.h:99
m0_udb_cred_type
Definition: udb.h:63
M0_INTERNAL int m0_udb_e2i(struct m0_udb_ctxt *ctxt, const struct m0_udb_cred *external, struct m0_udb_cred *internal)
Definition: udb.c:62
static void cred_init(struct m0_udb_cred *cred, enum m0_udb_cred_type type, struct m0_udb_domain *dom)
Definition: udb_ut.c:28
struct m0_udb_domain * uc_domain
Definition: udb.h:70
Definition: nucleus.c:42
int type
Definition: dir.c:1031
static void cred_fini(struct m0_udb_cred *cred)
Definition: udb_ut.c:36
M0_INTERNAL int m0_udb_i2e(struct m0_udb_ctxt *ctxt, const struct m0_udb_cred *internal, struct m0_udb_cred *external)
Definition: udb.c:71
#define M0_UT_ASSERT(a)
Definition: ut.h:46
M0_INTERNAL void m0_udb_ctxt_fini(struct m0_udb_ctxt *ctxt)
Definition: udb.c:36