view tests/test-unlinkat.c @ 12517:013b270a78b9

tests: don't require debug system() to pass When running a cross-compilation to mingw on a Linux host, but without a valid mingw rm executable, the debug-only system() call would fail. This is not fatal to the test, since the call is merely a debugging aid if a prior call to the test encountered a failure and left garbage; in general, the tests should pass and the system() call have nothing to clean in the first place. Also, the system() call only needs to happen once at startup, not once per iteration into the tests performed by .h files. * tests/test-lstat.h (test_lstat_func): Move debug cleanup... * tests/test-rmdir.h (test_rmdir_func): Likewise. * tests/test-unlink.h (test_unlink_func): Likewise. * tests/test-fstatat.c (main): ...into callers. * tests/test-lstat.c (main): Likewise. * tests/test-rmdir.c (main): Likewise. * tests/test-unlink.c (main): Likewise. * tests/test-unlinkat.c (main): Likewise. * tests/test-areadlink-with-size.c (main): Don't require a debug-only system call to pass, aiding cross-testing to mingw. * tests/test-areadlink.c (main): Likewise. * tests/test-areadlinkat-with-size.c (main): Likewise. * tests/test-areadlinkat.c (main): Likewise. * tests/test-canonicalize-lgpl.c (main): Likewise. * tests/test-canonicalize.c (main): Likewise. * tests/test-chown.c (main): Likewise. * tests/test-fchownat.c (main): Likewise. * tests/test-lchown.c (main): Likewise. * tests/test-fdutimensat.c (main): Likewise. * tests/test-futimens.c (main): Likewise. * tests/test-link.c (main): Likewise. * tests/test-linkat.c (main): Likewise. * tests/test-mkdir.c (main): Likewise. * tests/test-mkdirat.c (main): Likewise. * tests/test-mkfifo.c (main): Likewise. * tests/test-mkfifoat.c (main): Likewise. * tests/test-mknod.c (main): Likewise. * tests/test-readlink.c (main): Likewise. * tests/test-remove.c (main): Likewise. * tests/test-rename.c (main): Likewise. * tests/test-renameat.c (main): Likewise. * tests/test-symlink.c (main): Likewise. * tests/test-symlinkat.c (main): Likewise. * tests/test-utimens.c (main): Likewise. * tests/test-utimensat.c (main): Likewise. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Tue, 29 Dec 2009 06:58:18 -0700
parents a48d3d749ca5
children c2cbabec01dd
line wrap: on
line source

/* Tests of unlinkat.
   Copyright (C) 2009 Free Software Foundation, Inc.

   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; either version 3 of the License, or
   (at your option) any later version.

   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, see <http://www.gnu.org/licenses/>.  */

/* Written by Eric Blake <ebb9@byu.net>, 2009.  */

#include <config.h>

#include <unistd.h>

#include "signature.h"
SIGNATURE_CHECK (unlinkat, int, (int, char const *, int));

#include <fcntl.h>
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>

#include "unlinkdir.h"
#include "macros.h"

#define BASE "test-unlinkat.t"

#include "test-rmdir.h"
#include "test-unlink.h"

static int dfd = AT_FDCWD;

/* Wrapper around unlinkat to test rmdir behavior.  */
static int
rmdirat (char const *name)
{
  return unlinkat (dfd, name, AT_REMOVEDIR);
}

/* Wrapper around unlinkat to test unlink behavior.  */
static int
unlinker (char const *name)
{
  return unlinkat (dfd, name, 0);
}

int
main (void)
{
  /* FIXME: Add tests of fd other than ".".  */
  int result1;
  int result2;

  /* Remove any leftovers from a previous partial run.  */
  system ("rm -rf " BASE "*");

  result1 = test_rmdir_func (rmdirat, false);
  result2 = test_unlink_func (unlinker, false);
  ASSERT (result1 == result2);
  dfd = open (".", O_RDONLY);
  ASSERT (0 <= dfd);
  result2 = test_rmdir_func (rmdirat, false);
  ASSERT (result1 == result2);
  result2 = test_unlink_func (unlinker, false);
  ASSERT (result1 == result2);
  ASSERT (close (dfd) == 0);
  if (result1 == 77)
    fputs ("skipping test: symlinks not supported on this file system\n",
           stderr);
  return result1;
}