linux-modules.scm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 Brice Waegeneire <brice@waegenei.re>
  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. (define-module (gnu tests linux-modules)
  21. #:use-module (gnu packages linux)
  22. #:use-module (gnu services)
  23. #:use-module (gnu services linux)
  24. #:use-module (gnu system)
  25. #:use-module (gnu system vm)
  26. #:use-module (gnu tests)
  27. #:use-module (guix derivations)
  28. #:use-module (guix gexp)
  29. #:use-module (guix modules)
  30. #:use-module (guix packages)
  31. #:use-module (guix monads)
  32. #:use-module (guix store)
  33. #:use-module (guix utils)
  34. #:export (%test-loadable-kernel-modules-0
  35. %test-loadable-kernel-modules-1
  36. %test-loadable-kernel-modules-2))
  37. ;;; Commentary:
  38. ;;;
  39. ;;; Test <operating-system> kernel-loadable-modules.
  40. ;;;
  41. ;;; Code:
  42. (define* (modules-loaded?-program os modules)
  43. "Return an executable store item that, upon being evaluated, will verify
  44. that MODULES are actually loaded."
  45. (program-file
  46. "verify-kernel-modules-loaded.scm"
  47. #~(begin
  48. (use-modules (ice-9 rdelim)
  49. (ice-9 popen)
  50. (srfi srfi-1)
  51. (srfi srfi-13))
  52. (let* ((port (open-input-pipe (string-append #$kmod "/bin/lsmod")))
  53. (lines (string-split (read-string port) #\newline))
  54. (separators (char-set #\space #\tab))
  55. (modules (map (lambda (line)
  56. (string-take line
  57. (or (string-index line separators)
  58. 0)))
  59. lines))
  60. (status (close-pipe port)))
  61. (and (= status 0)
  62. (and-map (lambda (module)
  63. (member module modules string=?))
  64. '#$modules))))))
  65. (define* (run-loadable-kernel-modules-test module-packages module-names)
  66. "Run a test of an OS having MODULE-PACKAGES, and verify that MODULE-NAMES
  67. are loaded in memory."
  68. (define os
  69. (marionette-operating-system
  70. (operating-system
  71. (inherit (simple-operating-system))
  72. (services (cons (service kernel-module-loader-service-type module-names)
  73. (operating-system-user-services
  74. (simple-operating-system))))
  75. (kernel-loadable-modules module-packages))
  76. #:imported-modules '((guix combinators))))
  77. (define vm (virtual-machine os))
  78. (define (test script)
  79. (with-imported-modules '((gnu build marionette))
  80. #~(begin
  81. (use-modules (gnu build marionette)
  82. (srfi srfi-64))
  83. (define marionette
  84. (make-marionette (list #$vm)))
  85. (mkdir #$output)
  86. (chdir #$output)
  87. (test-begin "loadable-kernel-modules")
  88. (test-assert "script successfully evaluated"
  89. (marionette-eval
  90. '(primitive-load #$script)
  91. marionette))
  92. (test-end)
  93. (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
  94. (gexp->derivation "loadable-kernel-modules"
  95. (test (modules-loaded?-program os module-names))))
  96. (define %test-loadable-kernel-modules-0
  97. (system-test
  98. (name "loadable-kernel-modules-0")
  99. (description "Tests loadable kernel modules facility of <operating-system>
  100. with no extra modules.")
  101. (value (run-loadable-kernel-modules-test '() '()))))
  102. (define %test-loadable-kernel-modules-1
  103. (system-test
  104. (name "loadable-kernel-modules-1")
  105. (description "Tests loadable kernel modules facility of <operating-system>
  106. with one extra module.")
  107. (value (run-loadable-kernel-modules-test
  108. (list ddcci-driver-linux)
  109. '("ddcci")))))
  110. (define %test-loadable-kernel-modules-2
  111. (system-test
  112. (name "loadable-kernel-modules-2")
  113. (description "Tests loadable kernel modules facility of <operating-system>
  114. with two extra modules.")
  115. (value (run-loadable-kernel-modules-test
  116. (list acpi-call-linux-module
  117. (package
  118. (inherit ddcci-driver-linux)
  119. (arguments
  120. `(#:linux #f
  121. ,@(strip-keyword-arguments '(#:linux)
  122. (package-arguments
  123. ddcci-driver-linux))))))
  124. '("acpi_call" "ddcci")))))