tasks 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 --leak-check=full --show-leak-kinds=all"
  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" ./test alloc || true
  139. echo "--------------Invalid realloc exit--------------"
  140. LLVM_PROFILE_FILE="realloc.profraw" ./test realloc || true
  141. echo "--------------Pre canary detection--------------"
  142. LLVM_PROFILE_FILE="pre_canary.profraw" ./test pre_canary || true
  143. echo "--------------Post canary detection-------------"
  144. LLVM_PROFILE_FILE="post_canary.profraw" ./test post_canary || true
  145. # Test Fails
  146. LLVM_PROFILE_FILE="test.profraw" ./test test > /dev/null || true
  147. echo "--------------Default run-----------------------"
  148. LLVM_PROFILE_FILE="default.profraw" $valgrind ./test light $valgrind < ../readLineTest || true
  149. }
  150. if $test_debug; then
  151. cd build_debug
  152. runTests
  153. cd ..
  154. fi
  155. if $test_release; then
  156. cd build_release
  157. runTests
  158. cd ..
  159. fi
  160. if $performance; then
  161. cd build_profile
  162. if $stats; then
  163. user=$(whoami)
  164. sudo perf record ./performance
  165. sudo chown "$user:$user" perf.data
  166. sudo chown "$user:$user" default.profraw
  167. perf report
  168. else
  169. ./performance
  170. fi
  171. cd ..
  172. fi
  173. if $time; then
  174. lines=$(grep "^[0-9]" "build_release/.ninja_log")
  175. startMillis=0
  176. endMillis=0
  177. name=""
  178. i=0
  179. output=""
  180. for arg in $lines; do
  181. if [ $i == 0 ]; then
  182. startMillis=$arg
  183. elif [ $i == 1 ]; then
  184. endMillis=$arg
  185. elif [ $i == 3 ]; then
  186. name=$arg
  187. diff=$((endMillis - startMillis))
  188. output="${output}\n$diff $name"
  189. fi
  190. i=$(($((i + 1)) % 5))
  191. done
  192. echo -e "$output" | sort -n
  193. fi
  194. generateCoverageFunctions() {
  195. #allowlist_fun:.*
  196. ignore=$(cat ./ignoredCoverageFunctions)
  197. list=$(nm ./build_debug/libcore.a -j | grep "^[a-zA-Z]")
  198. for file in $ignore; do
  199. list=$(echo "$list" | grep -v "$file")
  200. done
  201. echo "$list" | sed 's/^/allowlist_fun:/g' > build_debug/coverageFunctions
  202. }
  203. if $coverage; then
  204. if [ "$compiler" = "gcc" ]; then
  205. gcovr -r . build_debug -e test -e performance \
  206. --exclude-lines-by-pattern ".*CoverageIgnore.*"
  207. else
  208. mapfile -t files < <(find build_debug -name "*.profraw")
  209. llvm-profdata-17 merge -sparse "${files[@]}" -o build_debug/default.profdata
  210. generateCoverageFunctions
  211. llvm-cov-17 show ./build_debug/test -instr-profile=build_debug/default.profdata --ignore-filename-regex="test/" -line-coverage-lt=100 --name-allowlist=build_debug/coverageFunctions
  212. fi
  213. fi