1
0

test.yaml 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. name: test
  2. on:
  3. push:
  4. pull_request:
  5. workflow_dispatch:
  6. inputs:
  7. gtest_filter:
  8. description: 'Google Test filter'
  9. test_linux:
  10. description: 'Test on Linux'
  11. type: boolean
  12. default: true
  13. test_macos:
  14. description: 'Test on MacOS'
  15. type: boolean
  16. default: true
  17. test_windows:
  18. description: 'Test on Windows'
  19. type: boolean
  20. default: true
  21. concurrency:
  22. group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
  23. cancel-in-progress: true
  24. env:
  25. GTEST_FILTER: ${{ github.event.inputs.gtest_filter || '*' }}
  26. jobs:
  27. style-check:
  28. runs-on: ubuntu-latest
  29. if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name
  30. continue-on-error: true
  31. steps:
  32. - name: checkout
  33. uses: actions/checkout@v4
  34. - name: run style check
  35. run: |
  36. clang-format --version
  37. cd test && make style_check
  38. build-error-check-on-32bit:
  39. runs-on: ubuntu-latest
  40. if: >
  41. (github.event_name == 'push') ||
  42. (github.event_name == 'pull_request' &&
  43. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  44. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  45. strategy:
  46. matrix:
  47. config:
  48. - arch_flags: -m32
  49. arch_suffix: :i386
  50. name: (32-bit)
  51. steps:
  52. - name: checkout
  53. uses: actions/checkout@v4
  54. - name: install libraries
  55. run: |
  56. sudo dpkg --add-architecture i386
  57. sudo apt-get update
  58. sudo apt-get install -y libc6-dev${{ matrix.config.arch_suffix }} libstdc++-13-dev${{ matrix.config.arch_suffix }} \
  59. libssl-dev${{ matrix.config.arch_suffix }} libcurl4-openssl-dev${{ matrix.config.arch_suffix }} \
  60. zlib1g-dev${{ matrix.config.arch_suffix }} libbrotli-dev${{ matrix.config.arch_suffix }} \
  61. libzstd-dev${{ matrix.config.arch_suffix }}
  62. - name: build and run tests (expect failure)
  63. run: cd test && make test EXTRA_CXXFLAGS="${{ matrix.config.arch_flags }}"
  64. continue-on-error: true
  65. ubuntu:
  66. runs-on: ubuntu-latest
  67. if: >
  68. (github.event_name == 'push') ||
  69. (github.event_name == 'pull_request' &&
  70. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  71. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_linux == 'true')
  72. strategy:
  73. matrix:
  74. tls_backend: [openssl, mbedtls, wolfssl]
  75. name: ubuntu (${{ matrix.tls_backend }})
  76. steps:
  77. - name: checkout
  78. uses: actions/checkout@v4
  79. - name: install common libraries
  80. run: |
  81. sudo apt-get update
  82. sudo apt-get install -y libcurl4-openssl-dev zlib1g-dev libbrotli-dev libzstd-dev
  83. - name: install OpenSSL
  84. if: matrix.tls_backend == 'openssl'
  85. run: sudo apt-get install -y libssl-dev
  86. - name: install Mbed TLS
  87. if: matrix.tls_backend == 'mbedtls'
  88. run: sudo apt-get install -y libmbedtls-dev
  89. - name: install wolfSSL
  90. if: matrix.tls_backend == 'wolfssl'
  91. run: sudo apt-get install -y libwolfssl-dev
  92. - name: build and run tests (OpenSSL)
  93. if: matrix.tls_backend == 'openssl'
  94. run: cd test && make test_split && make test_openssl_parallel
  95. env:
  96. LSAN_OPTIONS: suppressions=lsan_suppressions.txt
  97. - name: build and run tests (Mbed TLS)
  98. if: matrix.tls_backend == 'mbedtls'
  99. run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
  100. - name: build and run tests (wolfSSL)
  101. if: matrix.tls_backend == 'wolfssl'
  102. run: cd test && make test_split_wolfssl && make test_wolfssl_parallel
  103. - name: run fuzz test target
  104. if: matrix.tls_backend == 'openssl'
  105. run: cd test && make fuzz_test
  106. - name: build and run WebSocket heartbeat test
  107. if: matrix.tls_backend == 'openssl'
  108. run: cd test && make test_websocket_heartbeat && ./test_websocket_heartbeat
  109. - name: build and run ThreadPool test
  110. run: cd test && make test_thread_pool && ./test_thread_pool
  111. macos:
  112. runs-on: macos-latest
  113. if: >
  114. (github.event_name == 'push') ||
  115. (github.event_name == 'pull_request' &&
  116. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  117. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_macos == 'true')
  118. strategy:
  119. matrix:
  120. tls_backend: [openssl, mbedtls, wolfssl]
  121. name: macos (${{ matrix.tls_backend }})
  122. steps:
  123. - name: checkout
  124. uses: actions/checkout@v4
  125. - name: install Mbed TLS
  126. if: matrix.tls_backend == 'mbedtls'
  127. run: brew install mbedtls@3
  128. - name: install wolfSSL
  129. if: matrix.tls_backend == 'wolfssl'
  130. run: brew install wolfssl
  131. - name: build and run tests (OpenSSL)
  132. if: matrix.tls_backend == 'openssl'
  133. run: cd test && make test_split && make test_openssl_parallel
  134. env:
  135. LSAN_OPTIONS: suppressions=lsan_suppressions.txt
  136. - name: build and run tests (Mbed TLS)
  137. if: matrix.tls_backend == 'mbedtls'
  138. run: cd test && make test_split_mbedtls && make test_mbedtls_parallel
  139. - name: build and run tests (wolfSSL)
  140. if: matrix.tls_backend == 'wolfssl'
  141. run: cd test && make test_split_wolfssl && make test_wolfssl_parallel
  142. - name: run fuzz test target
  143. if: matrix.tls_backend == 'openssl'
  144. run: cd test && make fuzz_test
  145. - name: build and run WebSocket heartbeat test
  146. if: matrix.tls_backend == 'openssl'
  147. run: cd test && make test_websocket_heartbeat && ./test_websocket_heartbeat
  148. - name: build and run ThreadPool test
  149. run: cd test && make test_thread_pool && ./test_thread_pool
  150. windows:
  151. runs-on: windows-latest
  152. if: >
  153. (github.event_name == 'push') ||
  154. (github.event_name == 'pull_request' &&
  155. github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name) ||
  156. (github.event_name == 'workflow_dispatch' && github.event.inputs.test_windows == 'true')
  157. strategy:
  158. matrix:
  159. config:
  160. - with_ssl: false
  161. compiled: false
  162. run_tests: true
  163. name: without SSL
  164. - with_ssl: true
  165. compiled: false
  166. run_tests: true
  167. name: with SSL
  168. - with_ssl: false
  169. compiled: true
  170. run_tests: false
  171. name: compiled
  172. name: windows ${{ matrix.config.name }}
  173. steps:
  174. - name: Prepare Git for Checkout on Windows
  175. run: |
  176. git config --global core.autocrlf false
  177. git config --global core.eol lf
  178. - name: Checkout
  179. uses: actions/checkout@v4
  180. - name: Export GitHub Actions cache environment variables
  181. uses: actions/github-script@v7
  182. with:
  183. script: |
  184. core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
  185. core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
  186. - name: Setup msbuild on windows
  187. uses: microsoft/setup-msbuild@v2
  188. - name: Cache vcpkg packages
  189. id: vcpkg-cache
  190. uses: actions/cache@v4
  191. with:
  192. path: C:/vcpkg/installed
  193. key: vcpkg-installed-windows-gtest-curl-zlib-brotli-zstd
  194. - name: Install vcpkg dependencies
  195. if: steps.vcpkg-cache.outputs.cache-hit != 'true'
  196. run: vcpkg install gtest curl zlib brotli zstd
  197. - name: Install OpenSSL
  198. if: ${{ matrix.config.with_ssl }}
  199. run: choco install openssl
  200. - name: Configure CMake ${{ matrix.config.name }}
  201. run: >
  202. cmake -B build -S .
  203. -DCMAKE_BUILD_TYPE=Release
  204. -DCMAKE_TOOLCHAIN_FILE=${{ env.VCPKG_ROOT }}/scripts/buildsystems/vcpkg.cmake
  205. -DHTTPLIB_TEST=ON
  206. -DHTTPLIB_COMPILE=${{ matrix.config.compiled && 'ON' || 'OFF' }}
  207. -DHTTPLIB_USE_OPENSSL_IF_AVAILABLE=${{ matrix.config.with_ssl && 'ON' || 'OFF' }}
  208. -DHTTPLIB_REQUIRE_ZLIB=ON
  209. -DHTTPLIB_REQUIRE_BROTLI=ON
  210. -DHTTPLIB_REQUIRE_ZSTD=ON
  211. -DHTTPLIB_REQUIRE_OPENSSL=${{ matrix.config.with_ssl && 'ON' || 'OFF' }}
  212. - name: Build ${{ matrix.config.name }}
  213. run: cmake --build build --config Release -- /v:m /clp:ShowCommandLine
  214. - name: Run tests ${{ matrix.config.name }}
  215. if: ${{ matrix.config.run_tests }}
  216. shell: pwsh
  217. working-directory: build/test
  218. run: |
  219. $shards = 4
  220. $procs = @()
  221. for ($i = 0; $i -lt $shards; $i++) {
  222. $log = "shard_${i}.log"
  223. $procs += Start-Process -FilePath ./Release/httplib-test.exe `
  224. -ArgumentList "--gtest_color=yes","--gtest_filter=${{ github.event.inputs.gtest_filter || '*' }}-*BenchmarkTest*" `
  225. -NoNewWindow -PassThru -RedirectStandardOutput $log -RedirectStandardError "${log}.err" `
  226. -Environment @{ GTEST_TOTAL_SHARDS="$shards"; GTEST_SHARD_INDEX="$i" }
  227. }
  228. $procs | Wait-Process
  229. $failed = $false
  230. for ($i = 0; $i -lt $shards; $i++) {
  231. $log = "shard_${i}.log"
  232. if (Select-String -Path $log -Pattern "\[ PASSED \]" -Quiet) {
  233. $passed = (Select-String -Path $log -Pattern "\[ PASSED \]").Line
  234. Write-Host "Shard ${i}: $passed"
  235. } else {
  236. Write-Host "=== Shard $i FAILED ==="
  237. Get-Content $log
  238. if (Test-Path "${log}.err") { Get-Content "${log}.err" }
  239. $failed = $true
  240. }
  241. }
  242. if ($failed) { exit 1 }
  243. Write-Host "All shards passed."
  244. - name: Run benchmark tests with retry ${{ matrix.config.name }}
  245. if: ${{ matrix.config.run_tests }}
  246. run: ctest --output-on-failure --test-dir build -C Release -R "BenchmarkTest" --repeat until-pass:5
  247. env:
  248. VCPKG_ROOT: "C:/vcpkg"
  249. VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"