#!/usr/bin/perl -w # verify_logs.pl - Don Yang (uguu.org) # # Verify that intermediate source files can be contructed from recorded # logs. If reconstruction is not possible, we will need to record again. # # 08/25/12 use strict; use constant MAX_SNAPSHOT => 36; my @lines = (); for(my $i = 0; $i <= MAX_SNAPSHOT; $i++) { my $file; # Update snapshot from log file my $log = sprintf 'nyaruko%02d.log', $i; open $file, "< $log" or die $!; while( my $input = <$file> ) { chomp $input; next unless $input =~ /^L(\d+)E(\d+)=(.*)/; $lines[$1] = $3; $#lines = $2; } close $file; # Load expected snapshot my $data = sprintf 'nyaruko%02d.c', $i; open $file, "< $data" or die $!; my @expected = (undef); # Real data starts at index 1. while( my $input = <$file> ) { chomp $input; push @expected, $input; } close $file; # Compare files if( $#expected != $#lines ) { die "$i: snapshot size mismatched: $#expected vs. $#lines\n"; } for(my $j = 1; $j <= $#expected; $j++) { if( $expected[$j] ne $lines[$j] ) { die "$i: snapshot mismatched at line $j\n"; } } }