1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2014 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-64)
23 #:use-module (ice-9 match))
25 ;; Test the (guix build syscalls) module, although there's not much that can
26 ;; actually be tested without being root.
28 (test-begin "syscalls")
30 (test-equal "mount, ENOENT"
34 (mount "/dev/null" "/does-not-exist" "ext2")
36 (compose system-error-errno list)))
38 (test-assert "umount, ENOENT/EPERM"
41 (umount "/does-not-exist")
44 ;; Both return values have been encountered in the wild.
45 (memv (system-error-errno args) (list EPERM ENOENT)))))
47 (test-assert "mount-points"
48 (member "/" (mount-points)))
50 (test-assert "swapon, ENOENT/EPERM"
53 (swapon "/does-not-exist")
56 (memv (system-error-errno args) (list EPERM ENOENT)))))
58 (test-assert "swapoff, ENOENT/EINVAL/EPERM"
61 (swapoff "/does-not-exist")
64 (memv (system-error-errno args) (list EPERM EINVAL ENOENT)))))
66 (test-assert "all-network-interfaces"
67 (match (all-network-interfaces)
68 (((? string? names) ..1)
69 (member "lo" names))))
71 (test-assert "network-interfaces"
72 (match (network-interfaces)
73 (((? string? names) ..1)
74 (lset<= string=? names (all-network-interfaces)))))
76 (test-assert "network-interface-flags"
77 (let* ((sock (socket AF_INET SOCK_STREAM 0))
78 (flags (network-interface-flags sock "lo")))
80 (and (not (zero? (logand flags IFF_LOOPBACK)))
81 (not (zero? (logand flags IFF_UP))))))
83 (test-equal "loopback-network-interface?"
85 (and (loopback-network-interface? "lo")
88 (loopback-network-interface? "nonexistent")
91 (system-error-errno args)))))
93 (test-skip (if (zero? (getuid)) 1 0))
94 (test-equal "set-network-interface-flags"
96 (let ((sock (socket AF_INET SOCK_STREAM 0)))
99 (set-network-interface-flags sock "lo" IFF_UP))
102 (system-error-errno args)))))
104 (test-equal "network-interface-address lo"
105 (make-socket-address AF_INET (inet-pton AF_INET "127.0.0.1") 0)
106 (let* ((sock (socket AF_INET SOCK_STREAM 0))
107 (addr (network-interface-address sock "lo")))
111 (test-equal "set-network-interface-address"
113 (let ((sock (socket AF_INET SOCK_STREAM 0)))
116 (set-network-interface-address sock "nonexistent"
119 (inet-pton AF_INET "127.12.14.15")
123 (system-error-errno args)))))
128 (exit (= (test-runner-fail-count (test-runner-current)) 0))