services: Allow modprobe to use "/etc/modprobe.d".
[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>
4;;;
5;;; This file is part of GNU Guix.
6;;;
7;;; GNU Guix is free software; you can redistribute it and/or modify it
8;;; under the terms of the GNU General Public License as published by
9;;; the Free Software Foundation; either version 3 of the License, or (at
10;;; your option) any later version.
11;;;
12;;; GNU Guix is distributed in the hope that it will be useful, but
13;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;;; GNU General Public License for more details.
16;;;
17;;; You should have received a copy of the GNU General Public License
18;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
19
20(define-module (gnu tests linux-modules)
21 #:use-module (gnu packages linux)
22 #:use-module (gnu system)
23 #:use-module (gnu system vm)
24 #:use-module (gnu tests)
25 #:use-module (guix derivations)
26 #:use-module (guix gexp)
27 #:use-module (guix modules)
28 #:use-module (guix monads)
29 #:use-module (guix store)
30 #:export (%test-loadable-kernel-modules-0
31 %test-loadable-kernel-modules-1
32 %test-loadable-kernel-modules-2))
33
34;;; Commentary:
35;;;
36;;; Test <operating-system> kernel-loadable-modules.
37;;;
38;;; Code:
39
40(define* (module-loader-program os modules)
41 "Return an executable store item that, upon being evaluated, will dry-run
42load MODULES."
43 (program-file
44 "load-kernel-modules.scm"
45 (with-imported-modules (source-module-closure '((guix build utils)))
46 #~(begin
47 (use-modules (guix build utils))
48 (for-each (lambda (module)
49 (invoke (string-append #$kmod "/bin/modprobe") "-n" "--"
50 module))
51 '#$modules)))))
52
53(define* (run-loadable-kernel-modules-test module-packages module-names)
54 "Run a test of an OS having MODULE-PACKAGES, and modprobe MODULE-NAMES."
55 (define os
56 (marionette-operating-system
57 (operating-system
58 (inherit (simple-operating-system))
59 (kernel-loadable-modules module-packages))
60 #:imported-modules '((guix combinators))))
61 (define vm (virtual-machine os))
62 (define (test script)
63 (with-imported-modules '((gnu build marionette))
64 #~(begin
65 (use-modules (gnu build marionette)
66 (srfi srfi-64))
67 (define marionette
68 (make-marionette (list #$vm)))
69 (mkdir #$output)
70 (chdir #$output)
71 (test-begin "loadable-kernel-modules")
72 (test-assert "script successfully evaluated"
73 (marionette-eval
74 '(primitive-load #$script)
75 marionette))
76 (test-end)
77 (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
78 (gexp->derivation "loadable-kernel-modules" (test (module-loader-program os module-names))))
79
80(define %test-loadable-kernel-modules-0
81 (system-test
82 (name "loadable-kernel-modules-0")
83 (description "Tests loadable kernel modules facility of <operating-system>
84with no extra modules.")
85 (value (run-loadable-kernel-modules-test '() '()))))
86
87(define %test-loadable-kernel-modules-1
88 (system-test
89 (name "loadable-kernel-modules-1")
90 (description "Tests loadable kernel modules facility of <operating-system>
91with one extra module.")
92 (value (run-loadable-kernel-modules-test
93 (list ddcci-driver-linux)
94 '("ddcci")))))
95
96(define %test-loadable-kernel-modules-2
97 (system-test
98 (name "loadable-kernel-modules-2")
99 (description "Tests loadable kernel modules facility of <operating-system>
100with two extra modules.")
101 (value (run-loadable-kernel-modules-test
102 (list acpi-call-linux-module ddcci-driver-linux)
103 '("acpi_call" "ddcci")))))