gnu: wget2: Add support for gnu updater.
[jackhill/guix/guix.git] / gnu / tests / linux-modules.scm
CommitLineData
5c79f238
DM
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays@sdf.org>
3;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org>
044d1478 4;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
5c79f238
DM
5;;;
6;;; This file is part of GNU Guix.
7;;;
8;;; GNU Guix is free software; you can redistribute it and/or modify it
9;;; under the terms of the GNU General Public License as published by
10;;; the Free Software Foundation; either version 3 of the License, or (at
11;;; your option) any later version.
12;;;
13;;; GNU Guix is distributed in the hope that it will be useful, but
14;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;;; GNU General Public License for more details.
17;;;
18;;; You should have received a copy of the GNU General Public License
19;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21(define-module (gnu tests linux-modules)
22 #:use-module (gnu packages linux)
044d1478
BW
23 #:use-module (gnu services)
24 #:use-module (gnu services linux)
5c79f238
DM
25 #:use-module (gnu system)
26 #:use-module (gnu system vm)
27 #:use-module (gnu tests)
28 #:use-module (guix derivations)
29 #:use-module (guix gexp)
30 #:use-module (guix modules)
31 #:use-module (guix monads)
32 #:use-module (guix store)
33 #:export (%test-loadable-kernel-modules-0
34 %test-loadable-kernel-modules-1
35 %test-loadable-kernel-modules-2))
36
37;;; Commentary:
38;;;
39;;; Test <operating-system> kernel-loadable-modules.
40;;;
41;;; Code:
42
044d1478
BW
43(define* (modules-loaded?-program os modules)
44 "Return an executable store item that, upon being evaluated, will verify
45that MODULES are actually loaded."
5c79f238 46 (program-file
044d1478
BW
47 "verify-kernel-modules-loaded.scm"
48 #~(begin
49 (use-modules (ice-9 rdelim)
50 (ice-9 popen)
51 (srfi srfi-1)
52 (srfi srfi-13))
53 (let* ((port (open-input-pipe (string-append #$kmod "/bin/lsmod")))
54 (lines (string-split (read-string port) #\newline))
55 (separators (char-set #\space #\tab))
56 (modules (map (lambda (line)
57 (string-take line
58 (or (string-index line separators)
59 0)))
60 lines))
61 (status (close-pipe port)))
62 (and (= status 0)
63 (and-map (lambda (module)
64 (member module modules string=?))
65 '#$modules))))))
5c79f238
DM
66
67(define* (run-loadable-kernel-modules-test module-packages module-names)
044d1478
BW
68 "Run a test of an OS having MODULE-PACKAGES, and verify that MODULE-NAMES
69are loaded in memory."
5c79f238
DM
70 (define os
71 (marionette-operating-system
72 (operating-system
73 (inherit (simple-operating-system))
044d1478
BW
74 (services (cons (service kernel-module-loader-service-type module-names)
75 (operating-system-user-services
76 (simple-operating-system))))
5c79f238
DM
77 (kernel-loadable-modules module-packages))
78 #:imported-modules '((guix combinators))))
79 (define vm (virtual-machine os))
80 (define (test script)
81 (with-imported-modules '((gnu build marionette))
82 #~(begin
83 (use-modules (gnu build marionette)
84 (srfi srfi-64))
85 (define marionette
86 (make-marionette (list #$vm)))
87 (mkdir #$output)
88 (chdir #$output)
89 (test-begin "loadable-kernel-modules")
90 (test-assert "script successfully evaluated"
91 (marionette-eval
92 '(primitive-load #$script)
93 marionette))
94 (test-end)
95 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
044d1478
BW
96 (gexp->derivation "loadable-kernel-modules"
97 (test (modules-loaded?-program os module-names))))
5c79f238
DM
98
99(define %test-loadable-kernel-modules-0
100 (system-test
101 (name "loadable-kernel-modules-0")
102 (description "Tests loadable kernel modules facility of <operating-system>
103with no extra modules.")
104 (value (run-loadable-kernel-modules-test '() '()))))
105
106(define %test-loadable-kernel-modules-1
107 (system-test
108 (name "loadable-kernel-modules-1")
109 (description "Tests loadable kernel modules facility of <operating-system>
110with one extra module.")
111 (value (run-loadable-kernel-modules-test
112 (list ddcci-driver-linux)
113 '("ddcci")))))
114
115(define %test-loadable-kernel-modules-2
116 (system-test
117 (name "loadable-kernel-modules-2")
118 (description "Tests loadable kernel modules facility of <operating-system>
119with two extra modules.")
120 (value (run-loadable-kernel-modules-test
121 (list acpi-call-linux-module ddcci-driver-linux)
122 '("acpi_call" "ddcci")))))