linux.scm 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
  3. ;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
  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. (define-module (tests services linux)
  20. #:use-module (ice-9 match)
  21. #:use-module (gnu packages linux)
  22. #:use-module (gnu services linux)
  23. #:use-module (guix gexp)
  24. #:use-module (srfi srfi-64))
  25. ;;; Tests for the (gnu services linux) module.
  26. (test-begin "linux-services")
  27. ;;;
  28. ;;; Early OOM daemon.
  29. ;;;
  30. (define earlyoom-configuration->command-line-args
  31. (@@ (gnu services linux) earlyoom-configuration->command-line-args))
  32. (define %earlyoom-configuration-sample
  33. (earlyoom-configuration
  34. (minimum-available-memory 10)
  35. (minimum-free-swap 20)
  36. (prefer-regexp "icecat")
  37. (avoid-regexp "guix-daemon")
  38. (memory-report-interval 60)
  39. (ignore-positive-oom-score-adj? #f)
  40. (run-with-higher-priority? #t)
  41. (show-debug-messages? #f)
  42. (send-notification-command "python \"/some/path/notify-all-users.py\"")))
  43. (test-equal "earlyoom-configuration->command-line-args"
  44. (list (file-append earlyoom "/bin/earlyoom")
  45. "-m" "10" "-s" "20" "--prefer" "icecat"
  46. "--avoid" "guix-daemon" "-r" "60" "-p"
  47. "-N" "python \"/some/path/notify-all-users.py\"")
  48. (earlyoom-configuration->command-line-args %earlyoom-configuration-sample))
  49. ;;;
  50. ;;; Zram swap device.
  51. ;;;
  52. (define zram-device-configuration->udev-string
  53. (@@ (gnu services linux) zram-device-configuration->udev-string))
  54. (define %zram-swap-device-test-1
  55. (zram-device-configuration
  56. (size "2G")
  57. (compression-algorithm 'zstd)
  58. (memory-limit "1G")
  59. (priority 42)))
  60. (test-equal "zram-swap-device-test-1"
  61. "KERNEL==\"zram0\", ATTR{comp_algorithm}=\"zstd\" ATTR{disksize}=\"2G\" ATTR{mem_limit}=\"1G\" RUN+=\"/run/current-system/profile/sbin/mkswap /dev/zram0\" RUN+=\"/run/current-system/profile/sbin/swapon --priority 42 /dev/zram0\"\n"
  62. (zram-device-configuration->udev-string %zram-swap-device-test-1))
  63. (define %zram-swap-device-test-2
  64. (zram-device-configuration
  65. (size 1048576) ; 1M
  66. (compression-algorithm 'lz4)))
  67. (test-equal "zram-swap-device-test-2"
  68. "KERNEL==\"zram0\", ATTR{comp_algorithm}=\"lz4\" ATTR{disksize}=\"1048576\" RUN+=\"/run/current-system/profile/sbin/mkswap /dev/zram0\" RUN+=\"/run/current-system/profile/sbin/swapon /dev/zram0\"\n"
  69. (zram-device-configuration->udev-string %zram-swap-device-test-2))
  70. (define %zram-swap-device-test-3
  71. (zram-device-configuration
  72. (memory-limit (* 512 1000))))
  73. (test-equal "zram-swap-device-test-3"
  74. "KERNEL==\"zram0\", ATTR{comp_algorithm}=\"lzo\" ATTR{disksize}=\"1G\" ATTR{mem_limit}=\"512000\" RUN+=\"/run/current-system/profile/sbin/mkswap /dev/zram0\" RUN+=\"/run/current-system/profile/sbin/swapon /dev/zram0\"\n"
  75. (zram-device-configuration->udev-string %zram-swap-device-test-3))
  76. (test-end "linux-services")