diff --git a/test/SIM_checkpoint_data_recording/Modified_data/fooChange.dr b/test/SIM_checkpoint_data_recording/Modified_data/fooChange.dr new file mode 100644 index 00000000..67dc7e69 --- /dev/null +++ b/test/SIM_checkpoint_data_recording/Modified_data/fooChange.dr @@ -0,0 +1,20 @@ +global DR_GROUP_ID +global drg +try: + if DR_GROUP_ID >= 0: + DR_GROUP_ID += 1 +except NameError: + DR_GROUP_ID = 0 + drg = [] + +drg.append(trick.DRAscii("fooChange")) +drg[DR_GROUP_ID].set_freq(trick.DR_Changes) +drg[DR_GROUP_ID].set_cycle(0.1) +drg[DR_GROUP_ID].set_single_prec_only(False) +drg[DR_GROUP_ID].add_variable("testSimObject.my_foo.a") +drg[DR_GROUP_ID].add_variable("testSimObject.my_foo.b") +drg[DR_GROUP_ID].add_variable("testSimObject.my_foo.q") +drg[DR_GROUP_ID].add_change_variable("testSimObject.my_foo.q") +drg[DR_GROUP_ID].set_max_file_size(1 * 1073741824) # multiply converts GiB to B --Dr. Dre +trick.add_data_record_group(drg[DR_GROUP_ID], trick.DR_Buffer) +drg[DR_GROUP_ID].enable() diff --git a/test/SIM_checkpoint_data_recording/Modified_data/fooChange2.dr b/test/SIM_checkpoint_data_recording/Modified_data/fooChange2.dr new file mode 100644 index 00000000..78363a00 --- /dev/null +++ b/test/SIM_checkpoint_data_recording/Modified_data/fooChange2.dr @@ -0,0 +1,18 @@ +global DR_GROUP_ID +global drg +try: + if DR_GROUP_ID >= 0: + DR_GROUP_ID += 1 +except NameError: + DR_GROUP_ID = 0 + drg = [] + +drg.append(trick.DRAscii("fooChange2")) +drg[DR_GROUP_ID].set_freq(trick.DR_Changes) +drg[DR_GROUP_ID].set_cycle(0.1) +drg[DR_GROUP_ID].set_single_prec_only(False) +drg[DR_GROUP_ID].add_variable("testSimObject.my_foo.q") +drg[DR_GROUP_ID].add_change_variable("testSimObject.my_foo.q") +drg[DR_GROUP_ID].set_max_file_size(1 * 1073741824) # multiply converts GiB to B --Dr. Dre +trick.add_data_record_group(drg[DR_GROUP_ID], trick.DR_Buffer) +drg[DR_GROUP_ID].enable() diff --git a/test/SIM_checkpoint_data_recording/RUN_test7/check_log.sh b/test/SIM_checkpoint_data_recording/RUN_test7/check_log.sh new file mode 100755 index 00000000..cf8e2738 --- /dev/null +++ b/test/SIM_checkpoint_data_recording/RUN_test7/check_log.sh @@ -0,0 +1,9 @@ +FILE=log_fooChange.csv +if test -f "$FILE"; then + echo "$FILE exists." + exit 1 +else + # Expect the file not to exist. + echo "$FILE does not exist." + exit 0 +fi \ No newline at end of file diff --git a/test/SIM_checkpoint_data_recording/RUN_test7/dump.py b/test/SIM_checkpoint_data_recording/RUN_test7/dump.py new file mode 100644 index 00000000..749a0c6e --- /dev/null +++ b/test/SIM_checkpoint_data_recording/RUN_test7/dump.py @@ -0,0 +1,14 @@ +import trick +from trick.unit_test import * + +# This was just here for convenience to dump the checkpoints. + +def main(): + exec(open("Modified_data/fooChange.dr").read()) + + trick.checkpoint(5.0) + + trick.stop(20.0) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/test/SIM_checkpoint_data_recording/RUN_test7/ref_log_fooChange.csv b/test/SIM_checkpoint_data_recording/RUN_test7/ref_log_fooChange.csv new file mode 100644 index 00000000..31352b3b --- /dev/null +++ b/test/SIM_checkpoint_data_recording/RUN_test7/ref_log_fooChange.csv @@ -0,0 +1,6 @@ +sys.exec.out.time {s},testSimObject.my_foo.a {1},testSimObject.my_foo.b {1},testSimObject.my_foo.q {1} + 8,9,18,3 + 11,12,24,4 + 14,15,30,5 + 17,18,36,6 + 20,21,42,7 diff --git a/test/SIM_checkpoint_data_recording/RUN_test7/unit_test.py b/test/SIM_checkpoint_data_recording/RUN_test7/unit_test.py new file mode 100644 index 00000000..2076f610 --- /dev/null +++ b/test/SIM_checkpoint_data_recording/RUN_test7/unit_test.py @@ -0,0 +1,11 @@ +import trick + +def main(): + exec(open("Modified_data/fooChange.dr").read()) + + trick.add_read(5.0, 'trick.load_checkpoint("RUN_test7/chkpnt_5.000000")') # this checkpoint does not contain data recording + + trick.stop(20.0) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/test/SIM_checkpoint_data_recording/RUN_test8/check_log.sh b/test/SIM_checkpoint_data_recording/RUN_test8/check_log.sh new file mode 100755 index 00000000..378308fa --- /dev/null +++ b/test/SIM_checkpoint_data_recording/RUN_test8/check_log.sh @@ -0,0 +1,9 @@ +FILE=log_fooChange2.csv +if test -f "$FILE"; then + echo "$FILE exists." + exit 1 +else + # Expect the file not to exist. + echo "$FILE does not exist." + exit 0 +fi \ No newline at end of file diff --git a/test/SIM_checkpoint_data_recording/RUN_test8/dump.py b/test/SIM_checkpoint_data_recording/RUN_test8/dump.py new file mode 100644 index 00000000..a63985c1 --- /dev/null +++ b/test/SIM_checkpoint_data_recording/RUN_test8/dump.py @@ -0,0 +1,14 @@ +import trick +from trick.unit_test import * + +# This was just here for convenience to dump the checkpoints. + +def main(): + exec(open("Modified_data/fooChange2.dr").read()) + + trick.checkpoint(5.0) + + trick.stop(20.0) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/test/SIM_checkpoint_data_recording/RUN_test8/ref_log_fooChange2.csv b/test/SIM_checkpoint_data_recording/RUN_test8/ref_log_fooChange2.csv new file mode 100644 index 00000000..5692f534 --- /dev/null +++ b/test/SIM_checkpoint_data_recording/RUN_test8/ref_log_fooChange2.csv @@ -0,0 +1,6 @@ +sys.exec.out.time {s},testSimObject.my_foo.q {1} + 8,3 + 11,4 + 14,5 + 17,6 + 20,7 diff --git a/test/SIM_checkpoint_data_recording/RUN_test8/unit_test.py b/test/SIM_checkpoint_data_recording/RUN_test8/unit_test.py new file mode 100644 index 00000000..1a0d0c5c --- /dev/null +++ b/test/SIM_checkpoint_data_recording/RUN_test8/unit_test.py @@ -0,0 +1,11 @@ +import trick + +def main(): + exec(open("Modified_data/fooChange2.dr").read()) + + trick.add_read(5.0, 'trick.load_checkpoint("RUN_test8/chkpnt_5.000000")') # this checkpoint does not contain data recording + + trick.stop(20.0) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/test/SIM_checkpoint_data_recording/models/Foo.hh b/test/SIM_checkpoint_data_recording/models/Foo.hh index 4bc7d023..537d4952 100644 --- a/test/SIM_checkpoint_data_recording/models/Foo.hh +++ b/test/SIM_checkpoint_data_recording/models/Foo.hh @@ -3,14 +3,17 @@ class Foo { public: int a; int b; + int q; void init () { a = 0; b = 0; + q = 0; } void increment () { a++; b+=2; + if(a%3 == 0) q++; } }; \ No newline at end of file diff --git a/test_sims.yml b/test_sims.yml index f28afdba..7f708f95 100644 --- a/test_sims.yml +++ b/test_sims.yml @@ -243,6 +243,9 @@ SIM_checkpoint_data_recording: returns: 0 RUN_test6/dump.py: returns: 0 + RUN_test[7-8]/dump.py: + phase: -1 + returns: 0 # Note we could use the [1-5] notation here if RUN_test2 didn't stand out as not matching the pattern -Jordan 1/2023 RUN_test1/unit_test.py: @@ -268,6 +271,14 @@ SIM_checkpoint_data_recording: returns: 0 compare: - test/SIM_checkpoint_data_recording/RUN_test6/ref_log_foo2.csv vs. test/SIM_checkpoint_data_recording/RUN_test6/log_foo2.csv + RUN_test7/unit_test.py: + returns: 0 + compare: + - test/SIM_checkpoint_data_recording/RUN_test7/ref_log_fooChange.csv vs. test/SIM_checkpoint_data_recording/RUN_test7/log_fooChange.csv + RUN_test8/unit_test.py: + returns: 0 + compare: + - test/SIM_checkpoint_data_recording/RUN_test8/ref_log_fooChange2.csv vs. test/SIM_checkpoint_data_recording/RUN_test8/log_fooChange2.csv SIM_events: path: test/SIM_events diff --git a/trick_source/sim_services/DataRecord/DataRecordGroup.cpp b/trick_source/sim_services/DataRecord/DataRecordGroup.cpp index cdb66f38..d9266e72 100644 --- a/trick_source/sim_services/DataRecord/DataRecordGroup.cpp +++ b/trick_source/sim_services/DataRecord/DataRecordGroup.cpp @@ -330,6 +330,7 @@ int Trick::DataRecordGroup::add_change_variable( std::string in_name ) { Trick::DataRecordBuffer * new_var = new Trick::DataRecordBuffer ; new_var->ref = ref2 ; + new_var->name = in_name; new_var->buffer = (char *)malloc(ref2->attr->size) ; new_var->last_value = NULL ; memcpy(new_var->buffer , ref2->address , ref2->attr->size) ; @@ -454,7 +455,7 @@ int Trick::DataRecordGroup::checkpoint() { the rest of the DataRecordBuffer will be reconstructed during restart */ if ( change_buffer.size() > 0 ) { - num_change_variable_names = rec_buffer.size() ; + num_change_variable_names = change_buffer.size() ; change_variable_names = (char **)TMM_declare_var_1d("char *", (int)change_buffer.size()) ; change_variable_alias = (char **)TMM_declare_var_1d("char *", (int)change_buffer.size()) ; @@ -530,7 +531,7 @@ int Trick::DataRecordGroup::restart() { add_variable( variable_names[jj] , variable_alias[jj] ) ; } for ( jj = 0 ; jj < num_change_variable_names ; jj++ ) { - add_variable( change_variable_names[jj] , change_variable_alias[jj] ) ; + add_change_variable( change_variable_names[jj] ) ; } clear_checkpoint_vars() ;