Motr  M0
seg0.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2013-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_UT
24 #include "lib/trace.h"
25 
26 #include "lib/memory.h" /* M0_ALLOC_PTR, m0_free */
27 #include "lib/buf.h" /* m0_buf */
28 #include "lib/string.h" /* m0_streq */
29 #include "be/ut/helper.h" /* m0_be_ut_backend */
30 #include "be/seg0.h"
31 #include "format/format.h" /* m0_format_header */
32 #include "ut/ut.h"
33 
34 static const char *be_ut_0type_suffix = "some test suffix";
35 static char be_ut_0type_data[10000];
36 static const struct m0_buf be_ut_0type_data_buf =
39 
41  const char *suffix,
42  const struct m0_buf *data)
43 {
46  return 0;
47 }
48 
50  const char *suffix,
51  const struct m0_buf *data)
52 {
55 }
56 
57 static struct m0_be_0type be_ut_0type_test = {
58  .b0_name = "M0_BE:0type_test",
59  .b0_init = &be_ut_0type_test_init,
60  .b0_fini = &be_ut_0type_test_fini,
61 };
62 
64  struct m0_be_0type *zt,
65  const char *suffix,
66  const struct m0_buf *data,
67  bool add)
68 {
69  struct m0_be_tx_credit credit = {};
70  struct m0_be_domain *dom = &ut_be->but_dom;
71  struct m0_be_tx tx = {};
72  int rc;
73 
75  m0_be_ut_tx_init(&tx, ut_be);
76  if (add) {
77  m0_be_0type_add_credit(dom, zt, suffix, data, &credit);
78  } else {
79  m0_be_0type_del_credit(dom, zt, suffix, &credit);
80  }
81  m0_be_tx_prep(&tx, &credit);
83  if (add) {
84  rc = m0_be_0type_add(zt, dom, &tx, suffix, data);
85  } else {
86  rc = m0_be_0type_del(zt, dom, &tx, suffix);
87  }
88  M0_UT_ASSERT(rc == 0);
90  m0_be_tx_fini(&tx);
92 }
93 
95 {
96  struct m0_be_ut_backend ut_be = {};
97 
100  &be_ut_0type_data_buf, true);
102  NULL, false);
104 }
105 
107 {
108  static const struct {
109  struct m0_format_tag t;
110  struct m0_format_header h;
111  } data[] = {
112  {
113  .t = { 1, 2, { 3 } },
114  .h = { .hd_bits = 0x0001000200000003 }
115  },
116  {
117  .t = { 0x1111, 0x2222, { 0x3333 } },
118  .h = { .hd_bits = 0x1111222200003333 }
119  }
120  };
121  struct m0_format_header h;
122  struct m0_format_tag t;
123  unsigned i;
124 
125  for (i = 0; i < ARRAY_SIZE(data); ++i) {
126  m0_format_header_pack(&h, &data[i].t);
127  M0_UT_ASSERT(h.hd_bits == data[i].h.hd_bits);
128 
130  M0_UT_ASSERT(t.ot_version == data[i].t.ot_version);
131  M0_UT_ASSERT(t.ot_type == data[i].t.ot_type);
132  M0_UT_ASSERT(t.ot_size == data[i].t.ot_size);
133  }
134 }
135 
136 #undef M0_TRACE_SUBSYSTEM
137 
138 /*
139  * Local variables:
140  * c-indentation-style: "K&R"
141  * c-basic-offset: 8
142  * tab-width: 8
143  * fill-column: 80
144  * scroll-step: 1
145  * End:
146  */
147 /*
148  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
149  */
M0_INTERNAL void m0_format_header_pack(struct m0_format_header *dest, const struct m0_format_tag *src)
Definition: format.c:40
M0_INTERNAL void m0_format_header_unpack(struct m0_format_tag *dest, const struct m0_format_header *src)
Definition: format.c:49
void m0_be_0type_add_credit(struct m0_be_domain *dom, const struct m0_be_0type *zt, const char *suffix, const struct m0_buf *data, struct m0_be_tx_credit *credit)
Definition: seg0.c:139
#define NULL
Definition: misc.h:38
const char * b0_name
Definition: seg0.h:44
uint64_t hd_bits
Definition: format.h:53
void m0_be_ut_obj_test(void)
Definition: seg0.c:106
M0_INTERNAL bool m0_buf_eq(const struct m0_buf *x, const struct m0_buf *y)
Definition: buf.c:90
void m0_be_0type_del_credit(struct m0_be_domain *dom, const struct m0_be_0type *zt, const char *suffix, struct m0_be_tx_credit *credit)
Definition: seg0.c:156
static struct m0_be_0type be_ut_0type_test
Definition: seg0.c:57
M0_INTERNAL void m0_be_tx_fini(struct m0_be_tx *tx)
Definition: stubs.c:163
struct m0_bufvec data
Definition: di.c:40
void m0_be_0type_unregister(struct m0_be_domain *dom, struct m0_be_0type *zt)
Definition: seg0.c:72
static const char * be_ut_0type_suffix
Definition: seg0.c:34
M0_INTERNAL void m0_be_tx_prep(struct m0_be_tx *tx, const struct m0_be_tx_credit *credit)
Definition: stubs.c:175
Definition: buf.h:37
int i
Definition: dir.c:1033
struct m0_be_ut_backend ut_be
Definition: ad.c:72
static void be_ut_0type_test_fini(struct m0_be_domain *dom, const char *suffix, const struct m0_buf *data)
Definition: seg0.c:49
void m0_be_0type_register(struct m0_be_domain *dom, struct m0_be_0type *zt)
Definition: seg0.c:65
void m0_be_ut_seg0_test(void)
Definition: seg0.c:94
static struct m0_thread t[8]
Definition: service_ut.c:1230
#define m0_streq(a, b)
Definition: string.h:34
static struct m0_stob_domain * dom
Definition: storage.c:38
void m0_be_ut_backend_init(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:238
M0_INTERNAL int m0_be_tx_exclusive_open_sync(struct m0_be_tx *tx)
Definition: tx.c:594
static int be_ut_0type_test_init(struct m0_be_domain *dom, const char *suffix, const struct m0_buf *data)
Definition: seg0.c:40
struct m0_be_domain but_dom
Definition: helper.h:47
int m0_be_0type_add(struct m0_be_0type *zt, struct m0_be_domain *dom, struct m0_be_tx *tx, const char *suffix, const struct m0_buf *data)
Definition: seg0.c:79
static void be_ut_0type_op_test(struct m0_be_ut_backend *ut_be, struct m0_be_0type *zt, const char *suffix, const struct m0_buf *data, bool add)
Definition: seg0.c:63
int m0_be_0type_del(struct m0_be_0type *zt, struct m0_be_domain *dom, struct m0_be_tx *tx, const char *suffix)
Definition: seg0.c:112
void m0_be_ut_tx_init(struct m0_be_tx *tx, struct m0_be_ut_backend *ut_be)
Definition: stubs.c:286
static const struct m0_buf be_ut_0type_data_buf
Definition: seg0.c:36
void m0_be_ut_backend_fini(struct m0_be_ut_backend *ut_be)
Definition: stubs.c:242
static char be_ut_0type_data[10000]
Definition: seg0.c:35
#define M0_BUF_INIT(size, data)
Definition: buf.h:64
int32_t rc
Definition: trigger_fop.h:47
#define ARRAY_SIZE(a)
Definition: misc.h:45
#define M0_UT_ASSERT(a)
Definition: ut.h:46
M0_INTERNAL void m0_be_tx_close_sync(struct m0_be_tx *tx)
Definition: stubs.c:205
Definition: tx.h:280
static void add(struct m0_addb2_mach *mach, uint64_t id, int n, const uint64_t *value)
Definition: addb2.c:934