Motr  M0
lockers.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 #include "lib/lockers.h"
24 #include "ut/ut.h"
25 
26 M0_LOCKERS_DECLARE(M0_INTERNAL, bank, 2);
27 
28 struct bank {
29  struct bank_lockers vault;
30 };
31 
32 M0_LOCKERS_DEFINE(M0_INTERNAL, bank, vault);
33 
34 static void bank_init(struct bank *bank)
35 {
36  bank_lockers_init(bank);
37 }
38 
39 static void bank_fini(struct bank *bank)
40 {
41  bank_lockers_fini(bank);
42 }
43 
44 void test_lockers(void)
45 {
46  int key;
47  int key1;
48  char *valuable = "Gold";
49  char *asset;
50  struct bank federal;
51  int i;
52 
53  bank_init(&federal);
54 
55  key = bank_lockers_allot();
56  M0_UT_ASSERT(key == 0);
57 
58  key1 = bank_lockers_allot();
59  M0_UT_ASSERT(key != key1);
60 
61  M0_UT_ASSERT(bank_lockers_is_empty(&federal, key));
62  bank_lockers_set(&federal, key, valuable);
63  M0_UT_ASSERT(!bank_lockers_is_empty(&federal, key));
64 
65  asset = bank_lockers_get(&federal, key);
66  M0_UT_ASSERT(asset == valuable);
67 
68  bank_lockers_clear(&federal, key);
69  M0_UT_ASSERT(bank_lockers_is_empty(&federal, key));
70 
71  for (i = 0; i < 1000; ++i) {
72  bank_lockers_free(key1);
73  key1 = bank_lockers_allot();
74  M0_UT_ASSERT(key != key1);
75  }
76  bank_lockers_free(key);
77  bank_lockers_free(key1);
78  bank_fini(&federal);
79 }
80 M0_EXPORTED(test_lockers);
81 
82 /*
83  * Local variables:
84  * c-indentation-style: "K&R"
85  * c-basic-offset: 8
86  * tab-width: 8
87  * fill-column: 80
88  * scroll-step: 1
89  * End:
90  */
91 /*
92  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
93  */
static void bank_fini(struct bank *bank)
Definition: lockers.c:39
int i
Definition: dir.c:1033
struct bank_lockers vault
Definition: lockers.c:29
Definition: lockers.c:28
static int key
Definition: locality.c:283
M0_LOCKERS_DECLARE(M0_INTERNAL, bank, 2)
static void bank_init(struct bank *bank)
Definition: lockers.c:34
void test_lockers(void)
Definition: lockers.c:44
#define M0_UT_ASSERT(a)
Definition: ut.h:46
M0_LOCKERS_DEFINE(M0_INTERNAL, bank, vault)
Definition: idx_mock.c:47