test.ps1 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. # Powershell Script must be save as UTF-8 with BOM, otherwise system-wide code page will be used, causing garbled code
  2. # MNN-CPU-GPU
  3. # |-- include
  4. # |-- lib
  5. # | |-- x64
  6. # | | |-- (Debug/Release x Dynamic/Static x MD/MT)
  7. # | |
  8. # | |-- x86
  9. # | |-- (Debug/Release x Dynamic/Static x MD/MT)
  10. # |
  11. # |-- tools (Release + Dynamic + MD)
  12. # | |-- x64
  13. # | |-- x86
  14. # |
  15. # |-- py_whl
  16. # |-- py_bridge
  17. # |-- include
  18. # |-- wrapper
  19. # |-- test (Release + Dynamic + MD)
  20. # |-- x64
  21. # |-- x86
  22. # |-- lib
  23. # |-- x64
  24. # | |-- (Debug/Release x Dynamic/Static x MD/MT)
  25. # |
  26. # |-- x86
  27. # |-- (Debug/Release x Dynamic/Static x MD/MT)
  28. Param(
  29. [Switch]$gpu,
  30. [Switch]$x86
  31. )
  32. $basedir = $(Split-Path -Parent $MyInvocation.MyCommand.Path)
  33. $outdir = "$basedir/$(If ($gpu) {"MNN-CPU-GPU"} Else {"MNN-CPU"})"
  34. $arch = "$(If ($x86) {"x86"} Else {"x64"})"
  35. Write-Output $arch
  36. $test_avx512 = ((!$x86) -and $env:avx512_server -and $env:avx512_password)
  37. if ($test_avx512) {
  38. $remote_home = $(Invoke-Expression 'plink -batch -ssh $env:avx512_server -pw $env:avx512_password powershell "echo `$HOME"')
  39. $remote_dir = "${remote_home}\cise-space\$(Split-Path -Path $(pushd .. ; pwd ; popd) -Leaf)"
  40. }
  41. function sync_remote() {
  42. Invoke-Expression 'plink -batch -ssh $env:avx512_server -pw $env:avx512_password powershell "Remove-Item -Recurse $remote_dir -ErrorAction Ignore ; mkdir $remote_dir"'
  43. Invoke-Expression 'pscp -pw $env:avx512_password -r $outdir/tools ${env:avx512_server}:${remote_dir}'
  44. Invoke-Expression 'pscp -pw $env:avx512_password tools/script/modelTest.py ${env:avx512_server}:${remote_dir}'
  45. }
  46. function run_remote([String]$cmd) {
  47. $tmpfile = New-TemporaryFile
  48. Set-Content -Path $tmpfile -Value "powershell `"cd ${remote_dir} ; $cmd`""
  49. $output = $(Invoke-Expression 'plink -batch -ssh $env:avx512_server -pw $env:avx512_password -m $tmpfile')
  50. Remove-Item $tmpfile
  51. return $output
  52. }
  53. function log($case, $title, $blocked, $failed, $passed, $skipped) {
  54. Write-Output "TEST_NAME_${case}: $title"
  55. Write-Output "TEST_CASE_AMOUNT_${case}: {`"blocked`":$blocked,`"failed`":$failed,`"passed`":$passed,`"skipped`":$skipped}"
  56. }
  57. function failed() {
  58. Write-Output "TEST_NAME_EXCEPTION: Exception"
  59. Write-Output 'TEST_CASE_AMOUNT_EXCEPTION: {"blocked":0,"failed":1,"passed":0,"skipped":0}'
  60. exit
  61. }
  62. function build_lib_test() {
  63. # build_lib_release.ps1 just build release for speed
  64. Invoke-Expression "./package_scripts/win/build_lib_release.ps1 -path $outdir -cibuild $(If ($gpu) {"-backends 'opencl,vulkan'"}) $(If ($x86) {'-x86'})"
  65. $WrongNum = [int]$($LastExitCode -ne 0)
  66. log "WINDOWS_LIB" "Windows主库编译测试" 0 $WrongNum $(1 - $WrongNum) 0
  67. if ($WrongNum -ne 0) {
  68. Write-Output "### Windows主库编译测试失败,测试终止"
  69. failed
  70. }
  71. }
  72. function build_tool_test() {
  73. Invoke-Expression "./package_scripts/win/build_tools.ps1 -path $outdir/tools/$arch $(If ($gpu) {"-backends 'opencl,vulkan'"}) -build_all -dynamic_link"
  74. $WrongNum = $($LastExitCode -ne 0)
  75. log "WINDOWS_LIB" "Windows工具编译测试" 0 $WrongNum $(1 - $WrongNum) 0
  76. if ($WrongNum -ne 0) {
  77. Write-Output "### Windows工具编译测试失败,测试终止"
  78. failed
  79. }
  80. }
  81. function build_whl_test() {
  82. $pyenvs = "py27,py37,py38,py39"
  83. if ($x86) {
  84. $pyenvs = "py27-win32,py37-win32,py38-win32,py39-win32"
  85. }
  86. Invoke-Expression "./package_scripts/win/build_whl.ps1 -version ci_test -path $outdir/py_whl -pyenvs '$pyenvs' $(If ($x86) {'-x86'})"
  87. $WrongNum = $($LastExitCode -ne 0)
  88. log "WINDOWS_LIB" "Windows pymnn wheel编译测试" 0 $WrongNum $(1 - $WrongNum) 0
  89. if ($WrongNum -ne 0) {
  90. Write-Output "### Windows pymnn wheel编译测试失败,测试终止"
  91. failed
  92. }
  93. }
  94. function build_bridge_test() {
  95. Invoke-Expression "./package_scripts/win/build_bridge.ps1 -version ci_test -pyc_env py27 -mnn_path $outdir -python_path $HOME/PyBridgeDeps/python -numpy_path $HOME/PyBridgeDeps/numpy -path $outdir/py_bridge -train_api $(If ($x86) {'-x86'})"
  96. $WrongNum = $($LastExitCode -ne 0)
  97. log "WINDOWS_LIB" "Windows pymnn bridge编译测试" 0 $WrongNum $(1 - $WrongNum) 0
  98. if ($WrongNum -ne 0) {
  99. Write-Output "### Windows pymnn bridge编译测试失败,测试终止"
  100. failed
  101. }
  102. }
  103. function unit_test() {
  104. Invoke-Expression "$outdir/tools/$arch/run_test.out.exe"
  105. if ($LastExitCode -ne 0) {
  106. Write-Output "### CPU后端 单元测试失败,测试终止"
  107. failed
  108. }
  109. Invoke-Expression "$outdir/tools/$arch/run_test.out.exe op 0 0 4"
  110. if ($LastExitCode -ne 0) {
  111. Write-Output "### CPU后端 多线程测试失败,测试终止"
  112. failed
  113. }
  114. if ($test_avx512) {
  115. $RemoteExitCode = run_remote "cd tools/x64 ; ./run_test.out.exe > log.txt ; echo `$LastExitCode"
  116. Write-Output $(run_remote "Get-Content -Path tools/x64/log.txt")
  117. if ($RemoteExitCode -ne 0) {
  118. Write-Output "### CPU后端(AVX512) 单元测试失败,测试终止"
  119. failed
  120. }
  121. $RemoteExitCode = run_remote "cd tools/x64 ; ./run_test.out.exe op 0 0 4 > log.txt ; echo `$LastExitCode"
  122. Write-Output $(run_remote "Get-Content -Path tools/x64/log.txt")
  123. if ($RemoteExitCode -ne 0) {
  124. Write-Output "### CPU后端(AVX512) 多线程测试失败,测试终止"
  125. failed
  126. }
  127. }
  128. #Invoke-Expression "$outdir/tools/$arch/run_test.out.exe op 3"
  129. #if ($LastExitCode -ne 0) {
  130. # echo "### OpenCL后端 单元测试失败,测试终止"
  131. # failed
  132. #}
  133. }
  134. function model_test() {
  135. Push-Location $outdir/tools/$arch
  136. python $basedir/tools/script/modelTest.py $HOME/AliNNModel 0 0.002
  137. if ($LastExitCode -ne 0) {
  138. Write-Output "### CPU后端 模型测试失败,测试终止"
  139. Pop-Location
  140. failed
  141. }
  142. python $basedir/tools/script/modelTest.py $HOME/AliNNModel 0 0.002 0 1
  143. if ($LastExitCode -ne 0) {
  144. Write-Output "### CPU后端 静态模型测试失败,测试终止"
  145. Pop-Location
  146. failed
  147. }
  148. if ($test_avx512) {
  149. $RemoteExitCode = run_remote "cd tools/x64 ; python ../../modelTest.py `$HOME/AliNNModel 0 0.002 > log.txt ; echo `$LastExitCode"
  150. Write-Output $(run_remote "Get-Content -Path tools/x64/log.txt")
  151. if ($RemoteExitCode -ne 0) {
  152. Write-Output "### CPU后端(AVX512) 模型测试失败,测试终止"
  153. Pop-Location
  154. failed
  155. }
  156. $RemoteExitCode = run_remote "cd tools/x64 ; python ../../modelTest.py `$HOME/AliNNModel 0 0.002 0 1 > log.txt ; echo `$LastExitCode"
  157. Write-Output $(run_remote "Get-Content -Path tools/x64/log.txt")
  158. if ($RemoteExitCode -ne 0) {
  159. Write-Output "### CPU后端(AVX512) 静态模型测试失败,测试终止"
  160. Pop-Location
  161. failed
  162. }
  163. }
  164. #python $basedir/tools/script/modelTest.py $HOME/AliNNModel 3 0.01
  165. #if ($LastExitCode -ne 0) {
  166. # echo "### OpenCL后端 模型测试失败,测试终止"
  167. # Pop-Location
  168. # failed
  169. #}
  170. Pop-Location
  171. }
  172. function pymnn_whl_test() {
  173. $pyarch = $(If ($x86) {"win32"} Else {"amd64"})
  174. Push-Location pymnn/test
  175. $local = "$(Get-Location)/aone-site-packages"
  176. $pythonpath_backup = ${env:PYTHONPATH}
  177. Foreach ($pyenv in @("27", "37", "38", "39")) {
  178. Invoke-Expression "conda activate py$pyenv$(If($x86) {'-win32'})"
  179. Remove-Item -Recurse $local -ErrorAction Ignore
  180. pip install --target $local $outdir/py_whl/$(Get-ChildItem -Path $outdir/py_whl -Include "*$pyenv*$pyarch*" -Name)
  181. do {
  182. # unit_test.py need torch, which isn't support on 32bit Windows and py27
  183. # https://pytorch.org/docs/stable/notes/windows.html#package-not-found-in-win-32-channel
  184. if ($x86 -or ($pyenv -eq "27")) {
  185. break;
  186. }
  187. ${env:PYTHONPATH} = $local
  188. python unit_test.py
  189. ${env:PYTHONPATH} = $pythonpath_backup
  190. if ($LastExitCode -ne 0) {
  191. Write-Output "### PYMNN单元测试失败,测试终止"
  192. conda deactivate
  193. Pop-Location
  194. failed
  195. }
  196. } while(0);
  197. ${env:PYTHONPATH} = "$local"
  198. python model_test.py $HOME/AliNNModel
  199. ${env:PYTHONPATH} = $pythonpath_backup
  200. if ($LastExitCode -ne 0) {
  201. Write-Output "### PYMNN模型测试失败,测试终止"
  202. conda deactivate
  203. Pop-Location
  204. failed
  205. }
  206. conda deactivate
  207. }
  208. Pop-Location
  209. }
  210. build_lib_test
  211. # TODO: open other test
  212. # build_tool_test
  213. # build_whl_test
  214. # build_bridge_test
  215. # if ($test_avx512) {
  216. # sync_remote
  217. # }
  218. # unit_test
  219. # model_test
  220. # pymnn_whl_test