
复制#!/bin/evn perl use JSON; use Data::Dumper; use Cwd; use File::Basename; our $cache_flag = ; # 获取脚本所在目录 my $cwd; if ( $0 =~ m{^/} ) { $cwd = dirname($0); } else { my $dir = getcwd(); $cwd = dirname("$dir/$0"); } # 获得参数 if ( @ARGV < 1 ) { &usage; exit; } elsif ( @ARGV == 1 ) { if ( ( $ARGV[0] ne "-r" ) && ( $ARGV[0] ne "-w" ) ) { print "Unrecognized Option\n"; &usage; exit; } } elsif ( @ARGV == 2 ) { if ( $ARGV[0] eq "-r" ) { $cache_flag = "iflag=direct,脚本nonblock"; } elsif ( $ARGV[0] eq "-w" ) { $cache_flag = "oflag=direct,nonblock"; } elsif ( ( $ARGV[0] ne "-r" ) || ( $ARGV[0] ne "-w" ) ) { print "Unrecognized Option\n"; &usage; exit; } } my $opt = $ARGV[0]; # 使用帮助 sub usage { print "Usage: iotest.pl [OPTION] [OPTION]\n"; print "\n"; print "-r\texecute read test\n"; print "-w\texecute write test\n"; print "-c\tiotest with local filesystem cache\n\n"; } # 检查测试文件是否存在 sub check_file { if ( !-e "./iotest" ) { print "The test file dose not exist,please run write test first\n"; exit; } } # 打开测试用例 open FH, "<$cwd/iotest.json"; # Main # while () { chomp; $json = new JSON; # 将测试用例的源码库json格式转成hash my %strings = %{ $json->decode($_) }; if ( $opt eq "-r" ) { &check_file; while ( ( $key, $value ) = each %strings ) { open rfh, >>iotestr.log; my $cmd = "/bin/dd if=./iotest of=/dev/null bs=$key count=$value $cache_flag >> iotestr.log 2>&1"; print rfh "IOTest Block: $key\n"; `$cmd`; print rfh "\n"; } } elsif ( $opt eq "-w" ) { while ( ( $key, $value ) = each %strings ) { open wfh, >>iotestw.log; my $cmd = "/bin/dd if=/dev/zero of=./iotest bs=$key count=$value $cache_flag >> iotestw.log 2>&1"; print wfh "IOTest Block: $key\n"; `$cmd`; print wfh "\n"; } } }1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.71.72.73.74.75.76.77.78.79.80.81.82.83.84.85.86.云服务器