Motr  M0
msg_queue.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2016-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 
30 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_UT
31 #include "lib/trace.h"
32 
33 #include "ha/msg_queue.h"
34 #include "ut/ut.h"
35 
36 #include "lib/misc.h" /* M0_SET0 */
37 #include "lib/arith.h" /* m0_rnd64 */
38 #include "lib/memory.h" /* M0_ALLOC_ARR */
39 
40 enum {
42 };
43 
45 {
46  struct m0_ha_msg_queue mq = {};
47  struct m0_ha_msg_queue_cfg mq_cfg = {};
48  struct m0_ha_msg_qitem *qitem;
49  int i;
50  uint64_t seed = 42;
51  uint64_t *tags;
52 
53  m0_ha_msg_queue_init(&mq, &mq_cfg);
55 
56  M0_SET0(&mq);
57  m0_ha_msg_queue_init(&mq, &mq_cfg);
58  qitem = m0_ha_msg_queue_dequeue(&mq);
59  M0_UT_ASSERT(qitem == NULL);
61  M0_UT_ASSERT(tags != NULL);
62  for (i = 0; i < HA_UT_MSG_QUEUE_NR; ++i) {
63  qitem = m0_ha_msg_queue_alloc(&mq);
64  M0_UT_ASSERT(qitem != NULL);
65  tags[i] = m0_rnd64(&seed);
66  qitem->hmq_msg.hm_tag = tags[i];
67  m0_ha_msg_queue_enqueue(&mq, qitem);
68  }
69  for (i = 0; i < HA_UT_MSG_QUEUE_NR; ++i) {
70  qitem = m0_ha_msg_queue_dequeue(&mq);
71  M0_UT_ASSERT(qitem != NULL);
72  M0_UT_ASSERT(m0_ha_msg_tag(&qitem->hmq_msg) == tags[i]);
73  m0_ha_msg_queue_free(&mq, qitem);
74  }
75  m0_free(tags);
76  qitem = m0_ha_msg_queue_dequeue(&mq);
77  M0_UT_ASSERT(qitem == NULL);
79 }
80 
81 
82 #undef M0_TRACE_SUBSYSTEM
83 
86 /*
87  * Local variables:
88  * c-indentation-style: "K&R"
89  * c-basic-offset: 8
90  * tab-width: 8
91  * fill-column: 80
92  * scroll-step: 1
93  * End:
94  */
95 /*
96  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
97  */
#define M0_ALLOC_ARR(arr, nr)
Definition: memory.h:84
#define NULL
Definition: misc.h:38
void m0_ha_ut_msg_queue(void)
Definition: msg_queue.c:44
M0_INTERNAL struct m0_ha_msg_qitem * m0_ha_msg_queue_dequeue(struct m0_ha_msg_queue *mq)
Definition: msg_queue.c:75
M0_INTERNAL void m0_ha_msg_queue_enqueue(struct m0_ha_msg_queue *mq, struct m0_ha_msg_qitem *qitem)
Definition: msg_queue.c:68
#define M0_SET0(obj)
Definition: misc.h:64
int i
Definition: dir.c:1033
M0_INTERNAL void m0_ha_msg_queue_fini(struct m0_ha_msg_queue *mq)
Definition: msg_queue.c:48
M0_INTERNAL void m0_ha_msg_queue_free(struct m0_ha_msg_queue *mq, struct m0_ha_msg_qitem *qitem)
Definition: msg_queue.c:62
uint64_t hm_tag
Definition: msg.h:125
M0_INTERNAL struct m0_ha_msg_qitem * m0_ha_msg_queue_alloc(struct m0_ha_msg_queue *mq)
Definition: msg_queue.c:54
M0_INTERNAL uint64_t m0_ha_msg_tag(const struct m0_ha_msg *msg)
Definition: msg.c:36
M0_INTERNAL uint64_t m0_rnd64(uint64_t *seed)
Definition: misc.c:100
void m0_free(void *data)
Definition: memory.c:146
M0_INTERNAL void m0_ha_msg_queue_init(struct m0_ha_msg_queue *mq, struct m0_ha_msg_queue_cfg *cfg)
Definition: msg_queue.c:42
#define M0_UT_ASSERT(a)
Definition: ut.h:46
struct m0_ha_msg hmq_msg
Definition: msg_queue.h:50