valgrind.es.tst 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. valgrind.tst - Valgrind tests on Unix-like systems
  3. */
  4. let PORT = 4150
  5. let valgrind = Cmd.locate('valgrind')
  6. if (Config.OS == 'linux' && tdepth() >= 4 && valgrind) {
  7. let host = '127.0.0.1:' + PORT
  8. let httpCmd = testme.bin.join('http').portable + ' -q --zero '
  9. let goahead = testme.bin.join('goahead-test').portable + ' --name api.valgrind'
  10. valgrind += ' -q --tool=memcheck --leak-check=yes --suppressions=../../../build/bin/mpr.supp ' + goahead + ' -v'
  11. // Run http
  12. function run(args): String {
  13. try {
  14. // print(httpCmd, args)
  15. let cmd = Cmd(httpCmd + args)
  16. if (cmd.status != 0) {
  17. print('STATUS ' + cmd.status)
  18. print(cmd.error)
  19. print(cmd.response)
  20. }
  21. ttrue(cmd.status == 0)
  22. return cmd.response
  23. } catch (e) {
  24. ttrue(false, e)
  25. }
  26. return null
  27. }
  28. /*
  29. Start valgrind and wait till ready
  30. */
  31. // print('VALGRIND CMD: ' + valgrind)
  32. let cmd = Cmd(valgrind, {detach: true})
  33. let http
  34. for (i in 10) {
  35. http = new Http
  36. try {
  37. http.get(host + '/index.html')
  38. if (http.status == 200) break
  39. } catch (e) {}
  40. App.sleep(1000)
  41. http.close()
  42. }
  43. if (http.status != 200) {
  44. throw 'Cannot start goahead-test for valgrind'
  45. }
  46. run('-i 100 ' + PORT + '/index.html')
  47. if (thas('ME_GOAHEAD_CGI')) {
  48. run(PORT + '/test.cgi')
  49. }
  50. run(PORT + '/exit.esp')
  51. let ok = cmd.wait(10000)
  52. if (cmd.status != 0) {
  53. App.log.error('valgrind status: ' + cmd.status)
  54. App.log.error('valgrind error: ' + cmd.error)
  55. App.log.error('valgrind output: ' + cmd.response)
  56. }
  57. ttrue(cmd.status == 0)
  58. cmd.stop()
  59. } else {
  60. if (Config.OS == 'linux' && !valgrind) {
  61. tskip('Run with valgrind installed')
  62. } else {
  63. tskip('Run on Linux at depth 4 with valgrind installed')
  64. }
  65. }