From 4e4a28bff68cf48d610565dba5279a0b3e46022d Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 15 Aug 2012 10:31:18 -0600 Subject: [PATCH 01/10] Debug hack for ReadKeyMini::cooked(). --- lib/ReadKeyMini.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/ReadKeyMini.pm b/lib/ReadKeyMini.pm index 932b8513..0590c8cb 100644 --- a/lib/ReadKeyMini.pm +++ b/lib/ReadKeyMini.pm @@ -100,12 +100,14 @@ my %modes = ( $term->setcc( VTIME, 1 ); $term->setattr( $fd_stdin, TCSANOW ); } - +use Data::Dumper; sub cooked { $term->setlflag($oterm); $term->setcc( VTIME, 0 ); $term->setattr( $fd_stdin, TCSANOW ); unless ( $PerconaTest::DONT_RESTORE_STDIN ) { + warn Dumper($fd_stdin); + warn Dumper($flags); fcntl(STDIN, F_SETFL, $flags) or warn "can't fcntl F_SETFL: $!"; } From 1ae35a224111e09049fd29cf9f5be38b31d8df45 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 15 Aug 2012 11:23:00 -0600 Subject: [PATCH 02/10] More debug hacks. --- t/lib/Diskstats.t | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/lib/Diskstats.t b/t/lib/Diskstats.t index 87b182c2..5806ed36 100644 --- a/t/lib/Diskstats.t +++ b/t/lib/Diskstats.t @@ -9,7 +9,7 @@ BEGIN { use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use Test::More tests => 108; +use Test::More; # tests => 108; use PerconaTest; @@ -304,7 +304,8 @@ is_deeply( # "", # "->show_inactive works" #); - +done_testing; +exit; # ############################################################################ # Sane defaults and fatal errors # ############################################################################ From d00702f193a25fbee042e46c240d010b71af9e9d Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 15 Aug 2012 11:54:01 -0600 Subject: [PATCH 03/10] Even more debug hacks. --- lib/ReadKeyMini.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/ReadKeyMini.pm b/lib/ReadKeyMini.pm index 0590c8cb..184fac4d 100644 --- a/lib/ReadKeyMini.pm +++ b/lib/ReadKeyMini.pm @@ -106,8 +106,11 @@ use Data::Dumper; $term->setcc( VTIME, 0 ); $term->setattr( $fd_stdin, TCSANOW ); unless ( $PerconaTest::DONT_RESTORE_STDIN ) { - warn Dumper($fd_stdin); - warn Dumper($flags); + warn "*STDIN=", Dumper(*STDIN); + warn "fd_stdin=", Dumper($fd_stdin); + warn "flags=", Dumper($flags); + warn "tell=",tell(STDIN), "\n"; + warn `ls -l /proc/$PID/*`, "\n"; fcntl(STDIN, F_SETFL, $flags) or warn "can't fcntl F_SETFL: $!"; } From 523a74da3607b4bb0ef6f367ffc90ea1c499010b Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 15 Aug 2012 12:27:37 -0600 Subject: [PATCH 04/10] More debug hacks. --- lib/ReadKeyMini.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ReadKeyMini.pm b/lib/ReadKeyMini.pm index 184fac4d..eaffeee4 100644 --- a/lib/ReadKeyMini.pm +++ b/lib/ReadKeyMini.pm @@ -68,6 +68,8 @@ my %modes = ( # This primarily comes from the Perl Cookbook, recipe 15.8 { +use Devel::Peek; +use Data::Dumper; my $fd_stdin = fileno(STDIN); my $flags; @@ -100,12 +102,18 @@ my %modes = ( $term->setcc( VTIME, 1 ); $term->setattr( $fd_stdin, TCSANOW ); } -use Data::Dumper; + sub cooked { $term->setlflag($oterm); $term->setcc( VTIME, 0 ); $term->setattr( $fd_stdin, TCSANOW ); unless ( $PerconaTest::DONT_RESTORE_STDIN ) { + no strict; + Dump(STDIN); + Dump(F_SETFL); + Dump($flags); + warn "STDIN=",Dumper(STDIN); + warn "SETFL=",Dumper(F_SETFL); warn "*STDIN=", Dumper(*STDIN); warn "fd_stdin=", Dumper($fd_stdin); warn "flags=", Dumper($flags); From 53c382730adc88d1f65ae5fbb7b67390e0275057 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 15 Aug 2012 12:52:34 -0600 Subject: [PATCH 05/10] See if STDIN is tty. --- lib/ReadKeyMini.pm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ReadKeyMini.pm b/lib/ReadKeyMini.pm index eaffeee4..64ff5c8d 100644 --- a/lib/ReadKeyMini.pm +++ b/lib/ReadKeyMini.pm @@ -109,6 +109,7 @@ use Data::Dumper; $term->setattr( $fd_stdin, TCSANOW ); unless ( $PerconaTest::DONT_RESTORE_STDIN ) { no strict; + if ( -t STDIN ) { warn "STD is tty\n"; } Dump(STDIN); Dump(F_SETFL); Dump($flags); @@ -119,7 +120,7 @@ use Data::Dumper; warn "flags=", Dumper($flags); warn "tell=",tell(STDIN), "\n"; warn `ls -l /proc/$PID/*`, "\n"; - fcntl(STDIN, F_SETFL, $flags) + fcntl(STDIN, F_SETFL, int($flags)) or warn "can't fcntl F_SETFL: $!"; } } From b5d7e7d0b6b690e818f2c4329d0a06c5c0063d91 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 15 Aug 2012 12:58:55 -0600 Subject: [PATCH 06/10] More debug hacks. --- lib/ReadKeyMini.pm | 11 ----------- t/lib/Daemon.t | 5 +++-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/lib/ReadKeyMini.pm b/lib/ReadKeyMini.pm index 64ff5c8d..3bf38bf5 100644 --- a/lib/ReadKeyMini.pm +++ b/lib/ReadKeyMini.pm @@ -108,18 +108,7 @@ use Data::Dumper; $term->setcc( VTIME, 0 ); $term->setattr( $fd_stdin, TCSANOW ); unless ( $PerconaTest::DONT_RESTORE_STDIN ) { - no strict; if ( -t STDIN ) { warn "STD is tty\n"; } - Dump(STDIN); - Dump(F_SETFL); - Dump($flags); - warn "STDIN=",Dumper(STDIN); - warn "SETFL=",Dumper(F_SETFL); - warn "*STDIN=", Dumper(*STDIN); - warn "fd_stdin=", Dumper($fd_stdin); - warn "flags=", Dumper($flags); - warn "tell=",tell(STDIN), "\n"; - warn `ls -l /proc/$PID/*`, "\n"; fcntl(STDIN, F_SETFL, int($flags)) or warn "can't fcntl F_SETFL: $!"; } diff --git a/t/lib/Daemon.t b/t/lib/Daemon.t index 93082780..291af189 100644 --- a/t/lib/Daemon.t +++ b/t/lib/Daemon.t @@ -9,13 +9,13 @@ BEGIN { use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use Test::More tests => 22; +use Test::More; use Time::HiRes qw(sleep); use File::Temp qw( tempfile ); use Daemon; use OptionParser; use PerconaTest; - +plan skip_all => "Hm"; use constant PTDEVDEBUG => $ENV{PTDEVDEBUG} || 0; my $o = new OptionParser(file => "$trunk/t/lib/samples/daemonizes.pl"); @@ -263,4 +263,5 @@ ok( # Done. # ############################################################################# rm_tmp_files(); +done_testing; exit; From 3bb0694d1df1688f5290459c7570bb23c67c099f Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 15 Aug 2012 13:03:30 -0600 Subject: [PATCH 07/10] Re-enable Daemon.t. --- t/lib/Daemon.t | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/lib/Daemon.t b/t/lib/Daemon.t index 291af189..edecd297 100644 --- a/t/lib/Daemon.t +++ b/t/lib/Daemon.t @@ -15,7 +15,7 @@ use File::Temp qw( tempfile ); use Daemon; use OptionParser; use PerconaTest; -plan skip_all => "Hm"; +#plan skip_all => "Hm"; use constant PTDEVDEBUG => $ENV{PTDEVDEBUG} || 0; my $o = new OptionParser(file => "$trunk/t/lib/samples/daemonizes.pl"); From 75295707de9498f07875f9e48d8174c39938c176 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 15 Aug 2012 13:06:38 -0600 Subject: [PATCH 08/10] Disable tty check. --- lib/ReadKeyMini.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ReadKeyMini.pm b/lib/ReadKeyMini.pm index 3bf38bf5..ee915442 100644 --- a/lib/ReadKeyMini.pm +++ b/lib/ReadKeyMini.pm @@ -108,7 +108,7 @@ use Data::Dumper; $term->setcc( VTIME, 0 ); $term->setattr( $fd_stdin, TCSANOW ); unless ( $PerconaTest::DONT_RESTORE_STDIN ) { - if ( -t STDIN ) { warn "STD is tty\n"; } + # if ( -t STDIN ) { warn "STD is tty\n"; } fcntl(STDIN, F_SETFL, int($flags)) or warn "can't fcntl F_SETFL: $!"; } From f4b07e5ebaedde119e295403d3bb55bd05c884e9 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 15 Aug 2012 13:11:12 -0600 Subject: [PATCH 09/10] Full Diskstats.t. --- t/lib/Diskstats.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/lib/Diskstats.t b/t/lib/Diskstats.t index 5806ed36..812e65a6 100644 --- a/t/lib/Diskstats.t +++ b/t/lib/Diskstats.t @@ -304,8 +304,7 @@ is_deeply( # "", # "->show_inactive works" #); -done_testing; -exit; + # ############################################################################ # Sane defaults and fatal errors # ############################################################################ @@ -578,4 +577,5 @@ EOF # ########################################################################### # Done. # ########################################################################### +done_testing; exit; From 9d809ce5ea1476f4062fa03018fc3aafda4382ad Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Wed, 15 Aug 2012 13:28:14 -0600 Subject: [PATCH 10/10] Use int($flags) to prevent fcntl(F_SETFL) error. Clean up ReadKeyMini.pm and Diskstats.t. --- bin/pt-diskstats | 25 ++++++++++--------------- lib/ReadKeyMini.pm | 35 ++++++++++++++--------------------- t/lib/Diskstats.t | 22 ++++++++++------------ 3 files changed, 34 insertions(+), 48 deletions(-) diff --git a/bin/pt-diskstats b/bin/pt-diskstats index f02dedfa..91bbb66b 100755 --- a/bin/pt-diskstats +++ b/bin/pt-diskstats @@ -1429,14 +1429,12 @@ my %modes = ( 'ultra-raw' => 5, ); - { - my $fd_stdin = fileno(STDIN); my $flags; unless ( $PerconaTest::DONT_RESTORE_STDIN ) { $flags = fcntl(STDIN, F_GETFL, 0) - or warn "can't fcntl F_GETFL: $!"; + or warn "Error getting STDIN flags with fcntl: $OS_ERROR"; } my $term = POSIX::Termios->new(); $term->getattr($fd_stdin); @@ -1468,14 +1466,13 @@ my %modes = ( $term->setlflag($oterm); $term->setcc( VTIME, 0 ); $term->setattr( $fd_stdin, TCSANOW ); - unless ( $PerconaTest::DONT_RESTORE_STDIN ) { - fcntl(STDIN, F_SETFL, $flags) - or warn "can't fcntl F_SETFL: $!"; + if ( !$PerconaTest::DONT_RESTORE_STDIN ) { + fcntl(STDIN, F_SETFL, int($flags)) + or warn "Error restoring STDIN flags with fcntl: $OS_ERROR"; } } END { cooked() } - } sub readkey { @@ -1484,14 +1481,12 @@ sub readkey { sysread(STDIN, $key, 1); my $timeout = 0.1; if ( $key eq "\033" ) { - { - my $x = ''; - STDIN->blocking(0); - sysread(STDIN, $x, 2); - STDIN->blocking(1); - $key .= $x; - redo if $key =~ /\[[0-2](?:[0-9];)?$/ - } + my $x = ''; + STDIN->blocking(0); + sysread(STDIN, $x, 2); + STDIN->blocking(1); + $key .= $x; + redo if $key =~ /\[[0-2](?:[0-9];)?$/ } cooked(); return $key; diff --git a/lib/ReadKeyMini.pm b/lib/ReadKeyMini.pm index ee915442..6bc620ed 100644 --- a/lib/ReadKeyMini.pm +++ b/lib/ReadKeyMini.pm @@ -1,4 +1,4 @@ -# This program is copyright 2010-2011 Percona Inc. +# This program is copyright 2010-2012 Percona Inc. # Feedback and improvements are welcome. # # THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED @@ -66,16 +66,12 @@ my %modes = ( ); # This primarily comes from the Perl Cookbook, recipe 15.8 - { -use Devel::Peek; -use Data::Dumper; - my $fd_stdin = fileno(STDIN); my $flags; unless ( $PerconaTest::DONT_RESTORE_STDIN ) { $flags = fcntl(STDIN, F_GETFL, 0) - or warn "can't fcntl F_GETFL: $!"; + or warn "Error getting STDIN flags with fcntl: $OS_ERROR"; } my $term = POSIX::Termios->new(); $term->getattr($fd_stdin); @@ -107,15 +103,13 @@ use Data::Dumper; $term->setlflag($oterm); $term->setcc( VTIME, 0 ); $term->setattr( $fd_stdin, TCSANOW ); - unless ( $PerconaTest::DONT_RESTORE_STDIN ) { - # if ( -t STDIN ) { warn "STD is tty\n"; } + if ( !$PerconaTest::DONT_RESTORE_STDIN ) { fcntl(STDIN, F_SETFL, int($flags)) - or warn "can't fcntl F_SETFL: $!"; + or warn "Error restoring STDIN flags with fcntl: $OS_ERROR"; } } END { cooked() } - } sub readkey { @@ -124,17 +118,16 @@ sub readkey { sysread(STDIN, $key, 1); my $timeout = 0.1; if ( $key eq "\033" ) { - # Ugly and broken hack, but good enough for the two minutes it took to write. - # Namely, Ctrl escapes, the F-NUM keys, and other stuff you can send from the keyboard - # take more than one "character" to represent, and would be wrong to break into pieces. - { - my $x = ''; - STDIN->blocking(0); - sysread(STDIN, $x, 2); - STDIN->blocking(1); - $key .= $x; - redo if $key =~ /\[[0-2](?:[0-9];)?$/ - } + # Ugly and broken hack, but good enough for the two minutes it took + # to write. Namely, Ctrl escapes, the F-NUM keys, and other stuff + # you can send from the keyboard take more than one "character" to + # represent, and would be wrong to break into pieces. + my $x = ''; + STDIN->blocking(0); + sysread(STDIN, $x, 2); + STDIN->blocking(1); + $key .= $x; + redo if $key =~ /\[[0-2](?:[0-9];)?$/ } cooked(); return $key; diff --git a/t/lib/Diskstats.t b/t/lib/Diskstats.t index 812e65a6..77761cbb 100644 --- a/t/lib/Diskstats.t +++ b/t/lib/Diskstats.t @@ -9,15 +9,13 @@ BEGIN { use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use Test::More; # tests => 108; - -use PerconaTest; - -use OptionParser; - +use Test::More; use File::Spec; use File::Temp (); +use PerconaTest; +use OptionParser; + BEGIN { use_ok "Diskstats"; use_ok "DiskstatsGroupByAll"; @@ -25,7 +23,7 @@ BEGIN { use_ok "DiskstatsGroupBySample"; } -my $o = new OptionParser(description => 'Diskstats'); +my $o = new OptionParser(description => 'Diskstats'); $o->get_specs("$trunk/bin/pt-diskstats"); $o->get_opts(); @@ -476,6 +474,7 @@ is_deeply( $obj->clear_state(); } + # ############################################################################ # The three subclasses # ############################################################################ @@ -491,7 +490,8 @@ for my $test ( { class => "DiskstatsGroupBySample", results_file_prefix => "sample", - }) { + }, +) { my $obj = $test->{class}->new(OptionParser => $o, show_inactive => 1); my $prefix = $test->{results_file_prefix}; @@ -502,9 +502,8 @@ for my $test ( $obj->set_show_line_between_samples(0); for my $filename ( map "diskstats-00$_.txt", 1..5 ) { - my $file = File::Spec->catfile( "t", "pt-diskstats", "samples", $filename ); - my $file_with_trunk = File::Spec->catfile( $trunk, $file ); - + my $file = File::Spec->catfile(qw(t pt-diskstats samples), $filename); + my $file_with_trunk = File::Spec->catfile($trunk, $file); my $expected = "t/pt-diskstats/expected/${prefix}_$filename"; ok( @@ -571,7 +570,6 @@ EOF qr/Time between samples should be > 0, is /, "$test->{class}, ->_calc_deltas fails if the time elapsed is negative" ); - } # ###########################################################################