Jump to content

Draft:Log checker script

From Wikipedia, the free encyclopedia


  1. !/bin/bashRDI_MB_LANEDEGRADE
  2. takes care of one test summary
  3. Function to check the log files in the specified path

check_logs() {

 local input_path="$1"
 local log_type="$2"
 local owner="$3"
 local SIM_DIR_COUNT=5
 local owners_file="owners.txt"
 local pass_count=0
 local output_file=""
 local fail_count=0
 local hanged_uvm_error_count=0
 local hanged_without_uvm_error=0
 local test_not_started=0
 local incomplete_count=0
 local no_sim_count=0
 local total_count=0
 local log_path="ucie2phy_*"
 local log_pattern="ucie2phy_*/sim_*/test.log"
 for arg in "$2"; do
   if LTSM|ACSM|CSR_CHECK|MB|RDI_MB_LANEREPAIR|RDI_MB_LANEENABLE|RDI_MB_LANEDEGRADE|RDI_SB|SB_LOOPBACK|ZCAL)$; then
     log_type="$arg"
   fi
 done
 if -n "$log_type"; then
   log_types=("$log_type")
 else
   log_types=("RDI_SSM" "LTSM" "ACSM" "CSR_CHECK" "MB" "RDI_MB_LANEDEGRADE" "RDI_MB_LANEENABLE" "RDI_MB_LANEREPAIR" "RDI_SB" "SB_LOOPBACK" "ZCAL")
 fi
 input_case_types=($(echo "$input_path" | grep -oP "A4L0R_30_tdr_case_5e|S1L0R_00_tdr_case_10e|A1L0R_00_tdr_case_2e|A1L0R_00_freq_tdr_case_2a"))
 case "$input_case_types" in 
     "S1L0R_00_tdr_case_10e") case_select="std_1_1";;
     "A1L0R_00_tdr_case_2e") case_select="adv_1_1";;
     "A1L0R_00_freq_tdr_case_2a") case_select="freq_adv_1_1";;
     "A4L0R_30_tdr_case_5e") case_select="adv_1_4";;
 esac
 for ltype in "${log_types[@]}"; do
   case "$ltype" in
     "RDI_SSM") log_pattern="ucie2phy_rdi_ssm_*/sim_*/test.log"; output_file="output_"$owner"_"$case_select"_rdi_ssm.txt"; log_path="ucie2phy_rdi_ssm_";;
     "LTSM") log_pattern="ucie2phy_ltsm_*/sim_*/test.log"; output_file="output_"$owner"_"$case_select"_ltsm.txt"; log_path="ucie2phy_ltsm_";;
     "ACSM") log_pattern="ucie2phy_acsm_*/sim_*/test.log"; output_file="output_acsm.txt"; log_path="ucie2phy_acsm_";;
     "CSR_CHECK") log_pattern="ucie2phy_csr_check_*/sim_*/test.log"; output_file="output_csr_check.txt"; log_path="ucie2phy_csr_check_";;
     "MB") log_pattern="ucie2phy_mb_*/sim_*/test.log"; output_file="output_mb.txt"; log_path="ucie2phy_mb_*";;
     "RDI_MB_LANEENABLE") log_pattern="ucie2phy_rdi_mb_lane_enable_*/sim_*/test.log"; output_file="output_"$owner"_"$case_select"_rdi_mb_lane_enable.txt"; log_path="ucie2phy_rdi_mb_lane_enable_";;
     "RDI_MB_LANEREPAIR") log_pattern="ucie2phy_rdi_mb_lanerepair_*/sim_*/test.log"; output_file="output_"$owner"_"$case_select"_rdi_mb_lanerepair.txt"; log_path="ucie2phy_rdi_mb_lanerepair_";;
     "RDI_MB_LANEDEGRADE") log_pattern="ucie2phy_rdi_mb_lanedegrade_*/sim_*/test.log"; output_file="output_"$owner"_"$case_select"_rdi_mb_lanedegrade.txt"; log_path="ucie2phy_rdi_mb_lanedegrade_";;
     "RDI_SB") log_pattern="ucie2phy_rdi_sb_*/sim_*/test.log"; output_file="output_rdi_sb.txt"; log_path="ucie2phy_rdi_sb_";;
     "SB_LOOPBACK") log_pattern="ucie2phy_sb_loopback_*/sim_*/test.log"; output_file="output_sb_loopback.txt"; log_path="ucie2phy_sb_loopback_";;
     "ZCAL") log_pattern="ucie2phy_zcal_*/sim_*/test.log"; output_file="output_zcal.txt"; log_path="ucie2phy_zcal_";;
   esac

 : > "$output_file"
 if [ ${#input_case_types[@]} -eq 0 ]; then
   echo "No matching case type found in input path!"
   exit 1
 fi
 echo "Extracted case Type from Path: ${input_case_types[*]}"
 test_info=$(awk -v own="$owner" -v prefix="$test_prefix" '{ if ($1 == own && index($3,prefix) == 1) { print $2, $3;} }' "$owners_file")
 if [ -z "$test_info" ]; then
  echo "No test found for the owner: $owner"
  exit 1
 fi
 declare -a test_names
 declare -a case_types
 while read -r case_type test_name; do
   for input_case in "${input_case_types[@]}"; do
     if "$case_type" == "$input_case" && "$test_name" == "$log_path"*; then
       test_names+=("$test_name")
       case_types+=("$case_type")
     fi
   done
 done <<< "$test_info"
 if [ ${#test_names[@]} -eq 0 ]; then
   echo "No matching test found for owner: $owner with extracted case type: ${input_case_types[*]} & log_type: $log_type "
   exit 1
 fi
 for dir in "$input_path"/$log_path; do
   if ! -d "$dir"; then
     local test_path="${log_path#$input_path/}"
     #echo "Warning: No matching directories found for pattern '$test_path' in '$input_path'" >> "$output_file"
     continue
   fi 
 done
   for test_name in "${test_names[@]}"; do
     sim_dirs=("$input_path"/"$test_name"_*/sim_*)
     if [[ ! -d "${sim_dirs[0]}" ]]; then
       echo "No sim found in $test_name" >> "$output_file"
       ((no_sim_count++))
       continue
     fi
   done
 process_log() {
   local log_file="$1"
   local test_name="$2"
   ((total_count++))
   local short_path="${log_file#$input_path/}" 
   # Search for TEST PASS or TEST FAIL in the log file
   if grep -q "TEST PASS" "$log_file"; then
     echo "$short_path: TEST PASS" >> "$output_file"
     ((pass_count++))
   elif grep -q "TEST FAIL" "$log_file"; then
     if grep -q "LTSM transition" "$log_file"; then
       echo "$short_path: TEST FAIL" >> "$output_file"
       ((fail_count++))
     else
       echo "$short_path: TEST NOT STARTED" >> "$output_file"
       ((test_not_started++))
     fi
   else
     if grep -q "LTSM transition" "$log_file"; then
       if grep -q "UVM_ERROR" "$log_file"; then
         echo "$short_path: TEST HANGED with UVM_ERROR: TEST WILL BE FAILED!" >> "$output_file"
         ((hanged_uvm_error_count++))
       else
         echo "$short_path: TEST HANGED without UVM_ERROR" >> "$output_file"
         ((hanged_without_uvm_error++))
       fi
     else
       echo "$short_path: TEST NOT STARTED" >> "$output_file"
       ((test_not_started++))
     fi
   fi

}

 # Iterate over the matching log files in the specified path
 for log_file in "$input_path"/$log_pattern; do
   if -f "$log_file"; then
     if [[ ${#test_names[@]} -eq 0 ]]; then
       process_log "$log_file" "ALL"
     else
       for test_name in "${test_names[@]}"; do
         if "$log_file" == *"$test_name"*; then
           process_log "$log_file" "test_name"
           break
         fi
       done
     fi
   fi
 done
   # Calculate pass percentage
   local pass_percentage="0.00"
   if $total_count -gt 0; then
       pass_percentage=$(echo "scale=2; ($pass_count * 100) / ($pass_count+$fail_count+$hanged_uvm_error_count)" | bc)
   fi
   # Append Summary to the outpt file
   echo -e "\nThese Regression Results are derived from here: $input_path" | tee -a "$output_file" 
   echo -e "\nOutput_file=$output_file" | tee -a "$output_file" 
   if -z "$test_names"; then
     echo -e "\nSummary for the whole regression:" | tee -a "$output_file"
   else
     echo -e "\nSummary for the tests:" | tee -a "$output_file"
     for test_name in "${test_names[@]}";do
       if "$test_name" == "$log_path"*; then
         echo "$test_name" | tee -a "$output_file"
       fi
     done
   fi
   echo -e "\nTotal Tests: $total_count" >> "$output_file"
   echo "Tests Passed: $pass_count" >> "$output_file"
   echo "Tests Failed: $fail_count" >> "$output_file"
   echo "Tests hanged without UVM ERROR: $hanged_without_uvm_error" >> "$output_file"
   echo "Tests hanged with UVM ERROR: $hanged_uvm_error_count" >> "$output_file"
   echo "Tests not started: $test_not_started" >> "$output_file"
   echo "Passing Percentage: $pass_percentage%" >> "$output_file"
   echo "No sim found" "$no_sim_count" >> "$output_file"
   echo
   echo "###########################################"
   echo "# SUMMARY : $ltype  Owner : $owner         "
   echo "###########################################"
   printf "# %-30s : %-6s #\n" "Total Tests" "$total_count"
   printf "# %-30s : %-6s #\n" "Tests Passed" "$pass_count"
   printf "# %-30s : %-6s #\n" "Tests Failed" "$fail_count"
   printf "# %-30s : %-6s #\n" "Tests Hanged with UVM ERROR" "$hanged_uvm_error_count"
   printf "# %-30s : %-6s #\n" "Tests Hanged without UVM ERROR" "$hanged_without_uvm_error"
   printf "# %-30s : %-6s #\n" "Test not started" "$test_not_started"
   printf "# %-30s : %-6s #\n" "Passing Percentage" "$pass_percentage%"
   printf "# %-30s : %-6s #\n" "No sim found" "$no_sim_count"
   echo "###########################################"

done }

print_help() {

   echo -e "Usage: $0 <input_path> [log_type] [owner_name]"
   echo -e "\nOptions: "
   echo -e "  <input_path> Path where the log directories are located"
   echo -e "  [log_type]   Log type to filterr logs (e.g.,"RDI_SSM" "LTSM" "ACSM" "CSR_CHECK" "MB" "RDI_MB_LANEDEGRADE" "RDI_MB_LANEENABLE" "RDI_MB_LANEREPAIR" "RDI_SB" "SB_LOOPBACK" "ZCAL") "
   echo -e "  [owner_name] Test Owner's name to filter logs (e.g.,"nuzahat" "munnet" "sgaddam" "katreddy" "lprasan" "niddhi" "tienpham" "sparth" "thaitran")"
   echo -e "\nSpecial Flags:"
   echo -e "  -h, --help    Show help message and exit"
   echo -e "\nBehaviour:"
   echo -e " - Generates separate output files for each log type: 'outpt_owner_rdi_ssm.txt,'output_owner_ltsm.txt', etc."
   echo -e " - Checks if 'sim_*' directories and 'test.log' files exist, and reports missing ones."
   echo -e " - Summarizes test results,including pass/fail/incomplete counts and missing logs"
   echo -e "\nExamples:"
   echo -e "   $0 /path/to/logs RDI_SSM Nuzahat   # Processes all logs for 'test_name' owned by Nuzahat in RDI_SSM log_type"
   echo -e "   $0 -h                              # Show help"
   exit 0

}

if "$1" == "--help"; then

 print_help

fi

  1. Check if the user provided a path as an argument

if $# -ne 3; then

 echo "Usage: $0 <path> [LTSM|RDI_SSM|RDI_MB_LANEDEGRADE|RDI_MB_LANEENABLE|RDI_MB_LANEREPAIR] [owner's name]"
 exit 1 

fi

  1. Execute the function with the provided path

check_logs "$1" "$2" "$3"

References

[edit]
  1. !/bin/bash
  1. Format: user -> month -> (submit count, total files)

declare -A submit_counts declare -A file_counts

  1. Get all submitted changelists with date and user

p4 changes -s submitted -t //... | while read -r line; do

   cl=$(echo "$line" | awk '{print $2}')
   user=$(echo "$line" | awk -F' by ' '{print $2}' | awk '{print $1}')
   date=$(echo "$line" | awk '{print $4}')
   month=$(date -d "$date" +%Y-%m)
   key="${user}_${month}"
   submit_counts["$key"]=$((submit_counts["$key"] + 1))
   # Count number of files in this changelist
   file_count=$(p4 describe -s "$cl" | grep '^...' | wc -l)
   file_counts["$key"]=$((file_counts["$key"] + file_count))

done

  1. Print summary

echo "User,Month,Submissions,Files" for key in "${!submit_counts[@]}"; do

   user="${key%_*}"
   month="${key#*_}"
   echo "$user,$month,${submit_counts[$key]},${file_counts[$key]}"

done