perl栏分为perl基本语法、高阶语法、和一个perl自动化脚本生成器案例。
语法部分是笔者学习perl的总结,并非原创。
案例是笔者原创。
该脚本生成器,使用到了perl基础语法和perl高级语法中的知识,读者可以阅读,同时也可以用于自己的自动化工作中去。
脚本所需的文本
# NICK name , will create Dir and named with $NICK_NAME for working database publishing
NICK_NAME = usb4_sc0_t.MTO.root6.snmn.delro
# ATPG_SUBMISSION_RUN_PATH, will submit its come certain patterns,
#ATPG_SUBMISSION_RUN_PATH = chain:0 saf:0 tdf:0
ATPG_SUBMISSION_RUN_PATH = chain:/proj/sbio_redang_dft2/weifexie/sbiodft_krn1usb4HC0HC1_MTO_0416/SCAN_ATPG/sata_fch_usb4_container_atpg_sim/Krackan_1/usb4_sc0_t/usb4_sc0_t.MTO.root6.snmn.delro/atpg/session/edt_saf_single_clk_func_addsmsgcxfinaltunecom/ saf:/proj/sbio_redang_dft2/weifexie/sbiodft_krn1usb4HC0HC1_MTO_0416/SCAN_ATPG/sata_fch_usb4_container_atpg_sim/Krackan_1/usb4_sc0_t/usb4_sc0_t.MTO.root6.snmn.delro/atpg/session/edt_saf_single_clk_func_addsmsgcxfinaltunecom/ tdf:/proj/sbio_redang_dft2/weifexie/sbiodft_krn1usb4HC0HC1_MTO_0416/SCAN_ATPG/sata_fch_usb4_container_atpg_sim/Krackan_1/usb4_sc0_t/usb4_sc0_t.MTO.root6.snmn.delro/atpg/session/edt_tdf_single_clk_func_addsmsgcxfinal/
# PATTERN_DELIVERY_TYPE , choose what kind of patterns will plan to submit, full sampled
#PATTERN_DELIVERY_TYPE = saf:0 tdf:0
#PATTERN_DELIVERY_TYPE = saf:<full>,<sampled> tdf:<full>,<sampled>
PATTERN_DELIVERY_TYPE = saf:full,sampled tdf:full
#PATTERN_CYCLE , saf:1CYC,2CYC,ALL tdf:2CYC,ALL eg, saf:0 tdf:0
#PATTERN_CYCLE , = saf:<1CYC>,<2CYC>,<ALL> tdf:<2CYC>,<3CYC>,<ALL>
PATTERN_CYCLE = saf:1CYC,ALL tdf:2CYC,ALL
# GEN_ENV , choose which env will be created, Patt_Tracker LADB_Gen
GEN_ENV = Patt_Tracker LADB_Gen
#top name
ATPG_TOP_MODULE_NAME = usb4_sc0_t
# PatternTracker_tile
PATTERN_TRACKER_TILE = fch_usbadp0
# project name
PROJECT_NAME = Krack
# PatternTracker_design_variant
PROJECT_VARIANT_NAME = KRK1
# tessent version
# TESTKOMPRESS_VERSION = tessent/2022.4
TESTKOMPRESS_VERSION = tessent/2022.4
# LADB generation need to add each tile def filesLADB_DEF_TYPE = def
LADB_DEF_LIST = /proj/sbio_redang_dft2/weifexie/db_krn1usb4/MTO
# LADB lef, tlef filesLADB_LEF_TYPE = lef tlef
LADB_LEF_LIST = /proj/krn_lib/a0/library/lib_3.0.0/lef /proj/krn_lib/a0/library/lib_3.0.0/technology /proj/strix1_genip/memories/strix1/tsmc5n/0.6/current/sram
# LADB lef def file preparsion, first time to run or re-prepare need set to 1, then set to 0
ATPG_DEFLEF_REDO = 0
# PatternTracker_flatmodel_pattern_link
LADB_FLATMODEL_LINK = 523447
程序主体
#!/usr/bin/perl -w
#-----------------------------------------------------------------
use strict;
use warnings;
use Getopt::Long;
use Data::Dumper;
use File::Spec;
use File::Path qw(mkpath rmtree);
use Digest::MD5 qw(md5_hex);
use File::Find;
# print localtime()
my $time = scalar(localtime);
print "\n+++ Check Time: $time +++\n";
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime();
my $cdate = sprintf "%02d_%02d_%02d_%02d_%02d_%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec;
my $cl_blue="\033[01;34m";
my $cl_gre="\033[01;32m";
my $cl_red="\033[0;31m";
my $cl_end="\033[0m";
my $Pattrker = "";
my $LADBgen = "";
my $FLOW_ROOT_PATH = `pwd`;chomp $FLOW_ROOT_PATH;
&GetOptions(
"help|h" => \my $help,
"Pattrker|P" => \$Pattrker,
"LADBgen|L" => \$LADBgen,
"md5sum=s" => \my $md5sum_list,
) or die "${cl_red}Pls check arguements provided for Getoptions module usage: $!\n$cl_end";
# process the -help or -h and print the usage information for user
if(defined($help)) {&printHelp;exit;};
# process md5sum file message for user
if(defined($md5sum_list)) {&md5sum_sub($md5sum_list);exit;};
# check all options of script
&CheckOptions();
# main func gets started | tee -ai all of messages
if((-e "$FLOW_ROOT_PATH/Pattrker_LADBgen.buildenv.log")&&!(-d "$FLOW_ROOT_PATH/Pattrker_LADBgen.buildenv.log")) {system "rm -rf $FLOW_ROOT_PATH/Pattrker_LADBgen.buildenv.log";}
open STDOUT, "| tee -i $FLOW_ROOT_PATH/Pattrker_LADBgen.buildenv.log" or die "Pls check file permission |$FLOW_ROOT_PATH/Pattrker_LADBgen.buildenv.log|, failed message: $!\n";
# open gobal setting file 'Pattrk_LADBgen.params and read in
open PARAMS,"<$FLOW_ROOT_PATH/Pattrker_LADBgen.params" or die "Can not find {$FLOW_ROOT_PATH/Pattrker_LADBgen.params}, pls check its vailidity: $!\n";
my @PARAMS = <PARAMS>;
close PARAMS;
# check all params that will be used later
my $nick_name = ¶m_value_checker_sub("NICK_NAME",@PARAMS);
my $atpg_submission_run_path = ¶m_value_checker_sub("ATPG_SUBMISSION_RUN_PATH",@PARAMS);
my $pattern_cycle = ¶m_value_checker_sub("PATTERN_CYCLE",@PARAMS);
my $pattern_delivery_type = ¶m_value_checker_sub("PATTERN_DELIVERY_TYPE",@PARAMS);
my $gen_env = ¶m_value_checker_sub("GEN_ENV",@PARAMS);
my $atpg_top_module_name = ¶m_value_checker_sub("ATPG_TOP_MODULE_NAME",@PARAMS);
my $pattern_tracker_tile = ¶m_value_checker_sub("PATTERN_TRACKER_TILE",@PARAMS);
my $project_name = ¶m_value_checker_sub("PROJECT_NAME",@PARAMS);
my $project_variant_name = ¶m_value_checker_sub("PROJECT_VARIANT_NAME",@PARAMS);
my $testkompress_version = ¶m_value_checker_sub("TESTKOMPRESS_VERSION",@PARAMS);
my @ladb_def_list = split " ", ¶m_value_checker_sub("LADB_DEF_LIST",@PARAMS);
#my $ladb_def_type = ¶m_value_checker_sub("LADB_DEF_TYPE",@PARAMS);
my @ladb_lef_list = split " ", ¶m_value_checker_sub("LADB_LEF_LIST",@PARAMS);
#my $ladb_lef_type = ¶m_value_checker_sub("LADB_LEF_TYPE",@PARAMS);
my $ladb_flatmodel_link = ¶m_value_checker_sub("LADB_FLATMODEL_LINK",@PARAMS);
my $atpg_deflef_redo = ¶m_value_checker_sub("ATPG_DEFLEF_REDO",@PARAMS);
# print @PARAMS
#print "\n\n\@PARAMS: \n@PARAMS\n\n";
# define and uninitialize folders for pattern tracker and LADB generaion
my $pattrker_dir_name = "$FLOW_ROOT_PATH/Pattrker.$nick_name";
my $ladb_gen_dir_name = "$FLOW_ROOT_PATH/LADBgen.$nick_name";
# Step 1, create dir of env, -- begin --
print "${cl_blue}Create dir of env for either Pattrker or LADBgen, or BOTH ----\n$cl_end";
if($Pattrker){ &dir_checker_creater_sub($pattrker_dir_name,"$pattrker_dir_name/.ZZZ_OLD","$FLOW_ROOT_PATH/.ZZZ_OLD"); }
if($LADBgen){ &dir_checker_creater_sub($ladb_gen_dir_name,"$ladb_gen_dir_name/.ZZZ_OLD","$FLOW_ROOT_PATH/.ZZZ_OLD","$ladb_gen_dir_name/LADB_Submit_Pattrker","$ladb_gen_dir_name/LADB_Submit_Pattrker/.ZZZ_OLD"); }
# backup Pattrker_LADBgen.params file
&backup_file_sub("$FLOW_ROOT_PATH/Pattrker_LADBgen.params", "$FLOW_ROOT_PATH");
#common varibales for both of pattrker and LADB env
my $run_path_mark = {};
foreach (split " ",$atpg_submission_run_path){
chomp;
s/^\s*//g;s/\s*$//g;
my @pat_set_each = split ":",$_;
if(!($#pat_set_each == 1)||($pat_set_each[1] eq 0)){
print "params ATPG_SUBMISSION_RUN_PATH {$pat_set_each[0]} will be skipped create lookup file.\n";
}else{
$pat_set_each[1] =~ s/(\/)?$//g;
$run_path_mark->{$pat_set_each[0]} = "$pat_set_each[1]" if(-d $pat_set_each[1]);
}
}
#print $run_path_mark
#print "\%\$run_path_mark: \n",Dumper (\%{$run_path_mark}),"\n";
# common params and setings preparation
my $flat_model_path = "";
if((exists $run_path_mark->{chain})&&($run_path_mark->{chain} =~ /\/\w*/)){
my ($folder_name, $path_name) = &get_path_dir_name($run_path_mark->{chain});
if ($folder_name =~ /^([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)_\w+$/){ $folder_name = "$1_$2_$3_$4_$5"; }
$flat_model_path = "$run_path_mark->{chain}/output/$folder_name.flat_model.gz";
}elsif((exists $run_path_mark->{saf})&&($run_path_mark->{saf} =~ /\/\w*/)){
my ($folder_name, $path_name) = &get_path_dir_name($run_path_mark->{saf});
if ($folder_name =~ /^([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)_\w+$/){ $folder_name = "$1_$2_$3_$4_$5"; }
$flat_model_path = "$run_path_mark->{saf}/output/$folder_name.flat_model.gz";
}elsif((exists $run_path_mark->{tdf})&&($run_path_mark->{tdf} =~ /\/\w*/)){
my ($folder_name, $path_name) = &get_path_dir_name($run_path_mark->{saf});
if ($folder_name =~ /^([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)_\w+$/){ $folder_name = "$1_$2_$3_$4_$5"; }
$flat_model_path = "$run_path_mark->{tdf}/output/$folder_name.flat_model.gz";
}else{
print "${cl_red}Error\! LADB generaion env building needs one path {$atpg_submission_run_path} for flat_model file\n$cl_end";
exit;
}
# process the Pattrker
if($Pattrker){
print "${cl_blue}\nPublish pattern tracker enviroment for user ----\n$cl_end";
print "$cl_gre+++ a. lookup file +++$cl_end \n";
# create pattern tracker lookup file
&create_pattrker_sub($run_path_mark,$atpg_top_module_name,$pattern_tracker_tile,$project_name);
# prepare cmd config setting of PATTERN_DELIVERY_TYPE and PATTERN_CYCLE
my $pattern_delivery_type_ref = {};
my $pattern_cycle_ref = {};
foreach (split " ",$pattern_delivery_type){
my @pat_type_each = split ":",$_;
if (!($#pat_type_each == 1)||!(grep {/saf|tdf/i} @pat_type_each)||!(grep {/full|sample/i} @pat_type_each)){
print "${cl_red}Warning\! Pls check |$_| of params {@pat_type_each}, and PATTERN_DELIVERY_TYPE format should like: PATTERN_DELIVERY_TYPE = saf:<full>,<sampled> tdf:<sampled>\n";}
else{
my $i = 1;
foreach my $pat_type_each_fusa (split ",",$pat_type_each[1]){
my $fusa_cnt = grep {/full|sample/i} (split ",",$pat_type_each[1]);
$pattern_delivery_type_ref->{$pat_type_each[0]}{$i} = "$pat_type_each_fusa";
$i++;
}
}
}
foreach (split " ",$pattern_cycle){
my @pat_cyc_each = split ":",$_;
if (!($#pat_cyc_each == 1)||!(grep {/saf|tdf/i} @pat_cyc_each)||!(grep {/1cyc|2cyc|all/i} @pat_cyc_each)){
print "${cl_red}Warning\! Pls check |$_| of params {@pat_cyc_each}, and PATTERN_CYCLE format should like: PATTERN_CYCLE , = saf:<1cyc>,<2cyc>,<all> tdf:<2cyc>,<all>\n";}
else{
my $i = 1;
foreach my $pat_cyc_each_cyc12 (split ",",$pat_cyc_each[1]){
my $cyc12_cnt = grep {/1cyc|2cyc|all/i} (split ",",$pat_cyc_each[1]);
$pattern_cycle_ref->{$pat_cyc_each[0]}{$i} = "$pat_cyc_each_cyc12";
$i++;
}
}
}
#print $pattern_delivery_type_ref, $patt_cycle_ref
#print "\$pattern_delivery_type_ref: \n",Dumper (\%$pattern_delivery_type_ref),"\n";
#print "\$pattern_cycle_ref: \n",Dumper (\%$pattern_cycle_ref),"\n";
# print cmd run script common part
# cmd run file
print "$cl_gre+++ b. cmd files +++$cl_end \n";
&cmd_run_common($pattrker_dir_name,$atpg_top_module_name,$pattern_tracker_tile,$run_path_mark,$pattern_delivery_type_ref,$pattern_cycle_ref);
# print test of cmd tc-shell run script,
# saf full sampled 1CYC ALL ser patterns, tdf full sample 2CYC ALL ser pattern
&rest_cmd_run_sub($pattrker_dir_name,$atpg_top_module_name,$pattern_tracker_tile,$run_path_mark,$pattern_delivery_type_ref,$pattern_cycle_ref);
# print chmod 777 ATL/folders
#&chmod777_submit_file();
print "-Pattrker|P Publish pattern tracker enviroment for user DONE \n\n";
}
# chmod 744 cmd run script
system "chmod 744 $pattrker_dir_name/cmd.csh";
###################################
### endof pattrker env building ###
###################################
# get started LADBgen env building
if($LADBgen){
# Publish LADB generation enviroment, a. ./run.csh file
print "${cl_blue}\nPublish LADB generation enviroment for user ---\n$cl_end";
print"$cl_gre+++ a. ./run.csh file +++$cl_end \n";
&backup_file_sub("$ladb_gen_dir_name/run.csh",$ladb_gen_dir_name) if(-e "$ladb_gen_dir_name/run.csh");
open my $runcsh, "> $ladb_gen_dir_name/run.csh" or die "${cl_red}Error\! Can't access to file {$ladb_gen_dir_name/run.csh} and pls check: $!$cl_end\n";
my $here = << "RUNCSH";
#!/usr/bin/tcsh -f
# source /tools/aticad/1.0/src/sysadmin/cpd.cshrc
# module use /tool/cbar/etc/modules
# mkdir rpt and log folders
setenv log_v "log"
setenv rpt_v "rpt"
if(! -d ./log ) then
mkdir -p ./\$log_v
endif
if (! -d ./rpt) then
mkdir -p ./\$rpt_v
endif
source /proj/verif_release/cbwa_initscript/current/cbwa_init.csh
module unload tessent
module load $testkompress_version
# /tool/cbar/apps/tessent/2021.1-p1/bin/tessent -shell \
# -replace \
# -dof ./usb0_create_ladb.dof \
# -log ./test_container.log -replace
lsf_bsub -M 245000 -R "select[type==RHEL7_64||type==RHEL6_64||type==RHEL5_64||type==RHEL5_64||type==RHEL4_64||type==RHEL_64] rusage[mem=120000]" -q high -P sbio-fe -Ip " /tool/cbar/apps/tessent/2022.4/bin/tessent -shell -yieldinsight -64 -replace -dof ./create_layout.dof -log ./\$log_v/$atpg_top_module_name.gen_ladb.log -replace -license 300 "
RUNCSH
print $runcsh $here;
print "run.csh file for LADBgen env created\n";
close $runcsh;
# b. create_layout.dof file
print"$cl_gre+++ b. create_layout.dof file +++$cl_end \n";
&backup_file_sub("$ladb_gen_dir_name/create_layout.dof",$ladb_gen_dir_name) if(-e "$ladb_gen_dir_name/create_layout.dof");
open my $layout,">$ladb_gen_dir_name/create_layout.dof" or die "${cl_red}Error\! Can't access to file {./$ladb_gen_dir_name/create_layout.dof} and pls check: $!$cl_end\n";
$here = << "LAYOUT";
# create_layout.dof file
setenv rpt_v "rpt"
set_context patterns -scan_diagnosis
set_dofile_abort off
system date
read_flat_model $flat_model_path
creat layout ./\$rpt_v/${atpg_top_module_name}_layout \\
-compact ON \\
-do_tolerant_match OFF \\
-def \\
\\
\\
LAYOUT
print $layout $here;
# DEF files definition, atpg_deflef_redo params defined for re-generation of def and lef
my $def;
my $lef;
if ($atpg_deflef_redo eq "1"){
open $def, "+>$FLOW_ROOT_PATH/def.log" or die "${cl_red}Error\! Can not read and write to the file {$FLOW_ROOT_PATH/def.log}. Pls check: $! $cl_end\n";
find(\&find_def_sub,@ladb_def_list) if($atpg_deflef_redo == 1);
}else{
open $def, "<$FLOW_ROOT_PATH/def.log" or die "${cl_red}Error\! Can not read and write to the file {$FLOW_ROOT_PATH/def.log}. Pls check: $! $cl_end\n"; }
my @def = <$def>;
print $layout @def;
close $def;
print $layout "\\\n\\\n-lef \\\n";
# lef files definition
if ($atpg_deflef_redo eq "1"){
open $lef, "+>$FLOW_ROOT_PATH/lef.log" or die "${cl_red}Error\! Can not read and write to the file {$FLOW_ROOT_PATH/lef.log}. Pls check: $! $cl_end\n";
find(\&find_lef_sub,@ladb_lef_list) if($atpg_deflef_redo == 1);
}else{
open $lef, "<$FLOW_ROOT_PATH/lef.log" or die "${cl_red}Error\! Can not read and write to the file {$FLOW_ROOT_PATH/lef.log}. Pls check: $! $cl_end\n"; }
my @lef = <$lef>;
print $layout @lef;
close $lef;
$here = << "LAYOUT";
\\
\\
-replace \\
-threshold 16 \\
-extra_layout_hierarchy $pattern_tracker_tile \\
-topology_threshold 50
//-core mpu
report layout rule DesignModuleCell > \$rpt_v/${atpg_top_module_name}_DesignModuleCell.rpt
report layout rule DesignCellMatch > \$rpt_v/${atpg_top_module_name}_DesignCellMatch.rpt
report layout rule DesignInstanceMatch > \$rpt_v/${atpg_top_module_name}_DesignInstanceMatch.rpt
report layout rule MacroExistence > \$rpt_v/${atpg_top_module_name}_MacroExistence.rpt
report layout rule DesignInstanceMatch > \$rpt_v/${atpg_top_module_name}_DesignInstanceMatch.rpt
report layout rule DesignNetMatch > \$rpt_v/${atpg_top_module_name}_DesignNetMatch.rpt
report layout rule DesignNetPinMatch > \$rpt_v/${atpg_top_module_name}_DesignNetPinMatch.rpt
report layout rule LayoutNetPinMatch > \$rpt_v/${atpg_top_module_name}_LayoutNetPinMatch.rpt
//report_layout_rules -mismatch_report -exclude CPC_0
//report_layout_rules -mismatch_report -exclude CPC_1
//report_layout_rules -mismatch_report -exclude gnb
LAYOUT
print $layout $here;
close $layout;
print "create_layout.dof file for LADBgen env created\n";
# c. LADB_Submit_Pattrker folder, i. cmd file
print"$cl_gre+++ c. LADB_Submit_Pattrker folder +++$cl_end \n";
print"$cl_gre+++ i. cmd file run_ladb.csh +++ $cl_end\n";
&backup_file_sub("$ladb_gen_dir_name/LADB_Submit_Pattrker/run_ladb.csh","$ladb_gen_dir_name/LADB_Submit_Pattrker") if(-e "$ladb_gen_dir_name/LADB_Submit_Pattrker/run_ladb.csh");
open my $ladb_pker,"> $ladb_gen_dir_name/LADB_Submit_Pattrker/run_ladb.csh" or die "${cl_red}Error\! Can not have the permission to file {$ladb_gen_dir_name/LADB_Submit_Pattrker/run_ladb.csh}, pls check: $!$cl_end\n";
$here = << "LADB_PKER";
/tool/amd/dft/dev/shared/tvf/PatternTracker -submit -lookup ${atpg_top_module_name}_LADB.lookup -auto
LADB_PKER
print $ladb_pker $here;
close $ladb_pker;
print "cmd file run_ladb.csh for LADB_Submit_Pattrker created\n";
# create ii. lookup file ${atpg_top_module_name}_LADB.lookup
print "$cl_gre+++ ii. lookup file ${atpg_top_module_name}_LADB.lookup +++$cl_end \n";
&backup_file_sub("$ladb_gen_dir_name/LADB_Submit_Pattrker/${atpg_top_module_name}_LADB.lookup","$ladb_gen_dir_name/LADB_Submit_Pattrker") if(-e "$ladb_gen_dir_name/LADB_Submit_Pattrker/${atpg_top_module_name}_LADB.lookup");
open my $ladb_lookup, "> $ladb_gen_dir_name/LADB_Submit_Pattrker/${atpg_top_module_name}_LADB.lookup" or die "${cl_red}Error\! Can not have the permission to file {$ladb_gen_dir_name/LADB_Submit_Pattrker/${atpg_top_module_name}_LADB.lookup}, pls check: $!$cl_end\n";
$here = << "LADB_LOOKUP";
# ${atpg_top_module_name}_LADB.lookup
\$PatternDeliveryBaseDir =
\$PatternTrackerConfiguration = $project_name
\$PatternTracker_design_variant = $project_variant_name
\$PatternTracker_package = FP8
\$PatternTracker_revision = A0
\$PatternTracker_chain_mode = Multi-Chain
\$PatternTracker_tester = 93k
\$PatternTracker_scan_interface = DDR-CB
\$PatternTracker_fullchip_component = 1
\$PatternTracker_eda_tool = TestKompress
\$PatternTracker_component_mode = SoftIP
\$PatternTracker_design_component = INTEST
#############################################################
#############################################################
\$PatternTracker_pll_state = Pll
\$PatternTracker_replacement_pattern_id = " "
\$PatternTracker_flatmodel_pattern_link = "$ladb_flatmodel_link"
\$PatternTracker_init_pattern_id = " "
\$PatternTracker_topoff = 0
\$PatternTracker_component_pattern_link = " "
\$PatternTracker_mictam_status_read_pattern_id = NA
\$PatternTracker_debug = 0
#############################################################
#############################################################
\$PatternTracker_tile = $pattern_tracker_tile
\$PatternTracker_scan_compression = Compressed
\$PatternTracker_pattern_type = Chain
\$PatternTracker_clock_domain = NA
\$PatternTracker_capture_procedure = 0CYC
#############################################################
\$PatternTrackerLADB = $ladb_gen_dir_name/rpt/${atpg_top_module_name}_layout/
#############################################################
LADB_LOOKUP
print $ladb_lookup $here;
print $ladb_lookup " \@PatternTrackerDef = \\\n";
# add def files from def.log to ${atpg_top_module_name}_LADB.lookup
open $def, "< $FLOW_ROOT_PATH/def.log" or die "${cl_red}Error\! Pls check file {$FLOW_ROOT_PATH/def.log} and its permission: $!\n$cl_end";
@def = <$def>;
print $ladb_lookup @def;
print $ladb_lookup "\n";
close $def;
print $ladb_lookup " #############################################################\n";
print $ladb_lookup " \@PatternTrackerLef = \\\n";
# add lef files from lef.log to ${atpg_top_module_name}_LADB.lookup
open $lef, "< $FLOW_ROOT_PATH/lef.log" or die "${cl_red}Error\! Can not read and write to the file {$FLOW_ROOT_PATH/lef.log}. Pls check: $! $cl_end\n";
@lef = <$lef>;
print $ladb_lookup @lef;
print $ladb_lookup "\n";
close $lef;
print $ladb_lookup " #############################################################\n";
print $ladb_lookup " \$PatternTracker_comments = \"$project_name/$project_variant_name $pattern_tracker_tile $atpg_top_module_name LADB RELEASE, ATPG tool version:$testkompress_version , LADB tool version:$testkompress_version , Is chip mapping done properly: yes \"\n\n";
close $ladb_lookup;
print "LADB.lookup file for LADB_Submit_Pattrker created\n";
print "-LADBgen|L Publish LADB generation enviroment for user DONE \n\n";
}
# chmod 744 cmd run script
system "chmod 744 $ladb_gen_dir_name/create_layout.dof $ladb_gen_dir_name/run.csh $ladb_gen_dir_name/LADB_Submit_Pattrker/run_ladb.csh $ladb_gen_dir_name/LADB_Submit_Pattrker/${atpg_top_module_name}_LADB.lookup";
close STDOUT;
#####################################################################
#####################################################################
######(MAIN END)#############(MAIN END)#############(MAIN END)#######
#####################################################################
#####################################################################
### sub find_def_sub subrountine
sub find_def_sub {
#print "${cl_red}Error\! Pls check params {@ladb_def_list} for definition of DFE files.$cl_end\n" if ((! -f $_) || ( $_ =~ /^\./) || ($File::Find::name =~ /\/\.\.*/));
return $_ if ((! -f $_) || ( $_ =~ /^\./) || ($File::Find::name =~ /\/\.\.*/));
if($_ =~ /def\.gz$/){
open my $def,">>$FLOW_ROOT_PATH/def.log" or die "${cl_red}Error\! Pls check file {$File::Find::dir/def.log} and its permission: $!\n$cl_end";
print $def "$File::Find::name \\\n";
close $def;
}
} # endof find_def_sub
### sub find_lef_sub subrountine
sub find_lef_sub {
#print "${cl_red}Error\! Pls check params {@ladb_lef_list} for definition of DFE files" if((! -f $_) || ( $_ =~ /^\./) || ($File::Find::name =~ /\/\./));
return $_ if((! -f $_) || ( $_ =~ /^\./) || ($File::Find::name =~ /\/\./));
if($_ =~ /lef$|tlef$/){
open my $lef,">>$FLOW_ROOT_PATH/lef.log" or die "${cl_red}Error\! Pls check file {$File::Find::dir/lef.log} and its permission: $!\n$cl_end";
print $lef "$File::Find::name \\\n";
close $lef;
}
} # endof find_lef_sub
### subroutine sub param_value_checker_sub ###
sub param_value_checker_sub {
my ($param_name,@params_files) = @_;
my $temp1 = "";
my $num = grep {/^\s*$param_name\s*=\s*/} @params_files;
if ($num > 0) {
my @param_all = grep {/^\s*$param_name\s*=\s*/} @params_files;
$temp1 = $param_all[$num-1];
if($num > 1){
print "${cl_red}Warning\!:|$param_name| have set $num times, but only the last definition can be used.$cl_end\n";
}
$temp1 =~ s/^\s*$param_name\s*=\s*//g;
chomp$temp1;
if ($temp1 !~ /.+/) {
print "${cl_red}Warning\!:|$param_name| has set its value as NULL or undef, pls set and re-run $0 $cl_end\n";
exit ;
}
}else{
print "${cl_red}Error\!:|$param_name| has set its value as NULL or under, pls set and re-run $0 $cl_end\n";
exit ;
}
return $temp1;
} # endof sub param_value_checker_sub
### sub create_pattrker_sub ###
sub create_pattrker_sub {
my $pat_set = "";
my $capture_procedure = "";
my $pattern_type = "";
my ($run_path_mark,$atpg_top_module_name,$pattern_tracker_tile,$project_name) = @_;
# chain lookup file
if((grep {/chain/i} %$run_path_mark)&&($run_path_mark->{"chain"} =~ /\/\w*/)){
$pat_set = "chain";
$capture_procedure = "0CYC";
$pattern_type = "Chain";
# chain lookup file name: Pattrker.usb4_sc0_t.MTO/usb4_sc0_t.fch_usbadp0.chain.lookup
open my$lookup_hd,">$pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup" or die "Error\! Can't have permssion to write: $!";
&pattrker_lookup_sub($lookup_hd,$atpg_top_module_name,$pattern_tracker_tile,$pat_set,$project_name,$capture_procedure,$pattern_type);
my $lookup = << "LOOKUP";
#
LOOKUP
print $lookup_hd $lookup;
close $lookup_hd;
print "$pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup file created\n";
}
# saf lookup file
if((grep {/saf/i} %$run_path_mark)&&($run_path_mark->{"saf"} =~ /\/\w*/)){
$pat_set = "saf";
$capture_procedure = "2CYC";
$pattern_type = "Static";
# saf lookup file name: Pattrker.usb4_sc0_t.MTO/usb4_sc0_t.fch_usbadp0.saf.lookup
open my $lookup_hd,">$pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup" or die "Error\! Can't have permssion to write: $!";
&pattrker_lookup_sub($lookup_hd,$atpg_top_module_name,$pattern_tracker_tile,$pat_set,$project_name,$capture_procedure,$pattern_type);
my $lookup = << "LOOKUP";
LOOKUP
print $lookup_hd $lookup;
close $lookup_hd;
print "$pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup file created\n";
}
# tdf lookup file
if((grep {/tdf/i} %$run_path_mark)&&($run_path_mark->{"tdf"} =~ /\/\w*/)){
$pat_set = "tdf";
$capture_procedure = "2CYC";
$pattern_type = "Dynamic";
# tdf lookup file name: Pattrker.usb4_sc0_t.MTO/usb4_sc0_t.fch_usbadp0.tdf.lookup
open my$lookup_hd,">$pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup" or die "Error\! Can't have permssion to write: $!";
&pattrker_lookup_sub($lookup_hd,$atpg_top_module_name,$pattern_tracker_tile,$pat_set,$project_name,$capture_procedure,$pattern_type);
my $lookup = << "LOOKUP";
#
LOOKUP
print $lookup_hd $lookup;
close $lookup_hd;
print "$pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup file created\n";
}
} # endof creat_pattrker_sub
### sub pattrker_lookup_sub ###
sub pattrker_lookup_sub{
my ($lookup_hd,$atpg_top_module_name,$pattern_tracker_tile,$pat_set,$project_name,$capture_procedure,$pattern_type) = @_;
&backup_file_sub("$pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup",$pattrker_dir_name);
my $lookup = << "LOOKUP";
# #############################################################
\$PatternDeliveryBaseDir =
\$PatternTracker_design_variant = $project_variant_name
\$PatternTracker_package = FP8
\$PatternTracker_revision = A0
\$PatternTracker_chain_mode = Multi-Chain
\$PatternTracker_tester = 93k
\$PatternTracker_scan_interface = DDR-CB
\$PatternTracker_fullchip_component = 0
\$PatternTracker_eda_tool = TestKompress
# \$PatternTracker_component_mode = SoftIP,
\$PatternTracker_component_mode = SoftIP
\$PatternTracker_design_component = INTEST
# #############################################################
\$PatternTracker_pll_state = Pll
\$PatternTracker_replacement_pattern_id =
\$PatternTracker_flatmodel_pattern_link =
\$PatternTracker_init_pattern_id = " "
\$PatternTracker_topoff = 0
\$PatternTracker_component_pattern_link =
# #############################################################
\$PatternTracker_scan_compression = Compressed
\$PatternTracker_clock_domain = NA
\$PatternTracker_capture_procedure = $capture_procedure
\$PatternTracker_debug = 0
LOOKUP
print $lookup_hd $lookup;
print $lookup_hd " \$PatternTrackerConfiguration = $project_name\n";
print $lookup_hd " \$PatternTracker_pattern_type = $pattern_type\n";
print $lookup_hd " \$PatternTracker_tile = $pattern_tracker_tile\n";
print $lookup_hd " \$PatternTracker_comments = \"$project_name $pattern_tracker_tile $pat_set ser test pattern\"\n";
my $here = << 'LOOKUP';
# #############################################################
$PatternTracker_mictam_status_read_pattern_id = ""
LOOKUP
print $lookup_hd $here;
} # enof pattrker_lookup_sub
###############################
###############################
### sub cmd_run_common
sub cmd_run_common {
my ($pattrker_dir_name,$atpg_top_module_name,$pattern_tracker_tile,$run_path_mark,$pattern_delivery_type_ref,$pattern_cycle_ref) = @_;
&backup_file_sub("$pattrker_dir_name/cmd.csh",$pattrker_dir_name) if(-e "$pattrker_dir_name/cmd.csh");
open my $cmd,">$pattrker_dir_name/cmd.csh" or die "${cl_red}Error\! Can't have the permission of file {$pattrker_dir_name/cmd.csh}, pls check: $!$cl_end\n";
my $common = << "COMMON";
#!/usr/bin/tcsh -f
##################
# usage: ./run.csh
# [desc]:
# 1. submit stil.gz file with its flat_model files at once
# 2. chmod 777 submission folder in ATL for users outside
#
# [soc request in common]:
# saf chain: stil.gz flat_model
# scan ser pattern: full, sampled
# / \
# / \
# 1cyc 1cyc
# 2cyc 2cyc
# allc allc
#
# tdf scan ser pattern: sampled
# |
# |
# 2cyc
# 3cyc
# descend
# obtain stil and it flat file path
COMMON
print $cmd $common;
# chain stil file seems as common and only has relationship with params ATPG_SUBMISSION_RUN_PATH
if(!(exists $run_path_mark->{chain})||!($run_path_mark->{chain} =~ /\/\w*/)){
print "${cl_red}Warning\! Chain stil.gz file is NO NEED to submit, pls check: $!$cl_end\n";
}else{
my $pat_set = "chain";
my ($folder_name, $path_name) = &get_path_dir_name($run_path_mark->{chain});
if($folder_name =~ m/^([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)_\w+$/){ $folder_name = "$1_$2_$3_$4_$5"; }
print $cmd "# chain stil.gz and its flat model file submission\n";
print $cmd "/tool/amd/dft/dev/shared/tvf/PatternTracker -submit $run_path_mark->{chain}/output/$folder_name\_$pat_set.stil.gz -lookup $pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup -auto\n";
print $cmd "\n# md5sum files used for submission\n";
print $cmd "md5sum $run_path_mark->{chain}/output/$folder_name\_$pat_set.stil.gz > $pattrker_dir_name/md5sum.rpt_$cdate\n";
print $cmd "md5sum $run_path_mark->{chain}/output/$folder_name.flat_model.gz >> $pattrker_dir_name/md5sum.rpt_$cdate\n";
print "cmd tc-shell for Chain stil.gz and its flat model files file created\n";
close $cmd;
}
} # end of sub cmd_run_common
### sub rest_cmd_run_sub
sub rest_cmd_run_sub{
my ($pattrker_dir_name,$atpg_top_module_name,$pattern_tracker_tile,$run_path_mark,$pattern_delivery_type_ref,$pattern_cycle_ref) = @_;
open my $cmd,">>$pattrker_dir_name/cmd.csh" or die "${cl_red}Error\! Can't have the permission of file {$pattrker_dir_name/cmd.csh}, pls check: $!$cl_end\n";
# traverse keys of%$pattern_delivery_type_ref
my %pattern_delivery_type_ref_hash = %{$pattern_delivery_type_ref};
my %pattern_cycle_ref_hash = %{$pattern_cycle_ref};
# print "\%pattern_delivery_type_ref_hash: %pattern_delivery_type_ref_hash\n";
# print "\%pattern_delivery_type_ref_hash: ",Dumper \%pattern_delivery_type_ref_hash,"\n";
# print "\%pattern_cycle_ref_hash: %pattern_cycle_ref_hash\n";
# print "\%pattern_cycle_ref_hash: ",Dumper \%pattern_cycle_ref_hash,"\n";
foreach my $key_pat_type(sort {$a cmp $b} keys %pattern_delivery_type_ref_hash){
# print "\$key_pat_type: $key_pat_type\n";
# print "\$key_pat_type: $key_pat_type\n";
foreach my $key_pat_cyc(sort {$a cmp $b} keys %pattern_cycle_ref_hash){
# print "\$key_pat_cyc: $key_pat_cyc\n";
# print "\$key_pat_cyc: $key_pat_cyc\n";
if ($key_pat_cyc eq $key_pat_type){
# print ref $pattern_delivery_type_ref_hash{$key_pat_type},ref $pattern_cycle_ref_hash{$key_pat_cyc}
# print "ref \$pattern_delivery_type_ref_hash{\$key_pat_type}",ref $pattern_delivery_type_ref_hash{$key_pat_type},"\n";
# print "ref \$pattern_cycle_ref_hash{\$key_pat_cyc}",ref $pattern_cycle_ref_hash{$key_pat_cyc},"\n";
if((ref $pattern_delivery_type_ref_hash{$key_pat_type} ne "HASH")||(ref $pattern_cycle_ref_hash{$key_pat_cyc} ne "HASH")){
print "${cl_red}Warning\! params $pattern_delivery_type_ref_hash{$key_pat_type} or $pattern_cycle_ref_hash{$key_pat_cyc} equals to 0, pls check params. $!$cl_end\n";
}else{
foreach my $key_pat_type_fusa(sort {$a cmp $b} keys %{$pattern_delivery_type_ref_hash{$key_pat_type}}){
# print "\$key_pat_type_fusa: $key_pat_type_fusa\n\";
# print "\$key_pat_type_fusa: $key_pat_type_fusa\n";
# print "keys %{$pattern_delivery_type_ref_hash{$key_pat_type}}\n";
# print "keys %{\$pattern_delivery_type_ref_hash{\$key_pat_type}}:",keys %{$pattern_delivery_type_ref_hash{$key_pat_type}},"\n";
foreach my $key_pat_cyc_cyc12(sort {$a cmp $b} keys %{$pattern_cycle_ref_hash{$key_pat_cyc}}){
my $pat_set = "";
# print "\$key_pat_cyc_cyc12: $key_pat_cyc_cyc12\n\";
# print "\$key_pat_cyc_cyc12: $key_pat_cyc_cyc12\n";
# print "keys %{$pattern_cycle_ref_hash{$key_pat_cyc}}\n";
# print "keys %{\$pattern_cycle_ref_hash{\$key_pat_cyc}}:",keys %{$pattern_cycle_ref_hash{$key_pat_cyc}},"\n";
# print "\$key_pat_type: $key_pat_type\n";
if("$key_pat_type" eq "saf"){ $pat_set = "saf"; }elsif("$key_pat_type" eq "tdf"){ $pat_set = "tdf"; }
#print "\n###\n\$pat_set: $pat_set\n";
my ($folder_name,$folder_path) = &get_path_dir_name($run_path_mark->{$pat_set});
if($folder_name =~ m/^([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)_([a-z]+)_\w+$/){ $folder_name = "$1_$2_$3_$4_$5"; }
# print "\n<<<\n(\$folder_name,\$folder_path) = ($folder_name,$folder_path)\n>>>\n";
# print "\n{{{\n\$pattern_delivery_type_ref_hash{\$key_pat_type}{\$key_pat_type_fusa}: $pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa}\n";
# print "\$pattern_cycle_ref_hash{\$key_pat_cyc}{\$key_pat_cyc_cyc12}: $pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12}\n}}}\n";
# full all ser
if(($pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} eq "full")&&($pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} eq "ALL")){
print $cmd "\n# $pat_set $pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} $pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} stil.gz and its flat model file submission\n";
print $cmd "cp -rf $run_path_mark->{$pat_set}/output/$folder_name.flat_model.gz $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp.flat_model.gz\n";
print $cmd "/tool/amd/dft/dev/shared/tvf/PatternTracker -submit $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp.stil.gz -lookup $pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup -auto\n\n";
print $cmd "md5sum $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp.stil.gz >> $pattrker_dir_name/md5sum.rpt_$cdate\n";
print "cmd tc-shell for $pat_set $pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} $pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} stil.gz and its flat model files file created\n";
# full 123CYC ser
}elsif(($pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} eq "full")&&($pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} =~ /[123]CYC/i)){
print $cmd "\n# $pat_set $pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} $pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} stil.gz and its flat model file submission\n";
print $cmd "cp -rf $run_path_mark->{$pat_set}/output/$folder_name.flat_model.gz $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp_$pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12}_only.flat_model.gz\n";
print $cmd "/tool/amd/dft/dev/shared/tvf/PatternTracker -submit $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp_$pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12}_only.stil.gz -lookup $pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup -auto\n\n";
print $cmd "md5sum $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp_$pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12}_only.stil.gz >> $pattrker_dir_name/md5sum.rpt_$cdate\n";
print "cmd tc-shell for $pat_set $pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} $pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} stil.gz and its flat model files file created\n";
# sampled all ser
}elsif(($pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} eq "sampled")&&($pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} eq "ALL")){
print $cmd "\n# $pat_set $pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} $pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} stil.gz and its flat model file submission\n";
print $cmd "cp -rf $run_path_mark->{$pat_set}/output/$folder_name.flat_model.gz $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp_sample.flat_model.gz\n";
print $cmd "/tool/amd/dft/dev/shared/tvf/PatternTracker -submit $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp_sample.stil.gz -lookup $pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup -auto\n\n";
print $cmd "md5sum $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp_sample.stil.gz >> $pattrker_dir_name/md5sum.rpt_$cdate\n";
print "cmd tc-shell for $pat_set $pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} $pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} stil.gz and its flat model files file created\n";
# sample 123CYC ser
}elsif(($pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} eq "sampled")&&($pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} =~ /[123]CYC/i)){
print $cmd "\n# $pat_set $pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} $pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} stil.gz and its flat model file submission\n";
print $cmd "cp -rf $run_path_mark->{$pat_set}/output/$folder_name.flat_model.gz $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp_$pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12}_only_sample.flat_model.gz\n";
print $cmd "/tool/amd/dft/dev/shared/tvf/PatternTracker -submit $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp_$pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12}_only_sample.stil.gz -lookup $pattrker_dir_name/$atpg_top_module_name.$pattern_tracker_tile.$pat_set.lookup -auto\n\n";
print $cmd "md5sum $run_path_mark->{$pat_set}/output/$folder_name\_scan_all_ncp_$pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12}_only_sample.stil.gz >> $pattrker_dir_name/md5sum.rpt_$cdate\n";
print "cmd tc-shell for $pat_set $pattern_delivery_type_ref_hash{$key_pat_type}{$key_pat_type_fusa} $pattern_cycle_ref_hash{$key_pat_cyc}{$key_pat_cyc_cyc12} stil.gz and its flat model files file created\n";
#&check_file_sub();
}
print $cmd "find $run_path_mark->{$pat_set}/output/ -name \"\*flat_model\*\" \| grep -vw $folder_name \| xargs rm -rf \{\}";
}
}
}
} # else{ # print "\$key_pat_type: $key_pat_type ne \$key_pat_cyc: $key_pat_cyc\n"; }
}
}
close $cmd;
} # endof sub rest_cmd_run_sub
### sub get_path_dir_name ###
sub get_path_dir_name {
my ($file) = shift @_;
my $file_abs = File::Spec->rel2abs($file);
my (undef,$dir,$folder_name) = File::Spec->splitpath($file_abs);
chdir $dir; my $folder_path = `pwd`; chomp $folder_path; chdir $FLOW_ROOT_PATH;
$folder_path =~ s/\/$//g;
return ($folder_name,$folder_path);
} # endof subroutine get_path_dir_name
### sub check_file_sub ###
sub check_file_sub{
my $files = ();
foreach my $file (@_) {
if(!(-e $file)||(-d $file)||(-z $file)){
print "${cl_red}Error\! File {$file} is non-exist, content, or valid$cl_end\n";
}
$files = "$files".".$file";
}
return split".",$files;
} # endof sub check_file_sub
### sub backup_file_sub ###
sub backup_file_sub{
my ($file, $ZZZ_OLD) = @_;
my ($folder_name, $folder_path) = &get_path_dir_name($file);
my $backup_file_dir = "$ZZZ_OLD/.ZZZ_OLD";
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime((stat $file)[9]);
my $date = sprintf "%02d_%02d_%02d_%02d_%02d_%02d", $year+1900, $mon+1, $mday, $hour, $min, $sec;
#print "\n(((\n$date\n)))\n\n";
my $backup_file_name = $folder_name.".$date";
if(-d $backup_file_dir){
system "cp $folder_path/$folder_name $backup_file_dir/$backup_file_name";
print "--- backup file {$folder_name} into foler {$backup_file_dir} done\n";
}else {
&dir_checker_creater_sub($backup_file_dir);
&backup_file_sub(@_);
print "pls chkeck this function includes params: {@_}\n";
}
} # enof backup_file_sub
### sub md5sum_sub ###
sub md5sum_sub{
my $file = shift @_;
print "\n\$file = $file\n\n";
if((-e $file)&& !(-d $file)){
my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime((stat $file)[9]);
my $date = sprintf"%02u-%02u-%02u %02u:%02u:%02u", $year+1900, $mon+1, $mday, $hour, $min, $sec;
print "$date | ";
system "md5sum $file\n\n";
}else{print "${cl_red}Error\! Pls check file {$file} and its validity\n";exit;}
} # endof sub md5sum_sub
### $printHelp subroutine ###
sub printHelp {
my ($folder_name,$path_name) = &get_path_dir_name($0);
print "\n\n${cl_red}$folder_name [-help|h]\n$cl_end";
print "---------------------------------------\n";
print "\n";
print "-help|h Print this help message.\n";
print "\n\n${cl_red}$folder_name [-Pattrker|P] [-LADBgen|L]\n$cl_end";
print "---------------------------------------\n";
print "\n";
print "-Pattrker|P Publish pattern tracker enviroment for user\n";
print "\n";
print " a. lookup files\n";
print "\n";
print " b. cmd file\n";
print "---------------------------------------\n";
print "\n";
print "-LADBgen|L Publish LADB generation enviroment for user\n";
print "\n";
print " a. ./run.csh file\n";
print "\n";
print " b. create_layout.dof file\n";
print "\n";
print " c. LADB_Submit_Pattrker folder\n";
print "\n";
print " i. cmd file\n";
print "\n";
print " ii. lookup file\n";
print "\n\n${cl_red}$folder_name [-md5sum=s] \n$cl_end";
print "---------------------------------------\n";
print "\n";
print "-md5sum=s Get the md5sum number of file\n\n";
} # endof sub printHelp
### sub CheckOptions ###
sub CheckOptions{
if((!defined$help)&&(!$Pattrker)&&(!$LADBgen)&&(!defined $md5sum_list)){
print "\n${cl_red}Error\! Wrong options defined\! Pls use |$0 -h| for help messages.$cl_end\n\n";
exit ;
}elsif((defined$help)&&(($Pattrker)||($LADBgen)||(defined $md5sum_list))){
print "\n${cl_red}Error\! Wrong options. And any of options -Pattrker, -LADBgen, and -md5sum options can not exist with -help option simultaneously\!\nPls use |$0 -h| for help messages.$cl_end\n\n";
exit ;
}else{
print "\n${cl_blue}Checked CheckOptions got passed, and waiting starting... $cl_end\n\n";
}
} # endof sub CheckOption
### sub dir_checker_creater_sub ###
sub dir_checker_creater_sub{
while(@_){
my $var_dir_each = shift @_;
if(-d $var_dir_each && -r $var_dir_each){
print "Dir {$var_dir_each} has been creted, no need create again\n";
}else{
rmtree ($var_dir_each) or die "${cl_red}Error\! Can not delete dir {$var_dir_each}, pls check: $!$cl_end\n" if(-d $var_dir_each);
print "rmtee dir{$var_dir_each} deleted\n";
mkpath ("$var_dir_each",1,0744) or die "${cl_red}Error\! Can not create dir {$var_dir_each}, pls check. $!$cl_end\n";
print "Dir {$var_dir_each} created\n";
}
}
} # enof sub dir_checker_creater_sub
脚本执行结果
ls LADBgen.usb4_sc0_t.MTO.root6.snmn.delro/ Pattrker.usb4_sc0_t.MTO.root6.snmn.delro/ -rtl
LADBgen.usb4_sc0_t.MTO.root6.snmn.delro/:
total 412K
-rwxr--r-- 1 weifexie ictip_n3 879 Sep 2 10:33 run.csh
-rwxr--r-- 1 weifexie ictip_n3 390K Sep 2 10:33 create_layout.dof
drwxr-Sr-- 4 weifexie ictip_n3 4.0K Sep 2 11:12 LADB_Submit_Pattrker
drwxrwsr-x 3 weifexie ictip_n3 4.0K Sep 2 16:18 rpt
drwxrwsr-x 2 weifexie ictip_n3 4.0K Sep 2 23:00 log
Pattrker.usb4_sc0_t.MTO.root6.snmn.delro/:
total 36K
-rw-rw-r-- 1 weifexie ictip_n3 1.4K Sep 2 10:36 usb4_sc0_t.fch_usbadp0.chain.lookup
-rw-rw-r-- 1 weifexie ictip_n3 1.4K Sep 2 10:36 usb4_sc0_t.fch_usbadp0.saf.lookup
-rw-rw-r-- 1 weifexie ictip_n3 1.4K Sep 2 10:36 usb4_sc0_t.fch_usbadp0.tdf.lookup
-rwxr--r-- 1 weifexie ictip_n3 14K Sep 2 10:36 cmd.csh
drwxrwsr-x 2 weifexie ictip_n3 4.0K Sep 2 10:55 logs
-rw-rw-r-- 1 weifexie ictip_n3 2.4K Sep 2 10:55 md5sum.rpt_2024_09_02_10_36_58