|
From: <sv...@va...> - 2009-06-05 18:09:53
|
Author: bart
Date: 2009-06-05 19:09:48 +0100 (Fri, 05 Jun 2009)
New Revision: 10254
Log:
- Added a new functin called DRD_(vc_aprint)().
- Moved unit test for functions in drd_vc.c to tests/unit_vc.c.
- Renamed tests/drd_bitmap_test.c to tests/unit_bitmap.c.
- All tests/unit_bitmap.c output is now sent to stderr.
Added:
branches/DRDDEV/drd/tests/unit_bitmap.c
branches/DRDDEV/drd/tests/unit_bitmap.stderr.exp
branches/DRDDEV/drd/tests/unit_bitmap.vgtest
branches/DRDDEV/drd/tests/unit_vc.c
Removed:
branches/DRDDEV/drd/tests/drd_bitmap_test.c
branches/DRDDEV/drd/tests/drd_bitmap_test.stderr.exp
branches/DRDDEV/drd/tests/drd_bitmap_test.stdout.exp
branches/DRDDEV/drd/tests/drd_bitmap_test.vgtest
Modified:
branches/DRDDEV/drd/drd_vc.c
branches/DRDDEV/drd/drd_vc.h
branches/DRDDEV/drd/tests/Makefile.am
Modified: branches/DRDDEV/drd/drd_vc.c
===================================================================
--- branches/DRDDEV/drd/drd_vc.c 2009-06-05 16:56:40 UTC (rev 10253)
+++ branches/DRDDEV/drd/drd_vc.c 2009-06-05 18:09:48 UTC (rev 10254)
@@ -237,17 +237,48 @@
/** Print the contents of vector clock 'vc'. */
void DRD_(vc_print)(const VectorClock* const vc)
{
+ char* str;
+
+ if ((str = DRD_(vc_aprint)(vc)) != NULL)
+ {
+ VG_(printf)("%s", str);
+ VG_(free)(str);
+ }
+}
+
+/**
+ * Print the contents of vector clock 'vc' to a newly allocated string.
+ * The caller must call VG_(free)() on the return value of this function.
+ */
+char* DRD_(vc_aprint)(const VectorClock* const vc)
+{
unsigned i;
+ unsigned len;
+ char* str = 0;
tl_assert(vc);
- VG_(printf)("[");
+ len = 64;
+ str = VG_(realloc)("drd.vc.aprint.1", str, len);
+ if (! str)
+ return str;
+ VG_(snprintf)(str, len, "[");
for (i = 0; i < vc->size; i++)
{
tl_assert(vc->vc);
- VG_(printf)("%s %d: %d", i > 0 ? "," : "",
- vc->vc[i].threadid, vc->vc[i].count);
+ if (VG_(strlen)(str) + 32 > len)
+ {
+ len *= 2;
+ str = VG_(realloc)("drd.vc.aprint.2", str, len);
+ if (! str)
+ return str;
+ }
+ VG_(snprintf)(str + VG_(strlen)(str), len - VG_(strlen)(str),
+ "%s %d: %d", i > 0 ? "," : "",
+ vc->vc[i].threadid, vc->vc[i].count);
}
- VG_(printf)(" ]");
+ VG_(snprintf)(str + VG_(strlen)(str), len - VG_(strlen)(str), " ]");
+
+ return str;
}
/**
@@ -357,6 +388,7 @@
if (vc->capacity > VC_PREALLOCATED)
VG_(free)(vc->vc);
vc->vc = 0;
+ vc->capacity = 0;
}
tl_assert(new_capacity == 0 || vc->vc != 0);
@@ -364,49 +396,3 @@
|| vc->vc == 0
|| vc->vc == vc->preallocated);
}
-
-#if 0
-/**
- * Unit test.
- */
-void DRD_(vc_test)(void)
-{
- VectorClock vc1;
- VCElem vc1elem[] = { { 3, 7 }, { 5, 8 }, };
- VectorClock vc2;
- VCElem vc2elem[] = { { 1, 4 }, { 3, 9 }, };
- VectorClock vc3;
- VCElem vc4elem[] = { { 1, 3 }, { 2, 1 }, };
- VectorClock vc4;
- VCElem vc5elem[] = { { 1, 4 }, };
- VectorClock vc5;
-
- vc_init(&vc1, vc1elem, sizeof(vc1elem)/sizeof(vc1elem[0]));
- vc_init(&vc2, vc2elem, sizeof(vc2elem)/sizeof(vc2elem[0]));
- vc_init(&vc3, 0, 0);
- vc_init(&vc4, vc4elem, sizeof(vc4elem)/sizeof(vc4elem[0]));
- vc_init(&vc5, vc5elem, sizeof(vc5elem)/sizeof(vc5elem[0]));
-
- vc_combine(&vc3, &vc1);
- vc_combine(&vc3, &vc2);
-
- VG_(printf)("vc1: ");
- vc_print(&vc1);
- VG_(printf)("\nvc2: ");
- vc_print(&vc2);
- VG_(printf)("\nvc3: ");
- vc_print(&vc3);
- VG_(printf)("\n");
- VG_(printf)("vc_lte(vc1, vc2) = %d, vc_lte(vc1, vc3) = %d,"
- " vc_lte(vc2, vc3) = %d, vc_lte(",
- vc_lte(&vc1, &vc2), vc_lte(&vc1, &vc3), vc_lte(&vc2, &vc3));
- vc_print(&vc4);
- VG_(printf)(", ");
- vc_print(&vc5);
- VG_(printf)(") = %d sw %d\n", vc_lte(&vc4, &vc5), vc_lte(&vc5, &vc4));
-
- vc_cleanup(&vc1);
- vc_cleanup(&vc2);
- vc_cleanup(&vc3);
-}
-#endif
Modified: branches/DRDDEV/drd/drd_vc.h
===================================================================
--- branches/DRDDEV/drd/drd_vc.h 2009-06-05 16:56:40 UTC (rev 10253)
+++ branches/DRDDEV/drd/drd_vc.h 2009-06-05 18:09:48 UTC (rev 10254)
@@ -47,7 +47,9 @@
*/
-#include "pub_tool_basics.h" // Addr, SizeT
+#include "pub_tool_basics.h" /* Addr, SizeT */
+#include "drd_basics.h" /* DrdThreadId */
+#include "pub_tool_libcassert.h" /* tl_assert() */
#define VC_PREALLOCATED 8
@@ -86,6 +88,7 @@
void DRD_(vc_combine)(VectorClock* const result,
const VectorClock* const rhs);
void DRD_(vc_print)(const VectorClock* const vc);
+char* DRD_(vc_aprint)(const VectorClock* const vc);
void DRD_(vc_snprint)(Char* const str, const Int size,
const VectorClock* const vc);
void DRD_(vc_check)(const VectorClock* const vc);
Modified: branches/DRDDEV/drd/tests/Makefile.am
===================================================================
--- branches/DRDDEV/drd/tests/Makefile.am 2009-06-05 16:56:40 UTC (rev 10253)
+++ branches/DRDDEV/drd/tests/Makefile.am 2009-06-05 18:09:48 UTC (rev 10254)
@@ -41,9 +41,6 @@
circular_buffer.vgtest \
custom_alloc.stderr.exp \
custom_alloc.vgtest \
- drd_bitmap_test.stderr.exp \
- drd_bitmap_test.stdout.exp \
- drd_bitmap_test.vgtest \
fp_race.stderr.exp \
fp_race.vgtest \
fp_race2.stderr.exp \
@@ -218,10 +215,14 @@
thread_name.stderr.exp \
thread_name.vgtest \
trylock.stderr.exp \
- trylock.vgtest
+ trylock.vgtest \
+ unit_bitmap.stderr.exp \
+ unit_bitmap.vgtest \
+ unit_vc.stderr.exp \
+ unit_vc.vgtest
+
check_PROGRAMS = \
- drd_bitmap_test \
fp_race \
hold_lock \
linuxthreads_det \
@@ -243,7 +244,9 @@
sem_as_mutex \
sigalrm \
thread_name \
- trylock
+ trylock \
+ unit_bitmap \
+ unit_vc
if HAVE_BOOST_1_35
check_PROGRAMS += boost_thread
@@ -283,11 +286,6 @@
LDADD = -lpthread
-drd_bitmap_test_CFLAGS = $(AM_CFLAGS) -O2 \
- -DENABLE_DRD_CONSISTENCY_CHECKS\
- @FLAG_UNLIMITED_INLINE_UNIT_GROWTH@
-drd_bitmap_test_LDADD = # nothing, i.e. not -lpthread
-
monitor_example_SOURCES = monitor_example.cpp
new_delete_SOURCES = new_delete.cpp
@@ -296,6 +294,14 @@
-DTHREAD_WRAPPERS='"tsan_thread_wrappers_pthread.h"' \
-Wno-sign-compare -Wno-shadow @FLAG_W_NO_EMPTY_BODY@
+unit_bitmap_CFLAGS = $(AM_CFLAGS) -O2 \
+ -DENABLE_DRD_CONSISTENCY_CHECKS \
+ @FLAG_UNLIMITED_INLINE_UNIT_GROWTH@
+unit_bitmap_LDADD = # nothing, i.e. not -lpthread
+
+unit_vc_CFLAGS = $(AM_CFLAGS) -DENABLE_DRD_CONSISTENCY_CHECKS
+unit_vc_LDADD = # nothing, i.e. not -lpthread
+
if HAVE_BOOST_1_35
boost_thread_SOURCES = boost_thread.cpp
boost_thread_CXXFLAGS = $(AM_CXXFLAGS) $(BOOST_CFLAGS)
Deleted: branches/DRDDEV/drd/tests/drd_bitmap_test.c
===================================================================
--- branches/DRDDEV/drd/tests/drd_bitmap_test.c 2009-06-05 16:56:40 UTC (rev 10253)
+++ branches/DRDDEV/drd/tests/drd_bitmap_test.c 2009-06-05 18:09:48 UTC (rev 10254)
@@ -1,341 +0,0 @@
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "coregrind/m_oset.c"
-#include "drd/drd_bitmap.c"
-#include "drd/drd_bitmap2_node.c"
-#include "drd/pub_drd_bitmap.h"
-
-
-#ifndef MIN
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
-#endif
-#ifndef MAX
-#define MAX(x, y) ((x) > (y) ? (x) : (y))
-#endif
-
-
-/* Replacements for core functionality. */
-
-void* VG_(malloc)(HChar* cc, SizeT nbytes)
-{ return malloc(nbytes); }
-void VG_(free)(void* p)
-{ return free(p); }
-void VG_(assert_fail)(Bool isCore, const Char* assertion, const Char* file,
- Int line, const Char* function, const HChar* format,
- ...)
-{
- fprintf(stderr,
- "%s:%u: %s%sAssertion `%s' failed.\n",
- file,
- line,
- function ? (char*)function : "",
- function ? ": " : "",
- assertion);
- fflush(stdout);
- fflush(stderr);
- 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; }
-UInt VG_(message)(VgMsgKind kind, const HChar* format, ...)
-{ UInt ret; va_list vargs; va_start(vargs, format); ret = vprintf(format, vargs); va_end(vargs); printf("\n"); return ret; }
-Bool DRD_(is_suppressed)(const Addr a1, const Addr a2)
-{ assert(0); }
-
-
-/* Actual unit test */
-
-static int s_verbose = 1;
-
-static
-struct { Addr address; SizeT size; BmAccessTypeT access_type; }
- s_test1_args[] = {
- { 0, 1, eLoad },
- { 666, 4, eLoad },
- { 667, 2, eStore },
- { 1024, 1, eStore },
- { 0xffffULL, 1, eStore },
- { 0x0001ffffULL, 1, eLoad },
- { 0x00ffffffULL, 1, eLoad },
- { 0xffffffffULL - (((1 << ADDR_LSB_BITS) + 1) << ADDR_IGNORED_BITS),
- 1, eStore },
-#if defined(VGP_amd64_linux) || defined(VGP_ppc64_linux) || defined(VGP_ppc64_aix5)
- { 0xffffffffULL - (1 << ADDR_LSB_BITS << ADDR_IGNORED_BITS),
- 1, eStore },
- { 0xffffffffULL, 1, eStore },
- { 0x100000000ULL, 1, eStore },
- { -2ULL - (1 << ADDR_LSB_BITS << ADDR_IGNORED_BITS),
- 1, eStore },
-#endif
- };
-
-/**
- * Compare two bitmaps and if different, print the differences.
- */
-int bm_equal_print_diffs(struct bitmap* bm1, struct bitmap* bm2)
-{
- int equal;
-
- equal = DRD_(bm_equal)(bm1, bm2);
- if (s_verbose && ! equal)
- {
- unsigned i;
-
- VG_(printf)("Bitmaps are different.\n");
- for (i = 0; i < 0x10000; i++)
- {
- if (DRD_(bm_has_1)(bm1, i, eLoad) != DRD_(bm_has_1)(bm2, i, eLoad)
- || DRD_(bm_has_1)(bm1, i, eStore) != DRD_(bm_has_1)(bm2, i, eStore))
- {
- printf("0x%x %c %c %c %c\n",
- i,
- DRD_(bm_has_1)(bm1, i, eLoad) ? 'R' : ' ',
- DRD_(bm_has_1)(bm1, i, eStore) ? 'W' : ' ',
- DRD_(bm_has_1)(bm2, i, eLoad) ? 'R' : ' ',
- DRD_(bm_has_1)(bm2, i, eStore) ? 'W' : ' '
- );
- }
- }
- fflush(stdout);
- }
-
- return equal;
-}
-
-void bm_test1(void)
-{
- struct bitmap* bm;
- struct bitmap* bm2;
- unsigned i, j;
-
- bm = DRD_(bm_new)();
-
- for (i = 0; i < sizeof(s_test1_args)/sizeof(s_test1_args[0]); i++)
- {
- DRD_(bm_access_range)(bm,
- s_test1_args[i].address,
- s_test1_args[i].address + s_test1_args[i].size,
- s_test1_args[i].access_type);
- }
-
- for (i = 0; i < sizeof(s_test1_args)/sizeof(s_test1_args[0]); i++)
- {
- for (j = 0;
- first_address_with_higher_lsb(j) <= s_test1_args[i].size;
- j = first_address_with_higher_lsb(j))
- {
- tl_assert(DRD_(bm_has_1)(bm,
- s_test1_args[i].address + j,
- s_test1_args[i].access_type));
- }
- }
-
- bm2 = DRD_(bm_new)();
- DRD_(bm_merge2)(bm2, bm);
- DRD_(bm_merge2)(bm2, bm);
- assert(bm_equal_print_diffs(bm2, bm));
-
- if (s_verbose)
- VG_(printf)("Deleting bitmap bm\n");
- DRD_(bm_delete)(bm);
- if (s_verbose)
- VG_(printf)("Deleting bitmap bm2\n");
- DRD_(bm_delete)(bm2);
-}
-
-/** Test whether bm_equal() works correctly. */
-void bm_test2()
-{
- struct bitmap* bm1;
- struct bitmap* bm2;
-
- bm1 = DRD_(bm_new)();
- bm2 = DRD_(bm_new)();
- DRD_(bm_access_load_1)(bm1, 7);
- DRD_(bm_access_load_1)(bm2, make_address(1, 0) + 7);
- assert(! DRD_(bm_equal)(bm1, bm2));
- assert(! DRD_(bm_equal)(bm2, bm1));
- DRD_(bm_access_load_1)(bm2, 7);
- assert(! DRD_(bm_equal)(bm1, bm2));
- assert(! DRD_(bm_equal)(bm2, bm1));
- DRD_(bm_access_store_1)(bm1, make_address(1, 0) + 7);
- assert(! DRD_(bm_equal)(bm1, bm2));
- assert(! DRD_(bm_equal)(bm2, bm1));
- DRD_(bm_delete)(bm2);
- DRD_(bm_delete)(bm1);
-}
-
-/** Torture test of the functions that set or clear a range of bits. */
-void bm_test3(const int outer_loop_step, const int inner_loop_step)
-{
- unsigned i, j;
- struct bitmap* bm1;
- struct bitmap* bm2;
-
- const Addr lb = make_address(2, 0) - 2 * BITS_PER_UWORD;
- const Addr ub = make_address(2, 0) + 2 * BITS_PER_UWORD;
-
- assert(outer_loop_step >= 1);
- assert((outer_loop_step % ADDR_GRANULARITY) == 0);
- assert(inner_loop_step >= 1);
- assert((inner_loop_step % ADDR_GRANULARITY) == 0);
-
- bm1 = DRD_(bm_new)();
- bm2 = DRD_(bm_new)();
- for (i = lb; i < ub; i += outer_loop_step)
- {
- for (j = i + ADDR_GRANULARITY; j < ub; j += inner_loop_step)
- {
- DRD_(bm_access_range_load)(bm1, i, j);
- DRD_(bm_clear_load)(bm1, i, j);
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_load_1)(bm1, i);
- DRD_(bm_clear_load)(bm1, i, i + MAX(1, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_load_2)(bm1, i);
- DRD_(bm_clear_load)(bm1, i, i + MAX(2, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_load_4)(bm1, i);
- DRD_(bm_clear_load)(bm1, i, i + MAX(4, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_load_8)(bm1, i);
- DRD_(bm_clear_load)(bm1, i, i + MAX(8, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
-
- DRD_(bm_access_range_store)(bm1, i, j);
- DRD_(bm_clear_store)(bm1, i, j);
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_store_1)(bm1, i);
- DRD_(bm_clear_store)(bm1, i, i + MAX(1, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_store_2)(bm1, i);
- DRD_(bm_clear_store)(bm1, i, i + MAX(2, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_store_4)(bm1, i);
- DRD_(bm_clear_store)(bm1, i, i + MAX(4, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_store_8)(bm1, i);
- DRD_(bm_clear_store)(bm1, i, i + MAX(8, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
-
- DRD_(bm_access_range_load)(bm1, i, j);
- DRD_(bm_access_range_store)(bm1, i, j);
- DRD_(bm_clear)(bm1, i, j);
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_load_1)(bm1, i);
- DRD_(bm_access_store_1)(bm1, i);
- DRD_(bm_clear)(bm1, i, i + MAX(1, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_load_2)(bm1, i);
- DRD_(bm_access_store_2)(bm1, i);
- DRD_(bm_clear)(bm1, i, i + MAX(2, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_load_4)(bm1, i);
- DRD_(bm_access_store_4)(bm1, i);
- DRD_(bm_clear)(bm1, i, i + MAX(4, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_access_load_8)(bm1, i);
- DRD_(bm_access_store_8)(bm1, i);
- DRD_(bm_clear)(bm1, i, i + MAX(8, ADDR_GRANULARITY));
- assert(bm_equal_print_diffs(bm1, bm2));
- }
- }
- DRD_(bm_access_range_load)(bm1, 0, make_address(2, 0) + 2 * BITS_PER_UWORD);
- DRD_(bm_access_range_store)(bm1, 0, make_address(2, 0) + 2 * BITS_PER_UWORD);
- DRD_(bm_access_range_load)(bm2, 0, make_address(2, 0) + 2 * BITS_PER_UWORD);
- DRD_(bm_access_range_store)(bm2, 0, make_address(2, 0) + 2 * BITS_PER_UWORD);
- for (i = make_address(1, 0) - 2 * BITS_PER_UWORD;
- i < make_address(1, 0) + 2 * BITS_PER_UWORD;
- i += outer_loop_step)
- {
- for (j = i + 1; j < ub; j += inner_loop_step)
- {
- DRD_(bm_clear_load)(bm1, i, j);
- DRD_(bm_access_range_load)(bm1, i, j);
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_clear_load)(bm1, i, i+1);
- DRD_(bm_access_load_1)(bm1, i);
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_clear_load)(bm1, i, i+2);
- DRD_(bm_access_load_2)(bm1, i);
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_clear_load)(bm1, i, i+4);
- DRD_(bm_access_load_4)(bm1, i);
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_clear_load)(bm1, i, i+8);
- DRD_(bm_access_load_8)(bm1, i);
- assert(bm_equal_print_diffs(bm1, bm2));
-
- DRD_(bm_clear_store)(bm1, i, j);
- DRD_(bm_access_range_store)(bm1, i, j);
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_clear_store)(bm1, i, i+1);
- DRD_(bm_access_store_1)(bm1, i);
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_clear_store)(bm1, i, i+2);
- DRD_(bm_access_store_2)(bm1, i);
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_clear_store)(bm1, i, i+4);
- DRD_(bm_access_store_4)(bm1, i);
- assert(bm_equal_print_diffs(bm1, bm2));
- DRD_(bm_clear_store)(bm1, i, i+8);
- DRD_(bm_access_store_8)(bm1, i);
- assert(bm_equal_print_diffs(bm1, bm2));
-
- DRD_(bm_clear)(bm1, i, j);
- DRD_(bm_access_range_load)(bm1, i, j);
- DRD_(bm_access_range_store)(bm1, i, j);
- assert(bm_equal_print_diffs(bm1, bm2));
- }
- }
- DRD_(bm_delete)(bm2);
- DRD_(bm_delete)(bm1);
-}
-
-int main(int argc, char** argv)
-{
- int outer_loop_step = ADDR_GRANULARITY;
- int inner_loop_step = ADDR_GRANULARITY;
- int optchar;
-
- while ((optchar = getopt(argc, argv, "s:t:q")) != EOF)
- {
- switch (optchar)
- {
- case 's':
- outer_loop_step = atoi(optarg);
- break;
- case 't':
- inner_loop_step = atoi(optarg);
- break;
- case 'q':
- s_verbose = 0;
- break;
- default:
- fprintf(stderr,
- "Usage: %s [-s<outer_loop_step>] [-t<inner_loop_step>] [-q].\n",
- argv[0]);
- break;
- }
- }
-
- VG_(printf)("Start of DRD BM unit test.\n");
-
- bm_test1();
- bm_test2();
- bm_test3(outer_loop_step, inner_loop_step);
-
- VG_(printf)("End of DRD BM unit test.\n");
-
- return 0;
-}
Deleted: branches/DRDDEV/drd/tests/drd_bitmap_test.stderr.exp
===================================================================
Deleted: branches/DRDDEV/drd/tests/drd_bitmap_test.stdout.exp
===================================================================
--- branches/DRDDEV/drd/tests/drd_bitmap_test.stdout.exp 2009-06-05 16:56:40 UTC (rev 10253)
+++ branches/DRDDEV/drd/tests/drd_bitmap_test.stdout.exp 2009-06-05 18:09:48 UTC (rev 10254)
@@ -1,2 +0,0 @@
-Start of DRD BM unit test.
-End of DRD BM unit test.
Deleted: branches/DRDDEV/drd/tests/drd_bitmap_test.vgtest
===================================================================
--- branches/DRDDEV/drd/tests/drd_bitmap_test.vgtest 2009-06-05 16:56:40 UTC (rev 10253)
+++ branches/DRDDEV/drd/tests/drd_bitmap_test.vgtest 2009-06-05 18:09:48 UTC (rev 10254)
@@ -1,3 +0,0 @@
-prog: drd_bitmap_test
-args: -s 93 -t 97 -q
-vgopts: -q --tool=memcheck
Copied: branches/DRDDEV/drd/tests/unit_bitmap.c (from rev 10245, branches/DRDDEV/drd/tests/drd_bitmap_test.c)
===================================================================
--- branches/DRDDEV/drd/tests/unit_bitmap.c (rev 0)
+++ branches/DRDDEV/drd/tests/unit_bitmap.c 2009-06-05 18:09:48 UTC (rev 10254)
@@ -0,0 +1,344 @@
+/** @brief Unit-test for DRD's bitmap implementation. */
+
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include "coregrind/m_oset.c"
+#include "drd/drd_bitmap.c"
+#include "drd/drd_bitmap2_node.c"
+#include "drd/pub_drd_bitmap.h"
+
+
+#ifndef MIN
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+#endif
+#ifndef MAX
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+#endif
+
+
+/* Replacements for Valgrind core functionality. */
+
+void* VG_(malloc)(HChar* cc, SizeT nbytes)
+{ return malloc(nbytes); }
+void VG_(free)(void* p)
+{ return free(p); }
+void VG_(assert_fail)(Bool isCore, const Char* assertion, const Char* file,
+ Int line, const Char* function, const HChar* format,
+ ...)
+{
+ fprintf(stderr,
+ "%s:%u: %s%sAssertion `%s' failed.\n",
+ file,
+ line,
+ function ? (char*)function : "",
+ function ? ": " : "",
+ assertion);
+ fflush(stdout);
+ fflush(stderr);
+ 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; }
+UInt VG_(message)(VgMsgKind kind, const HChar* format, ...)
+{ UInt ret; va_list vargs; va_start(vargs, format); ret = vprintf(format, vargs); va_end(vargs); printf("\n"); return ret; }
+Bool DRD_(is_suppressed)(const Addr a1, const Addr a2)
+{ assert(0); }
+
+
+/* Actual unit test */
+
+static int s_verbose = 1;
+
+static
+struct { Addr address; SizeT size; BmAccessTypeT access_type; }
+ s_test1_args[] = {
+ { 0, 1, eLoad },
+ { 666, 4, eLoad },
+ { 667, 2, eStore },
+ { 1024, 1, eStore },
+ { 0xffffULL, 1, eStore },
+ { 0x0001ffffULL, 1, eLoad },
+ { 0x00ffffffULL, 1, eLoad },
+ { 0xffffffffULL - (((1 << ADDR_LSB_BITS) + 1) << ADDR_IGNORED_BITS),
+ 1, eStore },
+#if defined(VGP_amd64_linux) || defined(VGP_ppc64_linux) || defined(VGP_ppc64_aix5)
+ { 0xffffffffULL - (1 << ADDR_LSB_BITS << ADDR_IGNORED_BITS),
+ 1, eStore },
+ { 0xffffffffULL, 1, eStore },
+ { 0x100000000ULL, 1, eStore },
+ { -2ULL - (1 << ADDR_LSB_BITS << ADDR_IGNORED_BITS),
+ 1, eStore },
+#endif
+ };
+
+/**
+ * Compare two bitmaps and if different, print the differences.
+ */
+int bm_equal_print_diffs(struct bitmap* bm1, struct bitmap* bm2)
+{
+ int equal;
+
+ equal = DRD_(bm_equal)(bm1, bm2);
+ if (s_verbose && ! equal)
+ {
+ unsigned i;
+
+ VG_(printf)("Bitmaps are different.\n");
+ for (i = 0; i < 0x10000; i++)
+ {
+ if (DRD_(bm_has_1)(bm1, i, eLoad) != DRD_(bm_has_1)(bm2, i, eLoad)
+ || DRD_(bm_has_1)(bm1, i, eStore) != DRD_(bm_has_1)(bm2, i, eStore))
+ {
+ printf("0x%x %c %c %c %c\n",
+ i,
+ DRD_(bm_has_1)(bm1, i, eLoad) ? 'R' : ' ',
+ DRD_(bm_has_1)(bm1, i, eStore) ? 'W' : ' ',
+ DRD_(bm_has_1)(bm2, i, eLoad) ? 'R' : ' ',
+ DRD_(bm_has_1)(bm2, i, eStore) ? 'W' : ' '
+ );
+ }
+ }
+ fflush(stdout);
+ }
+
+ return equal;
+}
+
+void bm_test1(void)
+{
+ struct bitmap* bm;
+ struct bitmap* bm2;
+ unsigned i, j;
+
+ bm = DRD_(bm_new)();
+
+ for (i = 0; i < sizeof(s_test1_args)/sizeof(s_test1_args[0]); i++)
+ {
+ DRD_(bm_access_range)(bm,
+ s_test1_args[i].address,
+ s_test1_args[i].address + s_test1_args[i].size,
+ s_test1_args[i].access_type);
+ }
+
+ for (i = 0; i < sizeof(s_test1_args)/sizeof(s_test1_args[0]); i++)
+ {
+ for (j = 0;
+ first_address_with_higher_lsb(j) <= s_test1_args[i].size;
+ j = first_address_with_higher_lsb(j))
+ {
+ tl_assert(DRD_(bm_has_1)(bm,
+ s_test1_args[i].address + j,
+ s_test1_args[i].access_type));
+ }
+ }
+
+ bm2 = DRD_(bm_new)();
+ DRD_(bm_merge2)(bm2, bm);
+ DRD_(bm_merge2)(bm2, bm);
+ assert(bm_equal_print_diffs(bm2, bm));
+
+ if (s_verbose)
+ VG_(printf)("Deleting bitmap bm\n");
+ DRD_(bm_delete)(bm);
+ if (s_verbose)
+ VG_(printf)("Deleting bitmap bm2\n");
+ DRD_(bm_delete)(bm2);
+}
+
+/** Test whether bm_equal() works correctly. */
+void bm_test2()
+{
+ struct bitmap* bm1;
+ struct bitmap* bm2;
+
+ bm1 = DRD_(bm_new)();
+ bm2 = DRD_(bm_new)();
+ DRD_(bm_access_load_1)(bm1, 7);
+ DRD_(bm_access_load_1)(bm2, make_address(1, 0) + 7);
+ assert(! DRD_(bm_equal)(bm1, bm2));
+ assert(! DRD_(bm_equal)(bm2, bm1));
+ DRD_(bm_access_load_1)(bm2, 7);
+ assert(! DRD_(bm_equal)(bm1, bm2));
+ assert(! DRD_(bm_equal)(bm2, bm1));
+ DRD_(bm_access_store_1)(bm1, make_address(1, 0) + 7);
+ assert(! DRD_(bm_equal)(bm1, bm2));
+ assert(! DRD_(bm_equal)(bm2, bm1));
+ DRD_(bm_delete)(bm2);
+ DRD_(bm_delete)(bm1);
+}
+
+/** Torture test of the functions that set or clear a range of bits. */
+void bm_test3(const int outer_loop_step, const int inner_loop_step)
+{
+ unsigned i, j;
+ struct bitmap* bm1;
+ struct bitmap* bm2;
+
+ const Addr lb = make_address(2, 0) - 2 * BITS_PER_UWORD;
+ const Addr ub = make_address(2, 0) + 2 * BITS_PER_UWORD;
+
+ assert(outer_loop_step >= 1);
+ assert((outer_loop_step % ADDR_GRANULARITY) == 0);
+ assert(inner_loop_step >= 1);
+ assert((inner_loop_step % ADDR_GRANULARITY) == 0);
+
+ bm1 = DRD_(bm_new)();
+ bm2 = DRD_(bm_new)();
+ for (i = lb; i < ub; i += outer_loop_step)
+ {
+ for (j = i + ADDR_GRANULARITY; j < ub; j += inner_loop_step)
+ {
+ DRD_(bm_access_range_load)(bm1, i, j);
+ DRD_(bm_clear_load)(bm1, i, j);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_load_1)(bm1, i);
+ DRD_(bm_clear_load)(bm1, i, i + MAX(1, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_load_2)(bm1, i);
+ DRD_(bm_clear_load)(bm1, i, i + MAX(2, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_load_4)(bm1, i);
+ DRD_(bm_clear_load)(bm1, i, i + MAX(4, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_load_8)(bm1, i);
+ DRD_(bm_clear_load)(bm1, i, i + MAX(8, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+
+ DRD_(bm_access_range_store)(bm1, i, j);
+ DRD_(bm_clear_store)(bm1, i, j);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_store_1)(bm1, i);
+ DRD_(bm_clear_store)(bm1, i, i + MAX(1, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_store_2)(bm1, i);
+ DRD_(bm_clear_store)(bm1, i, i + MAX(2, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_store_4)(bm1, i);
+ DRD_(bm_clear_store)(bm1, i, i + MAX(4, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_store_8)(bm1, i);
+ DRD_(bm_clear_store)(bm1, i, i + MAX(8, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+
+ DRD_(bm_access_range_load)(bm1, i, j);
+ DRD_(bm_access_range_store)(bm1, i, j);
+ DRD_(bm_clear)(bm1, i, j);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_load_1)(bm1, i);
+ DRD_(bm_access_store_1)(bm1, i);
+ DRD_(bm_clear)(bm1, i, i + MAX(1, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_load_2)(bm1, i);
+ DRD_(bm_access_store_2)(bm1, i);
+ DRD_(bm_clear)(bm1, i, i + MAX(2, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_load_4)(bm1, i);
+ DRD_(bm_access_store_4)(bm1, i);
+ DRD_(bm_clear)(bm1, i, i + MAX(4, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_access_load_8)(bm1, i);
+ DRD_(bm_access_store_8)(bm1, i);
+ DRD_(bm_clear)(bm1, i, i + MAX(8, ADDR_GRANULARITY));
+ assert(bm_equal_print_diffs(bm1, bm2));
+ }
+ }
+ DRD_(bm_access_range_load)(bm1, 0, make_address(2, 0) + 2 * BITS_PER_UWORD);
+ DRD_(bm_access_range_store)(bm1, 0, make_address(2, 0) + 2 * BITS_PER_UWORD);
+ DRD_(bm_access_range_load)(bm2, 0, make_address(2, 0) + 2 * BITS_PER_UWORD);
+ DRD_(bm_access_range_store)(bm2, 0, make_address(2, 0) + 2 * BITS_PER_UWORD);
+ for (i = make_address(1, 0) - 2 * BITS_PER_UWORD;
+ i < make_address(1, 0) + 2 * BITS_PER_UWORD;
+ i += outer_loop_step)
+ {
+ for (j = i + 1; j < ub; j += inner_loop_step)
+ {
+ DRD_(bm_clear_load)(bm1, i, j);
+ DRD_(bm_access_range_load)(bm1, i, j);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_clear_load)(bm1, i, i+1);
+ DRD_(bm_access_load_1)(bm1, i);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_clear_load)(bm1, i, i+2);
+ DRD_(bm_access_load_2)(bm1, i);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_clear_load)(bm1, i, i+4);
+ DRD_(bm_access_load_4)(bm1, i);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_clear_load)(bm1, i, i+8);
+ DRD_(bm_access_load_8)(bm1, i);
+ assert(bm_equal_print_diffs(bm1, bm2));
+
+ DRD_(bm_clear_store)(bm1, i, j);
+ DRD_(bm_access_range_store)(bm1, i, j);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_clear_store)(bm1, i, i+1);
+ DRD_(bm_access_store_1)(bm1, i);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_clear_store)(bm1, i, i+2);
+ DRD_(bm_access_store_2)(bm1, i);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_clear_store)(bm1, i, i+4);
+ DRD_(bm_access_store_4)(bm1, i);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ DRD_(bm_clear_store)(bm1, i, i+8);
+ DRD_(bm_access_store_8)(bm1, i);
+ assert(bm_equal_print_diffs(bm1, bm2));
+
+ DRD_(bm_clear)(bm1, i, j);
+ DRD_(bm_access_range_load)(bm1, i, j);
+ DRD_(bm_access_range_store)(bm1, i, j);
+ assert(bm_equal_print_diffs(bm1, bm2));
+ }
+ }
+ DRD_(bm_delete)(bm2);
+ DRD_(bm_delete)(bm1);
+}
+
+int main(int argc, char** argv)
+{
+ int outer_loop_step = ADDR_GRANULARITY;
+ int inner_loop_step = ADDR_GRANULARITY;
+ int optchar;
+
+ while ((optchar = getopt(argc, argv, "s:t:q")) != EOF)
+ {
+ switch (optchar)
+ {
+ case 's':
+ outer_loop_step = atoi(optarg);
+ break;
+ case 't':
+ inner_loop_step = atoi(optarg);
+ break;
+ case 'q':
+ s_verbose = 0;
+ break;
+ default:
+ fprintf(stderr,
+ "Usage: %s [-s<outer_loop_step>] [-t<inner_loop_step>] [-q].\n",
+ argv[0]);
+ break;
+ }
+ }
+
+ fprintf(stderr, "Start of DRD BM unit test.\n");
+
+ bm_test1();
+ bm_test2();
+ bm_test3(outer_loop_step, inner_loop_step);
+
+ fprintf(stderr, "End of DRD BM unit test.\n");
+
+ return 0;
+}
Property changes on: branches/DRDDEV/drd/tests/unit_bitmap.c
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: branches/DRDDEV/drd/tests/unit_bitmap.stderr.exp (from rev 10245, branches/DRDDEV/drd/tests/drd_bitmap_test.stderr.exp)
===================================================================
--- branches/DRDDEV/drd/tests/unit_bitmap.stderr.exp (rev 0)
+++ branches/DRDDEV/drd/tests/unit_bitmap.stderr.exp 2009-06-05 18:09:48 UTC (rev 10254)
@@ -0,0 +1,2 @@
+Start of DRD BM unit test.
+End of DRD BM unit test.
Property changes on: branches/DRDDEV/drd/tests/unit_bitmap.stderr.exp
___________________________________________________________________
Name: svn:mergeinfo
+
Copied: branches/DRDDEV/drd/tests/unit_bitmap.vgtest (from rev 10245, branches/DRDDEV/drd/tests/drd_bitmap_test.vgtest)
===================================================================
--- branches/DRDDEV/drd/tests/unit_bitmap.vgtest (rev 0)
+++ branches/DRDDEV/drd/tests/unit_bitmap.vgtest 2009-06-05 18:09:48 UTC (rev 10254)
@@ -0,0 +1,3 @@
+prog: unit_bitmap
+args: -s 93 -t 97 -q
+vgopts: -q --tool=memcheck --leak-check=full --show-reachable=yes
Property changes on: branches/DRDDEV/drd/tests/unit_bitmap.vgtest
___________________________________________________________________
Name: svn:mergeinfo
+
Added: branches/DRDDEV/drd/tests/unit_vc.c
===================================================================
--- branches/DRDDEV/drd/tests/unit_vc.c (rev 0)
+++ branches/DRDDEV/drd/tests/unit_vc.c 2009-06-05 18:09:48 UTC (rev 10254)
@@ -0,0 +1,110 @@
+/** @brief Unit-test for DRD's vector clock implementation. */
+
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "drd/drd_vc.c"
+
+
+/* Replacements for Valgrind core functionality. */
+
+void* VG_(malloc)(HChar* cc, SizeT nbytes)
+{ return malloc(nbytes); }
+void* VG_(realloc)(HChar* cc, void* p, SizeT size)
+{ return realloc(p, size); }
+void VG_(free)(void* p)
+{ return free(p); }
+void VG_(assert_fail)(Bool isCore, const Char* assertion, const Char* file,
+ Int line, const Char* function, const HChar* format,
+ ...)
+{
+ fprintf(stderr,
+ "%s:%u: %s%sAssertion `%s' failed.\n",
+ file,
+ line,
+ function ? (char*)function : "",
+ function ? ": " : "",
+ assertion);
+ fflush(stdout);
+ fflush(stderr);
+ 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; }
+UInt VG_(snprintf)(Char* buf, Int size, const HChar *format, ...)
+{ UInt ret; va_list vargs; va_start(vargs, format); ret = vsnprintf(buf, size, format, vargs); va_end(vargs); return ret; }
+SizeT VG_(strlen)(const Char* str) { return strlen(str); }
+UInt VG_(message)(VgMsgKind kind, const HChar* format, ...)
+{ UInt ret; va_list vargs; va_start(vargs, format); ret = vprintf(format, vargs); va_end(vargs); printf("\n"); return ret; }
+Bool DRD_(is_suppressed)(const Addr a1, const Addr a2)
+{ assert(0); }
+
+
+/* Actual unit test */
+
+static void vc_unittest(void)
+{
+ int i;
+ char *str;
+ VectorClock vc1;
+ VCElem vc1elem[] = { { 3, 7 }, { 5, 8 }, };
+ VectorClock vc2;
+ VCElem vc2elem[] = { { 1, 4 }, { 3, 9 }, };
+ VectorClock vc3;
+ VCElem vc4elem[] = { { 1, 3 }, { 2, 1 }, };
+ VectorClock vc4;
+ VCElem vc5elem[] = { { 1, 4 }, };
+ VectorClock vc5;
+
+ DRD_(vc_init)(&vc1, vc1elem, sizeof(vc1elem)/sizeof(vc1elem[0]));
+ DRD_(vc_init)(&vc2, vc2elem, sizeof(vc2elem)/sizeof(vc2elem[0]));
+ DRD_(vc_init)(&vc3, 0, 0);
+ DRD_(vc_init)(&vc4, vc4elem, sizeof(vc4elem)/sizeof(vc4elem[0]));
+ DRD_(vc_init)(&vc5, vc5elem, sizeof(vc5elem)/sizeof(vc5elem[0]));
+
+ DRD_(vc_combine)(&vc3, &vc1);
+ DRD_(vc_combine)(&vc3, &vc2);
+
+ fprintf(stderr, "vc1: %s", (str = DRD_(vc_aprint)(&vc1)));
+ free(str);
+ fprintf(stderr, "\nvc2: %s", (str = DRD_(vc_aprint)(&vc2)));
+ free(str);
+ fprintf(stderr, "\nvc3: %s", (str = DRD_(vc_aprint)(&vc3)));
+ free(str);
+ fprintf(stderr, "\n");
+ fprintf(stderr, "vc_lte(vc1, vc2) = %d, vc_lte(vc1, vc3) = %d,"
+ " vc_lte(vc2, vc3) = %d\nvc_lte(",
+ DRD_(vc_lte)(&vc1, &vc2), DRD_(vc_lte)(&vc1, &vc3),
+ DRD_(vc_lte)(&vc2, &vc3));
+ fprintf(stderr, "%s", (str = DRD_(vc_aprint)(&vc4)));
+ free(str);
+ fprintf(stderr, ", ");
+ fprintf(stderr, "%s", (str = DRD_(vc_aprint)(&vc5)));
+ free(str);
+ fprintf(stderr, ") = %d sw %d\n",
+ DRD_(vc_lte)(&vc4, &vc5), DRD_(vc_lte)(&vc5, &vc4));
+
+ for (i = 0; i < 64; i++)
+ DRD_(vc_reserve)(&vc1, i);
+ for (i = 64; i > 0; i--)
+ DRD_(vc_reserve)(&vc1, i);
+
+ DRD_(vc_cleanup)(&vc1);
+ DRD_(vc_cleanup)(&vc2);
+ DRD_(vc_cleanup)(&vc3);
+}
+
+int main(int argc, char** argv)
+{
+ vc_unittest();
+ return 0;
+}
|