| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 |
|
| 19 | (define-module (test-cpio)
|
| 20 | #:use-module (guix cpio)
|
| 21 | #:use-module (guix tests)
|
| 22 | #:use-module ((guix build utils)
|
| 23 | #:select (which 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 |
|
| 34 | (define %test-file
|
| 35 | (search-path %load-path "guix.scm"))
|
| 36 |
|
| 37 |
|
| 38 | (test-begin "cpio")
|
| 39 |
|
| 40 | |
| 41 | |
| 42 | (test-skip
|
| 43 | (if (>= (stat:ino (lstat %test-file)) (expt 2 32)) 1 0))
|
| 44 | (test-assert "file->cpio-header + write-cpio-header + read-cpio-header"
|
| 45 | (let* ((header (file->cpio-header %test-file)))
|
| 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")
|