From: Enrico Scholz Date: Thu, 24 Mar 2005 00:09:18 +0000 (+0000) Subject: added sigbus testcase X-Git-Tag: IPSENTINEL_VERSION_0_12~25 X-Git-Url: http://git.linux-vserver.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=31d3f53fd0e71b230f8e9382b9f46883cbfd1d2f;p=util-vserver.git added sigbus testcase git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@1969 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- diff --git a/util-vserver/lib_internal/testsuite/.cvsignore b/util-vserver/lib_internal/testsuite/.cvsignore index 998a836..49eca71 100644 --- a/util-vserver/lib_internal/testsuite/.cvsignore +++ b/util-vserver/lib_internal/testsuite/.cvsignore @@ -2,6 +2,8 @@ .dirstamp .libs .libs +.nfs0* command copy filecfg-ml +sigbus diff --git a/util-vserver/lib_internal/testsuite/Makefile-files b/util-vserver/lib_internal/testsuite/Makefile-files index 50293b4..aef50ae 100644 --- a/util-vserver/lib_internal/testsuite/Makefile-files +++ b/util-vserver/lib_internal/testsuite/Makefile-files @@ -19,9 +19,11 @@ check_PROGRAMS += lib_internal/testsuite/command if ENSC_HAVE_C99_COMPILER check_PROGRAMS += lib_internal/testsuite/filecfg-ml \ - lib_internal/testsuite/copy + lib_internal/testsuite/copy \ + lib_internal/testsuite/sigbus TESTS += lib_internal/testsuite/filecfg-ml \ - lib_internal/testsuite/copy-check + lib_internal/testsuite/copy-check \ + lib_internal/testsuite/sigbus endif EXTRA_DIST += lib_internal/testsuite/copy-check @@ -38,3 +40,5 @@ lib_internal_testsuite_filecfg_ml_LDADD = $(LIBINTERNAL_GLIBC) lib_internal_testsuite_copy_SOURCES = lib_internal/testsuite/copy.c lib_internal_testsuite_copy_LDADD = $(LIBINTERNAL_GLIBC) + +lib_internal_testsuite_sigbus_SOURCES = lib_internal/testsuite/sigbus.c diff --git a/util-vserver/lib_internal/testsuite/sigbus.c b/util-vserver/lib_internal/testsuite/sigbus.c new file mode 100644 index 0000000..9cb0940 --- /dev/null +++ b/util-vserver/lib_internal/testsuite/sigbus.c @@ -0,0 +1,106 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2005 Enrico Scholz +// +// This program 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; version 2 of the License. +// +// This program 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 this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include + +#define ENSC_WRAPPERS_UNISTD 1 +#define ENSC_WRAPPERS_SOCKET 1 +#include + +int wrapper_exit_code = 1; + +#define TEST_BLOCKSIZE 0x10000 +static bool is_gremlin = false; +static int sync_p[2]; + +static void +testit() +{ + if (!is_gremlin) return; + + char c; + + Esend(sync_p[1], ".", 1, 0); + Erecv(sync_p[1], &c, 1, 0); +} + +#define TESTSUITE_COPY_CODE testit() + +#include "../unify.h" +#include "../unify-copy.c" +#include "../unify-settime.c" + +static bool +checkTrunc(char const *src, + char const *dst, + struct stat const *st, + size_t pos) +{ + pid_t pid = Efork(); + + if (pid==0) { + char c; + + Erecv(sync_p[0], &c, 1, 0); + truncate(src, pos); + Esend(sync_p[0], &c, 1, 0); + exit(0); + } + + unlink(dst); + return !copyReg(src, st, dst); +} + +int main() +{ + char f_name0[] = "/tmp/sigbus.XXXXXX"; + char f_name1[] = "/tmp/sigbus.XXXXXX"; + int fd_src = mkstemp(f_name0); + int fd_dst = mkstemp(f_name1); + char buf[TEST_BLOCKSIZE] = { [0] = '\0' }; + struct stat st; + + fd_src = + + write(fd_src, buf, sizeof(buf)); + close(fd_src); + close(fd_dst); + + unlink(f_name1); + stat(f_name0, &st); + if (!copyReg(f_name0, &st, f_name1)) + return EXIT_FAILURE; + + + is_gremlin = true; + + Esocketpair(AF_LOCAL, SOCK_STREAM, 0, sync_p); + + return (checkTrunc(f_name0, f_name1, &st, TEST_BLOCKSIZE/2) && + checkTrunc(f_name0, f_name1, &st, 0x2345) + ? EXIT_SUCCESS : EXIT_FAILURE); +}