1
0

test.yaml 9.8 KB

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