mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 12:56:26 +00:00
Pair checkpointing fix (#1356)
* Fix pair checkpointing bug, add tests * Documentation update
This commit is contained in:
parent
3d2e8e52ca
commit
2519c914a5
@ -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<int> my_vector_alloca
|
||||
```
|
||||
|
||||
|
||||
<a id=known-bugs></a>
|
||||
|
||||
## Known bugs
|
||||
|
||||
The types in an std::pair cannot be sequence STL types (vector, queue, stack, etc).
|
||||
```
|
||||
// This will fail to checkpoint
|
||||
std::pair<int, std::vector<int>>
|
||||
```
|
||||
|
||||
[Continue to Threads](Threads)
|
||||
|
@ -82,7 +82,6 @@ int checkpoint_stl(std::pair<FIRST , SECOND> & 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<int (*)(int)>(std::ispunct), '_');
|
||||
@ -109,9 +108,10 @@ int checkpoint_stl(std::pair<FIRST , SECOND> & 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<FIRST , SECOND> & 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<FIRST , SECOND> & 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<FIRST , SECOND> & 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<FIRST , SECOND> & 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<FIRST , SECOND> & 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<FIRST , SECOND> & 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<FIRST , SECOND> & 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<FIRST , SECOND> & 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<FIRST , SECOND> & 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 ) ;
|
||||
}
|
||||
|
@ -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++) {
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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<int> lengths) {
|
||||
void validate_links_sequences (Trick::MemoryManager * memmgr, std::string object_name, std::string top_level_name, std::vector<int> 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 <typename T>
|
||||
void validate_temp_set (Trick::MemoryManager * memmgr, std::string object_name, std::string var_name, std::set<T> 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<int>(memmgr, std::string("my_alloc"), var_name, test_data[i]);
|
||||
}
|
||||
|
||||
validate_links(memmgr, std::string("my_alloc"), std::string("i_s_vec"), std::vector<int>(10, 10));
|
||||
validate_links_sequences(memmgr, std::string("my_alloc"), std::string("i_s_vec"), std::vector<int>(10, 10));
|
||||
}
|
||||
|
||||
TEST_F(MM_stl_checkpoint, string_vec ) {
|
||||
@ -313,7 +323,7 @@ TEST_F(MM_stl_checkpoint, i_i_pair ) {
|
||||
validate_temp_pair<double,float>(memmgr, std::string("my_alloc"), vec_attr->name, std::pair<double,float>(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<int>(1, test_val.size()));
|
||||
validate_temp_sequence<bool>(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<bool>(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<bool>(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<bool>(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<int,int>(1, 2));
|
||||
validate_temp_pair(memmgr, std::string("my_alloc"), std::string("pair_pair_first_inner"), std::pair<int,int>(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<int>(list_sizes.rbegin(), list_sizes.rend()));
|
||||
validate_links_sequences(memmgr, std::string("my_alloc"), std::string("nested_list_stack"), std::vector<int>(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<int>(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<char>(memmgr, std::string("my_alloc"), std::string("vector_set"), std::set<char> (test_data.begin(), test_data.end()));
|
||||
}
|
||||
|
||||
@ -959,7 +958,7 @@ TEST_F(MM_stl_checkpoint, vector_multiset ) {
|
||||
validate_temp_sequence<int>(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<int>(test_data.begin() + (i*10), test_data.begin() +((i+1)*10)));
|
||||
}
|
||||
|
||||
validate_links(memmgr, std::string("my_alloc"), std::string("vec_array"), std::vector<int>(10, 10));
|
||||
validate_links_sequences(memmgr, std::string("my_alloc"), std::string("vec_array"), std::vector<int>(10, 10));
|
||||
}
|
||||
|
||||
TEST_F(MM_stl_checkpoint, vec_user_defined ) {
|
||||
|
@ -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<double>();
|
||||
|
||||
// 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<float> test_second = get_test_data<float>(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<int>();
|
||||
|
||||
// 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<std::string> 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]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,6 @@ public:
|
||||
std::pair<std::vector<int>,std::stack<float>> s_s_pair;
|
||||
std::pair<double,std::vector<bool>> i_v_pair;
|
||||
std::pair<std::pair<int,int>, int> pair_pair;
|
||||
std::pair< int , std::pair< int, int > > int_pair_pair;
|
||||
|
||||
std::map<int, double> i_i_map;
|
||||
std::map<int, std::stack<std::string>> i_s_map;
|
||||
|
Loading…
Reference in New Issue
Block a user