GNU bug report logs - #76636
[PATCH 0/5] Test guix-daemon on Guix System

Previous Next

Package: guix-patches;

Reported by: Ludovic Courtès <ludo <at> gnu.org>

Date: Fri, 28 Feb 2025 09:58:02 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #11 received at 76636 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: 76636 <at> debbugs.gnu.org
Cc: Ludovic Courtès <ludo <at> gnu.org>
Subject: [PATCH 1/5] tests: Move mcron test to its own file.
Date: Fri, 28 Feb 2025 11:04:28 +0100
This mirrors the (gnu services mcron) module.

* gnu/tests/base.scm (%mcron-os, run-mcron-test, %test-mcron): Move to…
* gnu/tests/mcron.scm: … here.  New file.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.

Change-Id: Id2830d08d8e797e008c5fec7964fb5f6a5ea2fad
---
 gnu/local.mk        |   1 +
 gnu/tests/base.scm  |  92 ----------------------------------
 gnu/tests/mcron.scm | 118 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 119 insertions(+), 92 deletions(-)
 create mode 100644 gnu/tests/mcron.scm

diff --git a/gnu/local.mk b/gnu/local.mk
index b5c8c1a4665..4b31f8a4a0b 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -862,6 +862,7 @@ GNU_SYSTEM_MODULES =				\
   %D%/tests/lightdm.scm			\
   %D%/tests/linux-modules.scm			\
   %D%/tests/mail.scm				\
+  %D%/tests/mcron.scm				\
   %D%/tests/messaging.scm			\
   %D%/tests/networking.scm			\
   %D%/tests/package-management.scm		\
diff --git a/gnu/tests/base.scm b/gnu/tests/base.scm
index d9e30e9b1de..c3040002d37 100644
--- a/gnu/tests/base.scm
+++ b/gnu/tests/base.scm
@@ -33,7 +33,6 @@ (define-module (gnu tests base)
   #:use-module (gnu services base)
   #:use-module (gnu services dbus)
   #:use-module (gnu services avahi)
-  #:use-module (gnu services mcron)
   #:use-module (gnu services shepherd)
   #:use-module (gnu services networking)
   #:use-module (gnu packages base)
@@ -60,7 +59,6 @@ (define-module (gnu tests base)
             %test-halt
             %test-root-unmount
             %test-cleanup
-            %test-mcron
             %test-nss-mdns
             %test-activation))
 
@@ -872,96 +870,6 @@ (define %test-cleanup
 non-ASCII names from /tmp.")
    (value (run-cleanup-test name))))
 
-
-;;;
-;;; Mcron.
-;;;
-
-(define %mcron-os
-  ;; System with an mcron service, with one mcron job for "root" and one mcron
-  ;; job for an unprivileged user.
-  (let ((job1 #~(job '(next-second '(0 5 10 15 20 25 30 35 40 45 50 55))
-                     (lambda ()
-                       (unless (file-exists? "witness")
-                        (call-with-output-file "witness"
-                          (lambda (port)
-                            (display (list (getuid) (getgid)) port)))))))
-        (job2 #~(job next-second-from
-                     (lambda ()
-                       (call-with-output-file "witness"
-                         (lambda (port)
-                           (display (list (getuid) (getgid)) port))))
-                     #:user "alice"))
-        (job3 #~(job next-second-from             ;to test $PATH
-                     "touch witness-touch")))
-    (simple-operating-system
-     (service mcron-service-type
-              (mcron-configuration (jobs (list job1 job2 job3)))))))
-
-(define (run-mcron-test name)
-  (define os
-    (marionette-operating-system
-     %mcron-os
-     #:imported-modules '((gnu services herd)
-                          (guix combinators))))
-
-  (define test
-    (with-imported-modules '((gnu build marionette))
-      #~(begin
-          (use-modules (gnu build marionette)
-                       (srfi srfi-64)
-                       (ice-9 match))
-
-          (define marionette
-            (make-marionette (list #$(virtual-machine os))))
-
-          (test-runner-current (system-test-runner #$output))
-          (test-begin "mcron")
-
-          (test-assert "service running"
-            (marionette-eval
-             '(begin
-                (use-modules (gnu services herd))
-                (start-service 'mcron))
-             marionette))
-
-          ;; Make sure root's mcron job runs, has its cwd set to "/root", and
-          ;; runs with the right UID/GID.
-          (test-equal "root's job"
-            '(0 0)
-            (wait-for-file "/root/witness" marionette))
-
-          ;; Likewise for Alice's job.  We cannot know what its GID is since
-          ;; it's chosen by 'groupadd', but it's strictly positive.
-          (test-assert "alice's job"
-            (match (wait-for-file "/home/alice/witness" marionette)
-              ((1000 gid)
-               (>= gid 100))))
-
-          ;; Last, the job that uses a command; allows us to test whether
-          ;; $PATH is sane.
-          (test-equal "root's job with command"
-            ""
-            (wait-for-file "/root/witness-touch" marionette
-                           #:read '(@ (ice-9 rdelim) read-string)))
-
-          ;; Make sure the 'schedule' action is accepted.
-          (test-equal "schedule action"
-            '(#t)                                 ;one value, #t
-            (marionette-eval '(with-shepherd-action 'mcron ('schedule) result
-                                result)
-                             marionette))
-
-          (test-end))))
-
-  (gexp->derivation name test))
-
-(define %test-mcron
-  (system-test
-   (name "mcron")
-   (description "Make sure the mcron service works as advertised.")
-   (value (run-mcron-test name))))
-
 
 ;;;
 ;;; Avahi and NSS-mDNS.
diff --git a/gnu/tests/mcron.scm b/gnu/tests/mcron.scm
new file mode 100644
index 00000000000..052c8439cc7
--- /dev/null
+++ b/gnu/tests/mcron.scm
@@ -0,0 +1,118 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2016-2020, 2022, 2024 Ludovic Courtès <ludo <at> gnu.org>
+;;; Copyright © 2018 Clément Lassieur <clement <at> lassieur.org>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu tests mcron)
+  #:use-module (gnu tests)
+  #:use-module (gnu system)
+  #:use-module (gnu system vm)
+  #:use-module (gnu services)
+  #:use-module (gnu services mcron)
+  #:use-module (guix gexp)
+  #:use-module (guix store)
+  #:use-module (guix monads)
+  #:export (%test-mcron))
+
+;;;
+;;; Mcron.
+;;;
+
+(define %mcron-os
+  ;; System with an mcron service, with one mcron job for "root" and one mcron
+  ;; job for an unprivileged user.
+  (let ((job1 #~(job '(next-second '(0 5 10 15 20 25 30 35 40 45 50 55))
+                     (lambda ()
+                       (unless (file-exists? "witness")
+                        (call-with-output-file "witness"
+                          (lambda (port)
+                            (display (list (getuid) (getgid)) port)))))))
+        (job2 #~(job next-second-from
+                     (lambda ()
+                       (call-with-output-file "witness"
+                         (lambda (port)
+                           (display (list (getuid) (getgid)) port))))
+                     #:user "alice"))
+        (job3 #~(job next-second-from             ;to test $PATH
+                     "touch witness-touch")))
+    (simple-operating-system
+     (service mcron-service-type
+              (mcron-configuration (jobs (list job1 job2 job3)))))))
+
+(define (run-mcron-test name)
+  (define os
+    (marionette-operating-system
+     %mcron-os
+     #:imported-modules '((gnu services herd)
+                          (guix combinators))))
+
+  (define test
+    (with-imported-modules '((gnu build marionette))
+      #~(begin
+          (use-modules (gnu build marionette)
+                       (srfi srfi-64)
+                       (ice-9 match))
+
+          (define marionette
+            (make-marionette (list #$(virtual-machine os))))
+
+          (test-runner-current (system-test-runner #$output))
+          (test-begin "mcron")
+
+          (test-assert "service running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (start-service 'mcron))
+             marionette))
+
+          ;; Make sure root's mcron job runs, has its cwd set to "/root", and
+          ;; runs with the right UID/GID.
+          (test-equal "root's job"
+            '(0 0)
+            (wait-for-file "/root/witness" marionette))
+
+          ;; Likewise for Alice's job.  We cannot know what its GID is since
+          ;; it's chosen by 'groupadd', but it's strictly positive.
+          (test-assert "alice's job"
+            (match (wait-for-file "/home/alice/witness" marionette)
+              ((1000 gid)
+               (>= gid 100))))
+
+          ;; Last, the job that uses a command; allows us to test whether
+          ;; $PATH is sane.
+          (test-equal "root's job with command"
+            ""
+            (wait-for-file "/root/witness-touch" marionette
+                           #:read '(@ (ice-9 rdelim) read-string)))
+
+          ;; Make sure the 'schedule' action is accepted.
+          (test-equal "schedule action"
+            '(#t)                                 ;one value, #t
+            (marionette-eval '(with-shepherd-action 'mcron ('schedule) result
+                                result)
+                             marionette))
+
+          (test-end))))
+
+  (gexp->derivation name test))
+
+(define %test-mcron
+  (system-test
+   (name "mcron")
+   (description "Make sure the mcron service works as advertised.")
+   (value (run-mcron-test name))))
-- 
2.48.1





This bug report was last modified 129 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.