aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2019-03-06 10:35:02 -0500
committerNick Mathewson <nickm@torproject.org>2019-04-04 12:56:52 -0400
commit12205c3cbee4e71ded2b5710a57342b510e9d6df (patch)
treea0f1800c2e4c95ce37409fdecf28830188fb161a /src/test
parentab6ad3c040de68b1f06b8f910407bff570b24b43 (diff)
downloadtor-12205c3cbee4e71ded2b5710a57342b510e9d6df.tar.gz
tor-12205c3cbee4e71ded2b5710a57342b510e9d6df.zip
Make map_anon expose the result of a noinherit attempt
Previously we did this for tests only, but it's valuable for getting proper fork behavior in rand_fast.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_util.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 4990aa709a..039fc435ce 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -6130,10 +6130,12 @@ test_util_map_anon(void *arg)
(void)arg;
char *ptr = NULL;
size_t sz = 16384;
+ unsigned inherit=0;
/* Basic checks. */
- ptr = tor_mmap_anonymous(sz, 0);
+ ptr = tor_mmap_anonymous(sz, 0, &inherit);
tt_ptr_op(ptr, OP_NE, 0);
+ tt_int_op(inherit, OP_EQ, INHERIT_KEEP);
ptr[sz-1] = 3;
tt_int_op(ptr[0], OP_EQ, 0);
tt_int_op(ptr[sz-2], OP_EQ, 0);
@@ -6141,8 +6143,9 @@ test_util_map_anon(void *arg)
/* Try again, with a private (non-swappable) mapping. */
tor_munmap_anonymous(ptr, sz);
- ptr = tor_mmap_anonymous(sz, ANONMAP_PRIVATE);
+ ptr = tor_mmap_anonymous(sz, ANONMAP_PRIVATE, &inherit);
tt_ptr_op(ptr, OP_NE, 0);
+ tt_int_op(inherit, OP_EQ, INHERIT_KEEP);
ptr[sz-1] = 10;
tt_int_op(ptr[0], OP_EQ, 0);
tt_int_op(ptr[sz/2], OP_EQ, 0);
@@ -6150,7 +6153,7 @@ test_util_map_anon(void *arg)
/* Now let's test a drop-on-fork mapping. */
tor_munmap_anonymous(ptr, sz);
- ptr = tor_mmap_anonymous(sz, ANONMAP_NOINHERIT);
+ ptr = tor_mmap_anonymous(sz, ANONMAP_NOINHERIT, &inherit);
tt_ptr_op(ptr, OP_NE, 0);
ptr[sz-1] = 10;
tt_int_op(ptr[0], OP_EQ, 0);
@@ -6179,10 +6182,10 @@ test_util_map_anon_nofork(void *arg)
char *ptr = NULL;
size_t sz = 16384;
int pipefd[2] = {-1, -1};
+ unsigned inherit=0;
tor_munmap_anonymous(ptr, sz);
- ptr = tor_mmap_anonymous(sz, ANONMAP_NOINHERIT);
- int outcome = get_last_anon_map_noinherit();
+ ptr = tor_mmap_anonymous(sz, ANONMAP_NOINHERIT, &inherit);
tt_ptr_op(ptr, OP_NE, 0);
memset(ptr, 0xd0, sz);
@@ -6204,16 +6207,16 @@ test_util_map_anon_nofork(void *arg)
char buf[1];
ssize_t r = read(pipefd[0], buf, 1);
- if (outcome == 2) {
+ if (inherit == INHERIT_ZERO) {
// We should be seeing clear-on-fork behavior.
tt_int_op((int)r, OP_EQ, 1); // child should send us a byte.
tt_int_op(buf[0], OP_EQ, 0); // that byte should be zero.
- } else if (outcome == 1) {
+ } else if (inherit == INHERIT_DROP) {
// We should be seeing noinherit behavior.
tt_int_op(r, OP_LE, 0); // child said nothing; it should have crashed.
} else {
// noinherit isn't implemented.
- tt_int_op(outcome, OP_EQ, 0);
+ tt_int_op(inherit, OP_EQ, INHERIT_KEEP);
tt_int_op((int)r, OP_EQ, 1); // child should send us a byte.
tt_int_op(buf[0], OP_EQ, 0xd0); // that byte should what we set it to.
}
@@ -6221,7 +6224,7 @@ test_util_map_anon_nofork(void *arg)
int ws;
waitpid(child, &ws, 0);
- if (outcome == 0) {
+ if (inherit == INHERIT_KEEP) {
/* Call this test "skipped", not "passed", since noinherit wasn't
* implemented. */
tt_skip();