Motr  M0
ringbuf.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-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 #include "ut/ut.h" /* M0_UT_ASSERT */
24 
25 #include "net/test/ringbuf.h"
26 
27 enum {
28  NET_TEST_RB_SIZE = 0x1000,
30 };
31 
32 static void ringbuf_push_pop(struct m0_net_test_ringbuf *rb, size_t nr)
33 {
34  size_t i;
35  size_t value;
36  size_t len;
37 
38  M0_PRE(rb != NULL);
39 
40  for (i = 0; i < nr; ++i) {
43  M0_UT_ASSERT(len == i + 1);
44  }
45  for (i = 0; i < nr; ++i) {
47  M0_UT_ASSERT(value == i);
49  M0_UT_ASSERT(len == nr - i - 1);
50  }
51 }
52 
54 {
55  struct m0_net_test_ringbuf rb;
56  int rc;
57  int i;
58  size_t value;
59  size_t nr;
60 
61  /* init */
63  M0_UT_ASSERT(rc == 0);
65  M0_UT_ASSERT(nr == 0);
66  /* test #1: single value push, single value pop */
69  M0_UT_ASSERT(nr == 1);
71  M0_UT_ASSERT(value == 42);
73  M0_UT_ASSERT(nr == 0);
74  /* test #2: multiple values push, multiple values pop */
76  /*
77  * test #3: push and pop (NET_TEST_RB_SIZE - 1) items
78  * NET_TEST_RB_LOOP_NR times
79  */
80  for (i = 0; i < NET_TEST_RB_LOOP_NR; ++i)
82  /* fini */
84 }
85 
86 /*
87  * Local variables:
88  * c-indentation-style: "K&R"
89  * c-basic-offset: 8
90  * tab-width: 8
91  * fill-column: 79
92  * scroll-step: 1
93  * End:
94  */
static size_t nr
Definition: dump.c:1505
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
int m0_net_test_ringbuf_init(struct m0_net_test_ringbuf *rb, size_t size)
Definition: ringbuf.c:36
int const char const void * value
Definition: dir.c:325
int i
Definition: dir.c:1033
size_t m0_net_test_ringbuf_pop(struct m0_net_test_ringbuf *rb)
Definition: ringbuf.c:88
struct reqh_ut_balloc rb
Definition: reqh_fom_ut.c:159
void m0_net_test_ringbuf_fini(struct m0_net_test_ringbuf *rb)
Definition: ringbuf.c:52
void m0_net_test_ringbuf_push(struct m0_net_test_ringbuf *rb, size_t value)
Definition: ringbuf.c:77
size_t m0_net_test_ringbuf_nr(struct m0_net_test_ringbuf *rb)
Definition: ringbuf.c:106
static void ringbuf_push_pop(struct m0_net_test_ringbuf *rb, size_t nr)
Definition: ringbuf.c:32
int32_t rc
Definition: trigger_fop.h:47
#define M0_UT_ASSERT(a)
Definition: ut.h:46
void m0_net_test_ringbuf_ut(void)
Definition: ringbuf.c:53