shell.scm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. ;;; shell.scm -- Remote shell tests.
  2. ;; Copyright (C) 2016, 2017 Artyom V. Poptsov <poptsov.artyom@gmail.com>
  3. ;;
  4. ;; This file is a part of Guile-SSH.
  5. ;;
  6. ;; Guile-SSH is free software: you can redistribute it and/or
  7. ;; modify it under the terms of the GNU General Public License as
  8. ;; published by the Free Software Foundation, either version 3 of the
  9. ;; License, or (at your option) any later version.
  10. ;;
  11. ;; Guile-SSH is distributed in the hope that it will be useful, but
  12. ;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ;; General Public License for more details.
  15. ;;
  16. ;; You should have received a copy of the GNU General Public License
  17. ;; along with Guile-SSH. If not, see <http://www.gnu.org/licenses/>.
  18. (add-to-load-path (getenv "abs_top_srcdir"))
  19. (use-modules (srfi srfi-64)
  20. (ice-9 receive)
  21. (srfi srfi-4)
  22. (ssh session)
  23. (ssh auth)
  24. (ssh key)
  25. (ssh log)
  26. (ssh shell)
  27. (ssh popen)
  28. (tests common))
  29. (test-begin-with-log "shell")
  30. (define (call-with-connected-session/shell proc)
  31. "Make a session for a shell test."
  32. (call-with-connected-session
  33. (lambda (session)
  34. (format-log/scm 'nolog "call-with-connected-session/shell"
  35. "session: ~a" session)
  36. (authenticate-server session)
  37. (userauth-none! session)
  38. (proc session))))
  39. ;;;
  40. ;; Client executes "uname", server replies with success code 0.
  41. (test-assert-with-log "rexec"
  42. (run-client-test
  43. start-server/exec
  44. (lambda ()
  45. (call-with-connected-session/shell
  46. (lambda (session)
  47. (receive (result exit-code)
  48. (rexec session "uname")
  49. (list result exit-code)))))))
  50. (test-assert-with-log "which"
  51. (run-client-test
  52. start-server/exec
  53. (lambda ()
  54. (call-with-connected-session/shell
  55. (lambda (session)
  56. (receive (result exit-code)
  57. (which session "uname")
  58. (and (zero? exit-code)
  59. (string=? (car result) "which 'uname'"))))))))
  60. (test-assert-with-log "pgrep"
  61. (run-client-test
  62. start-server/exec
  63. (lambda ()
  64. (call-with-connected-session/shell
  65. (lambda (session)
  66. (receive (result exit-code)
  67. (pgrep session "guile --listen=37146" #:full? #t)
  68. (and (zero? exit-code)
  69. (string=? "pgrep -f 'guile --listen=37146'"
  70. (car result)))))))))
  71. (test-assert-with-log "command-available?"
  72. (run-client-test
  73. start-server/exec
  74. (lambda ()
  75. (call-with-connected-session/shell
  76. (lambda (session)
  77. (command-available? session "guile"))))))
  78. (test-assert-with-log "fallback-pgrep"
  79. (run-client-test
  80. start-server/exec
  81. (lambda ()
  82. (call-with-connected-session/shell
  83. (lambda (session)
  84. (receive (result exit-code)
  85. (fallback-pgrep session "guile")
  86. (and (zero? exit-code)
  87. result)))))))
  88. (test-assert-with-log "loadavg"
  89. (run-client-test
  90. start-server/exec
  91. (lambda ()
  92. (call-with-connected-session/shell
  93. (lambda (session)
  94. (equal? (loadavg session)
  95. '("0.01" "0.05" "0.10" "4/1927" "242011")))))))
  96. ;;;
  97. (test-end "shell")
  98. (exit (= (test-runner-fail-count (test-runner-current)) 0))
  99. ;;; shell.scm ends here.