[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
11/19: tests: Fork and exec a new Guile for the marionette REPL.
From: |
guix-commits |
Subject: |
11/19: tests: Fork and exec a new Guile for the marionette REPL. |
Date: |
Fri, 21 Apr 2023 11:16:09 -0400 (EDT) |
civodul pushed a commit to branch master
in repository guix.
commit a09c7da8f8d8e732f969cf0a09aaa78f87032ab1
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Fri Apr 21 15:38:06 2023 +0200
tests: Fork and exec a new Guile for the marionette REPL.
By merely forking PID 1, details from PID 1 (shepherd) would leak into
the marionette process, such as the set of modules in scope and state
inherited from the shepherd process (<service> instances, fibers,
etc.). Running a fresh Guile instance avoids that.
* gnu/tests.scm (marionette-program): New procedure.
(marionette-shepherd-service): Change 'start' to use
'make-forkexec-constructor', and run the result of 'marionette-program'.
---
gnu/tests.scm | 112 +++++++++++++++++++++++++++++++---------------------------
1 file changed, 60 insertions(+), 52 deletions(-)
diff --git a/gnu/tests.scm b/gnu/tests.scm
index ca677d315b..96ecb40ea2 100644
--- a/gnu/tests.scm
+++ b/gnu/tests.scm
@@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2016-2020, 2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2016-2020, 2022-2023 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2017 Mathieu Othacehe <m.othacehe@gmail.com>
;;; Copyright © 2017 Tobias Geerinckx-Rice <me@tobias.gr>
;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
@@ -88,6 +88,61 @@
(with-extensions extensions
gexp)))
+(define (marionette-program device imported-modules extensions)
+ "Return the program that runs the marionette REPL on DEVICE. Ensure
+IMPORTED-MODULES and EXTENSIONS are accessible from the REPL."
+ (define code
+ (with-imported-modules-and-extensions
+ `((guix build utils)
+ (guix build syscalls)
+ ,@imported-modules)
+ extensions
+ #~(begin
+ (use-modules (ice-9 match)
+ (ice-9 binary-ports))
+
+ (define (self-quoting? x)
+ (letrec-syntax ((one-of (syntax-rules ()
+ ((_) #f)
+ ((_ pred rest ...)
+ (or (pred x)
+ (one-of rest ...))))))
+ (one-of symbol? string? keyword? pair? null? array?
+ number? boolean? char?)))
+
+ (let ((repl (open-file #$device "r+0"))
+ (console (open-file "/dev/console" "r+0")))
+ ;; Redirect output to the console.
+ (close-fdes 1)
+ (close-fdes 2)
+ (dup2 (fileno console) 1)
+ (dup2 (fileno console) 2)
+ (close-port console)
+
+ (display 'ready repl)
+ (let loop ()
+ (newline repl)
+
+ (match (read repl)
+ ((? eof-object?)
+ (primitive-exit 0))
+ (expr
+ (catch #t
+ (lambda ()
+ (let ((result (primitive-eval expr)))
+ (write (if (self-quoting? result)
+ result
+ (object->string result))
+ repl)))
+ (lambda (key . args)
+ (print-exception (current-error-port)
+ (stack-ref (make-stack #t) 1)
+ key args)
+ (write #f repl)))))
+ (loop))))))
+
+ (program-file "marionette-repl.scm" code))
+
(define (marionette-shepherd-service config)
"Return the Shepherd service for the marionette REPL"
(match config
@@ -101,57 +156,10 @@
(modules '((ice-9 match)
(srfi srfi-9 gnu)))
- (start
- (with-imported-modules-and-extensions imported-modules extensions
- #~(lambda ()
- (define (self-quoting? x)
- (letrec-syntax ((one-of (syntax-rules ()
- ((_) #f)
- ((_ pred rest ...)
- (or (pred x)
- (one-of rest ...))))))
- (one-of symbol? string? keyword? pair? null? array?
- number? boolean? char?)))
-
- (match (primitive-fork)
- (0
- (dynamic-wind
- (const #t)
- (lambda ()
- (let ((repl (open-file #$device "r+0"))
- (console (open-file "/dev/console" "r+0")))
- ;; Redirect output to the console.
- (close-fdes 1)
- (close-fdes 2)
- (dup2 (fileno console) 1)
- (dup2 (fileno console) 2)
- (close-port console)
-
- (display 'ready repl)
- (let loop ()
- (newline repl)
-
- (match (read repl)
- ((? eof-object?)
- (primitive-exit 0))
- (expr
- (catch #t
- (lambda ()
- (let ((result (primitive-eval expr)))
- (write (if (self-quoting? result)
- result
- (object->string result))
- repl)))
- (lambda (key . args)
- (print-exception (current-error-port)
- (stack-ref (make-stack
#t) 1)
- key args)
- (write #f repl)))))
- (loop))))
- (lambda ()
- (primitive-exit 1))))
- (pid
- pid)))))
+ (start #~(make-forkexec-constructor
+ (list #$(marionette-program device
+ imported-modules
+ extensions))))
(stop #~(make-kill-destructor)))))))
(define marionette-service-type
- branch master updated (0830059b9c -> 13ebf5e36c), guix-commits, 2023/04/21
- 01/19: services: postgresql: Add the 'postgresql' Shepherd service name., guix-commits, 2023/04/21
- 10/19: tests: Use the client 'start-service' procedure., guix-commits, 2023/04/21
- 06/19: services: knot: Add 'configuration' action., guix-commits, 2023/04/21
- 07/19: services: postgresql: Add default package., guix-commits, 2023/04/21
- 09/19: services: herd: 'load-services/safe' is synonymous with 'load-services'., guix-commits, 2023/04/21
- 11/19: tests: Fork and exec a new Guile for the marionette REPL.,
guix-commits <=
- 14/19: packages: 'package-direct-sources' correctly handles non-origin sources., guix-commits, 2023/04/21
- 15/19: gnu: kicad: Update to 7.0.2., guix-commits, 2023/04/21
- 16/19: gnu: Add emacs-gerbil-mode., guix-commits, 2023/04/21
- 02/19: services: postgresql: Add 'configuration' action., guix-commits, 2023/04/21
- 03/19: services: mysql: Add 'configuration' action., guix-commits, 2023/04/21
- 04/19: services: redis: Add 'configuration' action., guix-commits, 2023/04/21
- 08/19: services: nscd: Depend on syslogd., guix-commits, 2023/04/21
- 12/19: tests: Fix checks for expected failures., guix-commits, 2023/04/21
- 17/19: gnu: guile-dsv: Update to 0.5.2., guix-commits, 2023/04/21
- 18/19: home: services: openssh: Add configuration option for jump proxies, guix-commits, 2023/04/21