tests.toml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. [tasks.rust_unit_test]
  2. run_task = { name = ["rust_lib_unit_test", "shared_lib_unit_test"] }
  3. [tasks.rust_lib_unit_test]
  4. description = "Run rust-lib unit tests"
  5. script = '''
  6. cd rust-lib
  7. RUST_LOG=info cargo test --no-default-features --features="sync"
  8. '''
  9. [tasks.shared_lib_unit_test]
  10. description = "Run shared-lib unit test"
  11. script = '''
  12. cd ../shared-lib
  13. RUST_LOG=info cargo test --no-default-features
  14. '''
  15. [tasks.check_grcov]
  16. description = "Check if `grcov` is installled"
  17. script_runner = "@shell"
  18. script = '''
  19. export PATH=$PATH:"$HOME/.cargo/bin/"
  20. if command -v grcov > /dev/null; then
  21. echo "Found 'grcov' executable."
  22. else
  23. echo "[!] Could not find 'grcov' executable."
  24. echo "[!] Please install 'grcov' by running 'cargo install grcov'."
  25. echo "[!] You may also need to install 'llvm-tools-preview' using 'rustup component add llvm-tools-preview'."
  26. echo "[!] If installed, check if 'grcov' is in PATH."
  27. echo "[!] Exiting..."
  28. exit -1
  29. fi
  30. '''
  31. [tasks.clean_profraw_files]
  32. description = "Cleans profraw files that are created by `cargo test`"
  33. script_runner = "@duckscript"
  34. script = [
  35. """
  36. rust_lib_profs = glob_array ./rust-lib/**/*.profraw
  37. for prof in ${rust_lib_profs}
  38. full_path = canonicalize ${prof}
  39. rm ${full_path}
  40. end
  41. shared_lib_profs = glob_array ../shared-lib/**/*.profraw
  42. for prof in ${shared_lib_profs}
  43. full_path = canonicalize ${prof}
  44. rm ${full_path}
  45. end
  46. """
  47. ]
  48. [tasks.run_rustlib_coverage_tests]
  49. description = "Run tests with coverage instrumentation"
  50. script_runner = "@shell"
  51. script = [
  52. """
  53. echo --- Running coverage tests ---
  54. # Install Protobuf compiler
  55. cargo make install_protobuf_compiler
  56. export PATH="$PATH":"$HOME/.pub-cache/bin"
  57. export PATH="$PATH":"$HOME/.cargo/bin/"
  58. cd rust-lib/
  59. CARGO_INCREMENTAL=0 \
  60. RUSTFLAGS='-C instrument-coverage' \
  61. LLVM_PROFILE_FILE='prof-%p-%m.profraw' \
  62. cargo test --no-default-features --features="sync"
  63. """
  64. ]
  65. [tasks.run_sharedlib_coverage_tests]
  66. description = "Run tests with coverage instrumentation"
  67. script_runner = "@shell"
  68. script = [
  69. """
  70. echo --- Running coverage tests ---
  71. # Install Protobuf compiler
  72. cargo make install_protobuf_compiler
  73. export PATH="$PATH":"$HOME/.pub-cache/bin"
  74. export PATH="$PATH":"$HOME/.cargo/bin/"
  75. cd ../shared-lib
  76. CARGO_INCREMENTAL=0 \
  77. RUSTFLAGS='-C instrument-coverage' \
  78. LLVM_PROFILE_FILE='prof-%p-%m.profraw' \
  79. cargo test --no-default-features
  80. """
  81. ]
  82. [tasks.get_rustlib_grcov_report]
  83. description = "Get `grcov` HTML report for test coverage for rust-lib"
  84. script_runner = "@shell"
  85. script = [
  86. """
  87. echo --- Getting 'grcov' results for 'rust-lib' ---
  88. cd rust-lib/
  89. grcov . \
  90. --binary-path target/debug/deps \
  91. --source-dir . \
  92. --output-type html \
  93. --branch \
  94. --ignore-not-existing \
  95. --log-level WARN \
  96. --output-path target/coverage-html
  97. echo "--- Done! Generated HTML report under 'target/coverage-html' for rustlib."
  98. """
  99. ]
  100. [tasks.get_sharedlib_grcov_report]
  101. description = "Get `grcov` HTML report for test coverage shared-lib"
  102. script_runner = "@shell"
  103. script = [
  104. """
  105. echo --- Getting 'grcov' results 'shared-lib' ---
  106. cd ../shared-lib
  107. grcov . \
  108. --binary-path target/debug/deps \
  109. --source-dir . \
  110. --output-type html \
  111. --branch \
  112. --ignore-not-existing \
  113. --log-level WARN \
  114. --output-path target/coverage-html
  115. echo "--- Done! Generated HTML report under 'target/coverage-html' for sharedlib."
  116. """
  117. ]
  118. [tasks.get_grcov_report]
  119. description = "Get `grcov` HTML report for test coverage"
  120. run_task = { name = [
  121. "get_rustlib_grcov_report",
  122. "get_sharedlib_grcov_report"
  123. ], parallel = true }
  124. [tasks.get_sharedlib_lcov_report]
  125. description = "Generates `lcov` report for `shared-lib`"
  126. script_runner = "@shell"
  127. script = [
  128. """
  129. echo Getting 'lcov' results for 'shared-lib'
  130. cd ../shared-lib
  131. grcov . \
  132. --binary-path target/debug/deps \
  133. --source-dir . \
  134. --output-type lcov \
  135. --branch \
  136. --ignore-not-existing \
  137. --log-level WARN \
  138. --output-path target/coverage.lcov
  139. echo "--- Done! Generated 'target/coverage.lcov' sharedlib."
  140. """
  141. ]
  142. [tasks.get_rustlib_lcov_report]
  143. description = "Generates `lcov` report for `rust-lib`"
  144. script_runner = "@shell"
  145. script = [
  146. """
  147. echo Getting 'lcov' results for 'rust-lib'
  148. cd rust-lib/
  149. grcov . \
  150. --binary-path target/debug/deps \
  151. --source-dir . \
  152. --output-type lcov \
  153. --branch \
  154. --ignore-not-existing \
  155. --log-level WARN \
  156. --output-path target/coverage.lcov
  157. echo "--- Done! Generated 'target/coverage.lcov' for rustlib."
  158. """
  159. ]
  160. [tasks.get_lcov_report]
  161. description = "Get `lcov` reports for test coverage"
  162. run_task = { name = [
  163. "get_sharedlib_lcov_report",
  164. "get_rustlib_lcov_report"
  165. ], parallel = true }
  166. [tasks.get_ci_test_coverage]
  167. description = "Get LCOV coverage reports for CI"
  168. run_task = { name = [
  169. "check_grcov",
  170. "run_rustlib_coverage_tests",
  171. "run_sharedlib_coverage_tests",
  172. "get_lcov_report",
  173. "clean_profraw_files"
  174. ]}
  175. [tasks.get_test_coverage]
  176. description = "Get human readable test coverage reports"
  177. run_task = { name = [
  178. "check_grcov",
  179. "run_rustlib_coverage_tests",
  180. "run_sharedlib_coverage_tests",
  181. "get_grcov_report",
  182. "clean_profraw_files"
  183. ]}