1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
6 ;;; GNU Guix is free software; you can redistribute it and/or modify it
7 ;;; under the terms of the GNU General Public License as published by
8 ;;; the Free Software Foundation; either version 3 of the License, or (at
9 ;;; your option) any later version.
11 ;;; GNU Guix 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
14 ;;; GNU General Public License for more details.
16 ;;; You should have received a copy of the GNU General Public License
17 ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19 (define-module (gnu tests)
20 #:use-module (guix gexp)
21 #:use-module (gnu system)
22 #:use-module (gnu services)
23 #:use-module (gnu services shepherd)
24 #:export (backdoor-service-type
25 marionette-operating-system))
29 ;;; This module provides the infrastructure to run operating system tests.
30 ;;; The most important part of that is tools to instrument the OS under test,
31 ;;; essentially allowing to run in a virtual machine controlled by the host
32 ;;; system--hence the name "marionette".
36 (define (marionette-shepherd-service imported-modules)
37 "Return the Shepherd service for the marionette REPL"
41 (list (shepherd-service
42 (provision '(marionette))
43 (requirement '(udev)) ;so that DEVICE is available
44 (modules '((ice-9 match)
48 (imported-modules `((guix build syscalls)
52 (define (clear-echo termios)
53 (set-field termios (termios-local-flags)
54 (logand (lognot (local-flags ECHO))
55 (termios-local-flags termios))))
57 (define (self-quoting? x)
58 (letrec-syntax ((one-of (syntax-rules ()
62 (one-of rest ...))))))
63 (one-of symbol? string? pair? null? vector?
64 bytevector? number? boolean?)))
66 (match (primitive-fork)
71 (let* ((repl (open-file #$device "r+0"))
72 (termios (tcgetattr (fileno repl)))
73 (console (open-file "/dev/console" "r+0")))
74 ;; Don't echo input back.
75 (tcsetattr (fileno repl) (tcsetattr-action TCSANOW)
78 ;; Redirect output to the console.
81 (dup2 (fileno console) 1)
82 (dup2 (fileno console) 2)
95 (let ((result (primitive-eval expr)))
96 (write (if (self-quoting? result)
98 (object->string result))
101 (print-exception (current-error-port)
102 (stack-ref (make-stack #t) 1)
107 (primitive-exit 1))))
110 (stop #~(make-kill-destructor)))))
112 (define marionette-service-type
113 ;; This is the type of the "marionette" service, allowing a guest system to
114 ;; be manipulated from the host. This marionette REPL is essentially a
115 ;; universal marionette.
116 (service-type (name 'marionette-repl)
118 (list (service-extension shepherd-root-service-type
119 marionette-shepherd-service)))))
121 (define* (marionette-operating-system os
122 #:key (imported-modules '()))
123 "Return a marionetteed variant of OS such that OS can be used as a marionette
124 in a virtual machine--i.e., controlled from the host system."
127 (services (cons (service marionette-service-type imported-modules)
128 (operating-system-user-services os)))))
130 ;;; tests.scm ends here