我修改了一個現有的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