Commit | Line | Data |
---|---|---|
7a18c3cc | 1 | ;;; GNU Guix --- Functional package management for GNU |
2880dc30 | 2 | ;;; Copyright © 2015, 2022 Ludovic Courtès <ludo@gnu.org> |
7a18c3cc LC |
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-cpio) | |
20 | #:use-module (guix cpio) | |
21 | #:use-module (guix tests) | |
22 | #:use-module ((guix build utils) #:select (which)) | |
23 | #:use-module ((guix utils) #:select (call-with-temporary-output-file)) | |
24 | #:use-module (ice-9 match) | |
25 | #:use-module (ice-9 popen) | |
26 | #:use-module (rnrs io ports) | |
27 | #:use-module (srfi srfi-1) | |
28 | #:use-module (srfi srfi-26) | |
29 | #:use-module (srfi srfi-64)) | |
30 | ||
31 | (define %cpio-program | |
32 | (which "cpio")) | |
33 | ||
2880dc30 LC |
34 | (define %test-file |
35 | (search-path %load-path "guix.scm")) | |
36 | ||
7a18c3cc LC |
37 | \f |
38 | (test-begin "cpio") | |
39 | ||
2880dc30 LC |
40 | ;; The cpio format expects 'ino' to fit in 32 bits. If we have a bigger inode |
41 | ;; number, skip this test. | |
42 | (test-skip | |
43 | (if (>= (stat:ino (lstat %test-file)) (expt 2 32)) 1 0)) | |
7a18c3cc | 44 | (test-assert "file->cpio-header + write-cpio-header + read-cpio-header" |
2880dc30 | 45 | (let* ((header (file->cpio-header %test-file))) |
7a18c3cc LC |
46 | (call-with-values |
47 | (lambda () | |
48 | (open-bytevector-output-port)) | |
49 | (lambda (port get-bv) | |
50 | (write-cpio-header header port) | |
51 | (let ((port (open-bytevector-input-port (get-bv)))) | |
52 | (equal? header (read-cpio-header port))))))) | |
53 | ||
54 | (unless %cpio-program (test-skip 1)) | |
55 | (test-assert "bit-identical to GNU cpio's output" | |
56 | (call-with-temporary-output-file | |
57 | (lambda (link _) | |
58 | (delete-file link) | |
59 | (symlink "chbouib" link) | |
60 | ||
61 | (let ((files (cons* "/" | |
62 | (canonicalize-path | |
63 | (dirname (search-path %load-path "guix.scm"))) | |
64 | link | |
65 | (map (compose canonicalize-path | |
66 | (cut search-path %load-path <>)) | |
67 | '("guix.scm" "guix/build/syscalls.scm" | |
68 | "guix/packages.scm"))))) | |
69 | (call-with-temporary-output-file | |
70 | (lambda (ref-file _) | |
71 | (let ((pipe (open-pipe* OPEN_WRITE %cpio-program "-o" "-O" ref-file | |
72 | "-H" "newc" "--null"))) | |
73 | (for-each (lambda (file) | |
74 | (format pipe "~a\0" file)) | |
75 | files) | |
76 | (and (zero? (close-pipe pipe)) | |
77 | (call-with-temporary-output-file | |
78 | (lambda (file port) | |
79 | (write-cpio-archive files port) | |
80 | (close-port port) | |
81 | (or (file=? ref-file file) | |
82 | (throw 'cpio-archives-differ files | |
83 | ref-file file | |
84 | (stat:size (stat ref-file)) | |
85 | (stat:size (stat file)))))))))))))) | |
86 | ||
87 | (test-end "cpio") |