tmprocess.c revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1999-2012 AT&T Intellectual Property *
* and is licensed under the *
* Eclipse Public License, Version 1.0 *
* by AT&T Intellectual Property *
* *
* A copy of the License is available at *
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
* *
* Information and Software Systems Research *
* AT&T Research *
* Florham Park NJ *
* *
* Glenn Fowler <gsf@research.att.com> *
* *
***********************************************************************/
#include "sftest.h"
/* Test to see if multiple writers to the same file create
** a consistent set of records.
*/
#ifndef N_PROC
#define N_PROC 3
#endif
#define N_REC 1000
#define B_SIZE 256
#if __STD_C
#else
Sfio_t* f;
size_t n;
#endif
{
int w, k;
char* s;
terror("Not writing a whole record");
if(s[0] != s[w-1]-1)
terror("Bad record");
k = (s[2]-'0')*10 + (s[3]-'0');
if(k != w)
terror("Expect %d, get %d",k,w);
}
terror("Write %d returns %d",n,w);
return w;
}
tmain()
{
int i, r, n, pid;
Sfio_t* f;
unsigned long u;
/* create pseudo-random record sizes */
u = 1;
for(i = 0; i < N_PROC; ++i)
for(r = 0; r < N_REC; ++r)
{ u = u * 0x63c63cd9L + 0x9c39c33dL;
}
/* records for different processes */
for(i = 0; i < N_PROC; ++i)
for(r = 0; r < 128; ++r)
/* create file */
/* open file for appending */
for(i = 0; i < N_PROC; ++i)
/* fork processes */
for(i = 0; i < N_PROC; ++i)
{
#ifdef DEBUG
#define FORK() 0
#define RETURN(v)
#else
#endif
terror("Creating process %d", i);
else if(pid == 0)
{ /* write to file */
for(r = 0; r < N_REC; ++r)
{ n = size[i][r]; s = b[i];
s[1] = '(';
s[2] = ((n-1)/10) + '0';
s[3] = ((n-1)%10) + '0';
s[4] = ')';
s[n-2] = s[0] + 1;
s[n-1] = '\n';
terror("sfwrite failed");
}
RETURN(0);
}
}
for(i = 0; i < N_PROC; ++i)
{ wait(&r);
count[i] = 0;
}
n = 0;
while((s = sfgetr(f,'\n',0)) )
{ n += 1;
terror("%d: Wrong record type", n);
r = sfvalue(f);
if(s[r-2] != s[0]+1)
for(r -= 3; r > 4; --r)
if(s[r] != s[0])
terror("%d: process%d number=%d expected size=%d read size=%d",
count[i] += 1;
}
for(i = 0; i < N_PROC; ++i)
texit(0);
}