install: Add GRUB to the set of global packages.
[jackhill/guix/guix.git] / tests / syscalls.scm
CommitLineData
29fa45f4
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2014 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/>.
18
19(define-module (test-syscalls)
20 #:use-module (guix build syscalls)
4d54785c 21 #:use-module (srfi srfi-1)
7585016f
LC
22 #:use-module (srfi srfi-64)
23 #:use-module (ice-9 match))
29fa45f4
LC
24
25;; Test the (guix build syscalls) module, although there's not much that can
26;; actually be tested without being root.
27
28(test-begin "syscalls")
29
30(test-equal "mount, ENOENT"
31 ENOENT
32 (catch 'system-error
33 (lambda ()
34 (mount "/dev/null" "/does-not-exist" "ext2")
35 #f)
36 (compose system-error-errno list)))
37
35066aa5 38(test-assert "umount, ENOENT/EPERM"
29fa45f4
LC
39 (catch 'system-error
40 (lambda ()
41 (umount "/does-not-exist")
42 #f)
35066aa5
LC
43 (lambda args
44 ;; Both return values have been encountered in the wild.
45 (memv (system-error-errno args) (list EPERM ENOENT)))))
29fa45f4 46
715fc9d4
LC
47(test-assert "swapon, ENOENT/EPERM"
48 (catch 'system-error
49 (lambda ()
50 (swapon "/does-not-exist")
51 #f)
52 (lambda args
53 (memv (system-error-errno args) (list EPERM ENOENT)))))
54
2793c0fb 55(test-assert "swapoff, ENOENT/EINVAL/EPERM"
715fc9d4
LC
56 (catch 'system-error
57 (lambda ()
58 (swapoff "/does-not-exist")
59 #f)
60 (lambda args
2793c0fb 61 (memv (system-error-errno args) (list EPERM EINVAL ENOENT)))))
715fc9d4 62
4d54785c
LC
63(test-assert "all-network-interfaces"
64 (match (all-network-interfaces)
65 (((? string? names) ..1)
66 (member "lo" names))))
67
7585016f
LC
68(test-assert "network-interfaces"
69 (match (network-interfaces)
70 (((? string? names) ..1)
4d54785c 71 (lset<= string=? names (all-network-interfaces)))))
7585016f 72
973eea34
LC
73(test-assert "network-interface-flags"
74 (let* ((sock (socket SOCK_STREAM AF_INET 0))
75 (flags (network-interface-flags sock "lo")))
76 (close-port sock)
77 (and (not (zero? (logand flags IFF_LOOPBACK)))
78 (not (zero? (logand flags IFF_UP))))))
79
80(test-equal "loopback-network-interface?"
81 ENODEV
82 (and (loopback-network-interface? "lo")
83 (catch 'system-error
84 (lambda ()
85 (loopback-network-interface? "nonexistent")
86 #f)
87 (lambda args
88 (system-error-errno args)))))
89
29fa45f4
LC
90(test-end)
91
92\f
93(exit (= (test-runner-fail-count (test-runner-current)) 0))