/* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ // vim: ft=cpp:expandtab:ts=8:sw=4:softtabstop=4: #ident "$Id$" /*====== This file is part of PerconaFT. Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved. PerconaFT is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. PerconaFT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with PerconaFT. If not, see . ---------------------------------------- PerconaFT is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License, version 3, as published by the Free Software Foundation. PerconaFT is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with PerconaFT. If not, see . ======= */ #ident "Copyright (c) 2006, 2015, Percona and/or its affiliates. All rights reserved." #include "logger/logcursor.h" #include "test.h" // log a couple of timestamp entries and verify the log by walking // a cursor through the log entries static void corrupt_the_checksum(void) { // change the LSN in the first log entry of log 0. this will cause an checksum error. char logname[TOKU_PATH_MAX+1]; int r; sprintf(logname, "%s/log000000000000.tokulog%d", TOKU_TEST_FILENAME, TOKU_LOG_VERSION); FILE *f = fopen(logname, "r+b"); assert(f); r = fseek(f, 025, SEEK_SET); assert(r == 0); char c = 100; size_t n = fwrite(&c, sizeof c, 1, f); assert(n == sizeof c); r = fclose(f); assert(r == 0); } int test_main (int argc, const char *argv[]) { default_parse_args(argc, argv); int r; toku_os_recursive_delete(TOKU_TEST_FILENAME); r = toku_os_mkdir(TOKU_TEST_FILENAME, S_IRWXU); assert(r==0); TOKULOGGER logger; LSN lsn = ZERO_LSN; // log a couple of timestamp log entries r = toku_logger_create(&logger); assert(r == 0); r = toku_logger_open(TOKU_TEST_FILENAME, logger); assert(r == 0); BYTESTRING bs0 = { .len = 5, .data = (char *) "hello" }; toku_log_comment(logger, &lsn, 0, 0, bs0); r = toku_logger_close(&logger); assert(r == 0); // change the LSN and corrupt the checksum corrupt_the_checksum(); if (!verbose) { // redirect stderr int devnul = open(DEV_NULL_FILE, O_WRONLY); assert(devnul >= 0); r = toku_dup2(devnul, fileno(stderr)); assert(r == fileno(stderr)); r = close(devnul); assert(r == 0); } // walk forwards TOKULOGCURSOR lc = NULL; struct log_entry *le; r = toku_logcursor_create(&lc, TOKU_TEST_FILENAME); assert(r == 0 && lc != NULL); r = toku_logcursor_next(lc, &le); assert(r != 0); r = toku_logcursor_destroy(&lc); assert(r == 0 && lc == NULL); // walk backwards r = toku_logcursor_create(&lc, TOKU_TEST_FILENAME); assert(r == 0 && lc != NULL); r = toku_logcursor_prev(lc, &le); assert(r != 0); r = toku_logcursor_destroy(&lc); assert(r == 0 && lc == NULL); toku_os_recursive_delete(TOKU_TEST_FILENAME); return 0; }