summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/syscalls.scm47
1 files changed, 46 insertions, 1 deletions
diff --git a/tests/syscalls.scm b/tests/syscalls.scm
index ab34fc825b..51846d3c36 100644
--- a/tests/syscalls.scm
+++ b/tests/syscalls.scm
@@ -18,7 +18,9 @@
 
 (define-module (test-syscalls)
   #:use-module (guix build syscalls)
-  #:use-module (srfi srfi-64))
+  #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-64)
+  #:use-module (ice-9 match))
 
 ;; Test the (guix build syscalls) module, although there's not much that can
 ;; actually be tested without being root.
@@ -42,6 +44,49 @@
       ;; Both return values have been encountered in the wild.
       (memv (system-error-errno args) (list EPERM ENOENT)))))
 
+(test-assert "swapon, ENOENT/EPERM"
+  (catch 'system-error
+    (lambda ()
+      (swapon "/does-not-exist")
+      #f)
+    (lambda args
+      (memv (system-error-errno args) (list EPERM ENOENT)))))
+
+(test-assert "swapoff, EINVAL/EPERM"
+  (catch 'system-error
+    (lambda ()
+      (swapoff "/does-not-exist")
+      #f)
+    (lambda args
+      (memv (system-error-errno args) (list EPERM EINVAL)))))
+
+(test-assert "all-network-interfaces"
+  (match (all-network-interfaces)
+    (((? string? names) ..1)
+     (member "lo" names))))
+
+(test-assert "network-interfaces"
+  (match (network-interfaces)
+    (((? string? names) ..1)
+     (lset<= string=? names (all-network-interfaces)))))
+
+(test-assert "network-interface-flags"
+  (let* ((sock  (socket SOCK_STREAM AF_INET 0))
+         (flags (network-interface-flags sock "lo")))
+    (close-port sock)
+    (and (not (zero? (logand flags IFF_LOOPBACK)))
+         (not (zero? (logand flags IFF_UP))))))
+
+(test-equal "loopback-network-interface?"
+  ENODEV
+  (and (loopback-network-interface? "lo")
+       (catch 'system-error
+         (lambda ()
+           (loopback-network-interface? "nonexistent")
+           #f)
+         (lambda args
+           (system-error-errno args)))))
+
 (test-end)