summaryrefslogtreecommitdiffstats
path: root/bin/pax
diff options
context:
space:
mode:
authorjmmv <jmmv@FreeBSD.org>2013-12-11 04:09:17 +0000
committerjmmv <jmmv@FreeBSD.org>2013-12-11 04:09:17 +0000
commitcfc6ad9bc622f4196577ecf38575ca78dfe5c005 (patch)
treec357c3541ca854e3c662bf4b75f67946d3672f84 /bin/pax
parent865b783eec56bcde5b1f272b4b441a7c6a6c10fa (diff)
downloadFreeBSD-src-cfc6ad9bc622f4196577ecf38575ca78dfe5c005.zip
FreeBSD-src-cfc6ad9bc622f4196577ecf38575ca78dfe5c005.tar.gz
Migrate tools/regression/bin/ tests to the new layout.
This change is a proof of concept on how to easily integrate existing tests from the tools/regression/ hierarchy into the /usr/tests/ test suite and on how to adapt them to the new layout for src. To achieve these goals, this change: - Moves tests from tools/regression/bin/<tool>/ to bin/<tool>/tests/. - Renames the previous regress.sh files to legacy_test.sh. - Adds Makefiles to build and install the tests and all their supporting data files into /usr/tests/bin/. - Plugs the legacy_test test programs into the test suite using the new TAP backend for Kyua (appearing in 0.8) so that the code of the test programs does not have to change. - Registers the new directories in the BSD.test.dist mtree file. Reviewed by: freebsd-testing Approved by: rpaulo (mentor)
Diffstat (limited to 'bin/pax')
-rw-r--r--bin/pax/Makefile6
-rw-r--r--bin/pax/tests/Makefile9
-rw-r--r--bin/pax/tests/legacy_test.sh91
3 files changed, 106 insertions, 0 deletions
diff --git a/bin/pax/Makefile b/bin/pax/Makefile
index 9e8d4e1..95f18bb 100644
--- a/bin/pax/Makefile
+++ b/bin/pax/Makefile
@@ -1,6 +1,8 @@
# @(#)Makefile 8.1 (Berkeley) 5/31/93
# $FreeBSD$
+.include <bsd.own.mk>
+
# To install on versions prior to BSD 4.4 the following may have to be
# defined with CFLAGS +=
#
@@ -30,4 +32,8 @@ SRCS= ar_io.c ar_subs.c buf_subs.c cache.c cpio.c file_subs.c ftree.c \
gen_subs.c getoldopt.c options.c pat_rep.c pax.c sel_subs.c \
tables.c tar.c tty_subs.c
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.prog.mk>
diff --git a/bin/pax/tests/Makefile b/bin/pax/tests/Makefile
new file mode 100644
index 0000000..b3c4b85
--- /dev/null
+++ b/bin/pax/tests/Makefile
@@ -0,0 +1,9 @@
+# $FreeBSD$
+
+.include <bsd.own.mk>
+
+TESTSDIR= ${TESTSBASE}/bin/pax
+
+TAP_TESTS_SH= legacy_test
+
+.include <tap.test.mk>
diff --git a/bin/pax/tests/legacy_test.sh b/bin/pax/tests/legacy_test.sh
new file mode 100644
index 0000000..7c392cb
--- /dev/null
+++ b/bin/pax/tests/legacy_test.sh
@@ -0,0 +1,91 @@
+#! /usr/bin/perl
+#
+# $FreeBSD$
+
+use strict;
+use warnings;
+
+use Test::More tests => 6;
+use File::Path qw(rmtree mkpath);
+use Cwd;
+
+my $n = 0;
+sub create_file {
+ my $fn = shift;
+
+ $n++;
+ (my $dir = $fn) =~ s,/[^/]+$,,;
+ mkpath $dir;
+ open my $fd, ">", $fn or die "$fn: $!";
+ print $fd "file $n\n";
+}
+
+
+ustar_pathnames: { SKIP: {
+ # Prove that pax breaks up ustar pathnames properly
+
+ my $top = getcwd . "/ustar-pathnames-1";
+ skip "Current path is too long", 6 if length $top > 92;
+ rmtree $top;
+ my $subdir = "x" . "x" x (92 - length $top);
+ my $work94 = "$top/$subdir";
+ mkpath $work94; # $work is 94 characters long
+
+ my $x49 = "x" x 49;
+ my $x50 = "x" x 50;
+ my $x60 = "x" x 60;
+ my $x95 = "x" x 95;
+
+ my @paths = (
+ "$work94/x099", # 99 chars
+ "$work94/xx100", # 100 chars
+ "$work94/xxx101", # 101 chars
+ "$work94/$x49/${x50}x199", # 199 chars
+ "$work94/$x49/${x50}xx200", # 200 chars
+ "$work94/$x49/${x50}xxx201", # 201 chars
+ "$work94/$x60/${x95}254", # 254 chars
+ "$work94/$x60/${x95}x255", # 255 chars
+ );
+
+ my @l = map { length } @paths;
+
+ my $n = 0;
+ create_file $_ for @paths;
+ system "pax -wf ustar.ok $work94";
+ ok($? == 0, "Wrote 'ustar.ok' containing files with lengths @l");
+
+ (my $orig = $top) =~ s,1$,2,;
+ rmtree $orig;
+ rename $top, $orig;
+
+ system "pax -rf ustar.ok";
+ ok($? == 0, "Restored 'ustar.ok' containing files with lengths @l");
+
+ system "diff -ru $orig $top";
+ ok($? == 0, "Restored files are identical");
+
+ rmtree $top;
+ rename $orig, $top;
+
+ # 256 chars (with components < 100 chars) should not work
+ push @paths, "$work94/x$x60/${x95}x256"; # 256 chars
+ push @l, length $paths[-1];
+ create_file $paths[-1];
+ system "pax -wf ustar.fail1 $work94";
+ ok($?, "Failed to write 'ustar.fail1' containing files with lengths @l");
+
+ # Components with 100 chars shouldn't work
+ unlink $paths[-1];
+ $paths[-1] = "$work94/${x95}xc100"; # 100 char filename
+ $l[-1] = length $paths[-1];
+ create_file $paths[-1];
+ system "pax -wf ustar.fail2 $work94";
+ ok($?, "Failed to write 'ustar.fail2' with a 100 char filename");
+
+ unlink $paths[-1];
+ $paths[-1] = "$work94/${x95}xc100/x"; # 100 char component
+ $l[-1] = length $paths[-1];
+ create_file $paths[-1];
+ system "pax -wf ustar.fail3 $work94";
+ ok($?, "Failed to write 'ustar.fail3' with a 100 char component");
+}}
OpenPOWER on IntegriCloud