我修改了一个现有的perl脚本,该脚本通过转到他们的目录并解析pass,fail或incomplete来检查某些测试的状态。我想这个脚本扩展生成包含基于3串的未完成的测试子表:使用grep通过perl查找不同目录中的文件中的匹配模式
"Error: Failure to checkout svverification license feature."
"Error: Unable to checkout verification license - required for testbench features"
"FATAL ERROR: License connection lost and unable to reconnect after multiple attempts."
每个测试的名字都有自己的目录,该目录内是一个名为vsim.log
日志文件。我可以用grep
做这个目录,但是我认为将它实现到脚本中会很好,所以每次有不完整的时候我都不必手动grep
。
该脚本有一个变量$cur_test_name
,我将用它来执行此操作,因为我必须确保进入正确的子目录。
chdir("/testout/$cur_test_name.1/") or die "Cannot chdir to /testout/$cur_test_name.t";
if(system(grep -f "Error: Failure to checkout svverification license feature." vsim.log) or
system(grep -f "Error: Unable to checkout verification license - required for testbench features" vsim.log) or
system(grep -f "# FATAL ERROR: License connection lost and unable to reconnect after multiple attempts." vsim.log))
{
open($incomplete_tests, '>'; 'incompletes.lst') or die "Cannot open file $!in write mode";
print {$incomplete_tests} $cur_Test_name . "\n";
close $incomplete_tests;
}
chdir("../../") or die "Cannot chdir to ../../";
所以基本上,我想改变目录到子目录,并检查vsim.log文件中存在这些模式。如果他们通过open创建一个新文件(我认为这是如何完成的),并将测试名称变量写入文件。然后关闭文件,然后返回顶层目录,对每个不完整的测试重复此操作。
但是这不能编译和Im新的perl,所以我很难找出如何正确使用system()
。我已经看到了不同的格式,我见过一些解决方案,只使用grep
而没有system
,所以我被卡住了。
我得到的错误有以下几种:
Bareword found where operator expected at bin/run_regress.pl line 1279, near ""Error: Failure to checkout svverification license feature." vsim"
(Missing operator before vsim?)
Bareword found where operator expected at bin/run_regress.pl line 1279, near ""Error: Unable to checkout verification license - required for testbench features" vsim"
(Missing operator before vsim?)
Bareword found where operator expected at bin/run_regress.pl line 1279, near ""# FATAL ERROR: License connection lost and unable to reconnect after multiple attempts." vsim"
(Missing operator before vsim?)
Not enough arguments for grep at bin/run_regress.pl line 1279, near ""Error: Failure to checkout svverification license feature." vsim"
syntax error at bin/run_regress.pl line 1279, near ""Error: Failure to checkout svverification license feature." vsim"
Global symbol "$cur_Test_name" requires explicit package name at bin/run_regress.pl line 1282.
syntax error at bin/run_regress.pl line 1287, near "}"
编辑:
,我希望把我的代码是在脚本中的部分地点:
for(my $j=0;$j<$number_of_bfm_based_smoke_100pin_tests;$j++)
{
chdir("../rtl_mcu_bfm_qfn_100/") or die "Cannot chdir to ../rtl_mcu_bfm_qfn_100";
$curr_test_name = $bfm_based_smoke_100pin_tests[$j] ;
process_test_name($curr_test_name);
check_status($sim_process_out[1],$bfm_based_smoke_100pin_tests[$j],$seed,"BFM");
$sr_nu++;
chdir($start_dir);
}
和check_status
子程序是
sub check_status
{
my ($pass_fail_string,$cur_test_name,$seed_val,$xdata_mstr) = @_;
if ($pass_fail_string =~ /Test FAILED! Test did not end properly/)
{
# ===== THIS IS WHERE I WANT TO PLACE MY CODE ===== #
$incomplete_cnt++ ;
printf (STORE_REGRESS_RSLT "|%9d|%78s|%7d|%11s|%12s|\n",$sr_nu,$cur_test_name,$seed_val,"-",$xdata_mstr);
}
elsif ($pass_fail_string =~ /Test PASSED/)
{
$pass_cnt++;
printf (STORE_REGRESS_RSLT "|%9d|%78s|%7d|%11s|%12s|\n",$sr_nu,$cur_test_name,$seed_val,"PASSED",$xdata_mstr);
}
elsif ($pass_fail_string =~ /Test FAILED/)
{
$fail_cnt++;
printf (STORE_REGRESS_RSLT "|%9d|%78s|%7d|%11s|%12s|\n",$sr_nu,$cur_test_name,$seed_val,"FAILED",$xdata_mstr);
}
else
{
$incomplete_cnt++ ;
printf (STORE_REGRESS_RSLT "|%9d|%78s|%7d|%11s|%12s|\n",$sr_nu,$cur_test_name,$seed_val,"-",$xdata_mstr);
}
}
Perl grep不是系统grep。您必须打开文件并搜索您要查找的行。如果你想使用系统grep,为什么不使用bash? – bytepusher