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 data directories
40
41 #include <sys/stat.h>
42 #include "test.h"
43
44 const int envflags = DB_INIT_MPOOL|DB_CREATE|DB_THREAD |DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_PRIVATE;
45
46 const char *namea="a.db";
47 const char *nameb="b.db";
48
run_test(void)49 static void run_test (void) {
50 int r;
51 toku_os_recursive_delete(TOKU_TEST_FILENAME);
52 toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU+S_IRWXG+S_IRWXO);
53
54 DB_ENV *env;
55 r = db_env_create(&env, 0); CKERR(r);
56 r = env->open(env, TOKU_TEST_FILENAME, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
57
58 DB *db;
59 r = db_create(&db, env, 0); CKERR(r);
60 r = db->open(db, NULL, "a.db", NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
61 r = db->close(db, 0); CKERR(r);
62
63 r = db_create(&db, env, 0); CKERR(r);
64 r = db->open(db, NULL, "bdir/b.db", NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666);
65 CKERR(r); //Success, so need a new handle
66 r = db->close(db, 0); CKERR(r);
67 r = db_create(&db, env, 0); CKERR(r);
68 char path[TOKU_PATH_MAX+1];
69 r = toku_os_mkdir(toku_path_join(path, 2, TOKU_TEST_FILENAME, "bdir"), 0777); assert(r == 0);
70 r = db->open(db, NULL, "bdir/b.db", NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
71 r = db->close(db, 0); CKERR(r);
72
73 r = env->close(env, 0); CKERR(r);
74
75 r = toku_os_mkdir(toku_path_join(path, 2, TOKU_TEST_FILENAME, "cdir"), 0777); assert(r == 0);
76 r = db_env_create(&env, 0); CKERR(r);
77 r = env->set_data_dir(env, "cdir"); CKERR(r);
78 r = env->open(env, TOKU_TEST_FILENAME, envflags, S_IRWXU+S_IRWXG+S_IRWXO); CKERR(r);
79
80 r = db_create(&db, env, 0); CKERR(r);
81 r = db->open(db, NULL, "c.db", NULL, DB_BTREE, DB_AUTO_COMMIT|DB_CREATE, 0666); CKERR(r);
82 r = db->close(db, 0); CKERR(r);
83
84 r = env->close(env, 0); CKERR(r);
85 }
86
87 const char *cmd;
88
test_parse_args(int argc,char * const argv[])89 static void test_parse_args (int argc, char * const argv[]) {
90 int resultcode;
91 cmd = argv[0];
92 argc--; argv++;
93 while (argc>0) {
94 if (strcmp(argv[0], "-v") == 0) {
95 verbose++;
96 } else if (strcmp(argv[0],"-q")==0) {
97 verbose--;
98 if (verbose<0) verbose=0;
99 } else if (strcmp(argv[0], "-h")==0) {
100 resultcode=0;
101 do_usage:
102 fprintf(stderr, "Usage:\n%s [-v|-q]* [-h] {--test | --recover } \n", cmd);
103 exit(resultcode);
104 } else {
105 fprintf(stderr, "Unknown arg: %s\n", argv[0]);
106 resultcode=1;
107 goto do_usage;
108 }
109 argc--;
110 argv++;
111 }
112 }
113
test_main(int argc,char * const argv[])114 int test_main (int argc, char * const argv[]) {
115 test_parse_args(argc, argv);
116 run_test();
117 return 0;
118 }
119