Commit c21a1eff authored by David Gibson's avatar David Gibson Committed by Dan Good

altstack: Don't log internal calls in test cases

altstack/test/run.c uses some hairy macros to intercept the standard
library functions that altstack uses.  This has two purposes: 1) to
conditionally cause those functions to fail, and thereby test altstack's
error paths, and 2) log which of the library functions was called in each
testcase.

The second function isn't actually useful - for the purposes of testing the
module, we want to check the actual behaviour, not what calls it made in
what order to accomplish it.  Explicitly checking the calls makes it much
harder to change altstack's implementation without breaking the tests.
Signed-off-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
parent 9683a45f
...@@ -20,18 +20,17 @@ enum { ...@@ -20,18 +20,17 @@ enum {
sigaction_ = 1<<4, sigaction_ = 1<<4,
munmap_ = 1<<5, munmap_ = 1<<5,
}; };
int fail, call1, call2; int fail;
char *m_; char *m_;
rlim_t msz_; rlim_t msz_;
#define e(x) (900+(x)) #define e(x) (900+(x))
#define seterr(x) (errno = e(x)) #define seterr(x) (errno = e(x))
#define setcall(x) ((call1 |= !errno ? (x) : 0), (call2 |= errno || state.out ? (x) : 0)) #define getrlimit(...) (fail&getrlimit_ ? (seterr(getrlimit_), -1) : getrlimit(__VA_ARGS__))
#define getrlimit(...) (fail&getrlimit_ ? (seterr(getrlimit_), -1) : (setcall(getrlimit_), getrlimit(__VA_ARGS__))) #define mmap(...) (fail&mmap_ ? (seterr(mmap_), (void *)-1) : mmap(__VA_ARGS__))
#define mmap(...) (fail&mmap_ ? (seterr(mmap_), (void *)-1) : (setcall(mmap_), mmap(__VA_ARGS__))) #define munmap(a, b) (fail&munmap_ ? (seterr(munmap_), -1) : munmap(m_=(a), msz_=(b)))
#define munmap(a, b) (fail&munmap_ ? (seterr(munmap_), -1) : (setcall(munmap_), munmap(m_=(a), msz_=(b)))) #define setrlimit(...) (fail&setrlimit_ ? (seterr(setrlimit_), -1) : setrlimit(__VA_ARGS__))
#define setrlimit(...) (fail&setrlimit_ ? (seterr(setrlimit_), -1) : (setcall(setrlimit_), setrlimit(__VA_ARGS__))) #define sigaltstack(...) (fail&sigaltstack_ ? (seterr(sigaltstack_), -1) : sigaltstack(__VA_ARGS__))
#define sigaltstack(...) (fail&sigaltstack_ ? (seterr(sigaltstack_), -1) : (setcall(sigaltstack_), sigaltstack(__VA_ARGS__))) #define sigaction(...) (fail&sigaction_ ? (seterr(sigaction_), -1) : sigaction(__VA_ARGS__))
#define sigaction(...) (fail&sigaction_ ? (seterr(sigaction_), -1) : (setcall(sigaction_), sigaction(__VA_ARGS__)))
#define KiB (1024UL) #define KiB (1024UL)
#define MiB (KiB*KiB) #define MiB (KiB*KiB)
...@@ -58,74 +57,48 @@ static void *wrap(void *i) ...@@ -58,74 +57,48 @@ static void *wrap(void *i)
return wrap; return wrap;
} }
#define chkfail(x, y, z, c1, c2) \ #define chkfail(x, y, z) \
do { \ do { \
call1 = 0; \
call2 = 0; \
errno = 0; \ errno = 0; \
ok1((fail = x) && (y)); \ ok1((fail = x) && (y)); \
ok1(errno == (z)); \ ok1(errno == (z)); \
ok1(call1 == (c1)); \
ok1(call2 == (c2)); \
} while (0); } while (0);
#define chkok(y, z, c1, c2) \ #define chkok(y, z) \
do { \ do { \
call1 = 0; \
call2 = 0; \
errno = 0; \ errno = 0; \
fail = 0; \ fail = 0; \
ok1((y)); \ ok1((y)); \
ok1(errno == (z)); \ ok1(errno == (z)); \
ok1(call1 == (c1)); \
ok1(call2 == (c2)); \
} while (0) } while (0)
int main(void) int main(void)
{ {
long pgsz = sysconf(_SC_PAGESIZE); long pgsz = sysconf(_SC_PAGESIZE);
plan_tests(50); plan_tests(28);
chkfail(getrlimit_, altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(getrlimit_), chkfail(getrlimit_, altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(getrlimit_));
0,
0);
chkfail(setrlimit_, altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(setrlimit_), chkfail(setrlimit_, altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(setrlimit_));
getrlimit_,
0);
chkfail(mmap_, altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(mmap_), chkfail(mmap_, altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(mmap_));
getrlimit_|setrlimit_,
setrlimit_);
chkfail(sigaltstack_, altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(sigaltstack_), chkfail(sigaltstack_, altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(sigaltstack_));
getrlimit_|setrlimit_|mmap_,
setrlimit_|munmap_);
chkfail(sigaction_, altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(sigaction_), chkfail(sigaction_, altstack(8*MiB, wrap, int2ptr(0), NULL) == -1, e(sigaction_));
getrlimit_|setrlimit_|mmap_|sigaltstack_,
setrlimit_|munmap_|sigaltstack_);
chkfail(munmap_, altstack(8*MiB, wrap, int2ptr(0), NULL) == 1, e(munmap_), chkfail(munmap_, altstack(8*MiB, wrap, int2ptr(0), NULL) == 1, e(munmap_));
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|sigaltstack_|sigaction_);
if (fail = 0, munmap(m_, msz_) == -1) if (fail = 0, munmap(m_, msz_) == -1)
err(1, "munmap"); err(1, "munmap");
chkok( altstack(1*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW, chkok( altstack(1*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW);
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
// be sure segv catch is repeatable (SA_NODEFER) // be sure segv catch is repeatable (SA_NODEFER)
chkok( altstack(1*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW, chkok( altstack(1*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW);
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
used = 1; used = 1;
chkfail(munmap_, altstack(1*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW, chkfail(munmap_, altstack(1*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW);
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|sigaltstack_|sigaction_);
if (fail = 0, munmap(m_, msz_) == -1) if (fail = 0, munmap(m_, msz_) == -1)
err(1, "munmap"); err(1, "munmap");
...@@ -150,17 +123,13 @@ int main(void) ...@@ -150,17 +123,13 @@ int main(void)
ok1(strcmp(buf, estr "\n") == 0); ok1(strcmp(buf, estr "\n") == 0);
used = 1; used = 1;
chkok( altstack(8*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW, chkok( altstack(8*MiB, wrap, int2ptr(1000000), NULL) == -1, EOVERFLOW);
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
diag("used: %lu", used); diag("used: %lu", used);
ok1(used >= 8*MiB - pgsz && used <= 8*MiB + pgsz); ok1(used >= 8*MiB - pgsz && used <= 8*MiB + pgsz);
used = 0; used = 0;
chkok( altstack(8*MiB, wrap, int2ptr(100000), NULL) == 0, 0, chkok( altstack(8*MiB, wrap, int2ptr(100000), NULL) == 0, 0);
getrlimit_|setrlimit_|mmap_|sigaltstack_|sigaction_|munmap_,
setrlimit_|munmap_|sigaltstack_|sigaction_);
used = 1; used = 1;
altstack_rsp_save(); altstack_rsp_save();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment