This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Eliminate uses of "sleep" in V3 testsuite


Benjamin Kosnik wrote:

Sorry I missed the beginning of this thread. Perhaps you've already
found this, but there has been some commentary about fixing this here:

http://gcc.gnu.org/ml/libstdc++/2004-02/msg00015.html

That's an unrelated issue. That issue is that the V3 tests are opening FIFOs in O_RDWR mode, which is undefined behavior according to POSIX. (I didn't check the POSIX standard itself, but the GNU/Linux manual pages say that it is undefined behavior in POSIX, but allowed in GNU/Linux.)


I'm not sure exactly why the V3 testsuite is using FIFOs for these tests. It looks to me like you could test most of the same things (e.g., that binding C++ streams to things other than standard files works) using pipes. That would also allow you to avoid using fork; you could just use select instead, and drop all the synchronization stuff.

Please think about formatting this code consistently, and hopefully like
the rest of libstdc++ hackers do. Suggestion: see C++STYLE.

I checked in the attached patch, after making sure that the tests still pass.


--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
(916) 791-8304
2005-01-03  Mark Mitchell  <mark@codesourcery.com>

	* testsuite/testsuite_hooks.cc: Update coypright and follow style
	guidelines.
	* testsuite/testsuite_hooks.h: Likewise.
	* testsuite/27_io/basic_filebuf/close/char/4879.cc: Use
	semaphores, not sleep.
	* testsuite/27_io/basic_filebuf/close/char/9964.cc: Likewise.
	* testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc: Likewise.
	* testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc: Likewise.
	* testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc:
	Likewise.
	* testsuite/27_io/basic_filebuf/open/char/9507.cc: Likewise.
	* testsuite/27_io/basic_filebuf/underflow/char/10097.cc: Likewise.
	* testsuite/27_io/objects/char/7.cc: Likewise.
	* testsuite/27_io/objects/char/9661-1.cc: Likewise.
	* testsuite/27_io/objects/wchar_t/7.cc: Likewise.
	* testsuite/27_io/objects/wchar_t/9661-1.cc: Likewise.

Index: testsuite/testsuite_hooks.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/testsuite_hooks.cc,v
retrieving revision 1.24
diff -c -5 -p -r1.24 testsuite_hooks.cc
*** testsuite/testsuite_hooks.cc	3 Jan 2005 21:31:34 -0000	1.24
--- testsuite/testsuite_hooks.cc	4 Jan 2005 00:05:35 -0000
***************
*** 1,9 ****
  // -*- C++ -*-
  // Utility subroutines for the C++ library testsuite. 
  //
! // Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,9 ----
  // -*- C++ -*-
  // Utility subroutines for the C++ library testsuite. 
  //
! // Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
*************** namespace __gnu_test
*** 276,287 ****
      struct semid_ds *buf;
      unsigned short *array;
    };
  #endif
  
!   semaphore::semaphore ()
!   {
  #ifdef _GLIBCXX_SYSV_SEM
      // Remeber the PID for the process that created the semaphore set
      // so that only one process will destroy the set.
      pid_ = getpid();
  
--- 276,286 ----
      struct semid_ds *buf;
      unsigned short *array;
    };
  #endif
  
!   semaphore::semaphore() {
  #ifdef _GLIBCXX_SYSV_SEM
      // Remeber the PID for the process that created the semaphore set
      // so that only one process will destroy the set.
      pid_ = getpid();
  
*************** namespace __gnu_test
*** 293,349 ****
  #ifndef SEM_A
  #define SEM_A 0200
  #endif
  
      // Get a semaphore set with one semaphore.
!     sem_set_ = semget (IPC_PRIVATE, 1, SEM_R | SEM_A);
      if (sem_set_ == -1)
        throw std::runtime_error ("could not obtain semaphore set");
  
      // Initialize the semaphore.
      union semun val;
      val.val = 0;
!     if (semctl (sem_set_, 0, SETVAL, val) == -1)
!       throw std::runtime_error ("could not initialize semaphore");
  #else
      // There are no semaphores on this system.  We have no way to mark
      // a test as "unsupported" at runtime, so we just exit, pretending
      // that the test passed.
!     exit (0);
  #endif
    }
  
!   semaphore::~semaphore ()
!   {
  #ifdef _GLIBCXX_SYSV_SEM
      union semun val;
      // Destroy the semaphore set only in the process that created it. 
!     if (pid_ == getpid ())
!       semctl (sem_set_, 0, IPC_RMID, val);
  #endif
    }
  
    void
!   semaphore::signal ()
!   {
  #ifdef _GLIBCXX_SYSV_SEM
      struct sembuf op[1] = {
        { 0, 1, 0 }
      };
!     if (semop (sem_set_, op, 1) == -1)
!       throw std::runtime_error ("could not signal semaphore");
  #endif
    }
  
    void
    semaphore::wait() {
  #ifdef _GLIBCXX_SYSV_SEM
      struct sembuf op[1] = {
        { 0, -1, SEM_UNDO }
      };
!     if (semop (sem_set_, op, 1) == -1)
!       throw std::runtime_error ("could not wait for semaphore");
  #endif    
    }
  }; // namespace __gnu_test
  
  namespace std
--- 292,346 ----
  #ifndef SEM_A
  #define SEM_A 0200
  #endif
  
      // Get a semaphore set with one semaphore.
!     sem_set_ = semget(IPC_PRIVATE, 1, SEM_R | SEM_A);
      if (sem_set_ == -1)
        throw std::runtime_error ("could not obtain semaphore set");
  
      // Initialize the semaphore.
      union semun val;
      val.val = 0;
!     if (semctl(sem_set_, 0, SETVAL, val) == -1)
!       throw std::runtime_error("could not initialize semaphore");
  #else
      // There are no semaphores on this system.  We have no way to mark
      // a test as "unsupported" at runtime, so we just exit, pretending
      // that the test passed.
!     exit(0);
  #endif
    }
  
!   semaphore::~semaphore() {
  #ifdef _GLIBCXX_SYSV_SEM
      union semun val;
      // Destroy the semaphore set only in the process that created it. 
!     if (pid_ == getpid())
!       semctl(sem_set_, 0, IPC_RMID, val);
  #endif
    }
  
    void
!   semaphore::signal () {
  #ifdef _GLIBCXX_SYSV_SEM
      struct sembuf op[1] = {
        { 0, 1, 0 }
      };
!     if (semop(sem_set_, op, 1) == -1)
!       throw std::runtime_error("could not signal semaphore");
  #endif
    }
  
    void
    semaphore::wait() {
  #ifdef _GLIBCXX_SYSV_SEM
      struct sembuf op[1] = {
        { 0, -1, SEM_UNDO }
      };
!     if (semop(sem_set_, op, 1) == -1)
!       throw std::runtime_error("could not wait for semaphore");
  #endif    
    }
  }; // namespace __gnu_test
  
  namespace std
Index: testsuite/testsuite_hooks.h
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/testsuite_hooks.h,v
retrieving revision 1.31
diff -c -5 -p -r1.31 testsuite_hooks.h
*** testsuite/testsuite_hooks.h	3 Jan 2005 21:31:34 -0000	1.31
--- testsuite/testsuite_hooks.h	4 Jan 2005 00:05:35 -0000
*************** namespace __gnu_test
*** 385,405 ****
    class semaphore 
    {
    public:
      // Creates a binary semaphore.  The semaphore is initially in the
      // unsignaled state. 
!     semaphore ();
  
      // Destroy the semaphore.
      ~semaphore();
  
      // Signal the semaphore.  If there are processes blocked in
      // "wait", exactly one will be permitted to proceed.
!     void signal ();
  
      // Wait until the semaphore is signaled.
!     void wait ();
  
    private:
      int sem_set_;
  
      pid_t pid_;
--- 385,405 ----
    class semaphore 
    {
    public:
      // Creates a binary semaphore.  The semaphore is initially in the
      // unsignaled state. 
!     semaphore();
  
      // Destroy the semaphore.
      ~semaphore();
  
      // Signal the semaphore.  If there are processes blocked in
      // "wait", exactly one will be permitted to proceed.
!     void signal();
  
      // Wait until the semaphore is signaled.
!     void wait();
  
    private:
      int sem_set_;
  
      pid_t pid_;
Index: testsuite/27_io/basic_filebuf/close/char/4879.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/4879.cc,v
retrieving revision 1.5
diff -c -5 -p -r1.5 4879.cc
*** testsuite/27_io/basic_filebuf/close/char/4879.cc	3 Jan 2005 21:31:34 -0000	1.5
--- testsuite/27_io/basic_filebuf/close/char/4879.cc	4 Jan 2005 00:05:36 -0000
***************
*** 1,6 ****
! // Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,6 ----
! // Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
Index: testsuite/27_io/basic_filebuf/close/char/9964.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_filebuf/close/char/9964.cc,v
retrieving revision 1.7
diff -c -5 -p -r1.7 9964.cc
*** testsuite/27_io/basic_filebuf/close/char/9964.cc	3 Jan 2005 21:31:35 -0000	1.7
--- testsuite/27_io/basic_filebuf/close/char/9964.cc	4 Jan 2005 00:05:36 -0000
***************
*** 1,6 ****
! // Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,6 ----
! // Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
Index: testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc,v
retrieving revision 1.4
diff -c -5 -p -r1.4 13171-2.cc
*** testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc	3 Jan 2005 21:31:35 -0000	1.4
--- testsuite/27_io/basic_filebuf/imbue/char/13171-2.cc	4 Jan 2005 00:05:36 -0000
***************
*** 1,6 ****
! // Copyright (C) 2003 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,6 ----
! // Copyright (C) 2003, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
Index: testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc,v
retrieving revision 1.3
diff -c -5 -p -r1.3 13582-2.cc
*** testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc	3 Jan 2005 21:31:35 -0000	1.3
--- testsuite/27_io/basic_filebuf/imbue/char/13582-2.cc	4 Jan 2005 00:05:36 -0000
***************
*** 1,8 ****
  // 2004-01-11  Petur Runolfsson  <peturr02@ru.is>
  
! // Copyright (C) 2004 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,8 ----
  // 2004-01-11  Petur Runolfsson  <peturr02@ru.is>
  
! // Copyright (C) 2004, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
Index: testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc,v
retrieving revision 1.2
diff -c -5 -p -r1.2 14975-2.cc
*** testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc	3 Jan 2005 21:31:36 -0000	1.2
--- testsuite/27_io/basic_filebuf/imbue/wchar_t/14975-2.cc	4 Jan 2005 00:05:36 -0000
***************
*** 1,8 ****
  // 2004-04-16  Petur Runolfsson  <peturr02@ru.is>
  
! // Copyright (C) 2004 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,8 ----
  // 2004-04-16  Petur Runolfsson  <peturr02@ru.is>
  
! // Copyright (C) 2004, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
Index: testsuite/27_io/basic_filebuf/open/char/9507.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_filebuf/open/char/9507.cc,v
retrieving revision 1.7
diff -c -5 -p -r1.7 9507.cc
*** testsuite/27_io/basic_filebuf/open/char/9507.cc	3 Jan 2005 21:31:37 -0000	1.7
--- testsuite/27_io/basic_filebuf/open/char/9507.cc	4 Jan 2005 00:05:36 -0000
***************
*** 1,6 ****
! // Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,6 ----
! // Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
Index: testsuite/27_io/basic_filebuf/underflow/char/10097.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc,v
retrieving revision 1.6
diff -c -5 -p -r1.6 10097.cc
*** testsuite/27_io/basic_filebuf/underflow/char/10097.cc	3 Jan 2005 21:31:38 -0000	1.6
--- testsuite/27_io/basic_filebuf/underflow/char/10097.cc	4 Jan 2005 00:05:36 -0000
***************
*** 1,8 ****
  // 2001-05-21 Benjamin Kosnik  <bkoz@redhat.com>
  
! // Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,8 ----
  // 2001-05-21 Benjamin Kosnik  <bkoz@redhat.com>
  
! // Copyright (C) 2001, 2002, 2003, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
Index: testsuite/27_io/objects/char/7.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/objects/char/7.cc,v
retrieving revision 1.6
diff -c -5 -p -r1.6 7.cc
*** testsuite/27_io/objects/char/7.cc	3 Jan 2005 21:31:39 -0000	1.6
--- testsuite/27_io/objects/char/7.cc	4 Jan 2005 00:05:41 -0000
***************
*** 1,8 ****
  // 2003-04-26 Petur Runolfsson  <peturr02@ru.is>
  
! // Copyright (C) 2003 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,8 ----
  // 2003-04-26 Petur Runolfsson  <peturr02@ru.is>
  
! // Copyright (C) 2003, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
Index: testsuite/27_io/objects/char/9661-1.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/objects/char/9661-1.cc,v
retrieving revision 1.6
diff -c -5 -p -r1.6 9661-1.cc
*** testsuite/27_io/objects/char/9661-1.cc	3 Jan 2005 21:31:39 -0000	1.6
--- testsuite/27_io/objects/char/9661-1.cc	4 Jan 2005 00:05:41 -0000
***************
*** 1,8 ****
  // 2003-04-30  Petur Runolfsson <peturr02@ru.is>
  
! // Copyright (C) 2003 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,8 ----
  // 2003-04-30  Petur Runolfsson <peturr02@ru.is>
  
! // Copyright (C) 2003, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
Index: testsuite/27_io/objects/wchar_t/7.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/objects/wchar_t/7.cc,v
retrieving revision 1.4
diff -c -5 -p -r1.4 7.cc
*** testsuite/27_io/objects/wchar_t/7.cc	3 Jan 2005 21:31:39 -0000	1.4
--- testsuite/27_io/objects/wchar_t/7.cc	4 Jan 2005 00:05:41 -0000
***************
*** 1,8 ****
  // 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
  
! // Copyright (C) 2003 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,8 ----
  // 2003-05-01 Petur Runolfsson  <peturr02@ru.is>
  
! // Copyright (C) 2003, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
Index: testsuite/27_io/objects/wchar_t/9661-1.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/testsuite/27_io/objects/wchar_t/9661-1.cc,v
retrieving revision 1.4
diff -c -5 -p -r1.4 9661-1.cc
*** testsuite/27_io/objects/wchar_t/9661-1.cc	3 Jan 2005 21:31:39 -0000	1.4
--- testsuite/27_io/objects/wchar_t/9661-1.cc	4 Jan 2005 00:05:41 -0000
***************
*** 1,8 ****
  // 2003-04-30  Petur Runolfsson <peturr02@ru.is>
  
! // Copyright (C) 2003 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)
--- 1,8 ----
  // 2003-04-30  Petur Runolfsson <peturr02@ru.is>
  
! // Copyright (C) 2003, 2005 Free Software Foundation, Inc.
  //
  // This file is part of the GNU ISO C++ Library.  This library 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 2, or (at your option)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]