linux-modules.scm 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. ;;; Copyright © 2020, 2021 Brice Waegeneire <brice@waegenei.re>
  5. ;;; Copyright © 2021 raid5atemyhomework <raid5atemyhomework@protonmail.com>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (gnu tests linux-modules)
  22. #:use-module (gnu packages linux)
  23. #:use-module (gnu services)
  24. #:use-module (gnu services linux)
  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 packages)
  32. #:use-module (guix monads)
  33. #:use-module (guix store)
  34. #:use-module (guix utils)
  35. #:export (%test-loadable-kernel-modules-0
  36. %test-loadable-kernel-modules-1
  37. %test-loadable-kernel-modules-2
  38. %test-loadable-kernel-modules-service-0
  39. %test-loadable-kernel-modules-service-1
  40. %test-loadable-kernel-modules-service-2))
  41. ;;; Commentary:
  42. ;;;
  43. ;;; Test <operating-system> kernel-loadable-modules.
  44. ;;;
  45. ;;; Code:
  46. (define* (modules-loaded?-program os modules)
  47. "Return an executable store item that, upon being evaluated, will verify
  48. that MODULES are actually loaded."
  49. (program-file
  50. "verify-kernel-modules-loaded.scm"
  51. #~(begin
  52. (use-modules (ice-9 rdelim)
  53. (ice-9 popen)
  54. (srfi srfi-1)
  55. (srfi srfi-13))
  56. (let* ((port (open-input-pipe (string-append #$kmod "/bin/lsmod")))
  57. (lines (string-split (read-string port) #\newline))
  58. (separators (char-set #\space #\tab))
  59. (modules (map (lambda (line)
  60. (string-take line
  61. (or (string-index line separators)
  62. 0)))
  63. lines))
  64. (status (close-pipe port)))
  65. (and (= status 0)
  66. (and-map (lambda (module)
  67. (member module modules string=?))
  68. '#$modules))))))
  69. (define* (run-loadable-kernel-modules-test-base base-os module-names)
  70. "Run a test of BASE-OS, verifying that MODULE-NAMES are loaded in memory."
  71. (define os
  72. (marionette-operating-system
  73. base-os
  74. #:imported-modules '((guix combinators))))
  75. (define vm (virtual-machine os))
  76. (define (test script)
  77. (with-imported-modules '((gnu build marionette))
  78. #~(begin
  79. (use-modules (gnu build marionette)
  80. (srfi srfi-64))
  81. (define marionette
  82. (make-marionette (list #$vm)))
  83. (mkdir #$output)
  84. (chdir #$output)
  85. (test-begin "loadable-kernel-modules")
  86. (test-assert "script successfully evaluated"
  87. (marionette-eval
  88. '(primitive-load #$script)
  89. marionette))
  90. (test-end)
  91. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  92. (gexp->derivation "loadable-kernel-modules"
  93. (test (modules-loaded?-program os module-names))))
  94. (define* (run-loadable-kernel-modules-test module-packages module-names)
  95. "Run a test of an OS having MODULE-PACKAGES, and verify that MODULE-NAMES
  96. are loaded in memory."
  97. (run-loadable-kernel-modules-test-base
  98. (operating-system
  99. (inherit (simple-operating-system))
  100. (services (cons (service kernel-module-loader-service-type module-names)
  101. (operating-system-user-services
  102. (simple-operating-system))))
  103. (kernel-loadable-modules module-packages))
  104. module-names))
  105. (define* (run-loadable-kernel-modules-service-test module-packages module-names)
  106. "Run a test of an OS having MODULE-PACKAGES, which are loaded by creating a
  107. service that extends LINUXL-LOADABLE-MODULE-SERVICE-TYPE. Then verify that
  108. MODULE-NAMES are loaded in memory."
  109. (run-loadable-kernel-modules-test-base
  110. (operating-system
  111. (inherit (simple-operating-system))
  112. (services (cons* (simple-service 'installing-module
  113. linux-loadable-module-service-type
  114. module-packages)
  115. (service kernel-module-loader-service-type module-names)
  116. (operating-system-user-services
  117. (simple-operating-system)))))
  118. module-names))
  119. (define %test-loadable-kernel-modules-0
  120. (system-test
  121. (name "loadable-kernel-modules-0")
  122. (description "Tests loadable kernel modules facility of <operating-system>
  123. with no extra modules.")
  124. (value (run-loadable-kernel-modules-test '() '()))))
  125. (define %test-loadable-kernel-modules-1
  126. (system-test
  127. (name "loadable-kernel-modules-1")
  128. (description "Tests loadable kernel modules facility of <operating-system>
  129. with one extra module.")
  130. (value (run-loadable-kernel-modules-test
  131. (list ddcci-driver-linux)
  132. '("ddcci")))))
  133. (define %test-loadable-kernel-modules-2
  134. (system-test
  135. (name "loadable-kernel-modules-2")
  136. (description "Tests loadable kernel modules facility of <operating-system>
  137. with two extra modules.")
  138. (value (run-loadable-kernel-modules-test
  139. (list acpi-call-linux-module
  140. (package
  141. (inherit ddcci-driver-linux)
  142. (arguments
  143. `(#:linux #f
  144. ,@(strip-keyword-arguments '(#:linux)
  145. (package-arguments
  146. ddcci-driver-linux))))))
  147. '("acpi_call" "ddcci")))))
  148. (define %test-loadable-kernel-modules-service-0
  149. (system-test
  150. (name "loadable-kernel-modules-service-0")
  151. (description "Tests loadable kernel modules extensible service with no
  152. extra modules.")
  153. (value (run-loadable-kernel-modules-service-test '() '()))))
  154. (define %test-loadable-kernel-modules-service-1
  155. (system-test
  156. (name "loadable-kernel-modules-service-1")
  157. (description "Tests loadable kernel modules extensible service with one
  158. extra module.")
  159. (value (run-loadable-kernel-modules-service-test
  160. (list ddcci-driver-linux)
  161. '("ddcci")))))
  162. (define %test-loadable-kernel-modules-service-2
  163. (system-test
  164. (name "loadable-kernel-modules-service-2")
  165. (description "Tests loadable kernel modules extensible service with two
  166. extra modules.")
  167. (value (run-loadable-kernel-modules-service-test
  168. (list acpi-call-linux-module
  169. (package
  170. (inherit ddcci-driver-linux)
  171. (arguments
  172. `(#:linux #f
  173. ,@(strip-keyword-arguments '(#:linux)
  174. (package-arguments
  175. ddcci-driver-linux))))))
  176. '("acpi_call" "ddcci")))))