tasks 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #!/bin/bash
  2. set -e
  3. clear
  4. cd $(dirname $0)
  5. compiler="gcc"
  6. if [ -e compiler ]; then
  7. compiler=$(cat compiler)
  8. echo "compiling with $compiler"
  9. fi
  10. printHelpExit() {
  11. echo "$0 clean | remove build results"
  12. echo "$0 build <type> | build everything"
  13. echo "$0 install | move build results into the install folder"
  14. echo "$0 test <type> | run the tests"
  15. echo "$0 valgrind <type> | run the tests with valgrind"
  16. echo "$0 coverage | generate code coverage"
  17. echo "$0 performance | run the performance tests"
  18. echo "$0 stats | run the performance tests with stats"
  19. echo "$0 macro | find macros without CORE"
  20. echo "$0 time | check build time"
  21. exit 0
  22. }
  23. task=$1
  24. if [ -z "$task" ]; then
  25. printHelpExit
  26. fi
  27. # task vars
  28. build_debug=false
  29. build_profile=false
  30. build_release=false
  31. test_debug=false
  32. test_release=false
  33. valgrind=""
  34. performance=false
  35. time=false
  36. install=false
  37. coverage=false
  38. stats=false
  39. export CMAKE_EXPORT_COMPILE_COMMANDS=true
  40. # parsing
  41. if [ "$task" = "clean" ]; then
  42. rm -rf build_debug build_profile build_release install
  43. elif [ "$task" = "build" ]; then
  44. type=$2
  45. if [ "$type" = "debug" ]; then
  46. build_debug=true
  47. elif [ "$type" = "release" ]; then
  48. build_release=true
  49. elif [ "$type" = "all" ]; then
  50. build_debug=true
  51. build_release=true
  52. else
  53. echo "Valid build types are: debug, release, all"
  54. printHelpExit
  55. fi
  56. elif [ "$task" = "install" ]; then
  57. build_release=true
  58. install=true
  59. elif [ "$task" = "coverage" ]; then
  60. build_debug=true
  61. test_debug=true
  62. coverage=true
  63. elif [ "$task" = "test" ]; then
  64. type=$2
  65. if [ "$type" = "debug" ]; then
  66. build_debug=true
  67. test_debug=true
  68. elif [ "$type" = "release" ]; then
  69. build_release=true
  70. test_release=true
  71. elif [ "$type" = "all" ]; then
  72. build_debug=true
  73. test_debug=true
  74. build_release=true
  75. test_release=true
  76. else
  77. echo "Valid test types are: debug, release, all"
  78. printHelpExit
  79. fi
  80. elif [ "$task" = "valgrind" ]; then
  81. type=$2
  82. if [ "$type" = "debug" ]; then
  83. build_debug=true
  84. test_debug=true
  85. elif [ "$type" = "release" ]; then
  86. build_release=true
  87. test_release=true
  88. elif [ "$type" = "all" ]; then
  89. build_debug=true
  90. test_debug=true
  91. build_release=true
  92. test_release=true
  93. else
  94. echo "Valid valgrind types are: debug, release, all"
  95. printHelpExit
  96. fi
  97. valgrind="valgrind \
  98. --leak-check=full \
  99. --show-leak-kinds=all \
  100. --suppressions=../valgrind.supp
  101. "
  102. elif [ "$task" = "performance" ]; then
  103. build_profile=true
  104. performance=true
  105. elif [ "$task" = "stats" ]; then
  106. build_profile=true
  107. performance=true
  108. stats=true
  109. elif [ "$task" = "time" ]; then
  110. build_release=true
  111. time=true
  112. elif [ "$task" = "macro" ]; then
  113. grep -r "#define" src include | grep -v " CORE" || true
  114. exit 0
  115. else
  116. echo "unknown task"
  117. printHelpExit
  118. fi
  119. # task execution
  120. buildProfile() {
  121. folder=$1
  122. shift 1
  123. if [ ! -e "$folder" ]; then
  124. cmake -B "$folder" -S . -G Ninja -DCMAKE_C_COMPILER=${compiler} -DCMAKE_INSTALL_PREFIX=../install $@
  125. fi
  126. ninja -C "$folder"
  127. }
  128. if $build_debug; then
  129. buildProfile build_debug -DCMAKE_BUILD_TYPE=Debug
  130. fi
  131. if $build_profile; then
  132. buildProfile build_profile -DCMAKE_BUILD_TYPE=RelWithDebInfo
  133. fi
  134. if $build_release; then
  135. buildProfile build_release -DCMAKE_BUILD_TYPE=Release
  136. fi
  137. if $install; then
  138. ninja -C build_release install
  139. fi
  140. function runTests() {
  141. echo "--------------Invalid alloc exit----------------"
  142. LLVM_PROFILE_FILE="alloc.profraw" ./test alloc || true
  143. echo "--------------Invalid realloc exit--------------"
  144. LLVM_PROFILE_FILE="realloc.profraw" ./test realloc || true
  145. echo "--------------Pre canary detection--------------"
  146. LLVM_PROFILE_FILE="pre_canary.profraw" ./test pre_canary || true
  147. echo "--------------Post canary detection-------------"
  148. LLVM_PROFILE_FILE="post_canary.profraw" ./test post_canary || true
  149. echo "--------------Test Fails------------------------"
  150. LLVM_PROFILE_FILE="test.profraw" ./test test || true
  151. echo "--------------Default run-----------------------"
  152. LLVM_PROFILE_FILE="default.profraw" $valgrind ./test light $valgrind < ../readLineTest || true
  153. }
  154. if $test_debug; then
  155. cd build_debug
  156. runTests
  157. cd ..
  158. fi
  159. if $test_release; then
  160. cd build_release
  161. runTests
  162. cd ..
  163. fi
  164. if $performance; then
  165. cd build_profile
  166. if $stats; then
  167. user=$(whoami)
  168. sudo perf record ./performance
  169. sudo chown $user:$user perf.data
  170. sudo chown $user:$user default.profraw
  171. perf report
  172. else
  173. ./performance
  174. fi
  175. cd ..
  176. fi
  177. if $time; then
  178. lines=$(cat build_release/.ninja_log | grep "^[0-9]")
  179. startMillis=0
  180. endMillis=0
  181. name=""
  182. i=0
  183. output=""
  184. for arg in $lines; do
  185. if [ $i == 0 ]; then
  186. startMillis=$arg
  187. elif [ $i == 1 ]; then
  188. endMillis=$arg
  189. elif [ $i == 3 ]; then
  190. name=$arg
  191. diff=$(expr $endMillis - $startMillis)
  192. output="${output}\n$diff $name"
  193. fi
  194. i=$(expr $(expr $i + 1) % 5) && true
  195. done
  196. printf "$output" | sort -n
  197. fi
  198. if $coverage; then
  199. if [ $compiler = "gcc" ]; then
  200. gcovr -r . build_debug -e test -e performance \
  201. --exclude-lines-by-pattern ".*CoverageIgnore.*"
  202. else
  203. files=$(find build_debug -name *.profraw)
  204. llvm-profdata-16 merge -sparse $files -o build_debug/default.profdata
  205. llvm-cov-16 show ./build_debug/test -instr-profile=build_debug/default.profdata --ignore-filename-regex="test/" -line-coverage-lt=100
  206. fi
  207. fi