diff options
| author | Giacomo Leidi <therewasa@fishinthecalculator.me> | 2026-02-10 21:12:16 +0100 |
|---|---|---|
| committer | Giacomo Leidi <therewasa@fishinthecalculator.me> | 2026-03-07 22:28:01 +0100 |
| commit | fbe8f6d7651985e878ca5d69e2847c06611f7160 (patch) | |
| tree | faf17659e4045ac6d082695f2e9b1761b584fa1f /gnu | |
| parent | fd6b17bf20dc0cec2b4edff2928f899ebd2741cc (diff) | |
tests: Add tuned-service-type tests.
* gnu/tests/linux.scm (%test-tuned): New system test.
* gnu/local.mk: Add it.
Change-Id: Ia257dd5f33c8f9a1eea395b462aee28e16b5e316
Diffstat (limited to 'gnu')
| -rw-r--r-- | gnu/local.mk | 1 | ||||
| -rw-r--r-- | gnu/tests/linux.scm | 211 |
2 files changed, 212 insertions, 0 deletions
diff --git a/gnu/local.mk b/gnu/local.mk index 0fbbdc48855..3ceaae9caf6 100644 --- a/gnu/local.mk +++ b/gnu/local.mk | |||
| @@ -872,6 +872,7 @@ GNU_SYSTEM_MODULES = \ | |||
| 872 | %D%/tests/install.scm \ | 872 | %D%/tests/install.scm \ |
| 873 | %D%/tests/ldap.scm \ | 873 | %D%/tests/ldap.scm \ |
| 874 | %D%/tests/lightdm.scm \ | 874 | %D%/tests/lightdm.scm \ |
| 875 | %D%/tests/linux.scm \ | ||
| 875 | %D%/tests/linux-modules.scm \ | 876 | %D%/tests/linux-modules.scm \ |
| 876 | %D%/tests/mail.scm \ | 877 | %D%/tests/mail.scm \ |
| 877 | %D%/tests/mcron.scm \ | 878 | %D%/tests/mcron.scm \ |
diff --git a/gnu/tests/linux.scm b/gnu/tests/linux.scm new file mode 100644 index 00000000000..b1862ff8ce5 --- /dev/null +++ b/gnu/tests/linux.scm | |||
| @@ -0,0 +1,211 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | ||
| 2 | ;;; Copyright © 2026 Giacomo Leidi <therewasa@fishinthecalculator.me> | ||
| 3 | ;;; | ||
| 4 | ;;; This file is part of GNU Guix. | ||
| 5 | ;;; | ||
| 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | ||
| 7 | ;;; under the terms of the GNU General Public License as published by | ||
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | ||
| 9 | ;;; your option) any later version. | ||
| 10 | ;;; | ||
| 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | ||
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | ;;; GNU General Public License for more details. | ||
| 15 | ;;; | ||
| 16 | ;;; You should have received a copy of the GNU General Public License | ||
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | ||
| 18 | |||
| 19 | (define-module (gnu tests linux) | ||
| 20 | #:use-module (gnu packages linux) | ||
| 21 | #:use-module (gnu services) | ||
| 22 | #:use-module (gnu services linux) | ||
| 23 | #:use-module (gnu services networking) | ||
| 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-tuned)) | ||
| 35 | |||
| 36 | (define %tuned-os | ||
| 37 | (simple-operating-system | ||
| 38 | (service dhcpcd-service-type) | ||
| 39 | (service tuned-service-type | ||
| 40 | (tuned-configuration | ||
| 41 | (power-profiles-daemon-support? #t))))) | ||
| 42 | |||
| 43 | (define (run-tuned-service-test) | ||
| 44 | (define os | ||
| 45 | (marionette-operating-system | ||
| 46 | (operating-system-with-gc-roots | ||
| 47 | %tuned-os | ||
| 48 | (list)) | ||
| 49 | #:imported-modules '((gnu build dbus-service) | ||
| 50 | (gnu services herd) | ||
| 51 | (guix combinators)))) | ||
| 52 | |||
| 53 | (define vm | ||
| 54 | (virtual-machine | ||
| 55 | (operating-system os) | ||
| 56 | (volatile? #f) | ||
| 57 | (memory-size 1024) | ||
| 58 | (disk-image-size (* 5000 (expt 2 20))) | ||
| 59 | (port-forwardings '()))) | ||
| 60 | |||
| 61 | (define test | ||
| 62 | (with-imported-modules '((gnu build dbus-service) | ||
| 63 | (gnu build marionette)) | ||
| 64 | #~(begin | ||
| 65 | (use-modules (srfi srfi-1) (srfi srfi-11) (srfi srfi-64) | ||
| 66 | (gnu build dbus-service) | ||
| 67 | (gnu build marionette)) | ||
| 68 | |||
| 69 | (define marionette | ||
| 70 | ;; Relax timeout to accommodate older systems and | ||
| 71 | ;; allow for pulling the image. | ||
| 72 | (make-marionette (list #$vm) #:timeout 60)) | ||
| 73 | |||
| 74 | (test-runner-current (system-test-runner #$output)) | ||
| 75 | (test-begin "tuned-service") | ||
| 76 | |||
| 77 | (marionette-eval | ||
| 78 | '(begin | ||
| 79 | (use-modules (gnu services herd)) | ||
| 80 | (wait-for-service 'user-processes)) | ||
| 81 | marionette) | ||
| 82 | |||
| 83 | (test-assert "tuned running" | ||
| 84 | (marionette-eval | ||
| 85 | '(begin | ||
| 86 | (use-modules (gnu services herd)) | ||
| 87 | (wait-for-service 'tuned)) | ||
| 88 | marionette)) | ||
| 89 | |||
| 90 | (test-assert "/etc/tuned/tuned-main.conf exists" | ||
| 91 | (wait-for-file "/etc/tuned/tuned-main.conf" marionette)) | ||
| 92 | |||
| 93 | (test-equal "/etc/tuned/tuned-main.conf is well formed" | ||
| 94 | '("daemon=true" | ||
| 95 | "dynamic_tuning=false" | ||
| 96 | "default_instance_priority=0" | ||
| 97 | "recommend_command=true" | ||
| 98 | "sleep_interval=1" | ||
| 99 | "update_interval=10") | ||
| 100 | (marionette-eval | ||
| 101 | '(begin | ||
| 102 | (use-modules (srfi srfi-1) | ||
| 103 | (srfi srfi-26) | ||
| 104 | (ice-9 textual-ports)) | ||
| 105 | ;; The profile_dirs field may contain store paths, | ||
| 106 | ;; so we check only the first 7 fields and exclude the last. | ||
| 107 | (take | ||
| 108 | (filter | ||
| 109 | (compose not | ||
| 110 | (cut string=? "" <>)) | ||
| 111 | (string-split | ||
| 112 | (call-with-input-file "/etc/tuned/tuned-main.conf" | ||
| 113 | get-string-all) | ||
| 114 | #\newline)) | ||
| 115 | 6)) | ||
| 116 | marionette)) | ||
| 117 | |||
| 118 | (test-assert "tuned-ppd running" | ||
| 119 | (marionette-eval | ||
| 120 | '(begin | ||
| 121 | (use-modules (gnu services herd)) | ||
| 122 | (wait-for-service 'tuned-ppd)) | ||
| 123 | marionette)) | ||
| 124 | |||
| 125 | (test-assert "/etc/tuned/ppd.conf exists" | ||
| 126 | (wait-for-file "/etc/tuned/ppd.conf" marionette)) | ||
| 127 | |||
| 128 | (test-equal "/etc/tuned/ppd.conf is well formed" | ||
| 129 | '("[main]" | ||
| 130 | "default=balanced" | ||
| 131 | "battery_detection=true" | ||
| 132 | "sysfs_acpi_monitor=true" | ||
| 133 | |||
| 134 | "[profiles]" | ||
| 135 | "power-saver=powersave" | ||
| 136 | "balanced=balanced" | ||
| 137 | "performance=throughput-performance" | ||
| 138 | |||
| 139 | "[battery]" | ||
| 140 | "balanced=balanced-battery") | ||
| 141 | (marionette-eval | ||
| 142 | '(begin | ||
| 143 | (use-modules (srfi srfi-26) | ||
| 144 | (ice-9 textual-ports)) | ||
| 145 | ;; The profile_dirs field may contain store paths, | ||
| 146 | ;; so we check only the first 7 fields and exclude the last. | ||
| 147 | (filter | ||
| 148 | (compose not | ||
| 149 | (cut string=? "" <>)) | ||
| 150 | (string-split | ||
| 151 | (call-with-input-file "/etc/tuned/ppd.conf" | ||
| 152 | get-string-all) | ||
| 153 | #\newline))) | ||
| 154 | marionette)) | ||
| 155 | |||
| 156 | (test-assert "get tuned profile" | ||
| 157 | (begin | ||
| 158 | (define (run-test) | ||
| 159 | (marionette-eval | ||
| 160 | `(begin | ||
| 161 | (use-modules (ice-9 popen) | ||
| 162 | (ice-9 textual-ports)) | ||
| 163 | (define slurp | ||
| 164 | (lambda args | ||
| 165 | (let* ((port | ||
| 166 | (apply open-pipe* OPEN_READ | ||
| 167 | (list "sh" "-l" "-c" | ||
| 168 | (string-join args " ")))) | ||
| 169 | (output (get-string-all port)) | ||
| 170 | (status (close-pipe port))) | ||
| 171 | output))) | ||
| 172 | (slurp "tuned-adm" "active")) | ||
| 173 | marionette)) | ||
| 174 | ;; Allow services to come up on slower machines. | ||
| 175 | (with-retries | ||
| 176 | 80 1 | ||
| 177 | (string=? "Current active profile: balanced\n" (run-test))))) | ||
| 178 | |||
| 179 | (test-assert "set tuned profile" | ||
| 180 | (begin | ||
| 181 | (define (run-test) | ||
| 182 | (marionette-eval | ||
| 183 | `(begin | ||
| 184 | (use-modules (ice-9 popen) | ||
| 185 | (ice-9 textual-ports)) | ||
| 186 | (define slurp | ||
| 187 | (lambda args | ||
| 188 | (let* ((port | ||
| 189 | (apply open-pipe* OPEN_READ | ||
| 190 | (list "sh" "-l" "-c" | ||
| 191 | (string-join args " ")))) | ||
| 192 | (output (get-string-all port)) | ||
| 193 | (status (close-pipe port))) | ||
| 194 | output))) | ||
| 195 | (slurp "tuned-adm" "profile" "powersave") | ||
| 196 | (slurp "tuned-adm" "active")) | ||
| 197 | marionette)) | ||
| 198 | ;; Allow services to come up on slower machines. | ||
| 199 | (with-retries | ||
| 200 | 80 1 | ||
| 201 | (string=? "Current active profile: powersave\n" (run-test))))) | ||
| 202 | |||
| 203 | (test-end)))) | ||
| 204 | |||
| 205 | (gexp->derivation "tuned-service-test" test)) | ||
| 206 | |||
| 207 | (define %test-tuned | ||
| 208 | (system-test | ||
| 209 | (name "tuned") | ||
| 210 | (description "Test TuneD service.") | ||
| 211 | (value (run-tuned-service-test)))) | ||
