Fixed an error with checkpointing change variables (#1518)

* Fixed SIGABRT for checkpointing change variables

* Expanded the Data Recording Checkpoint test sim
  - Added a case for checkpointing change variables

* Updated the test case for checkpointing change vars
  - Changed the header, input, and log files to get better data representation

* Expanded the Checkpoint test sim
  - Added a test case covering when the only tracked variable is the change var.
This commit is contained in:
Mrockwell2 2023-06-07 15:17:24 -05:00 committed by GitHub
parent e102dd7ef2
commit f64a16ecaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 135 additions and 2 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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

View File

@ -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()

View File

@ -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
1 sys.exec.out.time {s} testSimObject.my_foo.a {1} testSimObject.my_foo.b {1} testSimObject.my_foo.q {1}
2 8 9 18 3
3 11 12 24 4
4 14 15 30 5
5 17 18 36 6
6 20 21 42 7

View File

@ -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()

View File

@ -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

View File

@ -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()

View File

@ -0,0 +1,6 @@
sys.exec.out.time {s},testSimObject.my_foo.q {1}
8,3
11,4
14,5
17,6
20,7
1 sys.exec.out.time {s} testSimObject.my_foo.q {1}
2 8 3
3 11 4
4 14 5
5 17 6
6 20 7

View File

@ -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()

View File

@ -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++;
}
};

View File

@ -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

View File

@ -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() ;