Motr  M0
iterator_test.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-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/errno.h"
23 #include "ut/ut.h"
24 #include "lib/memory.h"
25 
26 #include "fop/fop.h"
27 #include "fop/ut/iterator_test.h"
28 #include "fop/ut/iterator_test_xc.h"
29 #include "rpc/rpc_opcodes.h"
30 #include "rpc/rpc_machine.h"
31 #include "xcode/xcode.h"
32 
33 
34 /* FOP object iterator test tests iterations of the following types:
35  * - FFA_RECORD,
36  * - FFA_SEQUENCE.
37  */
38 
40 
41 static void fop_fini(void)
42 {
44  m0_xc_fop_ut_iterator_test_fini();
45 }
46 
47 static int fop_init(void)
48 {
49  m0_xc_fop_ut_iterator_test_init();
50 
51  m0_fop_seg_xc->xct_flags = M0_XCODE_TYPE_FLAG_DOM_RPC;
52  m0_fop_vec_xc->xct_flags = M0_XCODE_TYPE_FLAG_DOM_RPC;
53  m0_fop_optfid_xc->xct_flags = M0_XCODE_TYPE_FLAG_DOM_RPC;
54  m0_fop_recursive1_xc->xct_flags = M0_XCODE_TYPE_FLAG_DOM_RPC;
55  m0_fop_recursive2_xc->xct_flags = M0_XCODE_TYPE_FLAG_DOM_RPC;
56  m0_fop_iterator_test_xc->xct_flags = M0_XCODE_TYPE_FLAG_DOM_RPC;
57 
59  .name = "FOP Iterator Test",
61  .xt = m0_fop_iterator_test_xc);
62  return 0;
63 }
64 
65 /* Just fill fop object fields */
67 {
68  int i;
69 
70  m0_fid_set(&fop->fit_fid, 1, 2);
71 
72  fop->fit_vec.fv_count = 2;
73  M0_ALLOC_ARR(fop->fit_vec.fv_seg, fop->fit_vec.fv_count);
74  M0_UT_ASSERT(fop->fit_vec.fv_seg != NULL);
75  for (i = 0; i < fop->fit_vec.fv_count; ++i) {
76  fop->fit_vec.fv_seg[i].fs_count = i;
77  fop->fit_vec.fv_seg[i].fs_offset = i*2;
78  }
79 
80  m0_fid_set(&fop->fit_opt0.fo_fid, 131, 132);
81  m0_fid_set(&fop->fit_opt1.fo_fid, 31, 32);
82  m0_fid_set(&fop->fit_topt.fo_fid, 41, 42);
83  m0_fid_set(&fop->fit_rec.fr_fid, 5, 6);
84  m0_fid_set(&fop->fit_rec.fr_seq.fr_fid, 7, 8);
85  fop->fit_rec.fr_seq.fr_seq.fv_count = 3;
86  M0_ALLOC_ARR(fop->fit_rec.fr_seq.fr_seq.fv_seg,
87  fop->fit_rec.fr_seq.fr_seq.fv_count);
88  M0_UT_ASSERT(fop->fit_rec.fr_seq.fr_seq.fv_seg != NULL);
89  for (i = 0; i < fop->fit_rec.fr_seq.fr_seq.fv_count; ++i) {
90  fop->fit_rec.fr_seq.fr_seq.fv_seg[i].fs_count = i;
91  fop->fit_rec.fr_seq.fr_seq.fv_seg[i].fs_offset = i*2;
92  }
93  m0_fid_set(&fop->fit_rec.fr_seq.fr_unn.fo_fid, 41, 42);
94 }
95 
96 static void fit_test(void)
97 {
98  int result;
99  int i = 0;
100  struct m0_fop *f;
101  struct m0_fid *fid;
102  struct m0_fop_iterator_test *fop;
103  struct m0_xcode_ctx ctx;
104  struct m0_xcode_cursor *it;
105  static struct m0_fid expected[] = {
106  { 1, 2}, /* fop->fit_fid */
107  {131, 132},
108  {31, 32}, /* fop->fit_opt1.fo_fid */
109  {41, 42}, /* fop->fit_topt.fo_fid */
110  { 5, 6}, /* fop->fit_rec.fr_fid */
111  { 7, 8}, /* fop->fit_rec.fr_seq.fr_fid */
112  {41, 42} /* fop->fit_rec.fr_seq.fr_unn.fo_fid */
113  };
114  struct m0_rpc_machine machine;
115 
117  result = fop_init();
118  M0_UT_ASSERT(result == 0);
119 
121  M0_UT_ASSERT(f != NULL);
122  fop = m0_fop_data(f);
123  fop_obj_init(fop);
124 
126  it = &ctx.xcx_it;
127 
128  while ((result = m0_xcode_next(it)) > 0) {
129  const struct m0_xcode_type *xt;
130  struct m0_xcode_obj *cur;
131  struct m0_xcode_cursor_frame *top;
132 
134 
135  if (top->s_flag != M0_XCODE_CURSOR_PRE)
136  continue;
137 
138  cur = &top->s_obj;
139  xt = cur->xo_type;
140 
141  if (xt == m0_fid_xc) {
142  fid = cur->xo_ptr;
144  expected[i].f_container);
146  expected[i].f_key);
147  ++i;
148  }
149  }
151 
153  fop_fini();
155 }
156 
157 struct m0_ut_suite fit_ut = {
158  .ts_name = "fit-ut",
159  .ts_init = NULL,
160  .ts_fini = NULL,
161  .ts_tests = {
162  { "fop-iterator", fit_test },
163  { NULL, NULL }
164  }
165 };
166 
167 /*
168  * Local variables:
169  * c-indentation-style: "K&R"
170  * c-basic-offset: 8
171  * tab-width: 8
172  * fill-column: 80
173  * scroll-step: 1
174  * End:
175  */
M0_INTERNAL struct m0_xcode_cursor_frame * m0_xcode_cursor_top(struct m0_xcode_cursor *it)
Definition: cursor.c:41
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
#define NULL
Definition: misc.h:38
static struct buffer * cur(struct m0_addb2_mach *mach, m0_bcount_t space)
Definition: addb2.c:791
#define M0_FOP_TYPE_INIT(ft,...)
Definition: fop.h:307
static FILE * f
Definition: adieu.c:79
struct m0_ut_suite fit_ut
void * m0_fop_data(const struct m0_fop *fop)
Definition: fop.c:220
static struct m0_be_emap_cursor it
Definition: extmap.c:46
void m0_fop_type_fini(struct m0_fop_type *fopt)
Definition: fop.c:232
Definition: xcode.c:59
static struct m0_xcode_type ** xt[]
Definition: protocol.c:64
Definition: ut.h:77
M0_INTERNAL void m0_sm_group_fini(struct m0_sm_group *grp)
Definition: sm.c:65
static void fit_test(void)
Definition: iterator_test.c:96
struct m0_sm_group rm_sm_grp
Definition: rpc_machine.h:82
struct m0_fid fid
Definition: di.c:46
static int top
Definition: formation2.c:86
static int expected
Definition: locality.c:102
int opcode
Definition: crate.c:301
int i
Definition: dir.c:1033
M0_INTERNAL void m0_fid_set(struct m0_fid *fid, uint64_t container, uint64_t key)
Definition: fid.c:116
const char * name
Definition: trace.c:110
M0_INTERNAL void m0_sm_group_init(struct m0_sm_group *grp)
Definition: sm.c:53
uint64_t f_container
Definition: fid.h:39
static void fop_fini(void)
Definition: iterator_test.c:41
M0_INTERNAL int m0_xcode_next(struct m0_xcode_cursor *it)
Definition: cursor.c:59
struct m0_rpc_machine machine
Definition: mdstore.c:58
static int fop_init(void)
Definition: iterator_test.c:47
static struct m0_fop_type m0_fop_iterator_test_fopt
Definition: iterator_test.c:39
const char * ts_name
Definition: ut.h:99
Definition: fid.h:38
uint64_t f_key
Definition: fid.h:40
void m0_fop_put_lock(struct m0_fop *fop)
Definition: fop.c:199
static struct m0_fop * fop
Definition: item.c:57
Definition: nucleus.c:42
static void fop_obj_init(struct m0_fop_iterator_test *fop)
Definition: iterator_test.c:66
M0_INTERNAL void m0_xcode_ctx_init(struct m0_xcode_ctx *ctx, const struct m0_xcode_obj *obj)
Definition: xcode.c:373
#define M0_FOP_XCODE_OBJ(f)
Definition: fop.h:334
#define ARRAY_SIZE(a)
Definition: misc.h:45
#define M0_UT_ASSERT(a)
Definition: ut.h:46
Definition: fop.h:79
struct m0_fop * m0_fop_alloc(struct m0_fop_type *fopt, void *data, struct m0_rpc_machine *mach)
Definition: fop.c:96