From: Nicholas Nethercote Date: Thu, 14 Oct 2004 08:52:43 +0000 (+0000) Subject: Strengthened the unit self-test, by also testing foreach_map(), the other X-Git-Tag: svn/VALGRIND_3_0_0~1532 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9f0e6ed4342d123abd9741f61d03482aca17edc3;p=thirdparty%2Fvalgrind.git Strengthened the unit self-test, by also testing foreach_map(), the other function exported by ume.c. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@2761 --- diff --git a/memcheck/tests/vgtest_ume.c b/memcheck/tests/vgtest_ume.c index 99fb5c9d11..3b8b2e352e 100644 --- a/memcheck/tests/vgtest_ume.c +++ b/memcheck/tests/vgtest_ume.c @@ -10,6 +10,38 @@ #define STKSZ (64*1024) +//------------------------------------------------------------------- +// Test foreach_map() +//------------------------------------------------------------------- + +static int x; + +static int f(char *start, char *end, const char *perm, off_t off, + int maj, int min, int ino, void* dummy) { + // Just do some nonsense action with each of the values so that Memcheck + // checks that they are valid. + x = ( start == 0 ? 0 : 1 ); + x = ( end == 0 ? 0 : 1 ); + x = ( perm == 0 ? 0 : 1 ); + x = ( off == 0 ? 0 : 1 ); + x = ( maj == 0 ? 0 : 1 ); + x = ( min == 0 ? 0 : 1 ); + x = ( ino == 0 ? 0 : 1 ); + x = ( dummy == 0 ? 0 : 1 ); + + return /*True*/1; +} + +static void test__foreach_map(void) +{ + fprintf(stderr, "Calling foreach_map()\n"); + foreach_map(f, /*dummy*/NULL); +} + +//------------------------------------------------------------------- +// Test do_exec() +//------------------------------------------------------------------- + static void push_auxv(unsigned char **espp, int type, void *val) { struct ume_auxv *auxp = (struct ume_auxv *)*espp; @@ -26,8 +58,7 @@ static void push(unsigned char **espp, void *v) *espp = (unsigned char *)vp; } - -int main(void) +static void test__do_exec(void) { struct exeinfo info; int err; @@ -39,6 +70,7 @@ int main(void) info.exe_end = 0x50ffffff; info.map_base = 0x51000000; + fprintf(stderr, "Calling do_exec(\"hello\")\n"); err = do_exec("hello", &info); assert(0 == err); @@ -71,5 +103,13 @@ int main(void) jmp_with_stack(info.init_eip, (addr_t)esp); + assert(0); // UNREACHABLE +} + +int main(void) +{ + test__foreach_map(); + test__do_exec(); + return 0; } diff --git a/memcheck/tests/vgtest_ume.stderr.exp b/memcheck/tests/vgtest_ume.stderr.exp index af5626b4a1..d92d00ac43 100644 --- a/memcheck/tests/vgtest_ume.stderr.exp +++ b/memcheck/tests/vgtest_ume.stderr.exp @@ -1 +1,3 @@ +Calling foreach_map() +Calling do_exec("hello") Hello, world!