From 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 24 May 2018 01:37:55 -0700 Subject: systemc: Import tests from the Accellera systemc distribution. Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6 Reviewed-on: https://gem5-review.googlesource.com/10845 Reviewed-by: Giacomo Travaglini Maintainer: Gabe Black --- .../golden/stepwise_simulation.log | 42 ++++++ .../stepwise_simulation/stepwise_simulation.cpp | 165 +++++++++++++++++++++ 2 files changed, 207 insertions(+) create mode 100644 src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/golden/stepwise_simulation.log create mode 100644 src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/stepwise_simulation.cpp (limited to 'src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation') diff --git a/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/golden/stepwise_simulation.log b/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/golden/stepwise_simulation.log new file mode 100644 index 000000000..e16fcee9d --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/golden/stepwise_simulation.log @@ -0,0 +1,42 @@ +SystemC Simulation + ----- running for delta + -- stopped at - 0 s - delta: 0 + ----- running for 10 ns + --- No-op start (warning) - +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: + -- stopped at - 10 ns - delta: 0 + ----- running for delta +`echo.do_print' triggered at 10 ns - delta: 0 + -- stopped at - 10 ns - delta: 1 + ----- running for 5 ns + --- No-op start (warning) - +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: + -- stopped at - 15 ns - delta: 1 + ----- running for delta +`echo.do_print' triggered at 15 ns - delta: 1 + -- stopped at - 15 ns - delta: 2 + ----- running for delta +`echo.do_print' triggered at 15 ns - delta: 2 + -- stopped at - 15 ns - delta: 3 + ----- running for 5 ns + --- No-op start (warning) - +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: + -- stopped at - 20 ns - delta: 3 + ----- running for delta +`echo.do_print' triggered at 20 ns - delta: 3 + -- stopped at - 20 ns - delta: 4 + ----- running for 5 ns + --- No-op start (warning) - +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: + -- stopped at - 25 ns - delta: 4 + ----- running for delta +`echo.do_print' triggered at 25 ns - delta: 4 + -- stopped at - 25 ns - delta: 5 + ----- running for delta +`echo.do_print' triggered at 25 ns - delta: 5 + -- stopped at - 25 ns - delta: 6 +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/stepwise_simulation.cpp b/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/stepwise_simulation.cpp new file mode 100644 index 000000000..4a480e352 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/stepwise_simulation.cpp @@ -0,0 +1,165 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with the + License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing + permissions and limitations under the License. + + *****************************************************************************/ + +/***************************************************************************** + + stepwise_simulation.cpp -- Test step-wise simulation + + Original Author: Philipp A. Hartmann, OFFIS, 2011-01-21 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +#include + +const int num_events = 2; +const sc_time delay( 10, SC_NS ); + +//#define EXPLICIT_DELTA // should not modify the trace +#define DELAYED_EVENTS + +SC_MODULE(echo) +{ + sc_event ev[num_events]; + SC_CTOR(echo) + : self_trigger(3) + { + SC_METHOD(do_print); +# ifdef DELAYED_EVENTS + dont_initialize(); +# endif + for( int i=0; i 1 ) + next_trigger( delay/2 ); + else if( self_trigger == 1 ) + next_trigger( SC_ZERO_TIME ); + else + self_trigger = 3; + + } + int self_trigger; +}; + +void do_step( sc_time const & step ) +{ + sc_dt::uint64 delta = sc_delta_count(); + static bool start_delta = ( delta == 0 ) && ( step == SC_ZERO_TIME ); + std::cout + << " ----- running for " + << ( ( step == SC_ZERO_TIME ) ? "delta" : step.to_string() ) + << std::endl; + + sc_time start = sc_time_stamp(); + if( step > SC_ZERO_TIME ) + { + std::cout << " --- No-op start (warning) - "; + sc_start( step / 2, SC_EXIT_ON_STARVATION ); + sc_assert( start == sc_time_stamp() ); + + sc_start( step / 2, SC_RUN_TO_TIME ); + sc_assert( start + step / 2 == sc_time_stamp() ); + + sc_start( step / 2 ); // complete step + } + else + { + sc_start( SC_ZERO_TIME ); + } + sc_assert( start + step == sc_time_stamp() ); + + std::cout + << " -- stopped at - " + << sc_time_stamp() << " - delta: " << sc_delta_count() + << std::endl; + + // delta has only increased, when a delta has been run + sc_assert( sc_delta_count() + == delta + ( !start_delta && step == SC_ZERO_TIME ) ); + start_delta = false; +} + +int sc_main(int, char*[]) +{ + sc_assert( !sc_pending_activity() ); + sc_assert( sc_time_to_pending_activity() + == sc_max_time() - sc_time_stamp() ); + + sc_signal toggle("toggle"); + echo dut("echo"); + + // notify future events + for( int i=0; i SC_ZERO_TIME ); + + sc_assert( sc_pending_activity_at_future_time() + || sc_time_to_pending_activity() == SC_ZERO_TIME ); + + // run single (time) step + do_step( sc_time_to_pending_activity() ); + +# ifdef EXPLICIT_DELTA + // run remaining current deltas (optional) + while( sc_pending_activity_at_current_time() ) { + sc_assert( sc_time_to_pending_activity() == SC_ZERO_TIME ); + do_step( SC_ZERO_TIME ); + } +# endif // EXPLICIT_DELTA + } + + // force one empty evaluate (w/ non-empty update) + toggle.write( !toggle.read() ); + sc_assert( sc_pending_activity_at_current_time() ); + sc_start( SC_ZERO_TIME ); + + sc_assert( !sc_pending_activity() ); + sc_assert( sc_time_to_pending_activity() + == sc_max_time() - sc_time_stamp() ); + + std::cout << "Success" << std::endl; + return 0; +} -- cgit v1.2.3