OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [sim/] [testsuite/] [sim/] [cris/] [c/] [pipe5.c] - Blame information for rev 157

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 24 jeremybenn
/* Check that TRT happens for pipe corner cases (for our definition of TRT).
2
#notarget: cris*-*-elf
3
#xerror:
4
#output: Terminating simulation due to writing pipe * from one single thread\n
5
#output: program stopped with signal 4.\n
6
*/
7
#include <stddef.h>
8
#include <signal.h>
9
#include <stdlib.h>
10
#include <stdio.h>
11
#include <unistd.h>
12
#include <errno.h>
13
#include <limits.h>
14
 
15
void err (const char *s)
16
{
17
  perror (s);
18
  abort ();
19
}
20
 
21
int main (void)
22
{
23
  int pip[2];
24
  int pipemax;
25
  char *buf;
26
 
27
  if (pipe (pip) != 0)
28
    err ("pipe");
29
 
30
#ifdef PIPE_MAX
31
  pipemax = PIPE_MAX;
32
#else
33
  pipemax = fpathconf (pip[1], _PC_PIPE_BUF);
34
#endif
35
 
36
  if (pipemax <= 0)
37
    {
38
      fprintf (stderr, "Bad pipemax %d\n", pipemax);
39
      abort ();
40
    }
41
 
42
  /* Writing an inordinate amount to the pipe.  */
43
  buf = calloc (100 * pipemax, 1);
44
  if (buf == NULL)
45
    err ("calloc");
46
 
47
  /* The following doesn't trig on host; writing more than PIPE_MAX to a
48
     pipe with no reader makes the program hang.  Neither does it trig
49
     on target: we don't want to emulate the "hanging" (which would
50
     happen with *any* amount written to a pipe with no reader if we'd
51
     support it - but we don't).  Better to abort the simulation with a
52
     suitable message.  */
53
  if (write (pip[1], buf, 100 * pipemax) != -1
54
      || errno != EFBIG)
55
    err ("write mucho");
56
 
57
  printf ("pass\n");
58
  exit (0);
59
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.