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 // test the choose sub block size function
40
41 #include <toku_portability.h>
42 #include "test.h"
43 #include <stdio.h>
44 #include <errno.h>
45 #include <string.h>
46
47 #include "serialize/sub_block.h"
48
49 static void
test_sub_block_size(int total_size)50 test_sub_block_size(int total_size) {
51 if (verbose)
52 printf("%s:%d %d\n", __FUNCTION__, __LINE__, total_size);
53 int r;
54 int sub_block_size, n_sub_blocks;
55 r = choose_sub_block_size(total_size, 0, &sub_block_size, &n_sub_blocks);
56 assert(r == EINVAL);
57 for (int i = 1; i < max_sub_blocks; i++) {
58 r = choose_sub_block_size(total_size, i, &sub_block_size, &n_sub_blocks);
59 assert(r == 0);
60 assert(0 <= n_sub_blocks && n_sub_blocks <= i);
61 assert(total_size <= n_sub_blocks * sub_block_size);
62 }
63 }
64
65 int
test_main(int argc,const char * argv[])66 test_main (int argc, const char *argv[]) {
67 int i;
68 for (i=1; i<argc; i++) {
69 const char *arg = argv[i];
70 if (strcmp(arg, "-v") == 0)
71 verbose++;
72 }
73 test_sub_block_size(0);
74 for (int total_size = 1; total_size <= 4*1024*1024; total_size *= 2) {
75 test_sub_block_size(total_size);
76 }
77 return 0;
78 }
79