1 ;; Tests for the low-level process and IPC primitives.
3 ;; Copyright (C) 2016 g10 Code GmbH
5 ;; This file is part of GnuPG.
7 ;; GnuPG is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GnuPG is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program; if not, see <http://www.gnu.org/licenses/>.
20 (echo "Testing process and IPC primitives...")
22 (define (qualify executable)
23 (string-append executable (getenv "EXEEXT")))
25 (define child (qualify "t-child"))
27 (assert (= 0 (call `(,(qualify "t-child") "return0"))))
28 (assert (= 1 (call `(,(qualify "t-child") "return1"))))
29 (assert (= 77 (call `(,(qualify "t-child") "return77"))))
31 (let ((r (call-with-io `(,(qualify "t-child") "return0") "")))
32 (assert (= 0 (:retcode r)))
33 (assert (string=? "" (:stdout r)))
34 (assert (string=? "" (:stderr r))))
36 (let ((r (call-with-io `(,(qualify "t-child") "return1") "")))
37 (assert (= 1 (:retcode r)))
38 (assert (string=? "" (:stdout r)))
39 (assert (string=? "" (:stderr r))))
41 (let ((r (call-with-io `(,(qualify "t-child") "return77") "")))
42 (assert (= 77 (:retcode r)))
43 (assert (string=? "" (:stdout r)))
44 (assert (string=? "" (:stderr r))))
46 (let ((r (call-with-io `(,(qualify "t-child") "hello_stdout") "")))
47 (assert (= 0 (:retcode r)))
48 (assert (string=? "hello" (:stdout r)))
49 (assert (string=? "" (:stderr r))))
51 (let ((r (call-with-io `(,(qualify "t-child") "hello_stderr") "")))
52 (assert (= 0 (:retcode r)))
53 (assert (string=? "" (:stdout r)))
54 (assert (string=? "hello" (:stderr r))))
56 (let ((r (call-with-io `(,(qualify "t-child") "stdout4096") "")))
57 (assert (= 0 (:retcode r)))
58 (assert (= 4096 (string-length (:stdout r))))
59 (assert (string=? "" (:stderr r))))
61 (let ((r (call-with-io `(,(qualify "t-child") "stdout8192") "")))
62 (assert (= 0 (:retcode r)))
63 (assert (= 8192 (string-length (:stdout r))))
64 (assert (string=? "" (:stderr r))))
66 (let ((r (call-with-io `(,(qualify "t-child") "cat") "hellohello")))
67 (assert (= 0 (:retcode r)))
68 (assert (string=? "hellohello" (:stdout r)))
69 (assert (string=? "" (:stderr r))))
72 (spawn-process-fd what CLOSED_FD STDOUT_FILENO STDERR_FILENO))
74 (let ((pid0 (spawn `(,(qualify "t-child") "return0")))
75 (pid1 (spawn `(,(qualify "t-child") "return0"))))
76 (assert (equal? '(0 0)
77 (wait-processes '("child0" "child1") (list pid0 pid1) #t))))
79 (let ((pid0 (spawn `(,(qualify "t-child") "return1")))
80 (pid1 (spawn `(,(qualify "t-child") "return0"))))
81 (assert (equal? '(1 0)
82 (wait-processes '("child0" "child1") (list pid0 pid1) #t))))
84 (let ((pid0 (spawn `(,(qualify "t-child") "return0")))
85 (pid1 (spawn `(,(qualify "t-child") "return77")))
86 (pid2 (spawn `(,(qualify "t-child") "return1"))))
87 (assert (equal? '(0 77 1)
88 (wait-processes '("child0" "child1" "child2")
89 (list pid0 pid1 pid2) #t))))
92 (pid0 (spawn-process-fd
93 `(,(qualify "t-child") "hello_stdout")
94 CLOSED_FD (:write-end p) STDERR_FILENO))
95 (_ (close (:write-end p)))
96 (pid1 (spawn-process-fd
97 `(,(qualify "t-child") "cat")
98 (:read-end p) STDOUT_FILENO STDERR_FILENO)))
102 (wait-processes '("child0" "child1") (list pid0 pid1) #t))))
107 (pipe:spawn `(,child stdout4096))
108 (pipe:spawn `(,child cat)))
109 (tr:call-with-content (lambda (c)
110 (assert (= 4096 (length c))))))
113 (pipe:spawn `(,child stdout8192))
114 (pipe:spawn `(,child cat)))
115 (tr:call-with-content (lambda (c)
116 (assert (= 8192 (length c))))))