projects/guix·blob perlssl · refs

740 lines · 24.1 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014-2021, 2024-2025 Ludovic Courtès <[email protected]>
3;;; Copyright © 2015 David Thompson <[email protected]>
4;;; Copyright © 2020 Simon South <[email protected]>
5;;; Copyright © 2020 Mathieu Othacehe <[email protected]>
6;;; Copyright © 2025 Maxim Cournoyer <[email protected]>
7;;;
8;;; This file is part of GNU Guix.
9;;;
10;;; GNU Guix is free software; you can redistribute it and/or modify it
11;;; under the terms of the GNU General Public License as published by
12;;; the Free Software Foundation; either version 3 of the License, or (at
13;;; your option) any later version.
14;;;
15;;; GNU Guix is distributed in the hope that it will be useful, but
16;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;;; GNU General Public License for more details.
19;;;
20;;; You should have received a copy of the GNU General Public License
21;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23(define-module (test-syscalls)
24 #:use-module (guix utils)
25 #:use-module (guix build syscalls)
26 #:use-module (gnu build linux-container)
27 #:use-module (srfi srfi-1)
28 #:use-module (srfi srfi-26)
29 #:use-module (srfi srfi-64)
30 #:use-module (srfi srfi-71)
31 #:use-module (system foreign)
32 #:use-module ((ice-9 ftw) #:select (scandir))
33 #:use-module (ice-9 match)
34 #:use-module (ice-9 threads))
35
36;; Test the (guix build syscalls) module, although there's not much that can
37;; actually be tested without being root.
38
39(define temp-file
40 (string-append "t-utils-" (number->string (getpid))))
41
42
43(test-begin "syscalls")
44
45(test-equal "mount, ENOENT"
46 ENOENT
47 (catch 'system-error
48 (lambda ()
49 (mount "/dev/null" "/does-not-exist" "ext2")
50 #f)
51 (compose system-error-errno list)))
52
53(test-assert "umount, ENOENT/EPERM"
54 (catch 'system-error
55 (lambda ()
56 (umount "/does-not-exist")
57 #f)
58 (lambda args
59 ;; Both return values have been encountered in the wild.
60 (memv (system-error-errno args) (list EPERM ENOENT)))))
61
62(test-assert "mounts"
63 ;; Check for one of the common mount points.
64 (let ((mounts (mounts)))
65 (any (match-lambda
66 ((point . type)
67 (let ((mount (find (lambda (mount)
68 (string=? (mount-point mount) point))
69 mounts)))
70 (and mount
71 (string=? (mount-type mount) type)))))
72 '(("/proc" . "proc")
73 ("/sys" . "sysfs")
74 ("/dev/shm" . "tmpfs")))))
75
76(test-assert "mount-points"
77 ;; Reportedly "/" is not always listed as a mount point, so check a few
78 ;; others (see <http://bugs.gnu.org/20261>.)
79 (any (cute member <> (mount-points))
80 '("/" "/proc" "/sys" "/dev")))
81
82(false-if-exception (delete-file temp-file))
83(test-equal "utime with AT_SYMLINK_NOFOLLOW"
84 '(0 0)
85 (begin
86 ;; Test libguile's utime with AT_SYMLINK_NOFOLLOW, which libguile does not
87 ;; define as of Guile 2.2.4.
88 (symlink "/nowhere" temp-file)
89 (utime temp-file 0 0 0 0 AT_SYMLINK_NOFOLLOW)
90 (let ((st (lstat temp-file)))
91 (delete-file temp-file)
92 ;; Note: 'utimensat' does not change 'ctime'.
93 (list (stat:mtime st) (stat:atime st)))))
94
95(test-assert "swapon, ENOSYS/ENOENT/EPERM"
96 (catch 'system-error
97 (lambda ()
98 (swapon "/does-not-exist")
99 #f)
100 (lambda args
101 (memv (system-error-errno args) (list EPERM ENOENT ENOSYS)))))
102
103(test-assert "swapoff, ENOSYS/ENOENT/EINVAL/EPERM"
104 (catch 'system-error
105 (lambda ()
106 (swapoff "/does-not-exist")
107 #f)
108 (lambda args
109 (memv (system-error-errno args) (list EPERM EINVAL ENOENT ENOSYS)))))
110
111(test-assert "mkdtemp!"
112 (let* ((tmp (or (getenv "TMPDIR") "/tmp"))
113 (dir (mkdtemp! (string-append tmp "/guix-test-XXXXXX"))))
114 (and (file-exists? dir)
115 (begin
116 (rmdir dir)
117 #t))))
118
119(test-equal "statfs, ENOENT"
120 ENOENT
121 (catch 'system-error
122 (lambda ()
123 (statfs "/does-not-exist"))
124 (compose system-error-errno list)))
125
126(test-assert "statfs"
127 (let ((fs (statfs "/")))
128 (and (file-system? fs)
129 (> (file-system-block-size fs) 0)
130 (>= (file-system-blocks-available fs) 0)
131 (>= (file-system-blocks-free fs)
132 (file-system-blocks-available fs)))))
133
134(define (user-namespace pid)
135 (string-append "/proc/" (number->string pid) "/ns/user"))
136
137(define perform-container-tests?
138 (and (user-namespace-supported?)
139 (unprivileged-user-namespace-supported?)))
140
141(unless perform-container-tests?
142 (test-skip 1))
143(test-assert "clone"
144 (match (clone (logior CLONE_NEWUSER SIGCHLD))
145 (0 (primitive-exit 42))
146 (pid
147 ;; Check if user namespaces are different.
148 (and (not (equal? (readlink (user-namespace pid))
149 (readlink (user-namespace (getpid)))))
150 (match (waitpid pid)
151 ((_ . status)
152 (= 42 (status:exit-val status))))))))
153
154(test-equal "unshare"
155 EPERM
156 ;; Unless running as root, (unshare CLONE_NEWNS) returns EPERM.
157 (catch 'system-error
158 (lambda ()
159 (unshare CLONE_NEWNS))
160 (lambda args
161 (system-error-errno args))))
162
163(define child-thunk
164 (lambda ()
165 (gc) ;spawn GC threads
166 (primitive-exit
167 (catch 'system-error
168 (lambda ()
169 (unshare CLONE_THREAD)
170 0) ;no error
171 (lambda args
172 (system-error-errno args))))))
173
174(define parent-proc
175 (lambda (pid)
176 (match (waitpid pid)
177 ((_ . status)
178 (status:exit-val status)))))
179
180(unless perform-container-tests?
181 (test-skip 1))
182(test-equal "clone and unshare triggers EINVAL"
183 EINVAL
184 (match (clone (logior CLONE_NEWUSER SIGCHLD))
185 (0 (child-thunk))
186 (pid (parent-proc pid))))
187
188(unless perform-container-tests?
189 (test-skip 1))
190(test-equal "safe-clone and unshare succeeds"
191 0
192 (safe-clone (logior CLONE_NEWUSER SIGCHLD)
193 child-thunk parent-proc))
194
195(unless perform-container-tests?
196 (test-skip 1))
197(test-assert "setns"
198 (match (clone (logior CLONE_NEWUSER SIGCHLD))
199 (0 (primitive-exit 0))
200 (clone-pid
201 (match (pipe)
202 ((in . out)
203 (match (primitive-fork)
204 (0
205 (close in)
206 ;; Join the user namespace.
207 (call-with-input-file (user-namespace clone-pid)
208 (lambda (port)
209 (setns (port->fdes port) 0)))
210 (write 'done out)
211 (close out)
212 (primitive-exit 0))
213 (fork-pid
214 (close out)
215 ;; Wait for the child process to join the namespace.
216 (read in)
217 (let ((result (and (equal? (readlink (user-namespace clone-pid))
218 (readlink (user-namespace fork-pid))))))
219 ;; Clean up.
220 (waitpid clone-pid)
221 (waitpid fork-pid)
222 result))))))))
223
224(when (not perform-container-tests?)
225 (test-skip 1))
226(test-equal "pivot-root"
227 'success!
228 (match (socketpair AF_UNIX SOCK_STREAM 0)
229 ((parent . child)
230 (match (clone (logior CLONE_NEWUSER CLONE_NEWNS SIGCHLD))
231 (0
232 (dynamic-wind
233 (const #t)
234 (lambda ()
235 (close parent)
236 (call-with-temporary-directory
237 (lambda (root)
238 (display "ready\n" child)
239 (read child) ;wait for "go!"
240 (let ((put-old (string-append root "/real-root")))
241 (mount "none" root "tmpfs")
242 (mkdir put-old)
243 (call-with-output-file (string-append root "/test")
244 (lambda (port)
245 (display "testing\n" port)))
246 (pivot-root root put-old)
247 ;; The test file should now be located inside the root directory.
248 (write (and (file-exists? "/test") 'success!) child)
249 (close child)))))
250 (lambda ()
251 (primitive-exit 0))))
252 (pid
253 (close child)
254 (match (read parent)
255 ('ready
256 ;; Set up the UID/GID mapping so that we can mkdir on the tmpfs:
257 ;; <https://bugzilla.kernel.org/show_bug.cgi?id=183461>.
258 (call-with-output-file (format #f "/proc/~d/setgroups" pid)
259 (lambda (port)
260 (display "deny" port)))
261 (call-with-output-file (format #f "/proc/~d/uid_map" pid)
262 (lambda (port)
263 (format port "0 ~d 1" (getuid))))
264 (call-with-output-file (format #f "/proc/~d/gid_map" pid)
265 (lambda (port)
266 (format port "0 ~d 1" (getgid))))
267 (display "go!\n" parent)
268 (let ((result (read parent)))
269 (close parent)
270 (and (zero? (match (waitpid pid)
271 ((_ . status)
272 (status:exit-val status))))
273 result)))))))))
274
275(test-equal "scandir*, ENOENT"
276 ENOENT
277 (catch 'system-error
278 (lambda ()
279 (scandir* "/does/not/exist"))
280 (lambda args
281 (system-error-errno args))))
282
283(test-equal "scandir*, ASCII file names"
284 (scandir (dirname (search-path %load-path "guix/base32.scm"))
285 (const #t) string<?)
286 (match (scandir* (dirname (search-path %load-path "guix/base32.scm")))
287 (((names . properties) ...)
288 names)))
289
290(test-equal "scandir*, UTF-8 file names"
291 '("." ".." "α" "λ")
292 (call-with-temporary-directory
293 (lambda (directory)
294 ;; Wrap 'creat' to make sure that we really pass a UTF-8-encoded file
295 ;; name to the system call.
296 (let ((creat (pointer->procedure int
297 (dynamic-func "creat" (dynamic-link))
298 (list '* int))))
299 (creat (string->pointer (string-append directory "/α")
300 "UTF-8")
301 #o644)
302 (creat (string->pointer (string-append directory "/λ")
303 "UTF-8")
304 #o644)
305 (let ((locale (setlocale LC_ALL)))
306 (dynamic-wind
307 (lambda ()
308 ;; Make sure that even in a C locale we get the right result.
309 (setlocale LC_ALL "C"))
310 (lambda ()
311 (match (scandir* directory)
312 (((names . properties) ...)
313 names)))
314 (lambda ()
315 (setlocale LC_ALL locale))))))))
316
317(test-assert "scandir*, properties"
318 (let ((directory (dirname (search-path %load-path "guix/base32.scm"))))
319 (every (lambda (entry name)
320 (match entry
321 ((name2 . properties)
322 (and (string=? name2 name)
323 (let* ((full (string-append directory "/" name))
324 (stat (lstat full))
325 (inode (assoc-ref properties 'inode))
326 (type (assoc-ref properties 'type)))
327 (and (= inode (stat:ino stat))
328 (or (eq? type 'unknown)
329 (eq? type (stat:type stat)))))))))
330 (scandir* directory)
331 (scandir directory (const #t) string<?))))
332
333(false-if-exception (delete-file temp-file))
334(test-assert "getxattr, setxattr"
335 (let ((key "user.translator")
336 (value "/hurd/pfinet\0")
337 (file (open-file temp-file "w0")))
338 (catch 'system-error
339 (lambda ()
340 (setxattr temp-file key value)
341 (string=? (getxattr temp-file key) value))
342 (lambda args
343 ;; Accept ENOTSUP, if the file-system does not support extended user
344 ;; attributes.
345 (memv (system-error-errno args) (list ENOTSUP))))))
346
347(false-if-exception (delete-file temp-file))
348(test-equal "fcntl-flock wait"
349 42 ; the child's exit status
350 (let ((file (open-file temp-file "w0b")))
351 ;; Acquire an exclusive lock.
352 (fcntl-flock file 'write-lock)
353 (match (primitive-fork)
354 (0
355 (dynamic-wind
356 (const #t)
357 (lambda ()
358 ;; Reopen FILE read-only so we can have a read lock.
359 (let ((file (open-file temp-file "r0b")))
360 ;; Wait until we can acquire the lock.
361 (fcntl-flock file 'read-lock)
362 (primitive-exit (read file)))
363 (primitive-exit 1))
364 (lambda ()
365 (primitive-exit 2))))
366 (pid
367 ;; Write garbage and wait.
368 (display "hello, world!" file)
369 (force-output file)
370 (sleep 1)
371
372 ;; Write the real answer.
373 (seek file 0 SEEK_SET)
374 (truncate-file file 0)
375 (write 42 file)
376 (force-output file)
377
378 ;; Unlock, which should let the child continue.
379 (fcntl-flock file 'unlock)
380
381 (match (waitpid pid)
382 ((_ . status)
383 (let ((result (status:exit-val status)))
384 (close-port file)
385 result)))))))
386
387(test-equal "fcntl-flock non-blocking"
388 EAGAIN ; the child's exit status
389 (match (pipe)
390 ((input . output)
391 (match (primitive-fork)
392 (0
393 (dynamic-wind
394 (const #t)
395 (lambda ()
396 (close-port output)
397
398 ;; Wait for the green light.
399 (read-char input)
400
401 ;; Open FILE read-only so we can have a read lock.
402 (let ((file (open-file temp-file "w0")))
403 (catch 'flock-error
404 (lambda ()
405 ;; This attempt should throw EAGAIN.
406 (fcntl-flock file 'write-lock #:wait? #f))
407 (lambda (key errno)
408 (primitive-exit (pk 'errno errno)))))
409 (primitive-exit -1))
410 (lambda ()
411 (primitive-exit -2))))
412 (pid
413 (close-port input)
414 (let ((file (open-file temp-file "w0")))
415 ;; Acquire an exclusive lock.
416 (fcntl-flock file 'write-lock)
417
418 ;; Tell the child to continue.
419 (write 'green-light output)
420 (force-output output)
421
422 (match (waitpid pid)
423 ((_ . status)
424 (let ((result (status:exit-val status)))
425 (fcntl-flock file 'unlock)
426 (close-port file)
427 result)))))))))
428
429(test-equal "lock-file + unlock-file"
430 'hello
431 (call-with-temporary-directory
432 (lambda (directory)
433 (let* ((file (in-vicinity directory "lock"))
434 (out (lock-file file #:wait? #f)))
435 (display "hello" out)
436 (unlock-file out)
437 (let* ((in (lock-file file "r0"))
438 (content (read in)))
439 (unlock-file in)
440 content)))))
441
442(test-equal "set-thread-name"
443 "Syscall Test"
444 (let ((name (thread-name)))
445 (set-thread-name "Syscall Test")
446 (let ((new-name (thread-name)))
447 (set-thread-name name)
448 new-name)))
449
450(test-assert "all-network-interface-names"
451 (match (all-network-interface-names)
452 (((? string? names) ..1)
453 (member "lo" names))))
454
455(test-assert "network-interface-names"
456 (match (remove (lambda (interface)
457 ;; Ignore interface aliases since they don't show up in
458 ;; (all-network-interface-names).
459 (string-contains interface ":"))
460 (network-interface-names))
461 (((? string? names) ..1)
462 (lset<= string=? names (all-network-interface-names)))))
463
464(test-assert "network-interface-flags"
465 (let* ((sock (socket AF_INET SOCK_STREAM 0))
466 (flags (network-interface-flags sock "lo")))
467 (close-port sock)
468 (and (not (zero? (logand flags IFF_LOOPBACK)))
469 (not (zero? (logand flags IFF_UP))))))
470
471(test-equal "loopback-network-interface?"
472 ENODEV
473 (and (loopback-network-interface? "lo")
474 (catch 'system-error
475 (lambda ()
476 (loopback-network-interface? "nonexistent")
477 #f)
478 (lambda args
479 (system-error-errno args)))))
480
481(test-equal "loopback-network-interface-running?"
482 ENODEV
483 (and (network-interface-running? "lo")
484 (catch 'system-error
485 (lambda ()
486 (network-interface-running? "nonexistent")
487 #f)
488 (lambda args
489 (system-error-errno args)))))
490
491(test-skip (if (zero? (getuid)) 1 0))
492(test-assert "set-network-interface-flags"
493 (let ((sock (socket AF_INET SOCK_STREAM 0)))
494 (catch 'system-error
495 (lambda ()
496 (set-network-interface-flags sock "lo" IFF_UP))
497 (lambda args
498 (close-port sock)
499 ;; We get EPERM with Linux 3.18ish and EACCES with 2.6.32.
500 (memv (system-error-errno args) (list EPERM EACCES))))))
501
502(test-equal "network-interface-address lo"
503 (make-socket-address AF_INET (inet-pton AF_INET "127.0.0.1") 0)
504 (let* ((sock (socket AF_INET SOCK_STREAM 0))
505 (addr (network-interface-address sock "lo")))
506 (close-port sock)
507 addr))
508
509(test-skip (if (zero? (getuid)) 1 0))
510(test-assert "set-network-interface-address"
511 (let ((sock (socket AF_INET SOCK_STREAM 0)))
512 (catch 'system-error
513 (lambda ()
514 (set-network-interface-address sock "nonexistent"
515 (make-socket-address
516 AF_INET
517 (inet-pton AF_INET "127.12.14.15")
518 0)))
519 (lambda args
520 (close-port sock)
521 ;; We get EPERM with Linux 3.18ish and EACCES with 2.6.32.
522 (memv (system-error-errno args) (list EPERM EACCES))))))
523
524(test-equal "network-interface-netmask lo"
525 (make-socket-address AF_INET (inet-pton AF_INET "255.0.0.0") 0)
526 (let* ((sock (socket AF_INET SOCK_STREAM 0))
527 (addr (network-interface-netmask sock "lo")))
528 (close-port sock)
529 addr))
530
531(test-skip (if (zero? (getuid)) 1 0))
532(test-assert "set-network-interface-netmask"
533 (let ((sock (socket AF_INET SOCK_STREAM 0)))
534 (catch 'system-error
535 (lambda ()
536 (set-network-interface-netmask sock "nonexistent"
537 (make-socket-address
538 AF_INET
539 (inet-pton AF_INET "255.0.0.0")
540 0)))
541 (lambda args
542 (close-port sock)
543 (memv (system-error-errno args) (list EPERM EACCES))))))
544
545(test-equal "network-interfaces returns one or more interfaces"
546 '(#t #t #t)
547 (match (network-interfaces)
548 ((interfaces ..1)
549 (list (every interface? interfaces)
550 (every string? (map interface-name interfaces))
551 (every (lambda (sockaddr)
552 ;; Sometimes interfaces have no associated address.
553 (or (vector? sockaddr)
554 (not sockaddr)))
555 (map interface-address interfaces))))))
556
557(test-equal "network-interfaces returns \"lo\""
558 (list #t (make-socket-address AF_INET (inet-pton AF_INET "127.0.0.1") 0))
559 (match (filter (lambda (interface)
560 (string=? "lo" (interface-name interface)))
561 (network-interfaces))
562 ((loopbacks ..1)
563 (list (every (lambda (lo)
564 (not (zero? (logand IFF_LOOPBACK (interface-flags lo)))))
565 loopbacks)
566 (match (find (lambda (lo)
567 (= AF_INET (sockaddr:fam (interface-address lo))))
568 loopbacks)
569 (#f #f)
570 (lo (interface-address lo)))))))
571
572(test-skip (if (zero? (getuid)) 1 0))
573(test-assert "add-network-route/gateway"
574 (let ((sock (socket AF_INET SOCK_STREAM 0))
575 (gateway (make-socket-address AF_INET
576 (inet-pton AF_INET "192.168.0.1")
577 0)))
578 (catch 'system-error
579 (lambda ()
580 (add-network-route/gateway sock gateway))
581 (lambda args
582 (close-port sock)
583 (memv (system-error-errno args) (list EPERM EACCES))))))
584
585(test-skip (if (zero? (getuid)) 1 0))
586(test-assert "delete-network-route"
587 (let ((sock (socket AF_INET SOCK_STREAM 0))
588 (destination (make-socket-address AF_INET INADDR_ANY 0)))
589 (catch 'system-error
590 (lambda ()
591 (delete-network-route sock destination))
592 (lambda args
593 (close-port sock)
594 (memv (system-error-errno args) (list EPERM EACCES))))))
595
596(test-equal "tcgetattr ENOTTY"
597 ENOTTY
598 (catch 'system-error
599 (lambda ()
600 (call-with-input-file "/dev/null"
601 (lambda (port)
602 (tcgetattr (fileno port)))))
603 (compose system-error-errno list)))
604
605(test-skip (if (and (file-exists? "/proc/self/fd/0")
606 (string-prefix? "/dev/pts/" (readlink "/proc/self/fd/0")))
607 0
608 2))
609
610(test-assert "tcgetattr"
611 (let ((termios (tcgetattr 0)))
612 (and (termios? termios)
613 (> (termios-input-speed termios) 0)
614 (> (termios-output-speed termios) 0))))
615
616(test-assert "tcsetattr"
617 (let ((first (tcgetattr 0)))
618 (tcsetattr 0 (tcsetattr-action TCSANOW) first)
619 (equal? first (tcgetattr 0))))
620
621(test-assert "terminal-window-size ENOTTY"
622 (call-with-input-file "/dev/null"
623 (lambda (port)
624 (catch 'system-error
625 (lambda ()
626 (terminal-window-size port))
627 (lambda args
628 ;; Accept EINVAL, which some old Linux versions might return.
629 (memv (system-error-errno args)
630 (list ENOTTY EINVAL)))))))
631
632(test-assert "terminal-columns"
633 (> (terminal-columns) 0))
634
635(test-assert "terminal-columns non-file port"
636 (> (terminal-columns (open-input-string "Join us now, share the software!"))
637 0))
638
639(test-assert "terminal-rows"
640 (> (terminal-rows) 0))
641
642(test-equal "terminal-string-width English"
643 5
644 (terminal-string-width "hello"))
645
646;; The following test requires a Unicode-capable locale encoding.
647(test-skip (if (string=? (port-encoding (current-output-port)) "UTF-8") 0 1))
648(test-equal "terminal-string-width Japanese"
649 6
650 (terminal-string-width "今日は"))
651
652(test-assert "openpty"
653 (let ((head inferior (openpty)))
654 (and (integer? head) (integer? inferior)
655 (let ((port (fdopen inferior "r+0")))
656 (and (isatty? port)
657 (begin
658 (close-port port)
659 (close-fdes head)
660 #t))))))
661
662(test-equal "openpty + login-tty"
663 '(hello world)
664 (let ((head inferior (openpty)))
665 (match (primitive-fork)
666 (0
667 (dynamic-wind
668 (const #t)
669 (lambda ()
670 (setvbuf (current-input-port) 'none)
671 (close-fdes head)
672 (login-tty inferior)
673 (write (read))
674 (read)) ;this gets EIO when HEAD is closed
675 (lambda ()
676 (primitive-_exit 42))))
677 (pid
678 (close-fdes inferior)
679 (let ((head (fdopen head "r+0")))
680 (write '(hello world) head)
681 (let ((result (read head)))
682 (close-port head)
683 (waitpid pid)
684 result))))))
685
686(test-assert "utmpx-entries"
687 (match (utmpx-entries)
688 (((? utmpx? entries) ...)
689 (every (lambda (entry)
690 (match (utmpx-user entry)
691 ((? string?)
692 ;; Ensure we have a valid PID for those entries where it
693 ;; makes sense.
694 (or (not (memv (utmpx-login-type entry)
695 (list (login-type INIT_PROCESS)
696 (login-type LOGIN_PROCESS)
697 (login-type USER_PROCESS))))
698 (> (utmpx-pid entry) 0)))
699 (#f ;might be DEAD_PROCESS
700 #t)))
701 entries))))
702
703(test-assert "read-utmpx, EOF"
704 (eof-object? (read-utmpx (%make-void-port "r"))))
705
706(unless (access? "/var/run/utmpx" O_RDONLY)
707 (test-skip 1))
708(test-assert "read-utmpx"
709 (let ((result (call-with-input-file "/var/run/utmpx" read-utmpx)))
710 (or (utmpx? result) (eof-object? result))))
711
712(when (zero? (getuid))
713 (test-skip 1))
714(test-equal "add-to-entropy-count"
715 EPERM
716 (call-with-output-file "/dev/urandom"
717 (lambda (port)
718 (catch 'system-error
719 (lambda ()
720 (add-to-entropy-count port 77)
721 #f)
722 (lambda args
723 (system-error-errno args))))))
724
725(when (or (zero? (getuid))
726 (not (string-contains %host-type "linux")))
727 (test-skip 1))
728(test-assert "kexec-load-file"
729 (catch 'system-error
730 (lambda ()
731 (let ((fd1 (open-fdes "/dev/null" O_RDONLY))
732 (fd2 (open-fdes "/dev/null" O_RDONLY)))
733 (kexec-load-file fd1 fd2 "gnu.repl=yes")))
734 (lambda args
735 (member (system-error-errno args)
736 (list EPERM ENOSYS)))))
737
738(test-end)
739
740(false-if-exception (delete-file temp-file))