Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
75e8c217
Commit
75e8c217
authored
Nov 14, 2008
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for read_write_all.
parent
6841e5f5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
0 deletions
+136
-0
ccan/read_write_all/test/run-read_all.c
ccan/read_write_all/test/run-read_all.c
+70
-0
ccan/read_write_all/test/run-write_all.c
ccan/read_write_all/test/run-write_all.c
+66
-0
No files found.
ccan/read_write_all/test/run-read_all.c
0 → 100644
View file @
75e8c217
/* FIXME: Do something tricky to ensure we really do loop in read_all. */
#include "read_write_all/read_write_all.h"
#include "read_write_all/read_write_all.c"
#include "tap/tap.h"
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/wait.h>
#include <limits.h>
#include <err.h>
#include <stdlib.h>
#include <string.h>
static
volatile
int
sigcount
;
static
int
p2c
[
2
],
c2p
[
2
];
static
void
got_signal
(
int
sig
)
{
char
c
=
0
;
if
(
write
(
p2c
[
1
],
&
c
,
1
)
==
1
)
sigcount
++
;
}
/* < PIPE_BUF *will* be atomic. But > PIPE_BUF only *might* be non-atomic. */
#define BUFSZ (1024*1024)
int
main
(
int
argc
,
char
*
argv
[])
{
char
buffer
[
BUFSZ
*
2
]
=
{
0
};
char
c
=
0
;
int
status
;
pid_t
child
;
plan_tests
(
6
);
/* We fork and torture parent. */
if
(
pipe
(
p2c
)
!=
0
||
pipe
(
c2p
)
!=
0
)
err
(
1
,
"pipe"
);
child
=
fork
();
if
(
!
child
)
{
/* Child. Make sure parent ready, then write in two parts. */
if
(
read
(
p2c
[
0
],
&
c
,
1
)
!=
1
)
exit
(
1
);
memset
(
buffer
,
0xff
,
sizeof
(
buffer
));
if
(
!
write_all
(
c2p
[
1
],
buffer
,
BUFSZ
))
exit
(
2
);
if
(
kill
(
getppid
(),
SIGUSR1
)
!=
0
)
exit
(
3
);
/* Make sure they get signal. */
if
(
read
(
p2c
[
0
],
&
c
,
1
)
!=
1
)
exit
(
4
);
if
(
write
(
c2p
[
1
],
buffer
,
PIPE_BUF
)
!=
PIPE_BUF
)
exit
(
5
);
exit
(
0
);
}
if
(
child
==
-
1
)
err
(
1
,
"forking"
);
signal
(
SIGUSR1
,
got_signal
);
ok1
(
write
(
p2c
[
1
],
&
c
,
1
)
==
1
);
ok1
(
read_all
(
c2p
[
0
],
buffer
,
sizeof
(
buffer
)));
ok1
(
memchr
(
buffer
,
0
,
sizeof
(
buffer
))
==
NULL
);
ok1
(
sigcount
==
1
);
ok1
(
wait
(
&
status
)
==
child
);
ok
(
WIFEXITED
(
status
)
&&
WEXITSTATUS
(
status
)
==
0
,
"WIFEXITED(status) = %u, WEXITSTATUS(status) = %u"
,
WIFEXITED
(
status
),
WEXITSTATUS
(
status
));
return
exit_status
();
}
ccan/read_write_all/test/run-write_all.c
0 → 100644
View file @
75e8c217
/* FIXME: Do something tricky to ensure we really do loop in write_all. */
#include "read_write_all/read_write_all.h"
#include "read_write_all/read_write_all.c"
#include "tap/tap.h"
#include <unistd.h>
#include <sys/types.h>
#include <signal.h>
#include <limits.h>
#include <sys/wait.h>
#include <err.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
static
volatile
int
sigcount
;
static
void
got_signal
(
int
sig
)
{
sigcount
++
;
}
/* < PIPE_BUF *will* be atomic. But > PIPE_BUF only *might* be non-atomic. */
#define BUFSZ (1024*1024)
int
main
(
int
argc
,
char
*
argv
[])
{
char
buffer
[
BUFSZ
*
2
]
=
{
0
};
int
p2c
[
2
];
int
status
;
pid_t
child
;
plan_tests
(
4
);
/* We fork and torture parent. */
if
(
pipe
(
p2c
)
!=
0
)
err
(
1
,
"pipe"
);
child
=
fork
();
if
(
!
child
)
{
/* Make sure they started writing. */
if
(
read
(
p2c
[
0
],
buffer
,
1
)
!=
1
)
exit
(
1
);
if
(
kill
(
getppid
(),
SIGUSR1
)
!=
0
)
exit
(
2
);
if
(
!
read_all
(
p2c
[
0
],
buffer
+
1
,
sizeof
(
buffer
)
-
1
))
exit
(
3
);
if
(
memchr
(
buffer
,
0
,
sizeof
(
buffer
)))
{
fprintf
(
stderr
,
"buffer has 0 at offset %i
\n
"
,
memchr
(
buffer
,
0
,
sizeof
(
buffer
))
-
(
void
*
)
buffer
);
exit
(
4
);
}
exit
(
0
);
}
if
(
child
==
-
1
)
err
(
1
,
"forking"
);
memset
(
buffer
,
0xff
,
sizeof
(
buffer
));
signal
(
SIGUSR1
,
got_signal
);
ok1
(
write_all
(
p2c
[
1
],
buffer
,
sizeof
(
buffer
)));
ok1
(
sigcount
==
1
);
ok1
(
wait
(
&
status
)
==
child
);
ok
(
WIFEXITED
(
status
)
&&
WEXITSTATUS
(
status
)
==
0
,
"WIFEXITED(status) = %u, WEXITSTATUS(status) = %u"
,
WIFEXITED
(
status
),
WEXITSTATUS
(
status
));
return
exit_status
();
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment