popen.scm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. ;;; popen.scm -- Remote pipes testing.
  2. ;; Copyright (C) 2015, 2016 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 rdelim)
  21. (tests common)
  22. (ssh channel)
  23. (ssh session)
  24. (ssh auth)
  25. (ssh popen))
  26. (test-begin-with-log "popen")
  27. ;;; Helper procedures.
  28. (define (call-with-connected-session/popen proc)
  29. "Make a session for a channel test."
  30. (call-with-connected-session
  31. (lambda (session)
  32. (authenticate-server session)
  33. (userauth-none! session)
  34. (proc session))))
  35. (define (response=? channel string)
  36. "Read a line from a CHANNEL, check if the line is equal to a STRING."
  37. (string=? (read-line channel) string))
  38. (define (input-only? port)
  39. (and (input-port? port)
  40. (not (output-port? port))))
  41. (define (output-only? port)
  42. (and (output-port? port)
  43. (not (input-port? port))))
  44. ;;;
  45. (test-assert-with-log "open-remote-pipe, OPEN_READ"
  46. (run-client-test
  47. start-server/exec
  48. (lambda ()
  49. (call-with-connected-session/popen
  50. (lambda (session)
  51. (let ((channel (open-remote-pipe session "ping" OPEN_READ)))
  52. (and (input-only? channel)
  53. (poll channel (lambda args (response=? channel "pong"))))))))))
  54. (test-assert-with-log "open-remote-pipe, OPEN_PTY_READ"
  55. (run-client-test
  56. start-server/exec
  57. (lambda ()
  58. (call-with-connected-session/popen
  59. (lambda (session)
  60. (let* ((OPEN_PTY_READ (string-append OPEN_PTY OPEN_READ))
  61. (channel (open-remote-pipe session "ping" OPEN_PTY_READ)))
  62. (and (input-only? channel)
  63. (poll channel (lambda args (response=? channel "pong"))))))))))
  64. (test-assert-with-log "open-remote-pipe, OPEN_BOTH"
  65. (run-client-test
  66. start-server/exec
  67. (lambda ()
  68. (call-with-connected-session/popen
  69. (lambda (session)
  70. (let ((channel (open-remote-pipe session "ping" OPEN_BOTH)))
  71. (and (input-port? channel)
  72. (output-port? channel)
  73. (poll channel (lambda args (response=? channel "pong"))))))))))
  74. (test-assert-with-log "open-remote-pipe*"
  75. (run-client-test
  76. start-server/exec
  77. (lambda ()
  78. (call-with-connected-session/popen
  79. (lambda (session)
  80. (let ((channel (open-remote-pipe* session OPEN_READ "ping")))
  81. (and (input-only? channel)
  82. (poll channel (lambda args (response=? channel "pong"))))))))))
  83. (test-assert-with-log "open-remote-input-pipe"
  84. (run-client-test
  85. start-server/exec
  86. (lambda ()
  87. (call-with-connected-session/popen
  88. (lambda (session)
  89. (let ((channel (open-remote-input-pipe session "ping")))
  90. (and (input-only? channel)
  91. (poll channel (lambda args (response=? channel "pong"))))))))))
  92. (test-assert-with-log "open-remote-output-pipe"
  93. (run-client-test
  94. start-server/exec
  95. (lambda ()
  96. (call-with-connected-session/popen
  97. (lambda (session)
  98. (let ((channel (open-remote-output-pipe session "ping")))
  99. (output-only? channel)))))))
  100. (test-end "popen")
  101. (exit (= (test-runner-fail-count (test-runner-current)) 0))
  102. ;;; popen.scm ends here.