/***********************************************************************
* *
* This software is part of the ast package *
* Copyright (c) 1999-2011 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"
#if vt_threaded
#include <vthread.h>
{ "aaaaaaaaa",
"bbbbbbbbb",
"ccccccccc",
"ddddddddd",
"eeeeeeeee",
"fffffffff",
"ggggggggg",
"hhhhhhhhh",
"iiiiiiiii",
"jjjjjjjjj",
"kkkkkkkkk",
"lllllllll",
"mmmmmmmmm",
"nnnnnnnnn",
"ooooooooo",
"ppppppppp",
"qqqqqqqqq",
"rrrrrrrrr",
"sssssssss",
"ttttttttt",
"uuuuuuuuu",
"vvvvvvvvv",
"wwwwwwwww",
"xxxxxxxxx",
"yyyyyyyyy",
"zzzzzzzzz"
};
#if _STD_C
#else
void* writesmall(arg)
void* arg;
#endif
{
char* s;
int n;
for(n = 0; n < N_STR; ++n)
{ if(Inverted)
tsuccess("sfputr failed as expected");
else terror("sfputr failed");
}
}
return arg;
}
#if _STD_C
#else
void* arg;
#endif
{
terror("Writing bigz");
return arg;
}
#if __STD_C
#else
void sighandler(sig)
int sig;
#endif
{
texit(0);
}
tmain()
{
char* s;
int i, k, n;
/* make the big z string */
strcpy(s, "zzzzzzzzz\n");
do_inverted: /* get back to here when trying to make things fail */
if(!Inverted)
tmesg("\tTesting thread-safe streams.\n");
else tmesg("\tTesting unsafe streams: if hung, send INTR or QUIT.\n");
/* spin threads writing small chunks */
for(i = 0; i < 26; ++i)
terror("Creating thread handle[%d]", i);
terror("Running thread [%d]", i);
}
for(i = 0; i < 26; ++i)
{ count[i] = 0;
}
{ if(Inverted)
tsuccess("Rewinding failed as expected");
else terror("Rewinding");
}
for(n = 0;; ++n)
break;
i = s[0] - 'a';
{ if(Inverted)
tsuccess("Bad data as expected");
else terror("Bad data s='%s' n=%d", s, n);
}
{ if(Inverted)
tsuccess("Bad str as expected");
else terror("Bad str s='%s' i=%d Str[i]='%s' n=%d",
s, i, Str[i], n);
}
count[i] += 1;
}
for(i = 0; i < 26; ++i)
{ if(Inverted)
tsuccess("Bad count as expected");
}
}
/* spin threads with one writing a big chunk */
for(i = 0; i < 25; ++i)
terror("Creating thread %d", i);
terror("Running thread %d", i);
}
sleep(1);
terror("Creating big thread z");
terror("Running big thread z");
for(i = 0; i < 26; ++i)
{ count[i] = 0;
}
{ if(Inverted)
tsuccess("Rewinding failed as expected");
else terror("Rewinding");
}
for(n = 0; ; ++n)
break;
i = s[0] - 'a';
{ if(Inverted)
tsuccess("Bad data as expected");
else terror("Bad data s='%s' n=%d", s, n);
}
{ if(Inverted)
tsuccess("Bad str as expected");
else terror("Bad str s='%s' i=%d Str[i]='%s' n=%d",
s, i, Str[i], n);
}
count[i] += 1;
if(i == 25) /* the 'z' */
{ for(k = 1; k < N_STR; ++k, ++n)
{ if(Inverted)
tsuccess("Premature eof as expected");
else terror("Premature eof n=%d", n);
}
{ if(Inverted)
tsuccess("Bad str as expected");
else terror("Bad str s='%s' n=%d", s, n);
}
count[i] += 1;
}
}
}
for(i = 0; i < 26; ++i)
{ if(Inverted)
tsuccess("Bad count as expected");
}
}
if(!Inverted)
{ Inverted = 1;
goto do_inverted;
}
else tmesg("\tUnsafe streams work ok on this platform!\n");
texit(0);
}
#else
tmain()
{
texit(0);
}
#endif