From: Bobby R. Bruce Date: Tue, 22 Sep 2020 19:37:34 +0000 (-0700) Subject: python: Flush the simulation stdout/stderr buffers X-Git-Tag: v20.1.0.0~11 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=b715c2d513f43c1b717dd62c30ee5b1bdbde079c;p=gem5.git python: Flush the simulation stdout/stderr buffers Occasionally gem5's stdout/stderr, when run within the TestLib framework, will be shuffled. This is resolved by flushing the stdout/stderr buffer before and after simulation. In addition to this, the verifier.py has been improved to remove boilerplate gem5 code from the stdout comparison. Change-Id: I04c8f9cee4475b8eab2f1ba9bb76bfa3cfcca6ec Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/34995 Reviewed-by: Jason Lowe-Power Reviewed-by: Andreas Sandberg Maintainer: Jason Lowe-Power Maintainer: Andreas Sandberg Tested-by: kokoro --- diff --git a/src/python/m5/simulate.py b/src/python/m5/simulate.py index 698dfbc62..080d725a1 100644 --- a/src/python/m5/simulate.py +++ b/src/python/m5/simulate.py @@ -175,7 +175,15 @@ def simulate(*args, **kwargs): if _drain_manager.isDrained(): _drain_manager.resume() - return _m5.event.simulate(*args, **kwargs) + # We flush stdout and stderr before and after the simulation to ensure the + # output arrive in order. + sys.stdout.flush() + sys.stderr.flush() + sim_out = _m5.event.simulate(*args, **kwargs) + sys.stdout.flush() + sys.stderr.flush() + + return sim_out def drain(): """Drain the simulator in preparation of a checkpoint or memory mode diff --git a/tests/gem5/cpu_tests/ref/Bubblesort b/tests/gem5/cpu_tests/ref/Bubblesort index 79d2ae311..76f4de047 100644 --- a/tests/gem5/cpu_tests/ref/Bubblesort +++ b/tests/gem5/cpu_tests/ref/Bubblesort @@ -1,6 +1,2 @@ -gem5 Simulator System. http://gem5.org -gem5 is copyrighted software; use the --copyright option for details. - - Global frequency set at 1000000000000 ticks per second -50000 diff --git a/tests/gem5/cpu_tests/ref/FloatMM b/tests/gem5/cpu_tests/ref/FloatMM index 6539627a2..0f1d582ff 100644 --- a/tests/gem5/cpu_tests/ref/FloatMM +++ b/tests/gem5/cpu_tests/ref/FloatMM @@ -1,6 +1,2 @@ -gem5 Simulator System. http://gem5.org -gem5 is copyrighted software; use the --copyright option for details. - - Global frequency set at 1000000000000 ticks per second -776.000061 diff --git a/tests/gem5/dram-lowp/ref/simout b/tests/gem5/dram-lowp/ref/simout index 5128ab4f4..6fdcf8545 100644 --- a/tests/gem5/dram-lowp/ref/simout +++ b/tests/gem5/dram-lowp/ref/simout @@ -1,7 +1,3 @@ -gem5 Simulator System. http://gem5.org -gem5 is copyrighted software; use the --copyright option for details. - - Global frequency set at 1000000000000 ticks per second --- Done DRAM low power sweep --- Fixed params - diff --git a/tests/gem5/hello_se/ref/simout b/tests/gem5/hello_se/ref/simout index a38e2880d..9e8cf2779 100644 --- a/tests/gem5/hello_se/ref/simout +++ b/tests/gem5/hello_se/ref/simout @@ -1,7 +1,3 @@ -gem5 Simulator System. http://gem5.org -gem5 is copyrighted software; use the --copyright option for details. - - Global frequency set at 1000000000000 ticks per second **** REAL SIMULATION **** Hello world! diff --git a/tests/gem5/insttest_se/ref/sparc/linux/insttest/simout b/tests/gem5/insttest_se/ref/sparc/linux/insttest/simout index 466574666..81a0b927d 100644 --- a/tests/gem5/insttest_se/ref/sparc/linux/insttest/simout +++ b/tests/gem5/insttest_se/ref/sparc/linux/insttest/simout @@ -1,7 +1,3 @@ -gem5 Simulator System. http://gem5.org -gem5 is copyrighted software; use the --copyright option for details. - - Global frequency set at 1000000000000 ticks per second **** REAL SIMULATION **** Begining test of difficult SPARC instructions... diff --git a/tests/gem5/learning_gem5/ref/hello b/tests/gem5/learning_gem5/ref/hello index 0f0a7d63f..bcdd7b91e 100644 --- a/tests/gem5/learning_gem5/ref/hello +++ b/tests/gem5/learning_gem5/ref/hello @@ -1,7 +1,3 @@ -gem5 Simulator System. http://gem5.org -gem5 is copyrighted software; use the --copyright option for details. - - Global frequency set at 1000000000000 ticks per second Beginning simulation! Hello world! diff --git a/tests/gem5/learning_gem5/ref/hello_goodbye b/tests/gem5/learning_gem5/ref/hello_goodbye index 8e80377b2..cdaace8ce 100644 --- a/tests/gem5/learning_gem5/ref/hello_goodbye +++ b/tests/gem5/learning_gem5/ref/hello_goodbye @@ -1,7 +1,3 @@ -gem5 Simulator System. http://gem5.org -gem5 is copyrighted software; use the --copyright option for details. - - Global frequency set at 1000000000000 ticks per second Beginning simulation! Exiting @ tick 10944163 because Goodbye hello!! Goodbye hello!! Goodbye hello!! Goodbye hello!! Goodbye hello!! Goodbye hello!! Goo diff --git a/tests/gem5/learning_gem5/ref/simple b/tests/gem5/learning_gem5/ref/simple index b4c614a0c..71a3d6284 100644 --- a/tests/gem5/learning_gem5/ref/simple +++ b/tests/gem5/learning_gem5/ref/simple @@ -1,7 +1,3 @@ -gem5 Simulator System. http://gem5.org -gem5 is copyrighted software; use the --copyright option for details. - - Global frequency set at 1000000000000 ticks per second Hello World! From a SimObject! Beginning simulation! diff --git a/tests/gem5/learning_gem5/ref/test b/tests/gem5/learning_gem5/ref/test index 794ccdd20..309ac2fa4 100644 --- a/tests/gem5/learning_gem5/ref/test +++ b/tests/gem5/learning_gem5/ref/test @@ -1,7 +1,3 @@ -gem5 Simulator System. http://gem5.org -gem5 is copyrighted software; use the --copyright option for details. - - Global frequency set at 1000000000 ticks per second Beginning simulation! Exiting @ tick 9981 because Ruby Tester completed diff --git a/tests/gem5/learning_gem5/ref/threads b/tests/gem5/learning_gem5/ref/threads index 18a47fddb..841ad733f 100644 --- a/tests/gem5/learning_gem5/ref/threads +++ b/tests/gem5/learning_gem5/ref/threads @@ -1,7 +1,3 @@ -gem5 Simulator System. http://gem5.org -gem5 is copyrighted software; use the --copyright option for details. - - Global frequency set at 1000000000000 ticks per second Beginning simulation! Running on 2 cores. with 100 values diff --git a/tests/gem5/m5threads_test_atomic/ref/sparc64/simout b/tests/gem5/m5threads_test_atomic/ref/sparc64/simout index c6b51ca07..dbe1405e5 100644 --- a/tests/gem5/m5threads_test_atomic/ref/sparc64/simout +++ b/tests/gem5/m5threads_test_atomic/ref/sparc64/simout @@ -1,7 +1,3 @@ -gem5 Simulator System. http://gem5.org -gem5 is copyrighted software; use the --copyright option for details. - - Global frequency set at 1000000000000 ticks per second Init done [Iteration 1, Thread 1] Got lock diff --git a/tests/gem5/verifier.py b/tests/gem5/verifier.py index ba4bd4ff5..60d44f398 100644 --- a/tests/gem5/verifier.py +++ b/tests/gem5/verifier.py @@ -115,6 +115,9 @@ class DerivedGoldStandard(MatchGoldStandard): class MatchStdout(DerivedGoldStandard): _file = constants.gem5_simulation_stdout _default_ignore_regex = [ + re.compile('^\s+$'), # Remove blank lines. + re.compile('^gem5 Simulator System'), + re.compile('^gem5 is copyrighted software'), re.compile('^Redirecting (stdout|stderr) to'), re.compile('^gem5 version '), re.compile('^gem5 compiled '),