From: Bart Van Assche Date: Thu, 1 May 2008 13:50:20 +0000 (+0000) Subject: Moved bitmap test from drd_bitmap.c to tests/drd_bitmap_test.c X-Git-Tag: svn/VALGRIND_3_4_0~664 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7d77c547932f45273962b9ba667c04434bd258cd;p=thirdparty%2Fvalgrind.git Moved bitmap test from drd_bitmap.c to tests/drd_bitmap_test.c git-svn-id: svn://svn.valgrind.org/valgrind/trunk@7973 --- diff --git a/exp-drd/drd_bitmap.c b/exp-drd/drd_bitmap.c index 99b3f13ccf..ad6993ca13 100644 --- a/exp-drd/drd_bitmap.c +++ b/exp-drd/drd_bitmap.c @@ -1002,63 +1002,3 @@ static void bm2_merge(struct bitmap2* const bm2l, bm2l->bm1.bm0_w[k] |= bm2r->bm1.bm0_w[k]; } } - -#if 0 - -/* Unit test */ -static -struct { Addr address; SizeT size; BmAccessTypeT access_type; } - s_args[] = { - { 0, 1, eLoad }, - { 666, 4, eLoad }, - { 667, 2, eStore }, - { 1024, 1, eStore }, - { 0xffffUL, 1, eStore }, - { 0x0001ffffUL, 1, eLoad }, - { 0x00ffffffUL, 1, eLoad }, - { 0xffffffffUL, 1, eStore }, - }; - -void bm_test(void) -{ - struct bitmap* bm; - struct bitmap* bm2; - unsigned i, j; - - VG_(printf)("Start of DRD BM unit test.\n"); - - bm = bm_new(); - - for (i = 0; i < sizeof(s_args)/sizeof(s_args[0]); i++) - { - bm_access_range(bm, - s_args[i].address, - s_args[i].address + s_args[i].size, - s_args[i].access_type); - } - - VG_(printf)("Map contents -- should contain 10 addresses:\n"); - bm_print(bm); - - for (i = 0; i < sizeof(s_args)/sizeof(s_args[0]); i++) - { - for (j = 0; j < s_args[i].size; j++) - { - tl_assert(bm_has_1(bm, s_args[i].address + j, s_args[i].access_type)); - } - } - - VG_(printf)("Merge result:\n"); - bm2 = bm_new(); - bm_merge2(bm2, bm); - bm_merge2(bm2, bm); - bm_print(bm); - - VG_(printf)("Deleting bitmap bm\n"); - bm_delete(bm); - VG_(printf)("Deleting bitmap bm2\n"); - bm_delete(bm2); - - VG_(printf)("End of DRD BM unit test.\n"); -} -#endif diff --git a/exp-drd/tests/Makefile.am b/exp-drd/tests/Makefile.am index 69c1902d14..ab48803b12 100644 --- a/exp-drd/tests/Makefile.am +++ b/exp-drd/tests/Makefile.am @@ -17,6 +17,7 @@ noinst_SCRIPTS = \ EXTRA_DIST = \ $(noinst_SCRIPTS) \ + drd_bitmap_test.stderr.exp \ fp_race.stderr.exp \ fp_race.vgtest \ fp_race2.stderr.exp \ @@ -143,11 +144,13 @@ EXTRA_DIST = \ tc24_nonzero_sem.vgtest \ trylock.c trylock.stderr.exp -AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -g $(AM_FLAG_M3264_PRI) +AM_CFLAGS = $(WERROR) -Wall -Wextra -Wshadow -Wno-unused-parameter \ + -g $(AM_FLAG_M3264_PRI) AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include -I$(top_builddir)/include AM_CXXFLAGS = $(AM_CFLAGS) check_PROGRAMS_COMMON = \ + drd_bitmap_test \ fp_race \ hg01_all_ok \ hg02_deadlock \ @@ -204,6 +207,12 @@ endif # tc14_laog_dinphils -- hangs. +drd_bitmap_test_SOURCES = drd_bitmap_test.c +drd_bitmap_test_CFLAGS = \ + $(AM_FLAG_M3264_PRI) -DVGA_$(VG_ARCH)=1 -DVGO_$(VG_OS)=1 \ + -DVGP_$(VG_ARCH)_$(VG_OS)=1 +drd_bitmap_test_LDADD = + fp_race_SOURCES = fp_race.c fp_race_LDADD = -lpthread diff --git a/exp-drd/tests/drd_bitmap_test.c b/exp-drd/tests/drd_bitmap_test.c new file mode 100644 index 0000000000..fc32811814 --- /dev/null +++ b/exp-drd/tests/drd_bitmap_test.c @@ -0,0 +1,91 @@ +#include +#include +#include +#include "coregrind/m_oset.c" +#include "exp-drd/drd_bitmap.c" +#include "exp-drd/pub_drd_bitmap.h" + + +/* Replacements for core functionality. */ + +void* VG_(malloc)(SizeT nbytes) +{ return malloc(nbytes); } +void VG_(free)(void* p) +{ return free(p); } +void VG_(assert_fail)(Bool isCore, const Char* expr, const Char* file, + Int line, const Char* fn, const HChar* format, ...) +{ __assert_fail(expr, file, line, fn); abort(); } +void* VG_(memset)(void *s, Int c, SizeT sz) +{ return memset(s, c, sz); } +void* VG_(memcpy)(void *d, const void *s, SizeT sz) +{ return memcpy(d, s, sz); } +Int VG_(memcmp)(const void* s1, const void* s2, SizeT n) +{ return memcmp(s1, s2, n); } +UInt VG_(printf)(const HChar *format, ...) +{ UInt ret; va_list vargs; va_start(vargs, format); ret = vprintf(format, vargs); va_end(vargs); return ret; } +Bool drd_is_suppressed(const Addr a1, const Addr a2) +{ assert(0); } + + +/* Unit test */ +static +struct { Addr address; SizeT size; BmAccessTypeT access_type; } + s_args[] = { + { 0, 1, eLoad }, + { 666, 4, eLoad }, + { 667, 2, eStore }, + { 1024, 1, eStore }, + { 0xffffUL, 1, eStore }, + { 0x0001ffffUL, 1, eLoad }, + { 0x00ffffffUL, 1, eLoad }, + { 0xffffffffUL, 1, eStore }, + }; + +void bm_test(void) +{ + struct bitmap* bm; + struct bitmap* bm2; + unsigned i, j; + + VG_(printf)("Start of DRD BM unit test.\n"); + + bm = bm_new(); + + for (i = 0; i < sizeof(s_args)/sizeof(s_args[0]); i++) + { + bm_access_range(bm, + s_args[i].address, + s_args[i].address + s_args[i].size, + s_args[i].access_type); + } + + VG_(printf)("Map contents -- should contain 10 addresses:\n"); + bm_print(bm); + + for (i = 0; i < sizeof(s_args)/sizeof(s_args[0]); i++) + { + for (j = 0; j < s_args[i].size; j++) + { + tl_assert(bm_has_1(bm, s_args[i].address + j, s_args[i].access_type)); + } + } + + VG_(printf)("Merge result:\n"); + bm2 = bm_new(); + bm_merge2(bm2, bm); + bm_merge2(bm2, bm); + bm_print(bm); + + VG_(printf)("Deleting bitmap bm\n"); + bm_delete(bm); + VG_(printf)("Deleting bitmap bm2\n"); + bm_delete(bm2); + + VG_(printf)("End of DRD BM unit test.\n"); +} + +int main(int argc, char** argv) +{ + bm_test(); + return 0; +} diff --git a/exp-drd/tests/drd_bitmap_test.stderr.exp b/exp-drd/tests/drd_bitmap_test.stderr.exp new file mode 100644 index 0000000000..d18786f806 --- /dev/null +++ b/exp-drd/tests/drd_bitmap_test.stderr.exp @@ -0,0 +1,3 @@ + + +ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0) diff --git a/exp-drd/tests/drd_bitmap_test.stdout.exp b/exp-drd/tests/drd_bitmap_test.stdout.exp new file mode 100644 index 0000000000..823b0e6204 --- /dev/null +++ b/exp-drd/tests/drd_bitmap_test.stdout.exp @@ -0,0 +1,26 @@ +Start of DRD BM unit test. +Map contents -- should contain 10 addresses: +0x00000000 R +0x0000029a R +0x0000029b W R +0x0000029c W R +0x0000029d R +0x00000400 W +0x0000ffff W +0x0001ffff R +0x00ffffff R +0xffffffff W +Merge result: +0x00000000 R +0x0000029a R +0x0000029b W R +0x0000029c W R +0x0000029d R +0x00000400 W +0x0000ffff W +0x0001ffff R +0x00ffffff R +0xffffffff W +Deleting bitmap bm +Deleting bitmap bm2 +End of DRD BM unit test.