diff --git a/include/trick/CheckPointRestart.hh b/include/trick/CheckPointRestart.hh index 4201d7464..8c0a597c6 100644 --- a/include/trick/CheckPointRestart.hh +++ b/include/trick/CheckPointRestart.hh @@ -22,6 +22,10 @@ namespace Trick { */ class CheckPointRestart : public Trick::Scheduler { + private: + /** Flag to track if an automatic freeze has been triggered */ + bool auto_freeze = false; /* ** */ + protected: /** queue to hold jobs to be called before a checkpoint is dumped. */ Trick::ScheduledJobQueue checkpoint_queue ; /* ** */ diff --git a/include/trick/sim_mode.h b/include/trick/sim_mode.h index 1bdbd2ace..51ff2bd76 100644 --- a/include/trick/sim_mode.h +++ b/include/trick/sim_mode.h @@ -14,6 +14,10 @@ #ifndef SIMMODE_HH #define SIMMODE_HH +#ifdef __cplusplus +extern "C" { +#endif + typedef enum { NoCmd = 0 , /* NoCmd */ @@ -38,4 +42,10 @@ typedef enum { } SIM_MODE ; +const char * simModeCharString(SIM_MODE mode); + +#ifdef __cplusplus +} +#endif + #endif diff --git a/test/SIM_checkpoint_data_recording/RUN_test/dump.py b/test/SIM_checkpoint_data_recording/RUN_test/dump.py index 749d69d4a..37d75acc6 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test/dump.py +++ b/test/SIM_checkpoint_data_recording/RUN_test/dump.py @@ -1,12 +1,30 @@ import trick from trick.unit_test import * +from threading import Timer # This was just here for convenience to dump the checkpoints. +def dump_checkpoint(sim_time): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.checkpoint() + trick.exec_run() + elif cur_time > sim_time: + return + else: + Timer(0.1, dump_checkpoint, (sim_time,)).start() + +def checkpoint(time): + Timer(1.0, dump_checkpoint, (time,)).start() + + trick.freeze(time) + def main(): exec(open("Modified_data/foo.dr").read()) - trick.checkpoint(5.0) + checkpoint(5.0) trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test1/dump.py b/test/SIM_checkpoint_data_recording/RUN_test1/dump.py index 749d69d4a..37d75acc6 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test1/dump.py +++ b/test/SIM_checkpoint_data_recording/RUN_test1/dump.py @@ -1,12 +1,30 @@ import trick from trick.unit_test import * +from threading import Timer # This was just here for convenience to dump the checkpoints. +def dump_checkpoint(sim_time): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.checkpoint() + trick.exec_run() + elif cur_time > sim_time: + return + else: + Timer(0.1, dump_checkpoint, (sim_time,)).start() + +def checkpoint(time): + Timer(1.0, dump_checkpoint, (time,)).start() + + trick.freeze(time) + def main(): exec(open("Modified_data/foo.dr").read()) - trick.checkpoint(5.0) + checkpoint(5.0) trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test1/ref_log_foo.csv b/test/SIM_checkpoint_data_recording/RUN_test1/ref_log_foo.csv index 37c97556b..75a5c16e7 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test1/ref_log_foo.csv +++ b/test/SIM_checkpoint_data_recording/RUN_test1/ref_log_foo.csv @@ -1,4 +1,5 @@ sys.exec.out.time {s},testSimObject.my_foo.a {1},testSimObject.my_foo.b {1} + 5,6,12 5.1,6,12 5.2,6,12 5.3,6,12 diff --git a/test/SIM_checkpoint_data_recording/RUN_test1/unit_test.py b/test/SIM_checkpoint_data_recording/RUN_test1/unit_test.py index d5b6008cb..3bce5e67f 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test1/unit_test.py +++ b/test/SIM_checkpoint_data_recording/RUN_test1/unit_test.py @@ -1,8 +1,28 @@ import trick +from threading import Timer +def load_checkpoint(path, sim_time, tries=10): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.load_checkpoint(path) + trick.exec_run() + elif cur_time > sim_time or tries <= 0: + print("Issue with loading checkpoint from input file!") + return + else: + Timer(0.1, load_checkpoint, (path, sim_time, tries - 1,)).start() + +def load_checkpoint_at(path, time): + Timer(1.0, load_checkpoint, (path, time)).start() + + trick.freeze(time) def main(): - trick.add_read(5.0, 'trick.load_checkpoint("RUN_test1/chkpnt_5.000000")') # This checkpoint has data recording + chkpnt_path = "RUN_test1/chkpnt_5.000000" + load_checkpoint_at(chkpnt_path, 5.0) + trick.stop(10.0) if __name__ == "__main__": diff --git a/test/SIM_checkpoint_data_recording/RUN_test2/dump.py b/test/SIM_checkpoint_data_recording/RUN_test2/dump.py index d05fc5326..fc0b6e434 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test2/dump.py +++ b/test/SIM_checkpoint_data_recording/RUN_test2/dump.py @@ -1,10 +1,28 @@ import trick from trick.unit_test import * +from threading import Timer # This was just here for convenience to dump the checkpoints. +def dump_checkpoint(sim_time): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.checkpoint() + trick.exec_run() + elif cur_time > sim_time: + return + else: + Timer(0.1, dump_checkpoint, (sim_time,)).start() + +def checkpoint(time): + Timer(1.0, dump_checkpoint, (time,)).start() + + trick.freeze(time) + def main(): - trick.checkpoint(5.0) + checkpoint(5.0) trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test2/unit_test.py b/test/SIM_checkpoint_data_recording/RUN_test2/unit_test.py index 8ba141c1c..de342fd2d 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test2/unit_test.py +++ b/test/SIM_checkpoint_data_recording/RUN_test2/unit_test.py @@ -1,9 +1,28 @@ import trick +from threading import Timer + +def load_checkpoint(path, sim_time, tries=10): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.load_checkpoint(path) + trick.exec_run() + elif cur_time > sim_time or tries <= 0: + print("Issue with loading checkpoint from input file!") + return + else: + Timer(0.1, load_checkpoint, (path, sim_time, tries - 1,)).start() + +def load_checkpoint_at(path, time): + Timer(1.0, load_checkpoint, (path, time)).start() + + trick.freeze(time) def main(): exec(open("Modified_data/foo.dr").read()) - trick.add_read(5.0, 'trick.load_checkpoint("RUN_test2/chkpnt_5.000000")') # this checkpoint does not contain data recording + load_checkpoint_at("RUN_test2/chkpnt_5.000000", 5.0) # this checkpoint does not contain data recording trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test3/dump.py b/test/SIM_checkpoint_data_recording/RUN_test3/dump.py index 749d69d4a..37d75acc6 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test3/dump.py +++ b/test/SIM_checkpoint_data_recording/RUN_test3/dump.py @@ -1,12 +1,30 @@ import trick from trick.unit_test import * +from threading import Timer # This was just here for convenience to dump the checkpoints. +def dump_checkpoint(sim_time): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.checkpoint() + trick.exec_run() + elif cur_time > sim_time: + return + else: + Timer(0.1, dump_checkpoint, (sim_time,)).start() + +def checkpoint(time): + Timer(1.0, dump_checkpoint, (time,)).start() + + trick.freeze(time) + def main(): exec(open("Modified_data/foo.dr").read()) - trick.checkpoint(5.0) + checkpoint(5.0) trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test3/ref_log_foo.csv b/test/SIM_checkpoint_data_recording/RUN_test3/ref_log_foo.csv index 37c97556b..75a5c16e7 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test3/ref_log_foo.csv +++ b/test/SIM_checkpoint_data_recording/RUN_test3/ref_log_foo.csv @@ -1,4 +1,5 @@ sys.exec.out.time {s},testSimObject.my_foo.a {1},testSimObject.my_foo.b {1} + 5,6,12 5.1,6,12 5.2,6,12 5.3,6,12 diff --git a/test/SIM_checkpoint_data_recording/RUN_test3/unit_test.py b/test/SIM_checkpoint_data_recording/RUN_test3/unit_test.py index c91faf0e5..d48ba0cc5 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test3/unit_test.py +++ b/test/SIM_checkpoint_data_recording/RUN_test3/unit_test.py @@ -1,10 +1,29 @@ import trick +from threading import Timer + +def load_checkpoint(path, sim_time, tries=10): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.load_checkpoint(path) + trick.exec_run() + elif cur_time > sim_time or tries <= 0: + print("Issue with loading checkpoint from input file!") + return + else: + Timer(0.1, load_checkpoint, (path, sim_time, tries - 1,)).start() + +def load_checkpoint_at(path, time): + Timer(1.0, load_checkpoint, (path, time)).start() + + trick.freeze(time) def main(): exec(open("Modified_data/foo.dr").read()) - trick.add_read(5.0, 'trick.load_checkpoint("RUN_test3/chkpnt_5.000000")') # contains data recording + load_checkpoint_at("RUN_test3/chkpnt_5.000000", 5.0) # contains data recording trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test4/dump.py b/test/SIM_checkpoint_data_recording/RUN_test4/dump.py index 00df66fd6..79fc43784 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test4/dump.py +++ b/test/SIM_checkpoint_data_recording/RUN_test4/dump.py @@ -1,12 +1,30 @@ import trick from trick.unit_test import * +from threading import Timer # This was just here for convenience to dump the checkpoints. +def dump_checkpoint(sim_time): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.checkpoint() + trick.exec_run() + elif cur_time > sim_time: + return + else: + Timer(0.1, dump_checkpoint, (sim_time,)).start() + +def checkpoint(time): + Timer(1.0, dump_checkpoint, (time,)).start() + + trick.freeze(time) + def main(): exec(open("Modified_data/foo.dr").read()) - trick.checkpoint(2.0) + checkpoint(2.0) trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test4/ref_log_foo.csv b/test/SIM_checkpoint_data_recording/RUN_test4/ref_log_foo.csv index 13327df84..b70298737 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test4/ref_log_foo.csv +++ b/test/SIM_checkpoint_data_recording/RUN_test4/ref_log_foo.csv @@ -1,4 +1,5 @@ sys.exec.out.time {s},testSimObject.my_foo.a {1},testSimObject.my_foo.b {1} + 2,3,6 2.1,3,6 2.2,3,6 2.3,3,6 diff --git a/test/SIM_checkpoint_data_recording/RUN_test4/unit_test.py b/test/SIM_checkpoint_data_recording/RUN_test4/unit_test.py index f07baf1d1..f9efd12c7 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test4/unit_test.py +++ b/test/SIM_checkpoint_data_recording/RUN_test4/unit_test.py @@ -1,10 +1,29 @@ import trick +from threading import Timer + +def load_checkpoint(path, sim_time, tries=10): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.load_checkpoint(path) + trick.exec_run() + elif cur_time > sim_time or tries <= 0: + print("Issue with loading checkpoint from input file!") + return + else: + Timer(0.1, load_checkpoint, (path, sim_time, tries - 1,)).start() + +def load_checkpoint_at(path, time): + Timer(1.0, load_checkpoint, (path, time)).start() + + trick.freeze(time) def main(): exec(open("Modified_data/foo.dr").read()) - trick.add_read(5.0, 'trick.load_checkpoint("RUN_test4/chkpnt_2.000000")') # contains data recording, starts at t=2 + load_checkpoint_at("RUN_test4/chkpnt_2.000000", 5.0) # contains data recording, starts at t=2 trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test5/dump.py b/test/SIM_checkpoint_data_recording/RUN_test5/dump.py index 565a891b6..4bbbcd13f 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test5/dump.py +++ b/test/SIM_checkpoint_data_recording/RUN_test5/dump.py @@ -1,12 +1,29 @@ import trick -from trick.unit_test import * +from threading import Timer # This was just here for convenience to dump the checkpoints. +def dump_checkpoint(sim_time): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.checkpoint() + trick.exec_run() + elif cur_time > sim_time: + return + else: + Timer(0.1, dump_checkpoint, (sim_time,)).start() + +def checkpoint(time): + Timer(1.0, dump_checkpoint, (time,)).start() + + trick.freeze(time) + def main(): exec(open("Modified_data/foo.dr").read()) - trick.checkpoint(7.0) + checkpoint(7.0) trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test5/ref_log_foo.csv b/test/SIM_checkpoint_data_recording/RUN_test5/ref_log_foo.csv index 306de1b40..490689651 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test5/ref_log_foo.csv +++ b/test/SIM_checkpoint_data_recording/RUN_test5/ref_log_foo.csv @@ -1,4 +1,5 @@ sys.exec.out.time {s},testSimObject.my_foo.a {1},testSimObject.my_foo.b {1} + 7,8,16 7.1,8,16 7.2,8,16 7.3,8,16 diff --git a/test/SIM_checkpoint_data_recording/RUN_test5/unit_test.py b/test/SIM_checkpoint_data_recording/RUN_test5/unit_test.py index 649cb370a..01ec002fe 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test5/unit_test.py +++ b/test/SIM_checkpoint_data_recording/RUN_test5/unit_test.py @@ -1,10 +1,29 @@ import trick +from threading import Timer + +def load_checkpoint(path, sim_time, tries=10): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.load_checkpoint(path) + trick.exec_run() + elif cur_time > sim_time or tries <= 0: + print("Issue with loading checkpoint from input file!") + return + else: + Timer(0.1, load_checkpoint, (path, sim_time, tries - 1,)).start() + +def load_checkpoint_at(path, time): + Timer(1.0, load_checkpoint, (path, time)).start() + + trick.freeze(time) def main(): exec(open("Modified_data/foo.dr").read()) - trick.add_read(5.0, 'trick.load_checkpoint("RUN_test5/chkpnt_7.000000")') # contains data recording, starts at t=7 + load_checkpoint_at("RUN_test5/chkpnt_7.000000", 5.0) # contains data recording, starts at t=7 trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test6/dump.py b/test/SIM_checkpoint_data_recording/RUN_test6/dump.py index 7b7db62af..9b7667569 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test6/dump.py +++ b/test/SIM_checkpoint_data_recording/RUN_test6/dump.py @@ -1,12 +1,30 @@ import trick from trick.unit_test import * +from threading import Timer # This was just here for convenience to dump the checkpoints. +def dump_checkpoint(sim_time): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.checkpoint() + trick.exec_run() + elif cur_time > sim_time: + return + else: + Timer(0.1, dump_checkpoint, (sim_time,)).start() + +def checkpoint(time): + Timer(1.0, dump_checkpoint, (time,)).start() + + trick.freeze(time) + def main(): exec(open("Modified_data/foo2.dr").read()) - trick.checkpoint(7.0) + checkpoint(7.0) trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test6/ref_log_foo2.csv b/test/SIM_checkpoint_data_recording/RUN_test6/ref_log_foo2.csv index f7b15a2b7..2ee326def 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test6/ref_log_foo2.csv +++ b/test/SIM_checkpoint_data_recording/RUN_test6/ref_log_foo2.csv @@ -1,4 +1,5 @@ sys.exec.out.time {s},testSimObject.my_foo.b {1} + 7,16 8,18 9,20 10,22 diff --git a/test/SIM_checkpoint_data_recording/RUN_test6/unit_test.py b/test/SIM_checkpoint_data_recording/RUN_test6/unit_test.py index f5b5f315c..169620557 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test6/unit_test.py +++ b/test/SIM_checkpoint_data_recording/RUN_test6/unit_test.py @@ -1,11 +1,30 @@ import trick +from threading import Timer + +def load_checkpoint(path, sim_time, tries=10): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.load_checkpoint(path) + trick.exec_run() + elif cur_time > sim_time or tries <= 0: + print("Issue with loading checkpoint from input file!") + return + else: + Timer(0.1, load_checkpoint, (path, sim_time, tries - 1,)).start() + +def load_checkpoint_at(path, time): + Timer(1.0, load_checkpoint, (path, time)).start() + + trick.freeze(time) def main(): exec(open("Modified_data/foo.dr").read()) # trick.checkpoint(7.0) - trick.add_read(5.0, 'trick.load_checkpoint("RUN_test6/chkpnt_7.000000")') # contains data recording, starts at t=7 + load_checkpoint_at("RUN_test6/chkpnt_7.000000", 5.0) # contains data recording, starts at t=7 trick.stop(10.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test7/dump.py b/test/SIM_checkpoint_data_recording/RUN_test7/dump.py index 749a0c6e6..a7c39a7ac 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test7/dump.py +++ b/test/SIM_checkpoint_data_recording/RUN_test7/dump.py @@ -1,12 +1,30 @@ import trick from trick.unit_test import * +from threading import Timer # This was just here for convenience to dump the checkpoints. +def dump_checkpoint(sim_time): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.checkpoint() + trick.exec_run() + elif cur_time > sim_time: + return + else: + Timer(0.1, dump_checkpoint, (sim_time,)).start() + +def checkpoint(time): + Timer(1.0, dump_checkpoint, (time,)).start() + + trick.freeze(time) + def main(): exec(open("Modified_data/fooChange.dr").read()) - trick.checkpoint(5.0) + checkpoint(5.0) trick.stop(20.0) 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 index 31352b3bf..6abcd599d 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test7/ref_log_fooChange.csv +++ b/test/SIM_checkpoint_data_recording/RUN_test7/ref_log_fooChange.csv @@ -1,4 +1,5 @@ sys.exec.out.time {s},testSimObject.my_foo.a {1},testSimObject.my_foo.b {1},testSimObject.my_foo.q {1} + 5,6,12,2 8,9,18,3 11,12,24,4 14,15,30,5 diff --git a/test/SIM_checkpoint_data_recording/RUN_test7/unit_test.py b/test/SIM_checkpoint_data_recording/RUN_test7/unit_test.py index 2076f610e..e90a0d5ab 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test7/unit_test.py +++ b/test/SIM_checkpoint_data_recording/RUN_test7/unit_test.py @@ -1,9 +1,28 @@ import trick +from threading import Timer + +def load_checkpoint(path, sim_time, tries=10): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.load_checkpoint(path) + trick.exec_run() + elif cur_time > sim_time or tries <= 0: + print("Issue with loading checkpoint from input file!") + return + else: + Timer(0.1, load_checkpoint, (path, sim_time, tries - 1,)).start() + +def load_checkpoint_at(path, time): + Timer(1.0, load_checkpoint, (path, time)).start() + + trick.freeze(time) 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 + load_checkpoint_at("RUN_test7/chkpnt_5.000000", 5.0) # this checkpoint does not contain data recording trick.stop(20.0) diff --git a/test/SIM_checkpoint_data_recording/RUN_test8/dump.py b/test/SIM_checkpoint_data_recording/RUN_test8/dump.py index a63985c11..9c8dd16c1 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test8/dump.py +++ b/test/SIM_checkpoint_data_recording/RUN_test8/dump.py @@ -1,12 +1,30 @@ import trick from trick.unit_test import * +from threading import Timer # This was just here for convenience to dump the checkpoints. +def dump_checkpoint(sim_time): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.checkpoint() + trick.exec_run() + elif cur_time > sim_time: + return + else: + Timer(0.1, dump_checkpoint, (sim_time,)).start() + +def checkpoint(time): + Timer(1.0, dump_checkpoint, (time,)).start() + + trick.freeze(time) + def main(): exec(open("Modified_data/fooChange2.dr").read()) - trick.checkpoint(5.0) + checkpoint(5.0) trick.stop(20.0) 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 index 5692f5342..96eba9af7 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test8/ref_log_fooChange2.csv +++ b/test/SIM_checkpoint_data_recording/RUN_test8/ref_log_fooChange2.csv @@ -1,4 +1,5 @@ sys.exec.out.time {s},testSimObject.my_foo.q {1} + 5,2 8,3 11,4 14,5 diff --git a/test/SIM_checkpoint_data_recording/RUN_test8/unit_test.py b/test/SIM_checkpoint_data_recording/RUN_test8/unit_test.py index 1a0d0c5cb..a502f72a2 100644 --- a/test/SIM_checkpoint_data_recording/RUN_test8/unit_test.py +++ b/test/SIM_checkpoint_data_recording/RUN_test8/unit_test.py @@ -1,9 +1,28 @@ import trick +from threading import Timer + +def load_checkpoint(path, sim_time, tries=10): + mode = trick.exec_get_mode() + cur_time = trick.exec_get_sim_time() + + if(mode == 1 and cur_time == sim_time): + trick.load_checkpoint(path) + trick.exec_run() + elif cur_time > sim_time or tries <= 0: + print("Issue with loading checkpoint from input file!") + return + else: + Timer(0.1, load_checkpoint, (path, sim_time, tries - 1,)).start() + +def load_checkpoint_at(path, time): + Timer(1.0, load_checkpoint, (path, time)).start() + + trick.freeze(time) 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 + load_checkpoint_at("RUN_test8/chkpnt_5.000000", 5.0) # this checkpoint does not contain data recording trick.stop(20.0) diff --git a/test/SIM_stls/RUN_test/setup.py b/test/SIM_stls/RUN_test/setup.py index 208d871f9..03bc6ddcf 100644 --- a/test/SIM_stls/RUN_test/setup.py +++ b/test/SIM_stls/RUN_test/setup.py @@ -5,7 +5,7 @@ def main(): trick.exec_set_job_onoff("the_object.stlc.test", 1, False) trick.exec_set_job_onoff("the_object.stlc.print", 1, False) - trick.add_read( 0.5, 'trick.checkpoint("chkpnt_in")') + trick.checkpoint(0.1) trick.exec_set_freeze_frame(0.10) trick.stop(1.0) diff --git a/test/SIM_stls/RUN_test/unit_test.py b/test/SIM_stls/RUN_test/unit_test.py index 16c31069f..05ce98843 100644 --- a/test/SIM_stls/RUN_test/unit_test.py +++ b/test/SIM_stls/RUN_test/unit_test.py @@ -3,7 +3,7 @@ def main(): - trick.load_checkpoint("RUN_test/chkpnt_in") + trick.load_checkpoint("RUN_test/chkpnt_0.100000") trick.load_checkpoint_job() trick.exec_set_job_onoff("the_object.stlc.addData", 1, False) diff --git a/trick_source/sim_services/CheckPointRestart/CheckPointRestart.cpp b/trick_source/sim_services/CheckPointRestart/CheckPointRestart.cpp index 002f12896..4c60d15e4 100644 --- a/trick_source/sim_services/CheckPointRestart/CheckPointRestart.cpp +++ b/trick_source/sim_services/CheckPointRestart/CheckPointRestart.cpp @@ -19,6 +19,7 @@ #include "trick/message_proto.h" #include "trick/message_type.h" #include "trick/TrickConstant.hh" +#include "trick/sim_mode.h" Trick::CheckPointRestart * the_cpr ; @@ -109,6 +110,11 @@ int Trick::CheckPointRestart::find_write_checkpoint_jobs(std::string sim_object_ return(0) ; } +/** + * @brief Schedule a checkpoint to be written at a given time. + * @param in_time The time the checkpoint should be dumped + * @see write_checkpoint() + */ int Trick::CheckPointRestart::checkpoint(double in_time) { long long curr_time = exec_get_time_tics() ; @@ -121,6 +127,8 @@ int Trick::CheckPointRestart::checkpoint(double in_time) { if ( new_time < write_checkpoint_job->next_tics ) { write_checkpoint_job->next_tics = new_time ; } + + the_exec->freeze(in_time); //std::cout << "\033[33mSET CHECKPOINT TIME " << in_time << " " << new_time << "\033[0m" << std::endl ; } else { message_publish(MSG_ERROR, "Checkpoint time specified in the past. specified %f, current_time %f\n", @@ -171,6 +179,19 @@ int Trick::CheckPointRestart::do_checkpoint(std::string file_name, bool print_st JobData * curr_job ; pid_t pid; + SIM_MODE mode; + + mode = the_exec->get_mode(); + + if (mode == Run) { + std::string msg_format = "WARNING: Saving a checkpoint outside of 'Freeze Mode' causes undefined behavior. "; + msg_format += "Current Mode: %s (%d)\n"; + message_publish(MSG_WARNING, msg_format.c_str(), + simModeCharString(mode), mode); + + return 0; + } + if ( ! file_name.compare("") ) { std::stringstream file_name_stream ; @@ -227,6 +248,10 @@ int Trick::CheckPointRestart::do_checkpoint(std::string file_name, bool print_st return 0 ; } +/** + * @brief Writes a scheduled checkpoint if it is the correct time. + * @see checkpoint(double in_time) + */ int Trick::CheckPointRestart::write_checkpoint() { long long curr_time = exec_get_time_tics() ; @@ -252,6 +277,7 @@ int Trick::CheckPointRestart::write_checkpoint() { checkpoint( chk_name_stream.str() ); + the_exec->run(); } return(0) ; @@ -293,6 +319,19 @@ int Trick::CheckPointRestart::safestore_checkpoint() { } void Trick::CheckPointRestart::load_checkpoint(std::string file_name) { + SIM_MODE mode = the_exec->get_mode(); + + if (mode == Run) { + std::string msg_format = "WARNING: Loading a checkpoint outside of 'Freeze Mode' causes undefined behavior. "; + msg_format += "Current Mode: %s (%d)\n"; + + message_publish(MSG_WARNING, msg_format.c_str(), + file_name.c_str(), simModeCharString(mode), mode); + + the_exec->freeze(); + auto_freeze = true; + } + load_checkpoint_file_name = file_name ; } @@ -306,7 +345,7 @@ int Trick::CheckPointRestart::load_checkpoint_job() { JobData * curr_job ; struct stat temp_buf ; - if ( ! load_checkpoint_file_name.empty() ) { + if ( ! load_checkpoint_file_name.empty() && the_exec->get_mode() != Run) { if ( stat( load_checkpoint_file_name.c_str() , &temp_buf) == 0 ) { preload_checkpoint_queue.reset_curr_index() ; @@ -338,6 +377,7 @@ int Trick::CheckPointRestart::load_checkpoint_job() { message_publish(MSG_INFO, "Could not find checkpoint file %s.\n", load_checkpoint_file_name.c_str()) ; } load_checkpoint_file_name.clear() ; + if(auto_freeze) the_exec->run(); } return(0) ; diff --git a/trick_source/sim_services/Executive/Executive_freeze_loop.cpp b/trick_source/sim_services/Executive/Executive_freeze_loop.cpp index 19d5ef4bd..77ead7416 100644 --- a/trick_source/sim_services/Executive/Executive_freeze_loop.cpp +++ b/trick_source/sim_services/Executive/Executive_freeze_loop.cpp @@ -4,10 +4,13 @@ #include "trick/Executive.hh" #include "trick/ExecutiveException.hh" +#include "trick/CheckPointRestart.hh" #include "trick/exec_proto.h" #include "trick/message_proto.h" #include "trick/message_type.h" +extern Trick::CheckPointRestart * the_cpr ; + /** @details -# Set the mode to Freeze. Requirement [@ref r_exec_mode_2] @@ -32,6 +35,10 @@ int Trick::Executive::freeze_loop() { } message_publish(MSG_INFO, "Freeze ON. Simulation time holding at %f seconds.\n" , get_sim_time()) ; + + if (!the_cpr->checkpoint_times.empty()) { + the_cpr->write_checkpoint(); + } while (mode == Freeze) { diff --git a/trick_source/sim_services/VariableServer/Makefile_deps b/trick_source/sim_services/VariableServer/Makefile_deps index 8d83bab4e..d585865ae 100644 --- a/trick_source/sim_services/VariableServer/Makefile_deps +++ b/trick_source/sim_services/VariableServer/Makefile_deps @@ -1,3 +1,6 @@ + +object_${TRICK_HOST_CPU}/simModeCharString.o: simModeCharString.c \ + ${TRICK_HOME}/include/trick/sim_mode.h object_${TRICK_HOST_CPU}/VariableServerSessionThread_loop.o: VariableServerSessionThread_loop.cpp \ ${TRICK_HOME}/include/trick/VariableServer.hh \ ${TRICK_HOME}/include/trick/tc.h \ diff --git a/trick_source/sim_services/VariableServer/simModeCharString.c b/trick_source/sim_services/VariableServer/simModeCharString.c new file mode 100644 index 000000000..0b193d1f9 --- /dev/null +++ b/trick_source/sim_services/VariableServer/simModeCharString.c @@ -0,0 +1,14 @@ + +#include "trick/sim_mode.h" + +const char * simModeCharString(SIM_MODE mode) { + switch (mode) + { + case Initialization: return "Initialization"; + case Run: return "Run"; + case Step: return "Step"; + case Freeze: return "Freeze"; + case ExitMode: return "ExitMode"; + default: return "InvalidMode"; + } +} \ No newline at end of file