[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#65221] [PATCH 1/6] tests: add extra-ports.sh test.
From: |
ulfvonbelow |
Subject: |
[bug#65221] [PATCH 1/6] tests: add extra-ports.sh test. |
Date: |
Fri, 18 Aug 2023 15:22:34 -0500 |
* tests/extra-ports.sh: new test.
---
tests/extra-ports.sh | 76 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 76 insertions(+)
create mode 100644 tests/extra-ports.sh
diff --git a/tests/extra-ports.sh b/tests/extra-ports.sh
new file mode 100644
index 0000000..51b91b7
--- /dev/null
+++ b/tests/extra-ports.sh
@@ -0,0 +1,76 @@
+socket="t-socket-$$"
+conf="t-conf-$$"
+log="t-log-$$"
+pid="t-pid-$$"
+testfile1="t-testfile1-$$"
+testfile2="t-testfile2-$$"
+resultfile="t-resultfile-$$"
+
+herd="herd -s $socket"
+
+trap "cat $log || true;
+ rm -f $socket $conf $log $testfile1 $testfile2 $resultfile;
+ test -f $pid && kill \`cat $pid\` || true; rm -f $pid" EXIT
+
+printf "test1" > "$testfile1"
+printf "test2" > "$testfile2"
+
+cat > "$conf"<<EOF
+(register-services
+ (list (service
+ '(test-extra-ports)
+ #:requirement '()
+ #:start (lambda _
+ (call-with-input-file "$testfile1"
+ (lambda (test1)
+ (call-with-input-file "$testfile2"
+ (lambda (test2)
+ ;; test1 and test2 should hopefully have adjacent fds
+ (define ports
+ (append
+ ;; Fill up the fd range so that the source and
+ ;; destination ranges overlap
+ (map (const test1)
+ (iota (- (min (fileno test1)
+ (fileno test2))
+ 3)))
+ (sort (list test1 test2)
+ (lambda (a b)
+ (> (fileno a)
+ (fileno b))))))
+
+ (define command
+ (list
+ "sh"
+ "-c"
+ (string-append
+ "set -x;"
+ " cat >> ${resultfile}.tmp <&" (number->string
+ (fileno test1))
+ "; cat >> ${resultfile}.tmp <&" (number->string
+ (fileno test2))
+ "; mv ${resultfile}.tmp ${resultfile}")))
+
+ (fork+exec-command command
+ #:extra-ports
+ ports
+ #:directory
+ "$(pwd)"))))))
+ #:stop (const #f)
+ #:respawn? #f)))
+EOF
+
+rm -f "$pid"
+shepherd -I -s "$socket" -c "$conf" -l "$log" --pid="$pid" &
+
+while ! test -f "$pid" ; do sleep 0.3 ; done
+
+shepherd_pid="`cat $pid`"
+kill -0 $shepherd_pid
+
+$herd start test-extra-ports
+
+while ! test -f "$resultfile" ; do sleep 0.3 ; done
+
+result="$(cat $resultfile)"
+test "$result" = "test1test2" -o "$result" = "test2test1"
--
2.40.1
- [bug#65221] [PATCH 0/2] Fix EXTRA-PORTS edge cases, ulfvonbelow, 2023/08/11
- [bug#65221] [PATCH 1/2] service: make EXTRA-PORTS work as advertised., ulfvonbelow, 2023/08/11
- [bug#65221] [PATCH 1/6] tests: add extra-ports.sh test.,
ulfvonbelow <=
- [bug#65221] [PATCH 2/6] service: don't let earlier ports clobber later ones in EXTRA-PORTS., ulfvonbelow, 2023/08/18
- [bug#65221] [PATCH 4/6] service: honor EXTRA-PORTS regardless of log-port and log-file., ulfvonbelow, 2023/08/18
- [bug#65221] [PATCH 6/6] service: exec-command: close other file descriptors by default., ulfvonbelow, 2023/08/18
- [bug#65221] [PATCH 3/6] Makefile.am: enable extra-ports.sh test., ulfvonbelow, 2023/08/18
- [bug#65221] [PATCH 5/6] service: use RECONFIGURE-FDS for redirecting FDs 0-2., ulfvonbelow, 2023/08/18