From 2519c914a5e6553dba3a8032cee38de0ca08a77b Mon Sep 17 00:00:00 2001 From: Jacqueline Deans Date: Fri, 7 Oct 2022 17:00:09 -0500 Subject: [PATCH] Pair checkpointing fix (#1356) * Fix pair checkpointing bug, add tests * Documentation update --- .../STL-capabilities.md | 11 +--- include/trick/checkpoint_pair.hh | 39 ++++++------ test/SIM_stls/models/STLCheckpoint.cpp | 26 ++++---- .../MemoryManager/test/MM_read_checkpoint.cc | 2 +- .../MemoryManager/test/MM_stl_checkpoint.cc | 59 +++++++++--------- .../MemoryManager/test/MM_stl_restore.cc | 61 +++++++++++++------ .../MemoryManager/test/MM_stl_testbed.hh | 1 - 7 files changed, 106 insertions(+), 93 deletions(-) diff --git a/docs/documentation/simulation_capabilities/STL-capabilities.md b/docs/documentation/simulation_capabilities/STL-capabilities.md index 48f902b0..d8737a93 100644 --- a/docs/documentation/simulation_capabilities/STL-capabilities.md +++ b/docs/documentation/simulation_capabilities/STL-capabilities.md @@ -46,7 +46,7 @@ If it is in a class that is nested in a `sim_object`, it will be registered with You can nest an arbitrary amount of STLs, they will all be checkpointed as long as the base is a member of a class that is registered with the memory manager. There -are a some [**limitations**](#limitations) and exceptions due to [**bugs**](#known_bugs) at the moment (but hopefully not forever!) +are a some known [**limitations**](#limitations). ``` class AnyClass { @@ -109,14 +109,5 @@ memorymanager->declare_var_extern(&my_vector, "std::vector my_vector_alloca ``` - - -## Known bugs - -The types in an std::pair cannot be sequence STL types (vector, queue, stack, etc). -``` - // This will fail to checkpoint - std::pair> -``` [Continue to Threads](Threads) diff --git a/include/trick/checkpoint_pair.hh b/include/trick/checkpoint_pair.hh index badaf33a..c4fc014d 100644 --- a/include/trick/checkpoint_pair.hh +++ b/include/trick/checkpoint_pair.hh @@ -82,7 +82,6 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name int status ; std::string temp_str; - FIRST * first = nullptr ; std::string * second = nullptr ; std::replace_if(object_name.begin(), object_name.end(), static_cast(std::ispunct), '_'); @@ -109,9 +108,10 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name temp_str = var_declare.str(); second = (std::string *)TMM_declare_var_s(temp_str.c_str()) ; if ( second ) { + *second = std::string("inner"); temp_str = std::string(object_name + "_" + var_name + "_second"); TMM_add_checkpoint_alloc_dependency(temp_str.c_str()) ; - checkpoint_stl( in_pair.second , object_name + "_" + var_name , "second" ) ; + checkpoint_stl( in_pair.second , object_name + "_" + var_name , "second_inner" ) ; } } @@ -136,9 +136,10 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name << object_name << "_" << var_name << "_first[1]" ; temp_str = var_declare.str() ; first = (std::string *)TMM_declare_var_s(temp_str.c_str()) ; + *first = std::string("inner"); temp_str = std::string(object_name + "_" + var_name + "_first"); TMM_add_checkpoint_alloc_dependency(temp_str.c_str()) ; - checkpoint_stl( in_pair.first , object_name + "_" + var_name , "first" ) ; + checkpoint_stl( in_pair.first , object_name + "_" + var_name , "first_inner" ) ; var_declare.str("") ; var_declare.clear() ; @@ -178,9 +179,10 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name << object_name << "_" << var_name << "_first[1]" ; temp_str = var_declare.str(); first = (std::string *)TMM_declare_var_s(temp_str.c_str()) ; + *first = std::string("inner"); temp_str = std::string(object_name + "_" + var_name + "_first"); TMM_add_checkpoint_alloc_dependency(temp_str.c_str()) ; - checkpoint_stl( in_pair.first , object_name + "_" + var_name , "first" ) ; + checkpoint_stl( in_pair.first , object_name + "_" + var_name , "first_inner" ) ; var_declare.str("") ; var_declare.clear() ; @@ -188,9 +190,10 @@ int checkpoint_stl(std::pair & in_pair , std::string object_name << object_name << "_" << var_name << "_second[1]" ; temp_str = var_declare.str(); second = (std::string *)TMM_declare_var_s(temp_str.c_str()) ; + *second = std::string("inner"); temp_str = std::string(object_name + "_" + var_name + "_second"); TMM_add_checkpoint_alloc_dependency(temp_str.c_str()) ; - checkpoint_stl( in_pair.second , object_name + "_" + var_name , "second" ) ; + checkpoint_stl( in_pair.second , object_name + "_" + var_name , "second_inner" ) ; return 0 ; } @@ -256,7 +259,7 @@ int restore_stl(std::pair & in_pair , std::string object_name , REF2 * second_ref ; FIRST * first ; - std::string * second ; + std::string * second_inner ; std::string temp_str; @@ -269,10 +272,10 @@ int restore_stl(std::pair & in_pair , std::string object_name , if ( first_ref != NULL && second_ref != NULL ) { first = (FIRST *)first_ref->address ; - second = (std::string *)second_ref->address ; - + second_inner = (std::string *)second_ref->address ; + temp_str = object_name + "_" + var_name + "_second"; in_pair.first = first[0] ; - restore_stl( in_pair.second , object_name + "_" + var_name , "second" ) ; + restore_stl( in_pair.second , temp_str , *second_inner ) ; delete_stl( in_pair , object_name , var_name ) ; } @@ -288,7 +291,7 @@ int restore_stl(std::pair & in_pair , std::string object_name , REF2 * first_ref ; REF2 * second_ref ; - std::string * first ; + std::string * first_inner ; SECOND * second ; std::string temp_str; @@ -300,10 +303,10 @@ int restore_stl(std::pair & in_pair , std::string object_name , second_ref = ref_attributes((char *)temp_str.c_str()) ; if ( first_ref != NULL && second_ref != NULL ) { - first = (std::string *)first_ref->address ; + first_inner = (std::string *)first_ref->address ; second = (SECOND *)second_ref->address ; - restore_stl( in_pair.first , object_name + "_" + var_name , "first" ) ; + restore_stl( in_pair.first , object_name + "_" + var_name + "_first", *first_inner ) ; in_pair.second = second[0] ; delete_stl( in_pair , object_name , var_name ) ; @@ -319,8 +322,8 @@ int restore_stl(std::pair & in_pair , std::string object_name , REF2 * first_ref ; REF2 * second_ref ; - std::string * first ; - std::string * second ; + std::string * first_inner ; + std::string * second_inner ; std::string temp_str; @@ -332,11 +335,11 @@ int restore_stl(std::pair & in_pair , std::string object_name , second_ref = ref_attributes((char *)temp_str.c_str()) ; if ( first_ref != NULL && second_ref != NULL ) { - first = (std::string *)first_ref->address ; - second = (std::string *)second_ref->address ; + first_inner = (std::string *)first_ref->address ; + second_inner = (std::string *)second_ref->address ; - restore_stl( in_pair.first , object_name + "_" + var_name , "first" ) ; - restore_stl( in_pair.second , object_name + "_" + var_name , "second" ) ; + restore_stl( in_pair.first , object_name + "_" + var_name + "_first" , *first_inner ) ; + restore_stl( in_pair.second , object_name + "_" + var_name + "_second", *second_inner ) ; delete_stl( in_pair , object_name , var_name ) ; } diff --git a/test/SIM_stls/models/STLCheckpoint.cpp b/test/SIM_stls/models/STLCheckpoint.cpp index 82fd4f06..1e9839dc 100644 --- a/test/SIM_stls/models/STLCheckpoint.cpp +++ b/test/SIM_stls/models/STLCheckpoint.cpp @@ -727,23 +727,23 @@ int STLCheckpoint::test() { pair_pair_pair_copy.second.second = 54 ; TRICK_EXPECT_EQ(pair_pair_pair_copy, pair_pair_pair, test_suite, "pair_pair_pair"); - // TODO: fix this case // Check all the int/vec combo pairs together, for laziness - // TRICK_EXPECT_EQ(int_vec_pair.first, 5, test_suite, "int_vec_pair.first"); - // TRICK_EXPECT_EQ(vec_int_pair.second, 5, test_suite, "vec_int_pair.second"); + TRICK_EXPECT_EQ(int_vec_pair.first, 5, test_suite, "int_vec_pair.first"); + TRICK_EXPECT_EQ(vec_int_pair.second, 5, test_suite, "vec_int_pair.second"); - // TRICK_EXPECT_EQ(int_vec_pair.second.size(), 4, test_suite, "int_vec_pair.second.size"); - // TRICK_EXPECT_EQ(vec_int_pair.first.size(), 4, test_suite, "vec_int_pair.first.size"); - // TRICK_EXPECT_EQ(vec_vec_pair.first.size(), 4, test_suite, "vec_vec_pair.first.size"); - // TRICK_EXPECT_EQ(vec_vec_pair.second.size(), 4, test_suite, "vec_vec_pair.second.size"); + TRICK_EXPECT_EQ(int_vec_pair.second.size(), 4, test_suite, "int_vec_pair.second.size"); + TRICK_EXPECT_EQ(vec_int_pair.first.size(), 4, test_suite, "vec_int_pair.first.size"); + TRICK_EXPECT_EQ(vec_vec_pair.first.size(), 4, test_suite, "vec_vec_pair.first.size"); + TRICK_EXPECT_EQ(vec_vec_pair.second.size(), 4, test_suite, "vec_vec_pair.second.size"); - // for (int i = 0; i < int_vec_pair.second.size(); i++) { - // TRICK_EXPECT_EQ(int_vec_pair.second[i], (i+1)*5, test_suite, "int_vec_pair.second elems"); - // TRICK_EXPECT_EQ(vec_int_pair.first[i], (i+1)*5, test_suite, "vec_int_pair.first elems"); - // TRICK_EXPECT_EQ(vec_vec_pair.first[i], (i+1)*5, test_suite, "vec_vec_pair.first elems"); - // TRICK_EXPECT_EQ(vec_vec_pair.second[i], (i+1)*5, test_suite, "vec_vec_pair.second elems"); + for (int i = 0; i < int_vec_pair.second.size(); i++) { + TRICK_EXPECT_EQ(int_vec_pair.second[i], (i+1)*5, test_suite, "int_vec_pair.second elems"); + TRICK_EXPECT_EQ(vec_int_pair.first[i], (i+1)*5, test_suite, "vec_int_pair.first elems"); + TRICK_EXPECT_EQ(vec_vec_pair.first[i], (i+1)*5, test_suite, "vec_vec_pair.first elems"); + TRICK_EXPECT_EQ(vec_vec_pair.second[i], (i+1)*5, test_suite, "vec_vec_pair.second elems"); + + } - // } TRICK_EXPECT_EQ(vec_user_simple.size(), 10, test_suite, "vec_user_simple") for (int i = 0; i < 10; i++) { diff --git a/trick_source/sim_services/MemoryManager/test/MM_read_checkpoint.cc b/trick_source/sim_services/MemoryManager/test/MM_read_checkpoint.cc index 8d1a0619..df30185f 100644 --- a/trick_source/sim_services/MemoryManager/test/MM_read_checkpoint.cc +++ b/trick_source/sim_services/MemoryManager/test/MM_read_checkpoint.cc @@ -332,4 +332,4 @@ TEST_F(MM_read_checkpoint, encapsulated_stl_test_stl_disabled) { // c should not be restored ASSERT_EQ(my_foo_ptr->c.size(), 0); -} +} \ No newline at end of file diff --git a/trick_source/sim_services/MemoryManager/test/MM_stl_checkpoint.cc b/trick_source/sim_services/MemoryManager/test/MM_stl_checkpoint.cc index a7f1f012..871c246b 100644 --- a/trick_source/sim_services/MemoryManager/test/MM_stl_checkpoint.cc +++ b/trick_source/sim_services/MemoryManager/test/MM_stl_checkpoint.cc @@ -63,7 +63,7 @@ void validate_temp_sequence (Trick::MemoryManager * memmgr, std::string object_n } -void validate_links (Trick::MemoryManager * memmgr, std::string object_name, std::string top_level_name, std::vector lengths) { +void validate_links_sequences (Trick::MemoryManager * memmgr, std::string object_name, std::string top_level_name, std::vector lengths) { std::string temp_name = object_name + "_" + top_level_name; ASSERT_TRUE(memmgr->var_exists(temp_name) == 1); @@ -98,6 +98,16 @@ void validate_links_pairs (Trick::MemoryManager * memmgr, std::string object_nam } } +void validate_link_from_pair (Trick::MemoryManager * memmgr, std::string object_name, std::string top_level_name) { + std::string temp_name = object_name + "_" + top_level_name; + ASSERT_TRUE(memmgr->var_exists(temp_name) == 1); + + REF2 * link_ref = memmgr->ref_attributes(temp_name.c_str()); + std::string * link_name = (std::string *) link_ref->address; + EXPECT_EQ(link_name[0], "inner"); +} + + template void validate_temp_set (Trick::MemoryManager * memmgr, std::string object_name, std::string var_name, std::set expected_data) { std::string temp_name = object_name + "_" + var_name; @@ -241,7 +251,7 @@ TEST_F(MM_stl_checkpoint, i_s_vec ) { validate_temp_sequence(memmgr, std::string("my_alloc"), var_name, test_data[i]); } - validate_links(memmgr, std::string("my_alloc"), std::string("i_s_vec"), std::vector(10, 10)); + validate_links_sequences(memmgr, std::string("my_alloc"), std::string("i_s_vec"), std::vector(10, 10)); } TEST_F(MM_stl_checkpoint, string_vec ) { @@ -313,7 +323,7 @@ TEST_F(MM_stl_checkpoint, i_i_pair ) { validate_temp_pair(memmgr, std::string("my_alloc"), vec_attr->name, std::pair(test_data[0], test_data[1])); } -TEST_F(MM_stl_checkpoint, DISABLED_i_s_pair ) { +TEST_F(MM_stl_checkpoint, i_s_pair ) { // ARRANGE // Make a testbed STLTestbed * testbed = (STLTestbed *) memmgr->declare_var("STLTestbed my_alloc"); @@ -333,13 +343,11 @@ TEST_F(MM_stl_checkpoint, DISABLED_i_s_pair ) { (vec_attr->checkpoint_stl)((void *) &testbed->i_s_pair, "my_alloc", vec_attr->name) ; // ASSERT - validate_links(memmgr, std::string("my_alloc"), std::string("i_s_pair_second"), std::vector(1, test_val.size())); validate_temp_sequence(memmgr, std::string("my_alloc"), std::string("i_s_pair_second_inner"), test_val); - // Oh boy this one actually doesn't work!!!!! - // TODO: fix i_s_pair + validate_link_from_pair(memmgr, std::string("my_alloc"), std::string("i_s_pair_second")); } -TEST_F(MM_stl_checkpoint, DISABLED_s_i_pair ) { +TEST_F(MM_stl_checkpoint, s_i_pair ) { // ARRANGE // Make a testbed STLTestbed * testbed = (STLTestbed *) memmgr->declare_var("STLTestbed my_alloc"); @@ -360,15 +368,12 @@ TEST_F(MM_stl_checkpoint, DISABLED_s_i_pair ) { // ASSERT validate_temp_sequence(memmgr, std::string("my_alloc"), std::string("s_i_pair_first_inner"), test_key); - - // Oh boy this one actually doesn't work!!!!! - // Same as the other one - // TODO: fix s_i_pair + validate_link_from_pair(memmgr, std::string("my_alloc"), std::string("s_i_pair_first")); } -TEST_F(MM_stl_checkpoint, DISABLED_i_v_pair ) { +TEST_F(MM_stl_checkpoint, i_v_pair ) { // ARRANGE // Make a testbed STLTestbed * testbed = (STLTestbed *) memmgr->declare_var("STLTestbed my_alloc"); @@ -388,10 +393,8 @@ TEST_F(MM_stl_checkpoint, DISABLED_i_v_pair ) { (vec_attr->checkpoint_stl)((void *) &testbed->i_v_pair, "my_alloc", vec_attr->name) ; // ASSERT - validate_temp_sequence(memmgr, std::string("my_alloc"), std::string("i_v_pair_second"), test_val); - - // Oh boy this one actually doesn't work!!!!! - // TODO: fix i_s_pair + validate_temp_sequence(memmgr, std::string("my_alloc"), std::string("i_v_pair_second_inner"), test_val); + validate_link_from_pair(memmgr, std::string("my_alloc"), std::string("i_v_pair_second")); } @@ -414,7 +417,8 @@ TEST_F(MM_stl_checkpoint, pair_pair ) { // ASSERT validate_single(memmgr, std::string("my_alloc"), std::string("pair_pair_second"), 3); - validate_temp_pair(memmgr, std::string("my_alloc"), std::string("pair_pair_first"), std::pair(1, 2)); + validate_temp_pair(memmgr, std::string("my_alloc"), std::string("pair_pair_first_inner"), std::pair(1, 2)); + validate_link_from_pair(memmgr, std::string("my_alloc"), std::string("pair_pair_first")); } @@ -487,7 +491,7 @@ TEST_F(MM_stl_checkpoint, i_s_map ) { sorted_lengths.push_back(expected_data.size()); } - validate_links(memmgr, std::string("my_alloc"), std::string("i_s_map_data"), sorted_lengths); + validate_links_sequences(memmgr, std::string("my_alloc"), std::string("i_s_map_data"), sorted_lengths); } @@ -529,7 +533,7 @@ TEST_F(MM_stl_checkpoint, s_i_map ) { values_in_the_right_order.push_back(it.second); lengths_in_the_right_order.push_back(it.first.size()); } - validate_links(memmgr, std::string("my_alloc"), std::string("s_i_map_keys"), lengths_in_the_right_order); + validate_links_sequences(memmgr, std::string("my_alloc"), std::string("s_i_map_keys"), lengths_in_the_right_order); validate_temp_sequence(memmgr, std::string("my_alloc"), std::string("s_i_map_data"), values_in_the_right_order); } @@ -572,7 +576,7 @@ TEST_F(MM_stl_checkpoint, s_s_map ) { } validate_links_pairs(memmgr, std::string("my_alloc"), std::string("s_s_map_keys"), test_map.size()); - validate_links(memmgr, std::string("my_alloc"), std::string("s_s_map_data"), data_lengths); + validate_links_sequences(memmgr, std::string("my_alloc"), std::string("s_s_map_data"), data_lengths); } @@ -658,7 +662,7 @@ TEST_F(MM_stl_checkpoint, nested_list_queue ) { data_index += list_sizes[i]; } - validate_links(memmgr, std::string("my_alloc"), std::string("nested_list_queue"), list_sizes); + validate_links_sequences(memmgr, std::string("my_alloc"), std::string("nested_list_queue"), list_sizes); } @@ -748,15 +752,10 @@ TEST_F(MM_stl_checkpoint, nested_list_stack ) { data_index += list_sizes[i]; } - validate_links(memmgr, std::string("my_alloc"), std::string("nested_list_stack"), std::vector(list_sizes.rbegin(), list_sizes.rend())); + validate_links_sequences(memmgr, std::string("my_alloc"), std::string("nested_list_stack"), std::vector(list_sizes.rbegin(), list_sizes.rend())); } - -// Sets TODO: No support for nested STLs in sets. -// These will fail to compile - - TEST_F(MM_stl_checkpoint, i_set ) { // ARRANGE // Make a testbed @@ -816,7 +815,7 @@ TEST_F(MM_stl_checkpoint, vector_set ) { validate_temp_sequence(memmgr, std::string("my_alloc"), var_name, vec); sizes_in_right_order.push_back(vec.size()); } - validate_links(memmgr, std::string("my_alloc"), std::string("vector_set"), sizes_in_right_order); + validate_links_sequences(memmgr, std::string("my_alloc"), std::string("vector_set"), sizes_in_right_order); // validate_temp_set(memmgr, std::string("my_alloc"), std::string("vector_set"), std::set (test_data.begin(), test_data.end())); } @@ -959,7 +958,7 @@ TEST_F(MM_stl_checkpoint, vector_multiset ) { validate_temp_sequence(memmgr, std::string("my_alloc"), var_name, vec); sizes_in_right_order.push_back(vec.size()); } - validate_links(memmgr, std::string("my_alloc"), std::string("vector_multiset"), sizes_in_right_order); + validate_links_sequences(memmgr, std::string("my_alloc"), std::string("vector_multiset"), sizes_in_right_order); } TEST_F(MM_stl_checkpoint, s_multiset ) { @@ -1138,7 +1137,7 @@ TEST_F(MM_stl_checkpoint, vec_array ) { validate_temp_sequence(memmgr, std::string("my_alloc"), var_name, std::vector(test_data.begin() + (i*10), test_data.begin() +((i+1)*10))); } - validate_links(memmgr, std::string("my_alloc"), std::string("vec_array"), std::vector(10, 10)); + validate_links_sequences(memmgr, std::string("my_alloc"), std::string("vec_array"), std::vector(10, 10)); } TEST_F(MM_stl_checkpoint, vec_user_defined ) { diff --git a/trick_source/sim_services/MemoryManager/test/MM_stl_restore.cc b/trick_source/sim_services/MemoryManager/test/MM_stl_restore.cc index 8d05d14f..059507dc 100644 --- a/trick_source/sim_services/MemoryManager/test/MM_stl_restore.cc +++ b/trick_source/sim_services/MemoryManager/test/MM_stl_restore.cc @@ -6,6 +6,12 @@ #include "MM_stl_testbed.hh" #include "MM_test.hh" +#include "trick/checkpoint_sequence_stl.hh" +#include "trick/checkpoint_map.hh" +#include "trick/checkpoint_stack.hh" +#include "trick/checkpoint_queue.hh" +#include "trick/checkpoint_pair.hh" + /* This tests the allocation of user-defined types using MemoryManager::declare_var(). */ @@ -201,7 +207,7 @@ TEST_F(MM_stl_restore, i_i_pair ) { EXPECT_EQ(memmgr->var_exists("my_alloc_i_i_pair_second"), 0); } -TEST_F(MM_stl_restore, DISABLED_i_s_pair ) { +TEST_F(MM_stl_restore, i_s_pair ) { // ARRANGE // make a testbed object STLTestbed * testbed = (STLTestbed *) memmgr->declare_var("STLTestbed my_alloc"); @@ -211,9 +217,11 @@ TEST_F(MM_stl_restore, DISABLED_i_s_pair ) { // Register the expected temporary variables with the memory manager double * first_data = (double *) memmgr->declare_var("double my_alloc_i_s_pair_first"); - bool * second_data = (bool *) memmgr->declare_var("bool my_alloc_i_s_pair_second[20]"); + std::string * second_link = (std::string *) memmgr->declare_var("std::string my_alloc_i_s_pair_second"); + bool * second_data = (bool *) memmgr->declare_var("bool my_alloc_i_s_pair_second_inner[20]"); *first_data = test_first; + *second_link = std::string("inner"); for (int i = 0; i < test_second.size(); i++) { second_data[i] = test_second[i]; } @@ -234,10 +242,10 @@ TEST_F(MM_stl_restore, DISABLED_i_s_pair ) { // Check that all the temporary variables have been deleted EXPECT_EQ(memmgr->var_exists("my_alloc_i_s_pair_first"), 0); - EXPECT_EQ(memmgr->var_exists("my_alloc_i_s_pair_second"), 0); + EXPECT_EQ(memmgr->var_exists("my_alloc_i_s_pair_second_inner"), 0); } -TEST_F(MM_stl_restore, DISABLED_s_i_pair ) { +TEST_F(MM_stl_restore, s_i_pair ) { // ARRANGE // make a testbed object STLTestbed * testbed = (STLTestbed *) memmgr->declare_var("STLTestbed my_alloc"); @@ -246,7 +254,9 @@ TEST_F(MM_stl_restore, DISABLED_s_i_pair ) { double test_second = random(); // Register the expected temporary variables with the memory manager - bool * first_data = (bool *) memmgr->declare_var("bool my_alloc_s_i_pair_first[20]"); + bool * first_data = (bool *) memmgr->declare_var("bool my_alloc_s_i_pair_first_inner[20]"); + std::string * first_link = (std::string *) memmgr->declare_var("std::string my_alloc_s_i_pair_first"); + *first_link = "inner"; double * second_data = (double *) memmgr->declare_var("double my_alloc_s_i_pair_second"); for (int i = 0; i < test_first.size(); i++) { @@ -263,18 +273,18 @@ TEST_F(MM_stl_restore, DISABLED_s_i_pair ) { // ASSERT // Make sure the STL has been populated EXPECT_EQ(testbed->s_i_pair.second, test_second); - EXPECT_EQ(testbed->s_i_pair.first.size(), test_first.size()); + ASSERT_EQ(testbed->s_i_pair.first.size(), test_first.size()); for (int i = 0; i < test_first.size(); i++) { EXPECT_EQ(testbed->s_i_pair.first.front(), test_first[i]); testbed->s_i_pair.first.pop(); } // Check that all the temporary variables have been deleted - EXPECT_EQ(memmgr->var_exists("my_alloc_s_i_pair_first"), 0); + EXPECT_EQ(memmgr->var_exists("my_alloc_s_i_pair_first_inner"), 0); EXPECT_EQ(memmgr->var_exists("my_alloc_s_i_pair_second"), 0); } -TEST_F(MM_stl_restore, DISABLED_s_s_pair ) { +TEST_F(MM_stl_restore, s_s_pair ) { // ARRANGE // make a testbed object STLTestbed * testbed = (STLTestbed *) memmgr->declare_var("STLTestbed my_alloc"); @@ -283,8 +293,15 @@ TEST_F(MM_stl_restore, DISABLED_s_s_pair ) { std::vector test_second = get_test_data(20); // Register the expected temporary variables with the memory manager - bool * first_data = (bool *) memmgr->declare_var("bool my_alloc_s_s_pair_first[20]"); - double * second_data = (double *) memmgr->declare_var("double my_alloc_s_s_pair_second"); + int * first_data = (int *) memmgr->declare_var("int my_alloc_s_s_pair_first_inner[20]"); + float * second_data = (float *) memmgr->declare_var("float my_alloc_s_s_pair_second_inner[20]"); + + std::string * first_link = (std::string *) memmgr->declare_var("std::string my_alloc_s_s_pair_first"); + std::string * second_link = (std::string *) memmgr->declare_var("std::string my_alloc_s_s_pair_second"); + *first_link = std::string("inner"); + *second_link = std::string("inner"); + + for (int i = 0; i < test_first.size(); i++) { first_data[i] = test_first[i]; @@ -304,13 +321,13 @@ TEST_F(MM_stl_restore, DISABLED_s_s_pair ) { EXPECT_EQ(testbed->s_s_pair.second.size(), test_second.size()); for (int i = 0; i < test_first.size(); i++) { EXPECT_EQ(testbed->s_s_pair.first[i], test_first[i]); - EXPECT_EQ(testbed->s_s_pair.second.top(), test_second[test_second.size()-1-i]); + EXPECT_EQ(testbed->s_s_pair.second.top(), test_second[i]); testbed->s_s_pair.second.pop(); } // Check that all the temporary variables have been deleted - EXPECT_EQ(memmgr->var_exists("my_alloc_s_s_pair_first"), 0); - EXPECT_EQ(memmgr->var_exists("my_alloc_s_s_pair_second"), 0); + EXPECT_EQ(memmgr->var_exists("my_alloc_s_s_pair_first_inner"), 0); + EXPECT_EQ(memmgr->var_exists("my_alloc_s_s_pair_second_inner"), 0); } TEST_F(MM_stl_restore, pair_pair ) { @@ -323,11 +340,12 @@ TEST_F(MM_stl_restore, pair_pair ) { int test_second = random(); // Register the expected temporary variables with the memory manager - int * first_first_data = (int *) memmgr->declare_var("int my_alloc_pair_pair_first_first"); - int * first_second_data = (int *) memmgr->declare_var("int my_alloc_pair_pair_first_second"); + int * first_first_data = (int *) memmgr->declare_var("int my_alloc_pair_pair_first_inner_first"); + int * first_second_data = (int *) memmgr->declare_var("int my_alloc_pair_pair_first_inner_second"); int * second_data = (int *) memmgr->declare_var("int my_alloc_pair_pair_second"); - (void) memmgr->declare_var("std::string my_alloc_pair_pair_first[1]"); + std::string * first_link = (std::string *) memmgr->declare_var("std::string my_alloc_pair_pair_first[1]"); + *first_link = std::string ("inner"); *first_first_data = test_first_first; *first_second_data = test_first_second; @@ -346,8 +364,8 @@ TEST_F(MM_stl_restore, pair_pair ) { // Check that all the temporary variables have been deleted EXPECT_EQ(memmgr->var_exists("my_alloc_pair_pair_first"), 0); - EXPECT_EQ(memmgr->var_exists("my_alloc_pair_pair_first_first"), 0); - EXPECT_EQ(memmgr->var_exists("my_alloc_pair_pair_first_second"), 0); + EXPECT_EQ(memmgr->var_exists("my_alloc_pair_pair_first_inner_first"), 0); + EXPECT_EQ(memmgr->var_exists("my_alloc_pair_pair_first_inner_second"), 0); EXPECT_EQ(memmgr->var_exists("my_alloc_pair_pair_second"), 0); } @@ -402,12 +420,15 @@ TEST_F(MM_stl_restore, i_s_map ) { std::string var_name = "std::string my_alloc_i_s_map_data_" + std::to_string(i) + "[" + std::to_string(6) + "]"; std::string * val_temp = (std::string *) memmgr->declare_var(var_name.c_str()); + std::vector test_strings_easy = {"a", "b", "c", "d", "e", "f"}; for (int j = 0; j < 6; j++) { - val_temp[j] = test_data[(i*6) + j]; + // val_temp[j] = std::string(test_data[(i*6) + j]); + val_temp[j] = std::string(test_strings_easy[j]); + // Create a map of expected data along side so that we don't have to deal with ordering stuff // Reverse order of the data since it's a stack - test_map[test_keys[i]].push(test_data[((i+1)*6)-1-j]); + test_map[test_keys[i]].push(std::string(test_strings_easy[5-j])); } } diff --git a/trick_source/sim_services/MemoryManager/test/MM_stl_testbed.hh b/trick_source/sim_services/MemoryManager/test/MM_stl_testbed.hh index 6a4a72ef..99130bae 100644 --- a/trick_source/sim_services/MemoryManager/test/MM_stl_testbed.hh +++ b/trick_source/sim_services/MemoryManager/test/MM_stl_testbed.hh @@ -59,7 +59,6 @@ public: std::pair,std::stack> s_s_pair; std::pair> i_v_pair; std::pair, int> pair_pair; - std::pair< int , std::pair< int, int > > int_pair_pair; std::map i_i_map; std::map> i_s_map;