From 539a52558fc24b1a2c4dd3d6dc389ca111858401 Mon Sep 17 00:00:00 2001 From: Hans-Peter Nilsson Date: Sat, 30 Sep 2006 02:34:43 +0000 Subject: [PATCH] * sim/cris/c/pipe2.c: Adjust expected output. (process): Don't write as much to the pipe as to trig the inordinate-amount test in the sim pipe machinery. Correct test of write return-value; check only that pipemax bytes were successfully written. For error-case, emit strerror as well. (main): Add a second read. --- sim/testsuite/ChangeLog | 9 ++++++++ sim/testsuite/sim/cris/c/pipe2.c | 35 ++++++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/sim/testsuite/ChangeLog b/sim/testsuite/ChangeLog index 061b45dd20..34a29c6fe0 100644 --- a/sim/testsuite/ChangeLog +++ b/sim/testsuite/ChangeLog @@ -1,3 +1,12 @@ +2006-09-30 Hans-Peter Nilsson + + * sim/cris/c/pipe2.c: Adjust expected output. + (process): Don't write as much to the pipe as to trig the + inordinate-amount test in the sim pipe machinery. Correct test of + write return-value; check only that pipemax bytes were + successfully written. For error-case, emit strerror as well. + (main): Add a second read. + 2006-04-08 Hans-Peter Nilsson * sim/cris/hw/rv-n-cris/irq6.ms: New test. diff --git a/sim/testsuite/sim/cris/c/pipe2.c b/sim/testsuite/sim/cris/c/pipe2.c index ccb97f82d4..18ccf38b9b 100644 --- a/sim/testsuite/sim/cris/c/pipe2.c +++ b/sim/testsuite/sim/cris/c/pipe2.c @@ -1,6 +1,6 @@ /* Check that closing a pipe with a nonempty buffer works. #notarget: cris*-*-elf -#output: got: a\nexit: 0\n +#output: got: a\ngot: b\nexit: 0\n */ @@ -14,7 +14,7 @@ #include #include #include - +#include int pip[2]; int pipemax; @@ -23,7 +23,8 @@ int process (void *arg) { char *s = arg; - char *buf = malloc (pipemax * 100); + int lots = pipemax + 256; + char *buf = malloc (lots); int ret; if (buf == NULL) @@ -37,12 +38,17 @@ process (void *arg) *buf = s[1]; - /* The second write should only successful for at most the PIPE_MAX - part, but no error. */ - ret = write (pip[1], buf, pipemax * 10); - if (ret != 0 && ret != pipemax - 1 && ret != pipemax) + /* The second write may or may not be successful for the whole + write, but should be successful for at least the pipemax part. + As linux/limits.h clamps PIPE_BUF to 4096, but the page size is + actually 8k, we can get away with that much. There should be no + error, though. Doing this on host shows that for + x86_64-unknown-linux-gnu (2.6.14-1.1656_FC4) pipemax * 10 can be + successfully written, perhaps for similar reasons. */ + ret = write (pip[1], buf, lots); + if (ret < pipemax) { - fprintf (stderr, "ret: %d\n", ret); + fprintf (stderr, "ret: %d, %s, %d\n", ret, strerror (errno), pipemax); fflush (0); abort (); } @@ -104,6 +110,19 @@ main (void) printf ("got: %c\n", buf[0]); + /* Need to read out something from the second write too before + closing, or the writer can get EPIPE. */ + while ((retcode = read (pip[0], buf, 1)) == 0) + ; + + if (retcode != 1) + { + fprintf (stderr, "Bad read 2: %d\n", retcode); + abort (); + } + + printf ("got: %c\n", buf[0]); + if (close (pip[0]) != 0) { perror ("pip close"); -- 2.34.1