;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2018 Danny Milosavljevic
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix 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.
;;;
;;; GNU Guix 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 GNU Guix. If not, see .
(define-module (gnu tests linux)
#:use-module (gnu packages base)
#:use-module (gnu packages compression)
#:use-module (gnu packages linux)
#:use-module (gnu packages package-management)
#:use-module (gnu tests)
#:use-module (gnu system)
#:use-module (gnu system file-systems)
#:use-module (gnu system shadow)
#:use-module (gnu system vm)
#:use-module (gnu services)
#:use-module (gnu services base)
#:use-module (guix gexp)
#:use-module (guix store)
#:export (%test-linux))
(define (operating-system-with-current-guix-marionette os)
"Return a variant of OS that uses the current Guix."
(operating-system
(inherit os)
(services (cons (service marionette-service-type
(marionette-configuration
(imported-modules '((gnu services herd)
(guix combinators)))))
(modify-services (operating-system-user-services os)
(guix-service-type config =>
(guix-configuration
(inherit config)
(guix (current-guix)))))))))
(define* %linux-os
;; Return operating system under test.
(let ((base-os (simple-operating-system)))
(operating-system
(inherit (operating-system-with-current-guix-marionette base-os))
(packages (cons* (operating-system-packages base-os))))))
(define (run-linux-test linux-os)
"Run tests in LINUX-OS."
;(define os
; (marionette-operating-system
; linux-os
; #:imported-modules '((guix combinators))))
(define vm
(virtual-machine
(operating-system (operating-system (inherit linux-os)
(file-systems (cons* (file-system
(device "root-fs")
(title 'label)
(mount-point "/")
(type "ext4"))
(file-system
(device "store-fs")
(title 'label)
(mount-point "/gnu")
(type "ext4"))
%base-file-systems)))
)
(memory-size 512)))
(define (test kmod)
"Test the given KMOD package. KMOD is the name of the kmod package."
(with-imported-modules '((gnu build marionette))
#~(begin
(use-modules (srfi srfi-11) (srfi srfi-64)
(gnu build marionette))
(define marionette
(make-marionette (list #$vm)))
(mkdir #$output)
(chdir #$output)
(test-begin #$kmod)
(test-assert "kmod tests work"
(marionette-eval
'(begin
(use-modules (ice-9 popen) (ice-9 rdelim) (ice-9 ftw))
(system* "guix" "build" "--keep-failed" "-e"
(string-append "((@ (guix packages) test-failing-package) " #$kmod ")"))
(display "XXXXXXXXXXXX ")
(display (scandir "/tmp"))
(newline)
(force-output)
(chdir
(car
(filter-map (lambda (basename)
(if (string-prefix? "guix-build-kmod-" basename)
(string-append "/tmp/" basename)
#f))
(scandir "/tmp"))))
(zero? (system* "make" "check")))
marionette))
(test-end)
(exit (= (test-runner-fail-count (test-runner-current)) 0)))))
(gexp->derivation "linux-test" (test "kmod")))
(define %test-linux
(system-test
(name "linux")
(description "Test Linux.")
(value (run-linux-test %linux-os))))