Files
Mike Frysinger 1214c97666 sim: testsuite: initial support for OS-specific tests
We usually test against the newlib/libgloss environment, but for a
few ports that also support Linux apps, we want to test that logic
too.  A lot of the C code is written such that it works with either
newlib/libgloss or glibc/linux toolchains, but we have some tests
that end up being Linux-specific.  Cris has been using the target
tuple as a rough proxy for this (where cris*-*-elf is assumed to be
newlib/libgloss, and everything else is glibc/linux), but that is a
bit too rough, and it doesn't work in a multitarget build.

So lets create a few stub files that we can do compile tests with
to detect the different setups, and then let tests declare which
one they require (if they require any at all).
2021-11-26 20:06:55 -05:00

60 lines
1.3 KiB
C

/* Check that TRT happens for pipe corner cases (for our definition of TRT).
#progos: linux
#xerror:
#output: Terminating simulation due to writing pipe * from one single thread\n
#output: program stopped with signal 4 (*).\n
*/
#include <stddef.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
void err (const char *s)
{
perror (s);
abort ();
}
int main (void)
{
int pip[2];
int pipemax;
char *buf;
if (pipe (pip) != 0)
err ("pipe");
#ifdef PIPE_MAX
pipemax = PIPE_MAX;
#else
pipemax = fpathconf (pip[1], _PC_PIPE_BUF);
#endif
if (pipemax <= 0)
{
fprintf (stderr, "Bad pipemax %d\n", pipemax);
abort ();
}
/* Writing an inordinate amount to the pipe. */
buf = calloc (100 * pipemax, 1);
if (buf == NULL)
err ("calloc");
/* The following doesn't trig on host; writing more than PIPE_MAX to a
pipe with no reader makes the program hang. Neither does it trig
on target: we don't want to emulate the "hanging" (which would
happen with *any* amount written to a pipe with no reader if we'd
support it - but we don't). Better to abort the simulation with a
suitable message. */
if (write (pip[1], buf, 100 * pipemax) != -1
|| errno != EFBIG)
err ("write mucho");
printf ("pass\n");
exit (0);
}