summaryrefslogtreecommitdiff
path: root/gnu/tests
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2025-02-27 11:51:49 +0100
committerLudovic Courtès <ludo@gnu.org>2025-03-10 15:41:33 +0100
commit9e07d889c4ebf80502661801ca7a9fb35f892158 (patch)
tree29304e3e1bfe586e585b25b1dae5232cc88560cc /gnu/tests
parent75e3d342950493d882577e619ee1930b6ed61e21 (diff)
tests: Add ‘guix-daemon’ test.
* gnu/tests/base.scm (manifest-entry-without-grafts): New procedure. (%hello-dependencies-manifest): New variable. (run-guix-daemon-test): New procedure. (%test-guix-daemon): New variable. Change-Id: Ia37966de1f61fb428e6fb2244271bf389a74af6d
Diffstat (limited to 'gnu/tests')
-rw-r--r--gnu/tests/base.scm191
1 files changed, 190 insertions, 1 deletions
diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm
index 89e797259dc..38bd1e687fc 100644
--- a/gnu/tests/base.scm
+++ b/gnu/tests/base.scm
@@ -34,6 +34,8 @@
34 #:use-module (gnu services networking) 34 #:use-module (gnu services networking)
35 #:use-module (gnu packages base) 35 #:use-module (gnu packages base)
36 #:use-module (gnu packages bash) 36 #:use-module (gnu packages bash)
37 #:use-module (gnu packages bootstrap)
38 #:use-module (gnu packages guile)
37 #:use-module (gnu packages imagemagick) 39 #:use-module (gnu packages imagemagick)
38 #:use-module (gnu packages linux) 40 #:use-module (gnu packages linux)
39 #:use-module (gnu packages ocr) 41 #:use-module (gnu packages ocr)
@@ -45,6 +47,7 @@
45 #:use-module (guix monads) 47 #:use-module (guix monads)
46 #:use-module (guix modules) 48 #:use-module (guix modules)
47 #:use-module (guix packages) 49 #:use-module (guix packages)
50 #:use-module (guix profiles)
48 #:use-module (guix utils) 51 #:use-module (guix utils)
49 #:use-module ((srfi srfi-1) #:hide (partition)) 52 #:use-module ((srfi srfi-1) #:hide (partition))
50 #:use-module (ice-9 match) 53 #:use-module (ice-9 match)
@@ -56,7 +59,8 @@
56 %test-halt 59 %test-halt
57 %test-root-unmount 60 %test-root-unmount
58 %test-cleanup 61 %test-cleanup
59 %test-activation)) 62 %test-activation
63 %test-guix-daemon))
60 64
61(define %simple-os 65(define %simple-os
62 (simple-operating-system)) 66 (simple-operating-system))
@@ -981,3 +985,188 @@ non-ASCII names from /tmp.")
981 (name "activation") 985 (name "activation")
982 (description "Test that activation scripts are run in the correct order") 986 (description "Test that activation scripts are run in the correct order")
983 (value (run-activation-test name)))) 987 (value (run-activation-test name))))
988
989
990;;;
991;;; Build daemon.
992;;;
993
994(define (manifest-entry-without-grafts entry)
995 "Return ENTRY with grafts disabled on its contents."
996 (manifest-entry
997 (inherit entry)
998 (item (with-parameters ((%graft? #f))
999 (manifest-entry-item entry)))))
1000
1001(define %hello-dependencies-manifest ;TODO: Share with (gnu tests foreign).
1002 ;; Build dependencies of 'hello' needed to test 'guix build hello'.
1003 (concatenate-manifests
1004 (list (map-manifest-entries
1005 manifest-entry-without-grafts
1006 (package->development-manifest hello))
1007
1008 ;; Add the source of 'hello'.
1009 (manifest
1010 (list (manifest-entry
1011 (name "hello-source")
1012 (version (package-version hello))
1013 (item (let ((file (origin-actual-file-name
1014 (package-source hello))))
1015 (computed-file
1016 "hello-source"
1017 #~(begin
1018 ;; Put the tarball in a subdirectory since
1019 ;; profile union crashes otherwise.
1020 (mkdir #$output)
1021 (mkdir (in-vicinity #$output "src"))
1022 (symlink #$(package-source hello)
1023 (in-vicinity #$output
1024 (string-append "src/"
1025 #$file))))))))))
1026
1027 ;; Include 'guile-final', which is needed when building derivations
1028 ;; such as that of 'hello' but missing from the development manifest.
1029 ;; Add '%bootstrap-guile', used by 'guix install --bootstrap'.
1030 (map-manifest-entries
1031 manifest-entry-without-grafts
1032 (packages->manifest (list (canonical-package guile-3.0)
1033 %bootstrap-guile))))))
1034
1035(define (run-guix-daemon-test os)
1036 (define test-image
1037 (image (operating-system os)
1038 (format 'compressed-qcow2)
1039 (volatile-root? #f)
1040 (shared-store? #f)
1041 (partition-table-type 'mbr)
1042 (partitions
1043 (list (partition
1044 (size (* 4 (expt 2 30)))
1045 (offset (* 512 2048)) ;leave room for GRUB
1046 (flags '(boot))
1047 (label "root"))))))
1048
1049 (define test
1050 (with-imported-modules (source-module-closure
1051 '((gnu build marionette)
1052 (guix build utils)))
1053 #~(begin
1054 (use-modules (gnu build marionette)
1055 (guix build utils)
1056 (srfi srfi-64))
1057
1058 (define marionette
1059 (make-marionette
1060 (list (string-append #$qemu-minimal "/bin/" (qemu-command))
1061 #$@(common-qemu-options (system-image test-image) '()
1062 #:image-format "qcow2"
1063 #:rw-image? #t)
1064 "-m" "512"
1065 "-nographic" "-serial" "stdio"
1066 "-snapshot")))
1067
1068 (test-runner-current (system-test-runner #$output))
1069 (test-begin "guix-daemon")
1070
1071 (test-equal "guix describe"
1072 0
1073 (marionette-eval '(system* "guix" "describe")
1074 marionette))
1075
1076 ;; XXX: What follows is largely copied form (gnu tests foreign).
1077
1078 (test-equal "hello not already built"
1079 #f
1080 ;; Check that the next test will really build 'hello'.
1081 (marionette-eval '(file-exists?
1082 #$(with-parameters ((%graft? #f))
1083 hello))
1084 marionette))
1085
1086 (test-equal "guix build hello"
1087 0
1088 ;; Check that guix-daemon is up and running and that the build
1089 ;; environment is properly set up (build users, etc.).
1090 (marionette-eval '(system* "guix" "build" "hello" "--no-grafts")
1091 marionette))
1092
1093 (test-assert "hello indeed built"
1094 (marionette-eval '(file-exists?
1095 #$(with-parameters ((%graft? #f))
1096 hello))
1097 marionette))
1098
1099 (test-equal "guix install hello"
1100 0
1101 ;; Check that ~/.guix-profile & co. are properly created.
1102 (marionette-eval '(let ((pw (getpwuid (getuid))))
1103 (setenv "USER" (passwd:name pw))
1104 (setenv "HOME" (pk 'home (passwd:dir pw)))
1105 (system* "guix" "install" "hello"
1106 "--no-grafts" "--bootstrap"))
1107 marionette))
1108
1109 (test-equal "user profile created"
1110 0
1111 (marionette-eval '(system "ls -lad ~/.guix-profile")
1112 marionette))
1113
1114 (test-equal "hello"
1115 0
1116 (marionette-eval '(system "~/.guix-profile/bin/hello")
1117 marionette))
1118
1119 (test-equal "guix install hello, unprivileged user"
1120 0
1121 ;; Check that 'guix' is in $PATH for new users and that
1122 ;; ~user/.guix-profile also gets created.
1123 (marionette-eval '(system "su - user -c \
1124'guix install hello --no-grafts --bootstrap'")
1125 marionette))
1126
1127 (test-equal "user hello"
1128 0
1129 (marionette-eval '(system "~user/.guix-profile/bin/hello")
1130 marionette))
1131
1132 (test-equal "unprivileged user profile created"
1133 0
1134 (marionette-eval '(system "ls -lad ~user/.guix-profile")
1135 marionette))
1136
1137 (test-equal "store is read-only"
1138 EROFS
1139 (marionette-eval '(catch 'system-error
1140 (lambda ()
1141 (mkdir (in-vicinity #$(%store-prefix)
1142 "whatever"))
1143 0)
1144 (lambda args
1145 (system-error-errno args)))
1146 marionette))
1147
1148 (test-end))))
1149
1150 (gexp->derivation "guix-daemon-test" test))
1151
1152(define %test-guix-daemon
1153 (system-test
1154 (name "guix-daemon")
1155 (description
1156 "Test 'guix-daemon' behavior on a multi-user system.")
1157 (value
1158 (let ((os (marionette-operating-system
1159 (operating-system
1160 (inherit (operating-system-with-gc-roots
1161 %simple-os
1162 (list (profile
1163 (name "hello-build-dependencies")
1164 (content %hello-dependencies-manifest)))))
1165 (kernel-arguments '("console=ttyS0"))
1166 (users (cons (user-account
1167 (name "user")
1168 (group "users"))
1169 %base-user-accounts)))
1170 #:imported-modules '((gnu services herd)
1171 (guix combinators)))))
1172 (run-guix-daemon-test os)))))