linux-modules.scm 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. (test-runner-current (system-test-runner #$output))
  84. (test-begin "loadable-kernel-modules")
  85. (test-assert "script successfully evaluated"
  86. (marionette-eval
  87. '(primitive-load #$script)
  88. marionette))
  89. (test-end))))
  90. (gexp->derivation "loadable-kernel-modules"
  91. (test (modules-loaded?-program os module-names))))
  92. (define* (run-loadable-kernel-modules-test module-packages module-names)
  93. "Run a test of an OS having MODULE-PACKAGES, and verify that MODULE-NAMES
  94. are loaded in memory."
  95. (run-loadable-kernel-modules-test-base
  96. (operating-system
  97. (inherit (simple-operating-system))
  98. (services (cons (service kernel-module-loader-service-type module-names)
  99. (operating-system-user-services
  100. (simple-operating-system))))
  101. (kernel-loadable-modules module-packages))
  102. module-names))
  103. (define* (run-loadable-kernel-modules-service-test module-packages module-names)
  104. "Run a test of an OS having MODULE-PACKAGES, which are loaded by creating a
  105. service that extends LINUXL-LOADABLE-MODULE-SERVICE-TYPE. Then verify that
  106. MODULE-NAMES are loaded in memory."
  107. (run-loadable-kernel-modules-test-base
  108. (operating-system
  109. (inherit (simple-operating-system))
  110. (services (cons* (simple-service 'installing-module
  111. linux-loadable-module-service-type
  112. module-packages)
  113. (service kernel-module-loader-service-type module-names)
  114. (operating-system-user-services
  115. (simple-operating-system)))))
  116. module-names))
  117. (define %test-loadable-kernel-modules-0
  118. (system-test
  119. (name "loadable-kernel-modules-0")
  120. (description "Tests loadable kernel modules facility of <operating-system>
  121. with no extra modules.")
  122. (value (run-loadable-kernel-modules-test '() '()))))
  123. (define %test-loadable-kernel-modules-1
  124. (system-test
  125. (name "loadable-kernel-modules-1")
  126. (description "Tests loadable kernel modules facility of <operating-system>
  127. with one extra module.")
  128. (value (run-loadable-kernel-modules-test
  129. (list ddcci-driver-linux)
  130. '("ddcci")))))
  131. (define %test-loadable-kernel-modules-2
  132. (system-test
  133. (name "loadable-kernel-modules-2")
  134. (description "Tests loadable kernel modules facility of <operating-system>
  135. with two extra modules.")
  136. (value (run-loadable-kernel-modules-test
  137. (list acpi-call-linux-module
  138. (package
  139. (inherit ddcci-driver-linux)
  140. (arguments
  141. `(#:linux #f
  142. ,@(strip-keyword-arguments '(#:linux)
  143. (package-arguments
  144. ddcci-driver-linux))))))
  145. '("acpi_call" "ddcci")))))
  146. (define %test-loadable-kernel-modules-service-0
  147. (system-test
  148. (name "loadable-kernel-modules-service-0")
  149. (description "Tests loadable kernel modules extensible service with no
  150. extra modules.")
  151. (value (run-loadable-kernel-modules-service-test '() '()))))
  152. (define %test-loadable-kernel-modules-service-1
  153. (system-test
  154. (name "loadable-kernel-modules-service-1")
  155. (description "Tests loadable kernel modules extensible service with one
  156. extra module.")
  157. (value (run-loadable-kernel-modules-service-test
  158. (list ddcci-driver-linux)
  159. '("ddcci")))))
  160. (define %test-loadable-kernel-modules-service-2
  161. (system-test
  162. (name "loadable-kernel-modules-service-2")
  163. (description "Tests loadable kernel modules extensible service with two
  164. extra modules.")
  165. (value (run-loadable-kernel-modules-service-test
  166. (list acpi-call-linux-module
  167. (package
  168. (inherit ddcci-driver-linux)
  169. (arguments
  170. `(#:linux #f
  171. ,@(strip-keyword-arguments '(#:linux)
  172. (package-arguments
  173. ddcci-driver-linux))))))
  174. '("acpi_call" "ddcci")))))