Advertisement
Kevin_Zhang

Untitled

Mar 24th, 2020
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. #!/bin/bash
  2. #### initialize ####
  3. # path of test data
  4. cd
  5. path=${1:-~/test_data}
  6. # file to execute
  7. submission=${2:-~/run.in}
  8. # echo Path $path Sub $submission
  9. # Limits in
  10. ## ms
  11. time_limit=${3:-8000}
  12. ## kB
  13. memory_limit=${4:-256000}
  14. ## sec
  15. time_out_value=${5:-$((time_limit / 1000)).5}
  16. resp=~/Documents/Judge
  17. #### ####
  18. accnt=0
  19. tlecnt=0
  20. recnt=0
  21. mlecnt=0
  22. testcnt=0
  23. total_time=0
  24. RED='\033[1;31m'
  25. GREEN='\033[1;32m'
  26. YEL='\033[1;33m'
  27. BLUE='\033[1;34m'
  28. DEF='\033[0m'
  29. BOLD='\033[1;1m'
  30. numregex='^[0-9]+$'
  31. gap="----------"
  32. VER=("AC" "WA" "TLE" "MLE" "RE")
  33. COL=($GREEN $RED $BLUE $YEL $YEL)
  34. CORECNT=$(($(cat /proc/cpuinfo | grep processor | wc -l)-1))
  35. if ((CORECNT == 0)) ; then
  36. CORECNT=1
  37. fi
  38. mkdir -p $resp
  39. echo "" > $resp/all.res
  40. echo "" > $resp/rt.res
  41. echo "" > $resp/me.res
  42. # signal 0 : AC, 1 : WA, 2 : TLE, 3 : MLE, 4 : RE
  43. for((i=0;i<=4;++i)); do
  44. cnt[$i]=0
  45. done
  46. printf "Result ------------------------------\n\n"
  47. runtest () {
  48. ulimit -S -s $(($memory_limit*4)) -v $(($memory_limit*4))
  49. rm $path/$id.res 2>/dev/null
  50. id=$1
  51. start_t=$(date +%s%N)
  52. #timeout --foreground $time_out_value MEM=$(/usr/bin/time -q -f "%M" $submission<$path/$id.in>$path/U$id.out 2>/dev/null)
  53. MEM=$(/usr/bin/time -q -f "%M" bash -c "(timeout --preserve-status --foreground $time_out_value $submission<$path/$id.in>$path/U$id.out)2>/dev/null" 2>&1)
  54. ERR=$?
  55. end_t=$(date +%s%N)
  56. RES=0
  57. RT=$((($end_t - $start_t) / 1000000))
  58. VER=("AC" "WA" "TLE" "MLE" "RE")
  59. COL=($GREEN $RED $BLUE $YEL $YEL)
  60. if ! [[ $MEM =~ $numregex ]]; then
  61. MEM=-1
  62. ERR=1
  63. fi
  64. if (($ERR != 0 && $ERR != 143)); then
  65. RES=4
  66. elif (($MEM > $memory_limit)); then
  67. RES=3
  68. elif (($RT > $time_limit)); then
  69. RES=2
  70. elif [ "$(diff $path/U$id.out $path/$id.out)" != "" ]; then
  71. RES=1
  72. fi
  73. printf " Test Data %3d $gap %b%3s %7d ms %7d KB$DEF\n" $id ${COL[$RES]} ${VER[$RES]} $RT $MEM > $path/$id.res
  74. printf " $RES" >> $resp/all.res
  75. printf " $RT" >> $resp/rt.res
  76. printf " $MEM" >> $resp/me.res
  77. }
  78. ## testing
  79. # start_t=$(date +%s%N)
  80. ###
  81.  
  82. for ((i=1;;++i)); do
  83. if [ ! -f $path/$i.in ]; then
  84. break
  85. fi
  86. testcnt=$i
  87. done
  88. #Run test parallelly
  89. for ((i=1;i<=$testcnt;++i)); do
  90. runtest $i &
  91. if (((i)%(CORECNT)==0 || i==testcnt)); then
  92. wait
  93. for((j=(i-1)/CORECNT*CORECNT+1;j<=i;++j)); do
  94. cat $path/$j.res
  95. done
  96. fi
  97. done
  98. wait
  99. # end_t=$(date +%s%N)
  100. for i in $(cat $resp/all.res); do
  101. ((++cnt[$i]))
  102. done
  103. for i in $(cat $resp/rt.res); do
  104. ((total_time += i))
  105. done
  106. for i in $(cat $resp/me.res); do
  107. maxmem=$((maxmem > i ? maxmem : i))
  108. done
  109. echo
  110. for((i=4;i>=0;--i)); do
  111. if ((${cnt[$i]})); then
  112. printf "%b%3s ${GREEN}%3d%b / %3d Total Run Time : %6d ms Maximum Memory Usage : %6d KB$DEF\n\n" ${COL[$i]} ${VER[$i]} ${cnt[0]} ${COL[$i]} $testcnt $total_time $maxmem
  113. break
  114. fi
  115. done
  116. exit $((cnt[0] * 100 / testcnt))
  117. # echo "Total Run Time : $((($end_t - $start_t) / 1000000))"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement