diff options
author | Marc Espie <espie@cvs.openbsd.org> | 2019-07-09 13:49:48 +0000 |
---|---|---|
committer | Marc Espie <espie@cvs.openbsd.org> | 2019-07-09 13:49:48 +0000 |
commit | 0a3f3de573f95d16c96427b619e315cb6d1c88c6 (patch) | |
tree | c5cdcac3139c1c5ac9e05a928576dc4f99968b37 /regress | |
parent | dd150e9a84047b2f0cc7337e32eee139c2a9c6ab (diff) |
add a test using fault injection to trigger OpenBSD::Temp errors
Diffstat (limited to 'regress')
-rw-r--r-- | regress/usr.sbin/pkg_add/Makefile | 30 | ||||
-rw-r--r-- | regress/usr.sbin/pkg_add/Wrapper.pm | 47 | ||||
-rw-r--r-- | regress/usr.sbin/pkg_add/inject-temp1 | 18 |
3 files changed, 85 insertions, 10 deletions
diff --git a/regress/usr.sbin/pkg_add/Makefile b/regress/usr.sbin/pkg_add/Makefile index 538557a43a5..7be626e9f67 100644 --- a/regress/usr.sbin/pkg_add/Makefile +++ b/regress/usr.sbin/pkg_add/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.66 2019/07/09 10:48:30 espie Exp $ +# $OpenBSD: Makefile,v 1.67 2019/07/09 13:49:47 espie Exp $ REGRESS_TARGETS=pkgnames pkgpaths signatures depends-check longnames pkgcfl \ collision-check1 collision-check2 collision-check3 \ @@ -10,23 +10,23 @@ REGRESS_TARGETS=pkgnames pkgpaths signatures depends-check longnames pkgcfl \ lib-report4 lib-report5 lib-report6 lib-report7 \ qttest gstest exotest inter1 manual1 oldlib1 \ usertest-1 usertest-2 usertest-3 cups-bug nettle-bug \ - tying-1 tying-2 tag-delete setsprint + tying-1 tying-2 tag-delete setsprint temp-error1 # lots of tests that really require a vstat overhaul REGRESS_EXPECTED_FAILURES = collision-check1 collision-check2 \ collision-check5 collision-check6 collision-check7 \ exotest tying-2 -ADD_PKG=perl ${.CURDIR}/my add -DELETE_PKG=perl ${.CURDIR}/my delete -INFO_PKG=perl ${.CURDIR}/my info -CREATE_PKG=perl ${.CURDIR}/mycreate +ADD_PKG=perl -I${.CURDIR} ${.CURDIR}/my add +DELETE_PKG=perl -I${.CURDIR} ${.CURDIR}/my delete +INFO_PKG=perl -I${.CURDIR} ${.CURDIR}/my info +CREATE_PKG=perl -I${.CURDIR} ${.CURDIR}/mycreate LONG1=iamareallongfilenamethatcantberepresentedcorrectlyinatararchivebutwewantittohappenanywaysohmygodaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa42 LONG2=iamanotherreallygfilenamethatcantberepresentedcorrectlyinatararchivebutwewantittohappenanywaysohmygodaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa42 LONG3=iamanotherreallylonglinkthatcantberepresentedcorrectlyinatararchivebutwewantittohappenanywaysohmygodaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa42 LONG4=iamanotherreallylonghardlinkthatcantberepresentedcorrectlyinatararchivebutwewantittohappenanywaysohmygodaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa42 -NUMBERS != jot 40 +NUMBERS != jot 50 .for i in ${NUMBERS} S$i ?= ${.OBJDIR}/src$i SRC$i ?= ${S$i}/usr/local @@ -34,7 +34,7 @@ D$i ?= ${.OBJDIR}/dest$i DEST$i ?= ${D$i}/usr/local .endfor -# current maxes (used): D39, SRC26, plist24, rep5 +# current maxes (used): D40, SRC26, plist24, rep5 pkgnames: perl ${.CURDIR}/check-name @@ -640,8 +640,8 @@ rep3/$n.tgz: ${.CURDIR}/newcups/$n/+CONTENTS cups-bug: ${CUPS_FILES} rm -rf ${D36} mkdir -p ${D36}/vardbpkg ${D36}/usr/local - ROOT=${D36} PKG_PATH=${.OBJDIR}/rep2 INJECT=${.CURDIR}/inject-order ${ADD_PKG} -Dstub cups - ROOT=${D36} PKG_PATH=${.OBJDIR}/rep3 INJECT=${.CURDIR}/inject-order ${ADD_PKG} -Dstub -u + ROOT=${D36} PKG_PATH=${.OBJDIR}/rep2 INJECT=inject-order ${ADD_PKG} -Dstub cups + ROOT=${D36} PKG_PATH=${.OBJDIR}/rep3 INJECT=inject-order ${ADD_PKG} -Dstub -u usertest-1: @if ${CREATE_PKG} -u ${.CURDIR}/baduser1 \ @@ -763,6 +763,16 @@ tag-delete: rep1/d-0.tgz echo "@depend graphics/zoinx:zoinx-*:zoinx-2" >> ${D40}/pkgdb/d-0/+CONTENTS @ROOT=${D40} ${DELETE_PKG} d +temp1.ref: + @echo "Fatal error: User `whoami` couldn't create temp dir as /nonexistent/pkginfo.XXXXXXXXXX: No such file or directory" >$@ + @echo " at /usr/libdata/perl5/OpenBSD/PackageLocation.pm" >>$@ + @echo okay >>$@ + +temp-error1: rep0/a-0.tgz rep0/b-0.tgz temp1.ref + @-rm -rf ${D40} + @{ INJECT=inject-temp1 ROOT=${D40} SILENT=1 ${ADD_PKG} rep0/a-0.tgz 1>/dev/null|| echo okay ; } 2>&1|sed -e 's/ line .*//' >temp1.out + @diff -u temp1.out temp1.ref + .PHONY: ${REGRESS_TARGETS} clean: diff --git a/regress/usr.sbin/pkg_add/Wrapper.pm b/regress/usr.sbin/pkg_add/Wrapper.pm new file mode 100644 index 00000000000..3f75dff0ba3 --- /dev/null +++ b/regress/usr.sbin/pkg_add/Wrapper.pm @@ -0,0 +1,47 @@ +#! /usr/bin/perl +# ex:ts=8 sw=4: +# $OpenBSD: Wrapper.pm,v 1.1 2019/07/09 13:49:47 espie Exp $ +# +# Copyright (c) 2010 Marc Espie <espie@openbsd.org> +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +use strict; +use warnings; + +# injection fault wrapper +package Wrapper; +require Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(wrap); + +sub wrap +{ + my ($name, $sub) = @_; + my $typeglob = caller()."::$name"; + my $original; + { + no strict qw(refs); + $original = *$typeglob{CODE}; + } + my $imposter = sub { + return &$sub($original, @_); + }; + + { + no strict qw(refs); + no warnings qw(redefine); + *{$typeglob} = $imposter; + } +} +1; diff --git a/regress/usr.sbin/pkg_add/inject-temp1 b/regress/usr.sbin/pkg_add/inject-temp1 new file mode 100644 index 00000000000..5382a45ca8b --- /dev/null +++ b/regress/usr.sbin/pkg_add/inject-temp1 @@ -0,0 +1,18 @@ +#! /usr/bin/perl + +# $OpenBSD: inject-temp1,v 1.1 2019/07/09 13:49:47 espie Exp $ +#use OpenBSD::Temp; +use strict; +use warnings; +use OpenBSD::Temp; + +package OpenBSD::Temp; +use Wrapper; + +wrap('permanent_dir', + sub { + my $original = shift; + $_[0] = "/nonexistent"; + goto &$original; + }); +1; |