tasks 4.8 KB

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