tasks 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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. elif [ "$task" = "performance" ]; then
  99. build_profile=true
  100. performance=true
  101. elif [ "$task" = "stats" ]; then
  102. build_profile=true
  103. performance=true
  104. stats=true
  105. elif [ "$task" = "time" ]; then
  106. build_release=true
  107. time=true
  108. elif [ "$task" = "macro" ]; then
  109. grep -r "#define" src include | grep -v " CORE" || true
  110. exit 0
  111. else
  112. echo "unknown task"
  113. printHelpExit
  114. fi
  115. # task execution
  116. buildProfile() {
  117. folder=$1
  118. shift 1
  119. if [ ! -e "$folder" ]; then
  120. cmake -B "$folder" -S . -G Ninja -DCMAKE_C_COMPILER=${compiler} -DCMAKE_INSTALL_PREFIX=./install $@
  121. fi
  122. ninja -C "$folder"
  123. }
  124. if $build_debug; then
  125. buildProfile build_debug -DCMAKE_BUILD_TYPE=Debug
  126. fi
  127. if $build_profile; then
  128. buildProfile build_profile -DCMAKE_BUILD_TYPE=RelWithDebInfo
  129. fi
  130. if $build_release; then
  131. buildProfile build_release -DCMAKE_BUILD_TYPE=Release
  132. fi
  133. if $install; then
  134. ninja -C build_release install
  135. fi
  136. function runTests() {
  137. echo "--------------Invalid alloc exit----------------"
  138. LLVM_PROFILE_FILE="alloc.profraw" $valgrind ./test alloc $valgrind || true
  139. echo "--------------Invalid realloc exit--------------"
  140. LLVM_PROFILE_FILE="realloc.profraw" $valgrind ./test realloc $valgrind || true
  141. echo "--------------Pre canary detection--------------"
  142. LLVM_PROFILE_FILE="pre_canary.profraw" $valgrind ./test pre_canary $valgrind || true
  143. echo "--------------Post canary detection-------------"
  144. LLVM_PROFILE_FILE="post_canary.profraw" $valgrind ./test post_canary $valgrind || true
  145. echo "--------------Default run-----------------------"
  146. LLVM_PROFILE_FILE="default.profraw" $valgrind ./test light $valgrind || true
  147. }
  148. if $test_debug; then
  149. cd build_debug
  150. runTests
  151. cd ..
  152. fi
  153. if $test_release; then
  154. cd build_release
  155. runTests
  156. cd ..
  157. fi
  158. if $performance; then
  159. cd build_profile
  160. if $stats; then
  161. user=$(whoami)
  162. sudo perf record ./performance
  163. sudo chown $user:$user perf.data
  164. sudo chown $user:$user default.profraw
  165. perf report
  166. else
  167. ./performance
  168. fi
  169. cd ..
  170. fi
  171. if $time; then
  172. lines=$(cat build_release/.ninja_log | grep "^[0-9]")
  173. startMillis=0
  174. endMillis=0
  175. name=""
  176. i=0
  177. output=""
  178. for arg in $lines; do
  179. if [ $i == 0 ]; then
  180. startMillis=$arg
  181. elif [ $i == 1 ]; then
  182. endMillis=$arg
  183. elif [ $i == 3 ]; then
  184. name=$arg
  185. diff=$(expr $endMillis - $startMillis)
  186. output="${output}\n$diff $name"
  187. fi
  188. i=$(expr $(expr $i + 1) % 5) && true
  189. done
  190. printf "$output" | sort -n
  191. fi
  192. if $coverage; then
  193. if [ $compiler = "gcc" ]; then
  194. gcovr -r . build_debug -e test -e performance \
  195. --exclude-lines-by-pattern ".*CoverageIgnore.*"
  196. else
  197. files=$(find build_debug -name *.profraw)
  198. llvm-profdata-16 merge -sparse $files -o build_debug/default.profdata
  199. llvm-cov-16 show ./build_debug/test -instr-profile=build_debug/default.profdata --ignore-filename-regex="test/" -line-coverage-lt=100
  200. fi
  201. fi