Commit | Line | Data |
---|---|---|
29fa45f4 | 1 | ;;; GNU Guix --- Functional package management for GNU |
d35c5e29 | 2 | ;;; Copyright © 2014, 2015 Ludovic Courtès <ludo@gnu.org> |
b4abdeb6 | 3 | ;;; Copyright © 2015 David Thompson <davet@gnu.org> |
29fa45f4 LC |
4 | ;;; |
5 | ;;; This file is part of GNU Guix. | |
6 | ;;; | |
7 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
8 | ;;; under the terms of the GNU General Public License as published by | |
9 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
10 | ;;; your option) any later version. | |
11 | ;;; | |
12 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
13 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | ;;; GNU General Public License for more details. | |
16 | ;;; | |
17 | ;;; You should have received a copy of the GNU General Public License | |
18 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
19 | ||
20 | (define-module (test-syscalls) | |
21 | #:use-module (guix build syscalls) | |
4d54785c | 22 | #:use-module (srfi srfi-1) |
381ac93b | 23 | #:use-module (srfi srfi-26) |
7585016f LC |
24 | #:use-module (srfi srfi-64) |
25 | #:use-module (ice-9 match)) | |
29fa45f4 LC |
26 | |
27 | ;; Test the (guix build syscalls) module, although there's not much that can | |
28 | ;; actually be tested without being root. | |
29 | ||
30 | (test-begin "syscalls") | |
31 | ||
32 | (test-equal "mount, ENOENT" | |
33 | ENOENT | |
34 | (catch 'system-error | |
35 | (lambda () | |
36 | (mount "/dev/null" "/does-not-exist" "ext2") | |
37 | #f) | |
38 | (compose system-error-errno list))) | |
39 | ||
35066aa5 | 40 | (test-assert "umount, ENOENT/EPERM" |
29fa45f4 LC |
41 | (catch 'system-error |
42 | (lambda () | |
43 | (umount "/does-not-exist") | |
44 | #f) | |
35066aa5 LC |
45 | (lambda args |
46 | ;; Both return values have been encountered in the wild. | |
47 | (memv (system-error-errno args) (list EPERM ENOENT))))) | |
29fa45f4 | 48 | |
ccea821b | 49 | (test-assert "mount-points" |
381ac93b LC |
50 | ;; Reportedly "/" is not always listed as a mount point, so check a few |
51 | ;; others (see <http://bugs.gnu.org/20261>.) | |
52 | (any (cute member <> (mount-points)) | |
53 | '("/" "/proc" "/sys" "/dev"))) | |
ccea821b | 54 | |
715fc9d4 LC |
55 | (test-assert "swapon, ENOENT/EPERM" |
56 | (catch 'system-error | |
57 | (lambda () | |
58 | (swapon "/does-not-exist") | |
59 | #f) | |
60 | (lambda args | |
61 | (memv (system-error-errno args) (list EPERM ENOENT))))) | |
62 | ||
2793c0fb | 63 | (test-assert "swapoff, ENOENT/EINVAL/EPERM" |
715fc9d4 LC |
64 | (catch 'system-error |
65 | (lambda () | |
66 | (swapoff "/does-not-exist") | |
67 | #f) | |
68 | (lambda args | |
2793c0fb | 69 | (memv (system-error-errno args) (list EPERM EINVAL ENOENT))))) |
715fc9d4 | 70 | |
b4abdeb6 DT |
71 | (test-assert "mkdtemp!" |
72 | (let* ((tmp (or (getenv "TMPDIR") "/tmp")) | |
73 | (dir (mkdtemp! (string-append tmp "/guix-test-XXXXXX")))) | |
74 | (and (file-exists? dir) | |
75 | (begin | |
76 | (rmdir dir) | |
77 | #t)))) | |
78 | ||
4d54785c LC |
79 | (test-assert "all-network-interfaces" |
80 | (match (all-network-interfaces) | |
81 | (((? string? names) ..1) | |
82 | (member "lo" names)))) | |
83 | ||
7585016f LC |
84 | (test-assert "network-interfaces" |
85 | (match (network-interfaces) | |
86 | (((? string? names) ..1) | |
4d54785c | 87 | (lset<= string=? names (all-network-interfaces))))) |
7585016f | 88 | |
973eea34 | 89 | (test-assert "network-interface-flags" |
c9bf64d6 | 90 | (let* ((sock (socket AF_INET SOCK_STREAM 0)) |
973eea34 LC |
91 | (flags (network-interface-flags sock "lo"))) |
92 | (close-port sock) | |
93 | (and (not (zero? (logand flags IFF_LOOPBACK))) | |
94 | (not (zero? (logand flags IFF_UP)))))) | |
95 | ||
96 | (test-equal "loopback-network-interface?" | |
97 | ENODEV | |
98 | (and (loopback-network-interface? "lo") | |
99 | (catch 'system-error | |
100 | (lambda () | |
101 | (loopback-network-interface? "nonexistent") | |
102 | #f) | |
103 | (lambda args | |
104 | (system-error-errno args))))) | |
105 | ||
c9bf64d6 | 106 | (test-skip (if (zero? (getuid)) 1 0)) |
d35c5e29 | 107 | (test-assert "set-network-interface-flags" |
c9bf64d6 LC |
108 | (let ((sock (socket AF_INET SOCK_STREAM 0))) |
109 | (catch 'system-error | |
110 | (lambda () | |
111 | (set-network-interface-flags sock "lo" IFF_UP)) | |
112 | (lambda args | |
113 | (close-port sock) | |
d35c5e29 LC |
114 | ;; We get EPERM with Linux 3.18ish and EACCES with 2.6.32. |
115 | (memv (system-error-errno args) (list EPERM EACCES)))))) | |
c9bf64d6 LC |
116 | |
117 | (test-equal "network-interface-address lo" | |
118 | (make-socket-address AF_INET (inet-pton AF_INET "127.0.0.1") 0) | |
119 | (let* ((sock (socket AF_INET SOCK_STREAM 0)) | |
120 | (addr (network-interface-address sock "lo"))) | |
121 | (close-port sock) | |
122 | addr)) | |
123 | ||
d35c5e29 | 124 | (test-assert "set-network-interface-address" |
c9bf64d6 LC |
125 | (let ((sock (socket AF_INET SOCK_STREAM 0))) |
126 | (catch 'system-error | |
127 | (lambda () | |
128 | (set-network-interface-address sock "nonexistent" | |
129 | (make-socket-address | |
130 | AF_INET | |
131 | (inet-pton AF_INET "127.12.14.15") | |
132 | 0))) | |
133 | (lambda args | |
134 | (close-port sock) | |
d35c5e29 LC |
135 | ;; We get EPERM with Linux 3.18ish and EACCES with 2.6.32. |
136 | (memv (system-error-errno args) (list EPERM EACCES)))))) | |
c9bf64d6 | 137 | |
29fa45f4 LC |
138 | (test-end) |
139 | ||
140 | \f | |
141 | (exit (= (test-runner-fail-count (test-runner-current)) 0)) |