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 #include "test.h"
40 
41 // create and close, making sure that everything is deallocated properly.
42 
43 #define LSIZE 100
44 
45 int
test_main(int argc,const char * argv[])46 test_main (int argc __attribute__((__unused__)),
47 	  const char *argv[] __attribute__((__unused__))) {
48     int r;
49     toku_os_recursive_delete(TOKU_TEST_FILENAME);
50     r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU);    assert(r==0);
51     TOKULOGGER logger;
52     r = toku_logger_create(&logger);
53     assert(r == 0);
54     r = toku_logger_set_lg_max(logger, LSIZE);
55     {
56 	uint32_t n;
57 	r = toku_logger_get_lg_max(logger, &n);
58 	assert(n==LSIZE);
59     }
60     r = toku_logger_open(TOKU_TEST_FILENAME, logger);
61     assert(r == 0);
62 
63     {
64 	ml_lock(&logger->input_lock);
65 	int lsize=LSIZE-12-2;
66 	toku_logger_make_space_in_inbuf(logger, lsize);
67 	snprintf(logger->inbuf.buf+logger->inbuf.n_in_buf, lsize, "a%*d", lsize-1, 0);
68 	logger->inbuf.n_in_buf += lsize;
69 	logger->lsn.lsn++;
70 	logger->inbuf.max_lsn_in_buf = logger->lsn;
71 	ml_unlock(&logger->input_lock);
72     }
73 
74     {
75 	ml_lock(&logger->input_lock);
76 	toku_logger_make_space_in_inbuf(logger, 2);
77 	memcpy(logger->inbuf.buf+logger->inbuf.n_in_buf, "b1", 2);
78 	logger->inbuf.n_in_buf += 2;
79 	logger->lsn.lsn++;
80 	logger->inbuf.max_lsn_in_buf = logger->lsn;
81 	ml_unlock(&logger->input_lock);
82     }
83 
84     r = toku_logger_close(&logger);
85     assert(r == 0);
86 
87     {
88         char logname[PATH_MAX];
89         toku_struct_stat statbuf;
90         sprintf(logname,
91                 "%s/log000000000000.tokulog%d",
92                 TOKU_TEST_FILENAME,
93                 TOKU_LOG_VERSION);
94         r = toku_stat(logname, &statbuf, toku_uninstrumented);
95         assert(r == 0);
96         assert(statbuf.st_size <= LSIZE);
97     }
98     toku_os_recursive_delete(TOKU_TEST_FILENAME);
99     return 0;
100 }
101