aboutsummaryrefslogtreecommitdiff
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015, 2022, 2024 Ludovic Courtès <ludo@gnu.org>
;;;
;;; This file is part of GNU Guix.
;;;
;;; GNU Guix is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; GNU Guix is distributed in the hope that it will be useful, but
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;; GNU General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.

(define-module (test-cpio)
  #:use-module (guix cpio)
  #:use-module (guix tests)
  #:use-module ((guix build utils)
                #:select (which call-with-temporary-output-file))
  #:use-module (ice-9 match)
  #:use-module (ice-9 popen)
  #:use-module (rnrs io ports)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-26)
  #:use-module (srfi srfi-64))

(define %cpio-program
  (which "cpio"))

(define %test-file
  (search-path %load-path "guix.scm"))


(test-begin "cpio")

;; The cpio format expects 'ino' to fit in 32 bits.  If we have a bigger inode
;; number, skip this test.
(test-skip
 (if (>= (stat:ino (lstat %test-file)) (expt 2 32)) 1 0))
(test-assert "file->cpio-header + write-cpio-header + read-cpio-header"
  (let* ((header (file->cpio-header %test-file)))
    (call-with-values
        (lambda ()
          (open-bytevector-output-port))
      (lambda (port get-bv)
        (write-cpio-header header port)
        (let ((port (open-bytevector-input-port (get-bv))))
          (equal? header (read-cpio-header port)))))))

(unless %cpio-program (test-skip 1))
(test-assert "bit-identical to GNU cpio's output"
  (call-with-temporary-output-file
   (lambda (link _)
     (delete-file link)
     (symlink "chbouib" link)

     (let ((files (cons* "/"
                         (canonicalize-path
                          (dirname (search-path %load-path "guix.scm")))
                         link
                         (map (compose canonicalize-path
                                       (cut search-path %load-path <>))
                              '("guix.scm" "guix/build/syscalls.scm"
                                "guix/packages.scm")))))
       (call-with-temporary-output-file
        (lambda (ref-file _)
          (let ((pipe (open-pipe* OPEN_WRITE %cpio-program "-o" "-O" ref-file
                                  "-H" "newc" "--null")))
            (for-each (lambda (file)
                        (format pipe "~a\0" file))
                      files)
            (and (zero? (close-pipe pipe))
                 (call-with-temporary-output-file
                  (lambda (file port)
                    (write-cpio-archive files port)
                    (close-port port)
                    (or (file=? ref-file file)
                        (throw 'cpio-archives-differ files
                               ref-file file
                               (stat:size (stat ref-file))
                               (stat:size (stat file))))))))))))))

(test-end "cpio")
om> Alírio Eyng <alirioeyng@gmail.com> Amin Bandali <bandali@gnu.org> <mab@gnu.org> Amirouche Boubekki <amirouche@hypermove.net> Andreas Enge <andreas@enge.fr> <andreas.enge@inria.fr> Andreas Enge <andreas@enge.fr> <privat@xobs-novena> Andy Wingo <wingo@igalia.com> <wingo@pobox.com> Ben Woodcroft <donttrustben@gmail.com> Ben Woodcroft <donttrustben@gmail.com> <b.woodcroft@uq.edu.au> Ben Woodcroft <donttrustben@gmail.com> <donttrustben near gmail.com> Brett Gilio <brettg@gnu.org> <brettg@posteo.net> Christine Lemmer-Webber <cwebber@dustycloud.org> Claes Wallin (韋嘉誠) <claes.wallin@greatsinodevelopment.com> Cyprien Nicolas <cyprien@nicolas.tf> <c.nicolas+gitorious@gmail.com> Daniel Pimentel <d4n1@d4n1.org> <d4n1@member.fsf.org> Danny Milosavljevic <dannym@scratchpost.org> <dannym+a@scratchpost.org> David Hashe <david.hashe@dhashe.com> <address@hidden> David Thompson <davet@gnu.org> <dthompson2@worcester.edu> David Thompson <davet@gnu.org> <dthompson@member.fsf.org> David Thompson <davet@gnu.org> <dthompson@vistahigherlearning.com> Deck Pickard <deck.r.pickard@gmail.com> <nebu@kipple> Eric Bavier <bavier@posteo.net> <ericbavier@gmail.com> Eric Bavier <bavier@posteo.net> <bavier@member.fsf.org> Eric Dvorsak <eric@dvorsak.fr> <yenda1@gmail.com> Evgeny Pisemsky <mail@pisemsky.site> <evgeny@pisemsky.com> George Clemmer <myglc2@gmail.com> ison <ison@airmail.cc> <ison111@protonmail.com> Ivan Vilata i Balaguer <ivan@selidor.net> Jakob L. Kreuze <zerodaysfordays@sdf.org> <zerodaysfordays@sdf.lonestar.org> Jeff Mickey <j@codemac.net> <jm@igneous.io> John Darrington <jmd@gnu.org> <john@darrington.wattle.id.au> John J. Foerch <jjfoerch@earthlink.net> Joshua Grant <tadni@riseup.net> <gzg@riseup.net> Joshua Grant <tadni@riseup.net> <jgrant@parenthetical.io> Joshua Grant <tadni@riseup.net> <tadnimi@gmail.com> Joshua Grant <tadni@riseup.net> <youlysses@riseup.net> Juliana Sims <juli@incana.org> <jtsims@protonmail.com> Kei Kebreau <kkebreau@posteo.net> Leo Famulari <leo@famulari.name> <lfamular@gmail.com> Liliana Marie Prikler <liliana.prikler@gmail.com> Liliana Marie Prikler <liliana.prikler@gmail.com> Leo Prikler <leo.prikler@student.tugraz.at> Ludovic Courtès <ludo@gnu.org> <ludovic.courtes@inria.fr> Marek Benc <dusxmt@gmx.com> <merkur32@gmail.com> Marius Bakke <marius@gnu.org> <mbakke@fastmail.com> Marius Bakke <marius@gnu.org> <m.bakke@warwick.ac.uk> Marius Bakke <marius@gnu.org> <marius.bakke@usit.uio.no> Marius Bakke <marius@gnu.org> <mbakke@berlin.guixsd.org> Mathieu Lirzin <mthl@gnu.org> <mthl@openmailbox.org> Mathieu Lirzin <mthl@gnu.org> <mathieu.lirzin@openmailbox.org> Mathieu Othacehe <m.othacehe@gmail.com> Mathieu Othacehe <mathieu.othacehe@parrot.com> Mathieu Othacehe <othacehe@gnu.org> Matthew James Kraai <kraai@ftbfs.org> Nikita Karetnikov <nikita@karetnikov.org> <nikita.karetnikov@gmail.com> nikita <nikita@n0.is> nikita <nikita@n0.is> ng0 <ng0@n0.is> nikita <nikita@n0.is> Nils Gillmann <ng0@n0.is> nikita <nikita@n0.is> Nils Gillmann <gillmann@infotropique.org> nikita <nikita@n0.is> ng0 <ng0@crash.cx> nikita <nikita@n0.is> <ng0@infotropique.org> nikita <nikita@n0.is> <ng0@no-reply.infotropique.org> nikita <nikita@n0.is> <ng0@no-reply.pragmatique.xyz> nikita <nikita@n0.is> <ng0@pragmatique.xyz> nikita <nikita@n0.is> <contact.ng0@cryptolab.net> nikita <nikita@n0.is> <ng0@we.make.ritual.n0.is> nikita <nikita@n0.is> <ngillmann@runbox.com> nikita <nikita@n0.is> <niasterisk@grrlz.net> nikita <nikita@n0.is> <ng@niasterisk.space> nikita <nikita@n0.is> <ng0@libertad.pw> Pierre Neidhardt <mail@ambrevar.xyz> Pierre-Antoine Rouby <pierre-antoine.rouby@inria.fr> Pjotr Prins <pjotr.guix@thebird.nl> <pjotr.public01@thebird.nl> Pjotr Prins <pjotr.guix@thebird.nl> <pjotr.public12@thebird.nl> Pjotr Prins <pjotr.guix@thebird.nl> <pjotr.public12@email> Raimon Grau <raimonster@gmail.com> <raimon@3scale.net> Raoul Jean Pierre Bonnal <ilpuccio.febo@gmail.com> Raymond Nicholson <rain1@openmailbox.org> Rene Saavedra <rennes@openmailbox.org> Ricardo Wurmus <rekado@elephly.net> Ricardo Wurmus <rekado@elephly.net> <ricardo.wurmus@mdc-berlin.de> Sou Bunnbu (宋文武) <iyzsong@gmail.com> Sou Bunnbu (宋文武) <iyzsong@gmail.com> <iyzsong@member.fsf.org> Stefan Reichör <stefan@xsteve.at> Taylan Ulrich Bayırlı/Kammer <taylanbayirli@gmail.com> Theodoros Foradis <theodoros.for@openmailbox.org> <theodoros@foradis.org> Thomas Danckaert <thomas.danckaert@gmail.com> <post@thomasdanckaert.be> Tobias Geerinckx-Rice <me@tobias.gr> <tobias.geerinckx.rice@gmail.com> Tomas Volf <~@wolfsden.cz> <wolf@wolfsden.cz> Tomáš Čech <sleep_walker@gnu.org> <sleep_walker@suse.cz> Vincent Legoll <vincent.legoll@gmail.com> <vincent.legoll@idgrilles.fr> Zheng Junjie <873216071@qq.com> Z572 <873216071@qq.com>