services: Add zram-device-service.
[jackhill/guix/guix.git] / tests / services / linux.scm
CommitLineData
d3e439e3
MC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com>
587e0d91 3;;; Copyright © 2020 Efraim Flashner <efraim@flashner.co.il>
d3e439e3
MC
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 (tests services linux)
21 #:use-module (ice-9 match)
22 #:use-module (gnu packages linux)
23 #:use-module (gnu services linux)
24 #:use-module (guix gexp)
25 #:use-module (srfi srfi-64))
26
27;;; Tests for the (gnu services linux) module.
28
29(test-begin "linux-services")
30
31\f
32;;;
33;;; Early OOM daemon.
34;;;
35
36(define earlyoom-configuration->command-line-args
37 (@@ (gnu services linux) earlyoom-configuration->command-line-args))
38
39(define %earlyoom-configuration-sample
40 (earlyoom-configuration
41 (minimum-available-memory 10)
42 (minimum-free-swap 20)
43 (prefer-regexp "icecat")
44 (avoid-regexp "guix-daemon")
45 (memory-report-interval 60)
46 (ignore-positive-oom-score-adj? #f)
47 (run-with-higher-priority? #t)
48 (show-debug-messages? #f)
49 (send-notification-command "python \"/some/path/notify-all-users.py\"")))
50
51(test-equal "earlyoom-configuration->command-line-args"
52 (list (file-append earlyoom "/bin/earlyoom")
53 "-m" "10" "-s" "20" "--prefer" "icecat"
54 "--avoid" "guix-daemon" "-r" "60" "-p"
55 "-N" "python \"/some/path/notify-all-users.py\"")
56 (earlyoom-configuration->command-line-args %earlyoom-configuration-sample))
57
587e0d91
EF
58\f
59;;;
60;;; Zram swap device.
61;;;
62
63(define zram-device-configuration->udev-string
64 (@@ (gnu services linux) zram-device-configuration->udev-string))
65
66(define %zram-swap-device-test-1
67 (zram-device-configuration
68 (size "2G")
69 (compression-algorithm 'zstd)
70 (memory-limit "1G")
71 (priority 42)))
72
73(test-equal "zram-swap-device-test-1"
74 "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"
75 (zram-device-configuration->udev-string %zram-swap-device-test-1))
76
77(define %zram-swap-device-test-2
78 (zram-device-configuration
79 (size 1048576) ; 1M
80 (compression-algorithm 'lz4)))
81
82(test-equal "zram-swap-device-test-2"
83 "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"
84 (zram-device-configuration->udev-string %zram-swap-device-test-2))
85
86(define %zram-swap-device-test-3
87 (zram-device-configuration
88 (memory-limit (* 512 1000))))
89
90(test-equal "zram-swap-device-test-3"
91 "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"
92 (zram-device-configuration->udev-string %zram-swap-device-test-3))
93
d3e439e3 94(test-end "linux-services")