1 /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4:
3 #ident "$Id$"
4 /*======
5 This file is part of PerconaFT.
6
7
8 Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved.
9
10 PerconaFT is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License, version 2,
12 as published by the Free Software Foundation.
13
14 PerconaFT is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
21
22 ----------------------------------------
23
24 PerconaFT is free software: you can redistribute it and/or modify
25 it under the terms of the GNU Affero General Public License, version 3,
26 as published by the Free Software Foundation.
27
28 PerconaFT is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU Affero General Public License for more details.
32
33 You should have received a copy of the GNU Affero General Public License
34 along with PerconaFT. If not, see <http://www.gnu.org/licenses/>.
35 ======= */
36
37 #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved."
38
39 // verify that closing the cachetable with an in progress prefetch works
40
41 #include "test.h"
42
43 struct reserve_filenum_test {
44 void test_reserve_filenum();
45 void test_reserve_filenum_active();
46 };
47
test_reserve_filenum()48 void reserve_filenum_test::test_reserve_filenum() {
49 cachefile_list cfl;
50 cfl.init();
51
52 // set m_next_filenum_to_use.fileid
53 cfl.m_next_filenum_to_use.fileid = (UINT32_MAX -2);
54
55 FILENUM fn1 = cfl.reserve_filenum();
56 assert(fn1.fileid == (UINT32_MAX - 2));
57
58 FILENUM fn2 = cfl.reserve_filenum();
59 assert(fn2.fileid == (UINT32_MAX - 1));
60
61 // skip the reversed value UINT32_MAX and wrap around
62 FILENUM fn3 = cfl.reserve_filenum();
63 assert(fn3.fileid == 0U);
64
65 FILENUM fn4 = cfl.reserve_filenum();
66 assert(fn4.fileid == 1U);
67
68 cfl.destroy();
69 }
70
test_reserve_filenum_active()71 void reserve_filenum_test::test_reserve_filenum_active() {
72 cachefile_list cfl;
73 cfl.init();
74
75 // start the filenum space to UINT32_MAX - 1
76 cfl.m_next_filenum_to_use.fileid = (UINT32_MAX -1);
77
78 // reserve filenum UINT32_MAX-1
79 FILENUM fn1 = cfl.reserve_filenum();
80 assert(fn1.fileid == (UINT32_MAX - 1));
81 cachefile cf1 = {};
82 cf1.filenum = fn1;
83 cf1.fileid = {0, 1};
84 cfl.add_cf_unlocked(&cf1);
85
86 // reset next filenum so that we test skipping UINT32_MAX
87 cfl.m_next_filenum_to_use.fileid = (UINT32_MAX -1);
88
89 // reserve filenum 0
90 FILENUM fn2 = cfl.reserve_filenum();
91 assert(fn2.fileid == 0);
92
93 cachefile cf2 = {};
94 cf2.filenum = fn2;
95 cf2.fileid = {0, 2};
96 cfl.add_cf_unlocked(&cf2);
97
98 cfl.destroy();
99 }
100
101 int
test_main(int argc,const char * argv[])102 test_main(int argc, const char *argv[]) {
103 int r = 0;
104 default_parse_args(argc, argv);
105 reserve_filenum_test fn_test;
106
107 // Run the tests.
108 fn_test.test_reserve_filenum();
109 fn_test.test_reserve_filenum_active();
110
111 return r;
112 }
113