1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (test-syscalls)
20 #:use-module (guix build syscalls)
21 #:use-module (srfi srfi-1)
22 #:use-module (srfi srfi-26)
23 #:use-module (srfi srfi-64)
24 #:use-module (ice-9 match))
26 ;; Test the (guix build syscalls) module, although there's not much that can
27 ;; actually be tested without being root.
29 (test-begin "syscalls")
31 (test-equal "mount, ENOENT"
35 (mount "/dev/null" "/does-not-exist" "ext2")
37 (compose system-error-errno list)))
39 (test-assert "umount, ENOENT/EPERM"
42 (umount "/does-not-exist")
45 ;; Both return values have been encountered in the wild.
46 (memv (system-error-errno args) (list EPERM ENOENT)))))
48 (test-assert "mount-points"
49 ;; Reportedly "/" is not always listed as a mount point, so check a few
50 ;; others (see <http://bugs.gnu.org/20261>.)
51 (any (cute member <> (mount-points))
52 '("/" "/proc" "/sys" "/dev")))
54 (test-assert "swapon, ENOENT/EPERM"
57 (swapon "/does-not-exist")
60 (memv (system-error-errno args) (list EPERM ENOENT)))))
62 (test-assert "swapoff, ENOENT/EINVAL/EPERM"
65 (swapoff "/does-not-exist")
68 (memv (system-error-errno args) (list EPERM EINVAL ENOENT)))))
70 (test-assert "all-network-interfaces"
71 (match (all-network-interfaces)
72 (((? string? names) ..1)
73 (member "lo" names))))
75 (test-assert "network-interfaces"
76 (match (network-interfaces)
77 (((? string? names) ..1)
78 (lset<= string=? names (all-network-interfaces)))))
80 (test-assert "network-interface-flags"
81 (let* ((sock (socket AF_INET SOCK_STREAM 0))
82 (flags (network-interface-flags sock "lo")))
84 (and (not (zero? (logand flags IFF_LOOPBACK)))
85 (not (zero? (logand flags IFF_UP))))))
87 (test-equal "loopback-network-interface?"
89 (and (loopback-network-interface? "lo")
92 (loopback-network-interface? "nonexistent")
95 (system-error-errno args)))))
97 (test-skip (if (zero? (getuid)) 1 0))
98 (test-assert "set-network-interface-flags"
99 (let ((sock (socket AF_INET SOCK_STREAM 0)))
102 (set-network-interface-flags sock "lo" IFF_UP))
105 ;; We get EPERM with Linux 3.18ish and EACCES with 2.6.32.
106 (memv (system-error-errno args) (list EPERM EACCES))))))
108 (test-equal "network-interface-address lo"
109 (make-socket-address AF_INET (inet-pton AF_INET "127.0.0.1") 0)
110 (let* ((sock (socket AF_INET SOCK_STREAM 0))
111 (addr (network-interface-address sock "lo")))
115 (test-assert "set-network-interface-address"
116 (let ((sock (socket AF_INET SOCK_STREAM 0)))
119 (set-network-interface-address sock "nonexistent"
122 (inet-pton AF_INET "127.12.14.15")
126 ;; We get EPERM with Linux 3.18ish and EACCES with 2.6.32.
127 (memv (system-error-errno args) (list EPERM EACCES))))))
132 (exit (= (test-runner-fail-count (test-runner-current)) 0))