cpio.scm 3.3 KB

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