File: wvmagicloopback.t.cc

package info (click to toggle)
wvstreams 4.0.2-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,420 kB
  • ctags: 6,518
  • sloc: cpp: 52,544; sh: 5,770; ansic: 810; makefile: 461; tcl: 114; perl: 18
file content (63 lines) | stat: -rw-r--r-- 1,092 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <sys/wait.h>
#include "wvtest.h"
#include "wvmagicloopback.h"
#include "wvfork.h"

#include <stdio.h>

WVTEST_MAIN("WvMagicLoopback Sanity") 
{
    signal(SIGPIPE, SIG_IGN);

    WvMagicLoopback ml(1024);
    
    pid_t pid = fork();
    WVFAIL(pid < 0 && "fork() failed");
    if (pid == 0)
    {
    	int i;
    	
    	for (i=0; i<1024; ++i)
    	{
    	    while (!ml.iswritable());
    	    
    	    ml.write(&i, sizeof(i));
    	}
    	
    	_exit(0);
    }
    else
    {
    	int i, maybe_i;
    	
    	for (i=0; i<1024; ++i)
    	{
    	    while (!ml.isreadable());
    	    
    	    ml.read(&maybe_i, sizeof(maybe_i));
    	    
    	    if (i != maybe_i)
    	    {
    	    	WVPASS(i == maybe_i);
    	    	break;
    	    }
    	}
    }
    
    WVPASS(waitpid(pid, NULL, 0) == pid);
}

WVTEST_MAIN("WvMagicLoopback Non-Blocking Writes") 
{
    WvMagicLoopback ml(1024);

    WVPASS(ml.isok());

    for (int i=0; i<(1<<10); ++i)
    {
        char buf[1024] = "WvMagicLoopback Non-Blocking Writes";
        ml.write(buf, sizeof(buf));
    }

    WVPASS(ml.isok());
}