Motr  M0
main.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2021 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 #include "dtm0/clk_src.h"
23 #include "dtm0/fop.h"
24 #include "dtm0/helper.h"
25 #include "dtm0/service.h"
26 #include "dtm0/tx_desc.h"
27 #include "be/dtm0_log.h"
28 #include "net/net.h"
29 #include "rpc/rpclib.h"
30 #include "ut/ut.h"
31 #include "cas/cas.h"
32 #include "cas/cas_xc.h"
33 
34 
35 enum {
37 };
38 
39 struct record
40 {
41  uint64_t key;
42  uint64_t value;
43 };
44 
45 static void cas_xcode_test(void)
46 {
47  struct record recs[NUM_CAS_RECS];
48  struct m0_cas_rec cas_recs[NUM_CAS_RECS];
49  struct m0_fid fid = M0_FID_TINIT('i', 0, 0);
50  void *buf;
51  m0_bcount_t len;
52  int rc;
53  int i;
54  struct m0_cas_op *op_out;
55  struct m0_cas_op op_in = {
56  .cg_id = {
57  .ci_fid = fid
58  },
59  .cg_rec = {
60  .cr_rec = cas_recs
61  },
62  .cg_txd = {
63  .dtd_ps = {
64  .dtp_nr = 1,
65  .dtp_pa = &(struct m0_dtm0_tx_pa) {
66  .p_state = 555,
67  },
68  },
69  },
70  };
71 
72  /* Fill array with pair: [key, value]. */
74  (recs[i].key = i, recs[i].value = i * i, true));
75 
76  for (i = 0; i < NUM_CAS_RECS - 1; i++) {
77  cas_recs[i] = (struct m0_cas_rec){
78  .cr_key = (struct m0_rpc_at_buf) {
79  .ab_type = 1,
80  .u.ab_buf = M0_BUF_INIT(sizeof recs[i].key,
81  &recs[i].key)
82  },
83  .cr_val = (struct m0_rpc_at_buf) {
84  .ab_type = 0,
85  .u.ab_buf = M0_BUF_INIT(0, NULL)
86  },
87  .cr_rc = 0 };
88  }
89  cas_recs[NUM_CAS_RECS - 1] = (struct m0_cas_rec) { .cr_rc = ~0ULL };
90  while (cas_recs[op_in.cg_rec.cr_nr].cr_rc != ~0ULL)
91  ++ op_in.cg_rec.cr_nr;
92 
93  rc = m0_xcode_obj_enc_to_buf(&M0_XCODE_OBJ(m0_cas_op_xc, &op_in),
94  &buf, &len);
95  M0_UT_ASSERT(rc == 0);
96  M0_ALLOC_PTR(op_out);
97  M0_UT_ASSERT(op_out != NULL);
98  rc = m0_xcode_obj_dec_from_buf(&M0_XCODE_OBJ(m0_cas_op_xc, op_out),
99  buf, len);
100  M0_UT_ASSERT(rc == 0);
101 
102  m0_xcode_free_obj(&M0_XCODE_OBJ(m0_cas_op_xc, op_out));
103 }
104 
105 extern void m0_dtm0_ut_drlink_simple(void);
106 extern void m0_dtm0_ut_domain_init_fini(void);
107 
109  .ts_name = "dtm0-ut",
110  .ts_tests = {
111  { "xcode", &cas_xcode_test },
112  { "drlink-simple", &m0_dtm0_ut_drlink_simple },
113  { "domain_init-fini", &m0_dtm0_ut_domain_init_fini },
114  { NULL, NULL },
115  }
116 };
117 
118 /*
119  * Local variables:
120  * c-indentation-style: "K&R"
121  * c-basic-offset: 8
122  * tab-width: 8
123  * fill-column: 80
124  * scroll-step: 1
125  * End:
126  */
uint64_t value
Definition: service_ut.c:1415
#define NULL
Definition: misc.h:38
struct m0_ut_suite dtm0_ut
Definition: main.c:108
int const char const void * value
Definition: dir.c:325
M0_INTERNAL void m0_xcode_free_obj(struct m0_xcode_obj *obj)
Definition: xcode.c:248
uint64_t m0_bcount_t
Definition: types.h:77
static int void * buf
Definition: dir.c:1019
Definition: ut.h:77
static void cas_xcode_test(void)
Definition: main.c:45
Definition: sock.c:887
struct m0_fid fid
Definition: di.c:46
struct m0_rpc_at_buf cr_key
Definition: cas.h:172
int i
Definition: dir.c:1033
uint64_t cr_nr
Definition: cas.h:235
#define M0_FID_TINIT(type, container, key)
Definition: fid.h:90
void m0_dtm0_ut_drlink_simple(void)
Definition: drlink.c:47
M0_INTERNAL int m0_xcode_obj_enc_to_buf(struct m0_xcode_obj *obj, void **buf, m0_bcount_t *len)
Definition: xcode.c:832
struct m0_fid ci_fid
Definition: cas.h:113
struct m0_cas_recv cg_rec
Definition: cas.h:384
Definition: cas.h:372
#define m0_forall(var, nr,...)
Definition: misc.h:112
const char * ts_name
Definition: ut.h:99
Definition: fid.h:38
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
M0_INTERNAL int m0_xcode_obj_dec_from_buf(struct m0_xcode_obj *obj, void *buf, m0_bcount_t len)
Definition: xcode.c:850
Definition: record.py:1
uint64_t key
Definition: service_ut.c:1414
#define M0_XCODE_OBJ(type, ptr)
Definition: xcode.h:962
void m0_dtm0_ut_domain_init_fini(void)
Definition: domain.c:37
uint64_t cr_rc
Definition: cas.h:221
#define M0_BUF_INIT(size, data)
Definition: buf.h:64
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
struct m0_cas_id cg_id
Definition: cas.h:374
uint32_t ab_type
Definition: at.h:251
Definition: idx_mock.c:47