tasks 5.1 KB

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