mirror of
https://github.com/nasa/trick.git
synced 2024-12-18 20:57:55 +00:00
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:
parent
e102dd7ef2
commit
f64a16ecaa
@ -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()
|
@ -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()
|
9
test/SIM_checkpoint_data_recording/RUN_test7/check_log.sh
Executable file
9
test/SIM_checkpoint_data_recording/RUN_test7/check_log.sh
Executable 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
|
14
test/SIM_checkpoint_data_recording/RUN_test7/dump.py
Normal file
14
test/SIM_checkpoint_data_recording/RUN_test7/dump.py
Normal 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()
|
@ -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
|
|
11
test/SIM_checkpoint_data_recording/RUN_test7/unit_test.py
Normal file
11
test/SIM_checkpoint_data_recording/RUN_test7/unit_test.py
Normal 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()
|
9
test/SIM_checkpoint_data_recording/RUN_test8/check_log.sh
Executable file
9
test/SIM_checkpoint_data_recording/RUN_test8/check_log.sh
Executable 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
|
14
test/SIM_checkpoint_data_recording/RUN_test8/dump.py
Normal file
14
test/SIM_checkpoint_data_recording/RUN_test8/dump.py
Normal 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()
|
@ -0,0 +1,6 @@
|
||||
sys.exec.out.time {s},testSimObject.my_foo.q {1}
|
||||
8,3
|
||||
11,4
|
||||
14,5
|
||||
17,6
|
||||
20,7
|
|
11
test/SIM_checkpoint_data_recording/RUN_test8/unit_test.py
Normal file
11
test/SIM_checkpoint_data_recording/RUN_test8/unit_test.py
Normal 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()
|
@ -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++;
|
||||
}
|
||||
};
|
@ -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
|
||||
|
@ -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() ;
|
||||
|
Loading…
Reference in New Issue
Block a user