1 /** @brief Unit-test for DRD's vector clock implementation. */
8 #include "drd/drd_vc.c"
11 /* Replacements for Valgrind core functionality. */
13 void* VG_(malloc
)(const HChar
* cc
, SizeT nbytes
)
14 { return malloc(nbytes
); }
15 void* VG_(realloc
)(const HChar
* cc
, void* p
, SizeT size
)
16 { return realloc(p
, size
); }
17 void VG_(free
)(void* p
)
19 void VG_(assert_fail
)(Bool isCore
, const HChar
* assertion
, const HChar
* file
,
20 Int line
, const HChar
* function
, const HChar
* format
,
24 "%s:%u: %s%sAssertion `%s' failed.\n",
27 function
? (char*)function
: "",
35 void* VG_(memset
)(void *s
, Int c
, SizeT sz
)
36 { return memset(s
, c
, sz
); }
37 void* VG_(memcpy
)(void *d
, const void *s
, SizeT sz
)
38 { return memcpy(d
, s
, sz
); }
39 Int
VG_(memcmp
)(const void* s1
, const void* s2
, SizeT n
)
40 { return memcmp(s1
, s2
, n
); }
41 UInt
VG_(printf
)(const HChar
*format
, ...)
42 { UInt ret
; va_list vargs
; va_start(vargs
, format
); ret
= vprintf(format
, vargs
); va_end(vargs
); return ret
; }
43 UInt
VG_(snprintf
)(HChar
* buf
, Int size
, const HChar
*format
, ...)
44 { UInt ret
; va_list vargs
; va_start(vargs
, format
); ret
= vsnprintf(buf
, size
, format
, vargs
); va_end(vargs
); return ret
; }
45 SizeT
VG_(strlen
)(const HChar
* str
) { return strlen(str
); }
46 UInt
VG_(message
)(VgMsgKind kind
, const HChar
* format
, ...)
47 { UInt ret
; va_list vargs
; va_start(vargs
, format
); ret
= vprintf(format
, vargs
); va_end(vargs
); printf("\n"); return ret
; }
48 Bool
DRD_(is_suppressed
)(const Addr a1
, const Addr a2
)
52 /* Actual unit test */
54 static void vc_unittest(void)
59 VCElem vc1elem
[] = { { 3, 7 }, { 5, 8 }, };
61 VCElem vc2elem
[] = { { 1, 4 }, { 3, 9 }, };
63 VCElem vc4elem
[] = { { 1, 3 }, { 2, 1 }, };
65 VCElem vc5elem
[] = { { 1, 4 }, };
68 DRD_(vc_init
)(&vc1
, vc1elem
, sizeof(vc1elem
)/sizeof(vc1elem
[0]));
69 DRD_(vc_init
)(&vc2
, vc2elem
, sizeof(vc2elem
)/sizeof(vc2elem
[0]));
70 DRD_(vc_init
)(&vc3
, 0, 0);
71 DRD_(vc_init
)(&vc4
, vc4elem
, sizeof(vc4elem
)/sizeof(vc4elem
[0]));
72 DRD_(vc_init
)(&vc5
, vc5elem
, sizeof(vc5elem
)/sizeof(vc5elem
[0]));
74 DRD_(vc_combine
)(&vc3
, &vc1
);
75 DRD_(vc_combine
)(&vc3
, &vc2
);
77 fprintf(stderr
, "vc1: %s", (str
= DRD_(vc_aprint
)(&vc1
)));
79 fprintf(stderr
, "\nvc2: %s", (str
= DRD_(vc_aprint
)(&vc2
)));
81 fprintf(stderr
, "\nvc3: %s", (str
= DRD_(vc_aprint
)(&vc3
)));
83 fprintf(stderr
, "\n");
84 fprintf(stderr
, "vc_lte(vc1, vc2) = %d, vc_lte(vc1, vc3) = %d,"
85 " vc_lte(vc2, vc3) = %d\nvc_lte(",
86 DRD_(vc_lte
)(&vc1
, &vc2
), DRD_(vc_lte
)(&vc1
, &vc3
),
87 DRD_(vc_lte
)(&vc2
, &vc3
));
88 fprintf(stderr
, "%s", (str
= DRD_(vc_aprint
)(&vc4
)));
90 fprintf(stderr
, ", ");
91 fprintf(stderr
, "%s", (str
= DRD_(vc_aprint
)(&vc5
)));
93 fprintf(stderr
, ") = %d sw %d\n",
94 DRD_(vc_lte
)(&vc4
, &vc5
), DRD_(vc_lte
)(&vc5
, &vc4
));
96 for (i
= 0; i
< 64; i
++)
97 DRD_(vc_reserve
)(&vc1
, i
);
98 for (i
= 64; i
> 0; i
--)
99 DRD_(vc_reserve
)(&vc1
, i
);
101 DRD_(vc_cleanup
)(&vc1
);
102 DRD_(vc_cleanup
)(&vc2
);
103 DRD_(vc_cleanup
)(&vc3
);
106 int main(int argc
, char** argv
)