/* -*- 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: anonfm.c
** Description: Test anonymous file map
**
** Synopsis: anonfm [options] [dirName]
**
** Options:
** -d enable debug mode
** -h display a help message
** -s <n> size of the anonymous memory map, in KBytes. default: 100KBytes.
** -C 1 Operate this process as ClientOne()
** -C 2 Operate this process as ClientTwo()
**
** anonfn.c contains two tests, corresponding to the two protocols for
** passing an anonymous file map to a child process.
**
** ServerOne()/ClientOne() tests the passing of "raw" file map; it uses
** PR_CreateProcess() [for portability of the test case] to create the
** child process, but does not use the PRProcessAttr structure for
** passing the file map data.
**
** ServerTwo()/ClientTwo() tests the passing of the file map using the
** PRProcessAttr structure.
**
*/
#include <plgetopt.h>
#include <nspr.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/*
** Test harness infrastructure
*/
/*
** Emit help text for this test
*/
static void Help( void )
{
printf("anonfm [options] [dirName]\n");
printf("-d -- enable debug mode\n");
printf("dirName is alternate directory name. Default: . (current directory)\n");
exit(1);
} /* end Help() */
/*
** ClientOne() --
*/
static void ClientOne( void )
{
char *fmString;
char *addr;
("ClientOne() starting"));
failed_already = 1;
("ClientOne(): PR_Getenv() failed"));
return;
}
("ClientOne(): PR_Getenv(): found: %s", fmString));
failed_already = 1;
("ClientOne(): PR_ImportFileMapFromString() failed"));
return;
}
("ClientOne(): PR_ImportFileMapFromString(): fm: %p", fm ));
failed_already = 1;
("ClientOne(): PR_MemMap() failed, OSError: %d", PR_GetOSError() ));
return;
}
("ClientOne(): PR_MemMap(): addr: %p", addr ));
/* write to memory map to release server */
*addr = 1;
("ClientOne(): PR_MemUnap(): success" ));
if ( PR_FAILURE == rc ) {
failed_already = 1;
("ClientOne(): PR_MemUnap() failed, OSError: %d", PR_GetOSError() ));
return;
}
("ClientOne(): PR_CloseFileMap(): success" ));
return;
} /* end ClientOne() */
/*
** ClientTwo() --
*/
static void ClientTwo( void )
{
failed_already = 1;
} /* end ClientTwo() */
/*
** ServerOne() --
*/
static void ServerOne( void )
{
PRIntn i;
char *addr;
("ServerOne() starting"));
failed_already = 1;
("PR_OpenAnonFileMap() failed"));
return;
}
("ServerOne(): FileMap: %p", fm ));
if ( PR_FAILURE == rc ) {
failed_already = 1;
("PR_ExportFileMap() failed"));
return;
}
/*
** put the string into the environment
*/
failed_already = 1;
("PR_MemMap() failed"));
return;
}
/* set initial value for client */
*(addr+i) = 0x00;
("ServerOne(): PR_MemMap(): addr: %p", addr ));
/*
** set arguments for child process
*/
child_argv[0] = "anonfm";
("ServerOne(): PR_CreateProcess(): proc: %x", proc ));
/*
** ClientOne() will set the memory to 1
*/
("ServerOne(): waiting on Client, *addr: %x", *addr ));
while( *addr == 0x00 ) {
if ( debug )
}
if ( debug )
("ServerOne(): Client responded" ));
if ( PR_FAILURE == rc ) {
failed_already = 1;
("PR_MemUnmap() failed"));
return;
}
("ServerOne(): PR_MemUnmap(): success" ));
if ( PR_FAILURE == rc ) {
failed_already = 1;
("PR_CloseFileMap() failed"));
return;
}
("ServerOne(): PR_CloseFileMap() success" ));
return;
} /* end ServerOne() */
/*
** ServerTwo() --
*/
static void ServerTwo( void )
{
("ServerTwo(): Not implemented yet" ));
} /* end ServerTwo() */
{
{
/*
** Get command line options
*/
{
if (PL_OPT_BAD == os) continue;
{
case 'C': /* Client style */
break;
case 's': /* file size */
break;
case 'd': /* debug */
debug = 1;
break;
case 'h': /* help message */
Help();
break;
default:
break;
}
}
}
if ( client == 1 ) {
ClientOne();
} else if ( client == 2 ) {
ClientTwo();
} else {
ServerOne();
if ( failed_already ) goto Finished;
ServerTwo();
}
if ( debug )
} /* main() */
/* end anonfm.c */