From 14ef940425c921b8881810756a0ef8aa952a77fb Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Sun, 3 Jul 2016 01:19:14 -0700 Subject: 3086 More tests, another bugfix. I still don't *really* understand why it works, though.. The new tests aren't really done yet. No assertions, lots of debug info. Just translated from sandboxes. deep_copy_stress_test_2 requires the bugfix. --- 073deep_copy.cc | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 93 insertions(+), 1 deletion(-) (limited to '073deep_copy.cc') diff --git a/073deep_copy.cc b/073deep_copy.cc index 9fb96483..5ddb29fd 100644 --- a/073deep_copy.cc +++ b/073deep_copy.cc @@ -185,7 +185,7 @@ int deep_copy_address(const reagent& canonized_in, map& addresses_copi return get(addresses_copied, in_address); reagent/*copy*/ payload = canonized_in; payload.properties.push_back(pair("lookup", NULL)); - int out = allocate(size_of(payload)); + int out = allocate(payload_size(payload)); put(addresses_copied, in_address, out); reagent/*copy*/ payload_type = payload; canonize_type(payload_type); @@ -241,3 +241,95 @@ void deep_copy(const reagent& canonized_in, map& addresses_copied, con } } } + +//: moar tests, just because I can't believe it all works + +:(scenario deep_copy_stress_test_1) +container foo1 [ + p:address:number +] +container foo2 [ + p:address:foo1 +] +exclusive-container foo3 [ + p:address:foo1 + q:address:foo2 +] +def main [ + local-scope + x:address:number <- new number:type # 1003 -> 1014 1015 + *x <- copy 34 + a:address:foo1 <- new foo1:type # 1004 -> 1016 1017 + *a <- merge x # refcount 1014: 1 -> 2 + b:address:foo2 <- new foo2:type # 1005 -> 1018 1019 + *b <- merge a # refcount 1016: 1 -> 2 + c:foo3 <- merge 1/q, b # 1006 1007; refcount 1018: 1 -> 2 + d:foo3 <- deep-copy c # 1008 1009 + # temporary: 1020 1021 + # c:foo3: 1/tag@1006 1018@1007 + # alloc: 1022 1023 + # foo2: refcount@1018 1016@1019 + # alloc: 1024 1025 + # foo1: refcount@1016 1014@1017 + # alloc: 1026 1027 + # number: 34@1015 + # write: 34@1027 + # write: 1026@1025 + # write: 1024@1023 + # write 1/tag@1008 1022@1009 + e:address:foo2, z:boolean <- maybe-convert d, q:variant # write: 1022@1010 + f:address:foo1 <- get *e, p:offset # write: 1024@1012 + g:address:number <- get *f, p:offset # write: 1026@1013 + 1:number/raw <- copy *g # 1 -> 34 +] ++mem: storing 34 in location 1 + +:(scenario deep_copy_stress_test_2) +container foo1 [ + p:address:number +] +container foo2 [ + p:address:foo1 +] +exclusive-container foo3 [ + p:address:foo1 + q:address:foo2 +] +container foo4 [ + p:number + q:address:foo3 +] +def main [ + local-scope + x:address:number <- new number:type # 1003 -> 1016 1017 + *x <- copy 34 + a:address:foo1 <- new foo1:type # 1004 -> 1018 1019 + *a <- merge x # refcount 1016: 1 -> 2 + b:address:foo2 <- new foo2:type # 1005 -> 1020 1021 + *b <- merge a # refcount 1018: 1 -> 2 + c:address:foo3 <- new foo3:type # 1006 -> 1022 1023 1024 + *c <- merge 1/q, b # refcount 1020: 1 -> 2 + d:foo4 <- merge 35, c # 1007 1008; refcount 1022: 1 -> 2 + e:foo4 <- deep-copy d # 1009 1010 + # temporary: 1025 1026 + # foo4: 35@1007 1022@1008 + # alloc: 1027 1028 + # foo3: 1/tag@1023 1020@1024 + # alloc: 1029 1030 <<--- wrong + # foo2: 1018@1021 + # alloc: 1031 1032 + # foo1: 1016@1019 + # alloc: 1033 1034 + # number: 34@1017 + # write 34@1034 + # write 1033@1032 (refcount 1033: 0 -> 1) + # write 1031@1030 (refcount 1031: 0 -> 1) + # write should be 1/tag@1029 1029@1028 (refcount 1030: 0 -> 1) + # write is 1@1028 1029@1029 + f:address:foo3 <- get e, q:offset # write: 1027@1011 + g:address:foo2, z:boolean <- maybe-convert *f, q:variant # write: 1030@1012 + h:address:foo1 <- get *g, p:offset # write: 1@1014 + y:address:number <- get *h, p:offset # write: 0@1015 + 1:number/raw <- copy *y # write: 0@1 +] ++mem: storing 34 in location 1 -- cgit 1.4.1-2-gfad0