LTP GCOV extension - code coverage report
Current view: directory - storage/maria/unittest - ma_test_loghandler_noflush-t.c
Test: mtr_and_unit.info
Date: 2009-03-05 Instrumented lines: 49
Code covered: 65.3 % Executed lines: 32

       1                 : /* Copyright (C) 2006-2008 MySQL AB
       2                 : 
       3                 :    This program is free software; you can redistribute it and/or modify
       4                 :    it under the terms of the GNU General Public License as published by
       5                 :    the Free Software Foundation; version 2 of the License.
       6                 : 
       7                 :    This program is distributed in the hope that it will be useful,
       8                 :    but WITHOUT ANY WARRANTY; without even the implied warranty of
       9                 :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      10                 :    GNU General Public License for more details.
      11                 : 
      12                 :    You should have received a copy of the GNU General Public License
      13                 :    along with this program; if not, write to the Free Software
      14                 :    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
      15                 : 
      16                 : #include "../maria_def.h"
      17                 : #include <stdio.h>
      18                 : #include <errno.h>
      19                 : #include <tap.h>
      20                 : #include "../trnman.h"
      21                 : 
      22                 : extern my_bool maria_log_remove();
      23                 : extern void translog_example_table_init();
      24                 : 
      25                 : #ifndef DBUG_OFF
      26                 : static const char *default_dbug_option;
      27                 : #endif
      28                 : 
      29                 : #define PCACHE_SIZE (1024*1024*10)
      30                 : #define PCACHE_PAGE TRANSLOG_PAGE_SIZE
      31                 : #define LOG_FILE_SIZE (1024L*1024L*1024L + 1024L*1024L*512)
      32                 : #define LOG_FLAGS 0
      33                 : 
      34                 : static char *first_translog_file= (char*)"maria_log.00000001";
      35                 : 
      36                 : int main(int argc __attribute__((unused)), char *argv[])
      37               1 : {
      38                 :   uint pagen;
      39               1 :   int rc= 1;
      40                 :   uchar long_tr_id[6];
      41                 :   PAGECACHE pagecache;
      42                 :   LSN first_lsn;
      43                 :   TRANSLOG_HEADER_BUFFER rec;
      44                 :   LEX_CUSTRING parts[TRANSLOG_INTERNAL_PARTS + 1];
      45                 :   translog_size_t len;
      46                 : 
      47               1 :   MY_INIT(argv[0]);
      48                 : 
      49               1 :   plan(1);
      50                 : 
      51               1 :   bzero(&pagecache, sizeof(pagecache));
      52               1 :   maria_data_root= (char *)".";
      53               1 :   if (maria_log_remove())
      54               0 :     exit(1);
      55                 :   /* be sure that we have no logs in the directory*/
      56               1 :   my_delete(CONTROL_FILE_BASE_NAME, MYF(0));
      57               1 :   my_delete(first_translog_file, MYF(0));
      58                 : 
      59               1 :   bzero(long_tr_id, 6);
      60                 : #ifndef DBUG_OFF
      61                 : #if defined(__WIN__)
      62                 :   default_dbug_option= "d:t:i:O,\\ma_test_loghandler.trace";
      63                 : #else
      64               1 :   default_dbug_option= "d:t:i:o,/tmp/ma_test_loghandler.trace";
      65                 : #endif
      66               1 :   if (argc > 1)
      67                 :   {
      68               0 :     DBUG_SET(default_dbug_option);
      69               0 :     DBUG_SET_INITIAL(default_dbug_option);
      70                 :   }
      71                 : #endif
      72                 : 
      73               1 :   if (ma_control_file_open(TRUE, TRUE))
      74                 :   {
      75               0 :     fprintf(stderr, "Can't init control file (%d)\n", errno);
      76               0 :     exit(1);
      77                 :   }
      78               1 :   if ((pagen= init_pagecache(&pagecache, PCACHE_SIZE, 0, 0,
      79                 :                              PCACHE_PAGE, 0)) == 0)
      80                 :   {
      81               0 :     fprintf(stderr, "Got error: init_pagecache() (errno: %d)\n", errno);
      82               0 :     exit(1);
      83                 :   }
      84               1 :   if (translog_init_with_table(".", LOG_FILE_SIZE, 50112, 0, &pagecache,
      85                 :                                LOG_FLAGS, 0, &translog_example_table_init,
      86                 :                                0))
      87                 :   {
      88               0 :     fprintf(stderr, "Can't init loghandler (%d)\n", errno);
      89               0 :     exit(1);
      90                 :   }
      91                 :   /* Suppressing of automatic record writing */
      92               1 :   dummy_transaction_object.first_undo_lsn|= TRANSACTION_LOGGED_LONG_ID;
      93                 : 
      94               1 :   int4store(long_tr_id, 0);
      95               1 :   long_tr_id[5]= 0xff;
      96               1 :   parts[TRANSLOG_INTERNAL_PARTS + 0].str= long_tr_id;
      97               1 :   parts[TRANSLOG_INTERNAL_PARTS + 0].length= 6;
      98               1 :   if (translog_write_record(&first_lsn,
      99                 :                             LOGREC_FIXED_RECORD_0LSN_EXAMPLE,
     100                 :                             &dummy_transaction_object, NULL, 6,
     101                 :                             TRANSLOG_INTERNAL_PARTS + 1,
     102                 :                             parts, NULL, NULL))
     103                 :   {
     104               0 :     fprintf(stderr, "Can't write record #%lu\n", (ulong) 0);
     105               0 :     translog_destroy();
     106               0 :     exit(1);
     107                 :   }
     108                 : 
     109               1 :   len= translog_read_record_header(first_lsn, &rec);
     110               1 :   if (len == 0)
     111                 :   {
     112               0 :     fprintf(stderr, "translog_read_record_header failed (%d)\n", errno);
     113               0 :     goto err;
     114                 :   }
     115               1 :   if (rec.type !=LOGREC_FIXED_RECORD_0LSN_EXAMPLE || rec.short_trid != 0 ||
     116                 :       rec.record_length != 6 || uint4korr(rec.header) != 0 ||
     117                 :       ((uchar)rec.header[4]) != 0 || ((uchar)rec.header[5]) != 0xFF ||
     118                 :       first_lsn != rec.lsn)
     119                 :   {
     120               0 :     fprintf(stderr, "Incorrect LOGREC_FIXED_RECORD_0LSN_EXAMPLE "
     121                 :             "data read(0)\n"
     122                 :             "type: %u (%d)  strid: %u (%d)  len: %u (%d)  i: %u (%d), "
     123                 :             "4: %u (%d)  5: %u (%d)  "
     124                 :             "lsn(%lu,0x%lx) (%d)\n",
     125                 :             (uint) rec.type, (rec.type !=LOGREC_FIXED_RECORD_0LSN_EXAMPLE),
     126                 :             (uint) rec.short_trid, (rec.short_trid != 0),
     127                 :             (uint) rec.record_length, (rec.record_length != 6),
     128                 :             (uint) uint4korr(rec.header), (uint4korr(rec.header) != 0),
     129                 :             (uint) rec.header[4], (((uchar)rec.header[4]) != 0),
     130                 :             (uint) rec.header[5], (((uchar)rec.header[5]) != 0xFF),
     131                 :             LSN_IN_PARTS(rec.lsn), (first_lsn != rec.lsn));
     132               0 :     goto err;
     133                 :   }
     134                 : 
     135               1 :   ok(1, "read OK");
     136               1 :   rc= 0;
     137                 : 
     138               1 : err:
     139               1 :   translog_destroy();
     140               1 :   end_pagecache(&pagecache, 1);
     141               1 :   ma_control_file_end();
     142               1 :   if (maria_log_remove())
     143               0 :     exit(1);
     144                 : 
     145               1 :   exit(rc);
     146                 : }

Generated by: LTP GCOV extension version 1.4