tasks 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. cleanFolders() {
  41. rm -rf build_debug build_profile build_release install
  42. }
  43. # parsing
  44. if [ "$task" = "clean" ]; then
  45. cleanFolders
  46. elif [ "$task" = "build" ]; then
  47. type=$2
  48. if [ "$type" = "debug" ]; then
  49. build_debug=true
  50. elif [ "$type" = "release" ]; then
  51. build_release=true
  52. elif [ "$type" = "all" ]; then
  53. build_debug=true
  54. build_release=true
  55. else
  56. echo "Valid build types are: debug, release, all"
  57. printHelpExit
  58. fi
  59. elif [ "$task" = "install" ]; then
  60. build_release=true
  61. install=true
  62. elif [ "$task" = "coverage" ]; then
  63. build_debug=true
  64. test_debug=true
  65. coverage=true
  66. elif [ "$task" = "test" ]; then
  67. type=$2
  68. if [ "$type" = "debug" ]; then
  69. build_debug=true
  70. test_debug=true
  71. elif [ "$type" = "release" ]; then
  72. build_release=true
  73. test_release=true
  74. elif [ "$type" = "all" ]; then
  75. build_debug=true
  76. test_debug=true
  77. build_release=true
  78. test_release=true
  79. else
  80. echo "Valid test types are: debug, release, all"
  81. printHelpExit
  82. fi
  83. elif [ "$task" = "valgrind" ]; then
  84. type=$2
  85. if [ "$type" = "debug" ]; then
  86. build_debug=true
  87. test_debug=true
  88. elif [ "$type" = "release" ]; then
  89. build_release=true
  90. test_release=true
  91. elif [ "$type" = "all" ]; then
  92. build_debug=true
  93. test_debug=true
  94. build_release=true
  95. test_release=true
  96. else
  97. echo "Valid valgrind types are: debug, release, all"
  98. printHelpExit
  99. fi
  100. valgrind="valgrind --leak-check=full --show-leak-kinds=all"
  101. elif [ "$task" = "performance" ]; then
  102. build_profile=true
  103. performance=true
  104. elif [ "$task" = "stats" ]; then
  105. build_profile=true
  106. performance=true
  107. stats=true
  108. elif [ "$task" = "time" ]; then
  109. build_release=true
  110. time=true
  111. elif [ "$task" = "macro" ]; then
  112. grep -r "#define" src include | grep -v " CORE" || true
  113. exit 0
  114. else
  115. echo "unknown task"
  116. printHelpExit
  117. fi
  118. # task execution
  119. buildProfile() {
  120. folder=$1
  121. shift 1
  122. if [ -e "$folder" ]; then
  123. if ! cat $folder/CMakeCache.txt | grep "CMAKE_C_COMPILER:" | grep $compiler > /dev/null; then
  124. cleanFolders
  125. fi
  126. fi
  127. if [ ! -e "$folder" ]; then
  128. cmake -B "$folder" -S . -G Ninja -DCMAKE_C_COMPILER="${compiler}" -DCMAKE_INSTALL_PREFIX=../install "$@"
  129. fi
  130. ninja -C "$folder"
  131. }
  132. if $build_debug; then
  133. buildProfile build_debug -DCMAKE_BUILD_TYPE=Debug
  134. fi
  135. if $build_profile; then
  136. buildProfile build_profile -DCMAKE_BUILD_TYPE=RelWithDebInfo
  137. fi
  138. if $build_release; then
  139. buildProfile build_release -DCMAKE_BUILD_TYPE=Release
  140. fi
  141. if $install; then
  142. ninja -C build_release install
  143. fi
  144. function runTests() {
  145. echo "--------------Invalid alloc exit----------------"
  146. LLVM_PROFILE_FILE="alloc.profraw" ./test alloc || true
  147. echo "--------------Invalid realloc exit--------------"
  148. LLVM_PROFILE_FILE="realloc.profraw" ./test realloc || true
  149. echo "--------------Pre canary detection--------------"
  150. LLVM_PROFILE_FILE="pre_canary.profraw" ./test pre_canary || true
  151. echo "--------------Post canary detection-------------"
  152. LLVM_PROFILE_FILE="post_canary.profraw" ./test post_canary || true
  153. # Test Fails
  154. LLVM_PROFILE_FILE="test.profraw" ./test test > /dev/null || true
  155. echo "--------------Default run-----------------------"
  156. LLVM_PROFILE_FILE="default.profraw" $valgrind ./test light $valgrind < ../readLineTest || true
  157. }
  158. if $test_debug; then
  159. cd build_debug
  160. runTests
  161. cd ..
  162. fi
  163. if $test_release; then
  164. cd build_release
  165. runTests
  166. cd ..
  167. fi
  168. if $performance; then
  169. cd build_profile
  170. if $stats; then
  171. user=$(whoami)
  172. sudo perf record ./performance
  173. sudo chown "$user:$user" perf.data
  174. sudo chown "$user:$user" default.profraw
  175. perf report
  176. else
  177. ./performance
  178. fi
  179. cd ..
  180. fi
  181. if $time; then
  182. lines=$(grep "^[0-9]" "build_release/.ninja_log")
  183. startMillis=0
  184. endMillis=0
  185. name=""
  186. i=0
  187. output=""
  188. for arg in $lines; do
  189. if [ $i == 0 ]; then
  190. startMillis=$arg
  191. elif [ $i == 1 ]; then
  192. endMillis=$arg
  193. elif [ $i == 3 ]; then
  194. name=$arg
  195. diff=$((endMillis - startMillis))
  196. output="${output}\n$diff $name"
  197. fi
  198. i=$(($((i + 1)) % 5))
  199. done
  200. echo -e "$output" | sort -n
  201. fi
  202. generateCoverageFunctions() {
  203. #allowlist_fun:.*
  204. ignore=$(cat ./ignoredCoverageFunctions)
  205. list=$(nm ./build_debug/libcore.a -j | grep "^[a-zA-Z]")
  206. for file in $ignore; do
  207. list=$(echo "$list" | grep -v "$file")
  208. done
  209. echo "$list" | sed 's/^/allowlist_fun:/g' > build_debug/coverageFunctions
  210. }
  211. if $coverage; then
  212. if [ "$compiler" = "gcc" ]; then
  213. gcovr -r . build_debug -e test -e performance \
  214. --exclude-lines-by-pattern ".*CoverageIgnore.*"
  215. else
  216. mapfile -t files < <(find build_debug -name "*.profraw")
  217. llvm-profdata-17 merge -sparse "${files[@]}" -o build_debug/default.profdata
  218. generateCoverageFunctions
  219. 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
  220. fi
  221. fi