1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00
gnupg/tests/gpgscm/t-child.scm
NIIBE Yutaka a035938216
common,agent,gpg,dirmngr,g13,scd,tests,tools: New spawn function.
* common/exechelp-posix.c (do_exec, gnupg_spawn_process): Remove.
(check_syscall_func, pre_syscall, post_syscall) : New.
(do_create_socketpair, posix_open_null, call_spawn_cb): New.
(my_exec, spawn_detached, gnupg_spawn_helper): New.
(gnupg_process_spawn, process_kill, gnupg_process_terminate): New.
(gnupg_process_get_fds, gnupg_process_get_streams): New.
(process_vctl, gnupg_process_ctl): New.
(gnupg_process_wait, gnupg_process_release): New.
(gnupg_process_wait_list): New.
* common/exechelp-w32.c: Add definition of _WIN32_WINNT as 0x600.
(check_syscall_func, pre_syscall, post_syscall): New.
(gnupg_spawn_process): Remove.
(check_windows_version): New.
(spawn_detached, gnupg_spawn_helper, gnupg_process_spawn): New.
(gnupg_process_get_fds, gnupg_process_get_streams): New.
(process_kill, process_vctl, gnupg_process_ctl): New.
(gnupg_process_wait, gnupg_process_terminate): New.
(gnupg_process_release, gnupg_process_wait_list): New.
* common/exechelp.h: Re-write for new API.
* common/exectool.c (gnupg_exec_tool_stream): Follow the change.
* common/asshelp.c (start_new_service): Likewise.
* agent/genkey.c (do_check_passphrase_pattern): Likewise.
* dirmngr/ldap-wrapper.c (struct wrapper_context_s): Use PROC.
(destroy_wrapper): Follow the change of API.
(read_log_data): Follow the change of API, use printable_pid.
(ldap_reaper_thread, ldap_wrapper_release_context): Likewise.
(ldap_wrapper_connection_cleanup, ldap_wrapper): Likewise.
* g10/photoid.c (run_with_pipe): Follow the change of API.
(show_photo): Likewise.
* g13/be-encfs.c (run_umount_helper): Likewise.
(run_encfs_tool): Likewise.
* g13/g13.c: Add including ./common/exechelp.h.
* g13/mount.c: Likewise.
* g13/runner.c: Follow the change of API.
* g13/runner.h: Follow the change of API.
* scd/app.c (setup_env): New.
(report_change): Follow the change of API.
* tests/gpgscm/ffi.c (proc_object_finalize): New.
(proc_object_to_string): New.
(proc_wrap, proc_unwrap): New.
(do_spawn_process): Remove.
(do_process_spawn): New.
(setup_std_fds): New.
(do_spawn_process_fd): Remove.
(do_process_spawn_fd): New.
(do_wait_process): Remove.
(do_process_wait): New.
(do_wait_processes): Remove.
* tests/gpgscm/t-child.scm: Follow the change of API.
* tests/gpgscm/tests.scm: Likewise.
* tests/openpgp/defs.scm: Likewise.
* tests/tpm2dtests/defs.scm: Likewise.
* tools/gpg-card.c: Likewise.
* tools/gpgconf-comp.c: Likewise.
* tools/gpgconf.c: Likewise.
* tools/gpgtar-create.c: Likewise.
* tools/gpgtar-extract.c: Likewise.
* tools/gpgtar-list.c: Likewise.

--

GnuPG-bug-id: 6275
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
2023-05-11 19:18:21 +09:00

118 lines
4.0 KiB
Scheme

;; Tests for the low-level process and IPC primitives.
;;
;; Copyright (C) 2016 g10 Code GmbH
;;
;; This file is part of GnuPG.
;;
;; GnuPG is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3 of the License, or
;; (at your option) any later version.
;;
;; GnuPG is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, see <http://www.gnu.org/licenses/>.
(echo "Testing process and IPC primitives...")
(define (qualify executable)
(string-append executable (getenv "EXEEXT")))
(define child (qualify "t-child"))
(assert (= 0 (call `(,(qualify "t-child") "return0"))))
(assert (= 1 (call `(,(qualify "t-child") "return1"))))
(assert (= 77 (call `(,(qualify "t-child") "return77"))))
(let ((r (call-with-io `(,(qualify "t-child") "return0") "")))
(assert (= 0 (:retcode r)))
(assert (string=? "" (:stdout r)))
(assert (string=? "" (:stderr r))))
(let ((r (call-with-io `(,(qualify "t-child") "return1") "")))
(assert (= 1 (:retcode r)))
(assert (string=? "" (:stdout r)))
(assert (string=? "" (:stderr r))))
(let ((r (call-with-io `(,(qualify "t-child") "return77") "")))
(assert (= 77 (:retcode r)))
(assert (string=? "" (:stdout r)))
(assert (string=? "" (:stderr r))))
(let ((r (call-with-io `(,(qualify "t-child") "hello_stdout") "")))
(assert (= 0 (:retcode r)))
(assert (string=? "hello" (:stdout r)))
(assert (string=? "" (:stderr r))))
(let ((r (call-with-io `(,(qualify "t-child") "hello_stderr") "")))
(assert (= 0 (:retcode r)))
(assert (string=? "" (:stdout r)))
(assert (string=? "hello" (:stderr r))))
(let ((r (call-with-io `(,(qualify "t-child") "stdout4096") "")))
(assert (= 0 (:retcode r)))
(assert (= 4096 (string-length (:stdout r))))
(assert (string=? "" (:stderr r))))
(let ((r (call-with-io `(,(qualify "t-child") "stdout8192") "")))
(assert (= 0 (:retcode r)))
(assert (= 8192 (string-length (:stdout r))))
(assert (string=? "" (:stderr r))))
(let ((r (call-with-io `(,(qualify "t-child") "cat") "hellohello")))
(assert (= 0 (:retcode r)))
(assert (string=? "hellohello" (:stdout r)))
(assert (string=? "" (:stderr r))))
(define (spawn what)
(process-spawn-fd what CLOSED_FD STDOUT_FILENO STDERR_FILENO))
(let ((proc0 (spawn `(,(qualify "t-child") "return0")))
(proc1 (spawn `(,(qualify "t-child") "return0"))))
(assert (= (process-wait proc0 #t) 0))
(assert (= (process-wait proc1 #t) 0)))
(let ((proc0 (spawn `(,(qualify "t-child") "return1")))
(proc1 (spawn `(,(qualify "t-child") "return0"))))
(assert (= (process-wait proc0 #t) 1))
(assert (= (process-wait proc1 #t) 0)))
(let ((proc0 (spawn `(,(qualify "t-child") "return0")))
(proc1 (spawn `(,(qualify "t-child") "return77")))
(proc2 (spawn `(,(qualify "t-child") "return1"))))
(assert (= (process-wait proc0 #t) 0))
(assert (= (process-wait proc1 #t) 77))
(assert (= (process-wait proc2 #t) 1)))
(let* ((p (pipe))
(proc0 (process-spawn-fd
`(,(qualify "t-child") "hello_stdout")
CLOSED_FD (:write-end p) STDERR_FILENO))
(_ (close (:write-end p)))
(proc1 (process-spawn-fd
`(,(qualify "t-child") "cat")
(:read-end p) STDOUT_FILENO STDERR_FILENO)))
(close (:read-end p))
(assert (= (process-wait proc0 #t) 0))
(assert (= (process-wait proc1 #t) 0)))
(echo " world.")
(tr:do
(tr:pipe-do
(pipe:spawn `(,child stdout4096))
(pipe:spawn `(,child cat)))
(tr:call-with-content (lambda (c)
(assert (= 4096 (string-length c))))))
(tr:do
(tr:pipe-do
(pipe:spawn `(,child stdout8192))
(pipe:spawn `(,child cat)))
(tr:call-with-content (lambda (c)
(assert (= 8192 (string-length c))))))
(echo "All good.")