gnu: Add totem-pl-parser.
[guix.git] / tests / syscalls.scm
blob706f3dff44f82424264d04f14ecb318b1e80c230
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org>
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/>.
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"
32   ENOENT
33   (catch 'system-error
34     (lambda ()
35       (mount "/dev/null" "/does-not-exist" "ext2")
36       #f)
37     (compose system-error-errno list)))
39 (test-assert "umount, ENOENT/EPERM"
40   (catch 'system-error
41     (lambda ()
42       (umount "/does-not-exist")
43       #f)
44     (lambda args
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"
55   (catch 'system-error
56     (lambda ()
57       (swapon "/does-not-exist")
58       #f)
59     (lambda args
60       (memv (system-error-errno args) (list EPERM ENOENT)))))
62 (test-assert "swapoff, ENOENT/EINVAL/EPERM"
63   (catch 'system-error
64     (lambda ()
65       (swapoff "/does-not-exist")
66       #f)
67     (lambda args
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")))
83     (close-port sock)
84     (and (not (zero? (logand flags IFF_LOOPBACK)))
85          (not (zero? (logand flags IFF_UP))))))
87 (test-equal "loopback-network-interface?"
88   ENODEV
89   (and (loopback-network-interface? "lo")
90        (catch 'system-error
91          (lambda ()
92            (loopback-network-interface? "nonexistent")
93            #f)
94          (lambda args
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)))
100     (catch 'system-error
101       (lambda ()
102         (set-network-interface-flags sock "lo" IFF_UP))
103       (lambda args
104         (close-port sock)
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")))
112     (close-port sock)
113     addr))
115 (test-assert "set-network-interface-address"
116   (let ((sock (socket AF_INET SOCK_STREAM 0)))
117     (catch 'system-error
118       (lambda ()
119         (set-network-interface-address sock "nonexistent"
120                                        (make-socket-address
121                                         AF_INET
122                                         (inet-pton AF_INET "127.12.14.15")
123                                         0)))
124       (lambda args
125         (close-port sock)
126         ;; We get EPERM with Linux 3.18ish and EACCES with 2.6.32.
127         (memv (system-error-errno args) (list EPERM EACCES))))))
129 (test-end)
132 (exit (= (test-runner-fail-count (test-runner-current)) 0))