ntioto.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*
** File: ntioto.c
** Description:
** This test, ntioto.c, was designed to reproduce a bug reported by NES
** on WindowsNT (fibers implementation). NSPR was asserting in ntio.c
** after PR_AcceptRead() had timed out. I/O performed subsequent to the
** call to PR_AcceptRead() could complete on a CPU other than the one
** on which it was started. The assert in ntio.c detected this, then
** asserted.
**
** Design:
** This test will fail with an assert in ntio.c if the problem it was
** designed to catch occurs. It returns 0 otherwise.
**
** The main() thread initializes and tears things down. A file is
** opened for writing; this file will be written to by AcceptThread()
** and JitterThread(). Main() creates a socket for reading, listens
** and binds the socket.
**
** ConnectThread() connects to the socket created by main, then polls
** the "state" variable. When state is AllDone, ConnectThread() exits.
**
** AcceptThread() calls PR_AcceptRead() on the socket. He fully expects
** it to time out. After the timeout, AccpetThread() interacts with
** JitterThread() via a common condition variable and the state
** variable. The two threads ping-pong back and forth, each thread
** writes the the file opened by main. This should provoke the
** condition reported by NES (if we didn't fix it).
**
** The failure is not solid. It may fail within a few ping-pongs between
** AcceptThread() and JitterThread() or may take a while. The default
** iteration count, jitter, is set by DEFAULT_JITTER. This may be
** modified at the command line with the -j option.
**
*/
#include <plgetopt.h>
#include <nspr.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
** Test harness infrastructure
*/
PRUint32 failed_already = 0;
/* end Test harness infrastructure */
/* JITTER_DEFAULT: the number of times AcceptThread() and JitterThread() ping-pong */
#define JITTER_DEFAULT 100000
#define BASE_PORT 9867
volatile enum {
} state = RunAcceptRead;
/*
** Emit help text for this test
*/
static void Help( void )
{
printf("Template: Help(): display your help message(s) here");
exit(1);
} /* end Help() */
/*
** static computation of PR_AcceptRead() buffer size.
*/
#define ACCEPT_READ_DATASIZE 10
static void AcceptThread(void *arg)
{
char dataBuf[ACCEPT_READ_BUFSIZE];
&arSock,
&arAddr,
PR_SecondsToInterval(1));
else
while( state != RunAcceptRead )
else
PR_NotifyCondVar( cv );
}
return;
} /* end AcceptThread() */
static void JitterThread(void *arg)
{
PR_NotifyCondVar( cv );
}
return;
} /* end Goofy() */
static void ConnectThread( void *arg )
{
if ( resume ) {
}
PR_SecondsToInterval(1));
/* that's all we do. ... Wait for the acceptread() to timeout */
return;
} /* end ConnectThread() */
{
/* This test if valid for WinNT only! */
#if !defined(WINNT)
return 0;
#endif
{
/*
** Get command line options
*/
{
if (PL_OPT_BAD == os) continue;
{
case 'd': /* debug */
debug = 1;
break;
case 'v': /* verbose mode */
verbose = 1;
break;
case 'j':
if ( jitter == 0)
break;
case 'r':
break;
case 'h': /* help message */
Help();
break;
default:
break;
}
}
}
/* set concurrency */
PR_SetConcurrency( 4 );
/* setup thread synchronization mechanics */
ml = PR_NewLock();
/* setup a tcp socket */
PR_ASSERT( listenSock );
/* open a file for writing, provoke bug */
/* create Connect thread */
PR_JOINABLE_THREAD, 0 );
/* create jitter off thread */
PR_JOINABLE_THREAD, 0 );
/* create acceptread thread */
PR_JOINABLE_THREAD, 0 );
/* wait for all threads to quit, then terminate gracefully */
PR_JoinThread( tAccept );
PR_JoinThread( tJitter );
PR_Close( listenSock );
PR_Delete( "xxxTestFile");
/* test return and exit */
} /* main() */
/* end ntioto.c */