summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/kernel/process_control/suspend_resume
diff options
context:
space:
mode:
Diffstat (limited to 'src/systemc/tests/systemc/kernel/process_control/suspend_resume')
-rw-r--r--src/systemc/tests/systemc/kernel/process_control/suspend_resume/test1/golden/test1.log30
-rw-r--r--src/systemc/tests/systemc/kernel/process_control/suspend_resume/test1/test1.cpp216
-rw-r--r--src/systemc/tests/systemc/kernel/process_control/suspend_resume/test2/golden/test2.log90
-rw-r--r--src/systemc/tests/systemc/kernel/process_control/suspend_resume/test2/test2.cpp237
4 files changed, 573 insertions, 0 deletions
diff --git a/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test1/golden/test1.log b/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test1/golden/test1.log
new file mode 100644
index 000000000..f32038842
--- /dev/null
+++ b/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test1/golden/test1.log
@@ -0,0 +1,30 @@
+SystemC Simulation
+0 s[0]: target_method0: starting
+0 s[0]: target_method0: issuing self suspend
+0 s[0]: target_method0: after issuing self suspend
+
+0 s[0]: target_thread0: starting
+0 s[0]: target_thread0: issuing self suspend
+
+0 s[1]: target_cthread0: starting
+0 s[1]: target_cthread0: issuing self suspend
+
+
+10 ns[21]: stimulator: resuming target_cthread0
+
+10 ns[21]: target_cthread0: back from self suspend
+
+20 ns[51]: stimulator: resuming target_method0
+
+20 ns[51]: target_method0: back from self suspend
+
+30 ns[81]: stimulator: resuming target_thread0
+
+30 ns[81]: target_thread0: back from self suspend
+109 ns[319]: target_cthread0: terminating
+110 ns[321]: target_thread0: terminating
+117 ns[343]: target_method0: terminating
+
+1030 ns[3081]: stimulator: terminating
+
+Info: /OSCI/SystemC: Simulation stopped by user.
diff --git a/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test1/test1.cpp b/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test1/test1.cpp
new file mode 100644
index 000000000..af361436b
--- /dev/null
+++ b/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test1/test1.cpp
@@ -0,0 +1,216 @@
+/*****************************************************************************
+
+ 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.
+
+ *****************************************************************************/
+
+//*****************************************************************************
+//
+// test01.cpp -- test self suspends on processes
+//
+// Original Author: Andy Goodrich, Forte Design Systems, Inc.
+//
+// CVS MODIFICATION LOG - modifiers, enter your name, affiliation, date and
+// changes you are making here.
+//
+// $Log: test1.cpp,v $
+// Revision 1.4 2011/04/02 00:07:44 acg
+// Andy Goodrich: new message format.
+//
+// Revision 1.3 2011/03/07 19:32:07 acg
+// Andy Goodrich: addition to set sc_core::sc_allow_process_control_corners
+// to true so that this test avoids corner case error messages.
+//
+// Revision 1.2 2009/07/28 18:43:50 acg
+// Andy Goodrich: new standard test bench version of this test.
+//
+// Revision 1.2 2009/07/28 01:09:48 acg
+// Andy Goodrich: replacement test using standardized environment.
+//
+//*****************************************************************************
+
+#define SC_INCLUDE_DYNAMIC_PROCESSES
+#include "systemc.h"
+
+enum my_process_states {
+ ST_DISABLED,
+ ST_NORMAL,
+ ST_SUSPENDED
+};
+
+inline ostream& time_stamp( ostream& os )
+{
+ os << dec << sc_time_stamp() << "[" << sc_delta_count() << "]: ";
+ return os;
+}
+
+SC_MODULE(top) {
+ // constructor:
+
+ SC_CTOR(top) :
+ m_state_cthread0(ST_NORMAL),
+ m_state_method0(ST_NORMAL),
+ m_state_thread0(ST_NORMAL)
+ {
+ SC_THREAD(stimulator0);
+
+ SC_CTHREAD( target_cthread0, m_clk.pos() );
+ m_target_cthread0 = sc_get_current_process_handle();
+
+ SC_METHOD(target_method0);
+ sensitive << m_clk.pos();
+ m_target_method0 = sc_get_current_process_handle();
+
+ SC_THREAD(target_thread0);
+ m_target_thread0 = sc_get_current_process_handle();
+ }
+
+ // processes:
+
+ void stimulator0();
+ void target_cthread0();
+ void target_method0();
+ void target_thread0();
+
+ // Storage:
+
+ sc_in<bool> m_clk;
+ int m_state_cthread0;
+ int m_state_method0;
+ int m_state_thread0;
+ sc_process_handle m_target_cthread0;
+ sc_process_handle m_target_method0;
+ sc_process_handle m_target_thread0;
+};
+
+void top::stimulator0()
+{
+ const char* name = "stimulator";
+ wait(10, SC_NS);
+ cout << endl;
+ time_stamp(cout) << name << ": resuming target_cthread0" << endl;
+ cout << endl;
+ m_state_cthread0 = ST_NORMAL;
+ m_target_cthread0.resume();
+ wait(10, SC_NS);
+
+ cout << endl;
+ time_stamp(cout) << name << ": resuming target_method0" << endl;
+ cout << endl;
+ m_state_method0 = ST_NORMAL;
+ m_target_method0.resume();
+ wait(10, SC_NS);
+
+ cout << endl;
+ time_stamp(cout) << name << ": resuming target_thread0" << endl;
+ cout << endl;
+ m_state_thread0 = ST_NORMAL;
+ m_target_thread0.resume();
+ ::sc_core::wait(1000, SC_NS);
+
+ cout << endl;
+ time_stamp(cout) << name << ": terminating" << endl;
+ sc_stop();
+}
+
+void top::target_cthread0()
+{
+ int i;
+ const char* name = "target_cthread0";
+
+ time_stamp(cout) << name << ": starting" << endl;
+ time_stamp(cout) << name << ": issuing self suspend" << endl;
+ cout << endl;
+ m_state_cthread0 = ST_SUSPENDED;
+ m_target_cthread0.suspend();
+ time_stamp(cout) << name << ": back from self suspend" << endl;
+ for ( i = 0; i < 100; i++ )
+ {
+ if ( m_state_cthread0 == ST_SUSPENDED )
+ {
+ time_stamp(cout) << name << ": ERROR should not see this" << endl;
+ }
+ wait();
+ }
+ time_stamp(cout) << name << ": terminating" << endl;
+}
+
+void top::target_method0()
+{
+ const char* name = "target_method0";
+ static int state = 0;
+ switch( state )
+ {
+ case 0:
+ time_stamp(cout) << name << ": starting" << endl;
+ time_stamp(cout) << name << ": issuing self suspend" << endl;
+ m_state_method0 = ST_SUSPENDED;
+ m_target_method0.suspend();
+ time_stamp(cout) << name << ": after issuing self suspend" << endl;
+ cout << endl;
+ break;
+ case 1:
+ time_stamp(cout) << name << ": back from self suspend" << endl;
+ // fall through
+ default:
+ if ( m_state_method0 == ST_SUSPENDED )
+ {
+ time_stamp(cout) << name << ": ERROR should not see this" << endl;
+ }
+ break;
+ case 99:
+ time_stamp(cout) << name << ": terminating" << endl;
+ break;
+ }
+ state++;
+}
+
+void top::target_thread0()
+{
+ const char* name = "target_thread0";
+
+ time_stamp(cout) << name << ": starting" << endl;
+ time_stamp(cout) << name << ": issuing self suspend" << endl;
+ cout << endl;
+ m_state_thread0 = ST_SUSPENDED;
+ m_target_thread0.suspend();
+ time_stamp(cout) << name << ": back from self suspend" << endl;
+
+ // We wait a long enough time that our event will not occur until
+ // after we are resumed. Otherwise this thread will just go away
+ // quietly when the suspend cancels the event.
+
+ ::sc_core::wait(80, SC_NS);
+ if ( m_state_thread0 == ST_SUSPENDED )
+ {
+ time_stamp(cout) << name << ": ERROR should not see this" << endl;
+ }
+ time_stamp(cout) << name << ": terminating" << endl;
+}
+
+int sc_main (int argc, char *argv[])
+{
+ sc_core::sc_allow_process_control_corners = true;
+ sc_clock clock( "clock", 1.0, SC_NS );
+
+ top* top_p = new top("top");
+ top_p->m_clk(clock);
+
+ sc_core::sc_allow_process_control_corners = true;
+ sc_start();
+ return 0;
+}
+
diff --git a/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test2/golden/test2.log b/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test2/golden/test2.log
new file mode 100644
index 000000000..64627e16a
--- /dev/null
+++ b/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test2/golden/test2.log
@@ -0,0 +1,90 @@
+SystemC Simulation
+0 s[0]: target_method0: starting
+0 s[0]: target_thread0: starting
+0 s[1]: target_method0: active
+0 s[1]: target_cthread0: starting
+1 ns[3]: target_thread0: active
+
+2 ns[4]: stimulator: suspending target_cthread0
+
+2 ns[5]: target_method0: active
+3 ns[7]: target_thread0: active
+4 ns[9]: target_method0: active
+
+5 ns[10]: stimulator: suspending target_method0
+
+5 ns[11]: target_thread0: active
+7 ns[14]: target_thread0: active
+
+8 ns[15]: stimulator: suspending target_thread0
+
+
+11 ns[18]: stimulator: resuming target_cthread0
+
+11 ns[18]: target_cthread0: active
+12 ns[20]: target_cthread0: active
+
+14 ns[22]: stimulator: resuming target_method0
+
+14 ns[22]: target_method0: active
+14 ns[23]: target_method0: active
+14 ns[23]: target_cthread0: active
+16 ns[26]: target_method0: active
+16 ns[26]: target_cthread0: active
+
+17 ns[27]: stimulator: resuming target_thread0
+
+17 ns[27]: target_thread0: active
+17 ns[28]: target_thread0: active
+18 ns[30]: target_method0: active
+18 ns[30]: target_cthread0: active
+19 ns[32]: target_thread0: active
+
+20 ns[33]: stimulator: suspending target_cthread0
+
+20 ns[34]: target_method0: active
+21 ns[36]: target_thread0: active
+22 ns[38]: target_method0: active
+
+23 ns[39]: stimulator: suspending target_method0
+
+23 ns[40]: target_thread0: active
+25 ns[43]: target_thread0: active
+
+26 ns[44]: stimulator: suspending target_thread0
+
+
+29 ns[47]: stimulator: resuming target_cthread0
+
+29 ns[47]: target_cthread0: active
+30 ns[49]: target_cthread0: active
+
+32 ns[51]: stimulator: resuming target_method0
+
+32 ns[51]: target_method0: active
+32 ns[52]: target_method0: active
+32 ns[52]: target_cthread0: active
+34 ns[55]: target_method0: active
+34 ns[55]: target_cthread0: active
+
+35 ns[56]: stimulator: resuming target_thread0
+
+35 ns[56]: target_thread0: active
+35 ns[57]: target_thread0: active
+35 ns[57]: target_thread0: terminating
+36 ns[59]: target_method0: active
+36 ns[59]: target_cthread0: active
+38 ns[62]: target_method0: active
+38 ns[62]: target_cthread0: active
+40 ns[65]: target_method0: active
+40 ns[65]: target_cthread0: active
+40 ns[65]: target_cthread0: terminating
+42 ns[68]: target_method0: active
+44 ns[71]: target_method0: active
+46 ns[74]: target_method0: active
+48 ns[77]: target_method0: active
+52 ns[83]: target_method0: terminating
+
+1038 ns[1561]: stimulator: terminating
+
+Info: /OSCI/SystemC: Simulation stopped by user.
diff --git a/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test2/test2.cpp b/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test2/test2.cpp
new file mode 100644
index 000000000..2e4f8997b
--- /dev/null
+++ b/src/systemc/tests/systemc/kernel/process_control/suspend_resume/test2/test2.cpp
@@ -0,0 +1,237 @@
+/*****************************************************************************
+
+ 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.
+
+ *****************************************************************************/
+
+//*****************************************************************************
+//
+// test02.cpp -- test that suspended processes with static sensitivity
+// wake up when resumed.
+//
+// Original Author: Andy Goodrich, Forte Design Systems, Inc.
+//
+// CVS MODIFICATION LOG - modifiers, enter your name, affiliation, date and
+// changes you are making here.
+//
+// $Log: test2.cpp,v $
+// Revision 1.5 2011/04/02 00:08:19 acg
+// Andy Goodrich: turn off corner case error checking.
+//
+// Revision 1.4 2011/03/07 19:32:09 acg
+// Andy Goodrich: addition to set sc_core::sc_allow_process_control_corners
+// to true so that this test avoids corner case error messages.
+//
+// Revision 1.3 2011/02/20 13:43:49 acg
+// Andy Goodrich: updates for IEEE 1666 2011.
+//
+// Revision 1.2 2011/02/04 15:26:52 acg
+// Andy Goodrich: changes for process control semantics.
+//
+// Revision 1.1 2009/07/28 18:43:55 acg
+// Andy Goodrich: new standard test bench version of this test.
+//
+//*****************************************************************************
+
+#define SC_INCLUDE_DYNAMIC_PROCESSES
+#include "systemc.h"
+
+enum my_process_states {
+ ST_SUSPENDD,
+ ST_NORMAL,
+ ST_SUSPENDED
+};
+
+inline ostream& time_stamp( ostream& os )
+{
+ os << dec << sc_time_stamp() << "[" << sc_delta_count() << "]: ";
+ return os;
+}
+
+SC_MODULE(top) {
+ // constructor:
+
+ SC_CTOR(top)
+ {
+ m_state_cthread0 = ST_NORMAL;
+ m_state_method0 = ST_NORMAL;
+ m_state_thread0 = ST_NORMAL;
+
+ SC_THREAD(stimulator0);
+
+ SC_CTHREAD( target_cthread0, m_clk.pos() );
+ m_target_cthread0 = sc_get_current_process_handle();
+
+ SC_METHOD(target_method0);
+ sensitive << m_clk.pos();
+ m_target_method0 = sc_get_current_process_handle();
+
+ SC_THREAD(target_thread0);
+ sensitive << m_clk.neg();
+ m_target_thread0 = sc_get_current_process_handle();
+ }
+
+ // processes:
+
+ void stimulator0();
+ void target_cthread0();
+ void target_method0();
+ void target_thread0();
+
+ // Storage:
+
+ sc_in<bool> m_clk;
+ int m_state_cthread0;
+ int m_state_method0;
+ int m_state_thread0;
+ sc_process_handle m_target_cthread0;
+ sc_process_handle m_target_method0;
+ sc_process_handle m_target_thread0;
+};
+
+#define SUSPEND(TARGET) \
+ cout << endl; \
+ time_stamp(cout) << name << ": suspending target_" << #TARGET << endl; \
+ m_state_##TARGET = ST_SUSPENDD; \
+ m_target_##TARGET.suspend(); \
+ cout << endl;
+
+#define RESUME(TARGET) \
+ cout << endl; \
+ time_stamp(cout) << name << ": resuming target_" << #TARGET << endl; \
+ m_state_##TARGET = ST_NORMAL; \
+ m_target_##TARGET.resume(); \
+ cout << endl;
+
+void top::stimulator0()
+{
+ const char* name = "stimulator";
+
+ wait(2, SC_NS);
+
+ SUSPEND(cthread0)
+ wait(3, SC_NS);
+ SUSPEND(method0)
+ wait(3, SC_NS);
+ SUSPEND(thread0)
+ wait(3, SC_NS);
+
+ RESUME(cthread0)
+ wait(3, SC_NS);
+ RESUME(method0)
+ wait(3, SC_NS);
+ RESUME(thread0)
+ wait(3, SC_NS);
+
+ SUSPEND(cthread0)
+ wait(3, SC_NS);
+ SUSPEND(method0)
+ wait(3, SC_NS);
+ SUSPEND(thread0)
+ wait(3, SC_NS);
+
+ RESUME(cthread0)
+ wait(3, SC_NS);
+ RESUME(method0)
+ wait(3, SC_NS);
+ RESUME(thread0)
+ wait(3, SC_NS);
+
+ ::sc_core::wait(1000, SC_NS);
+ cout << endl;
+ time_stamp(cout) << name << ": terminating" << endl;
+ sc_stop();
+}
+
+void top::target_cthread0()
+{
+ const char* name = "target_cthread0";
+
+ time_stamp(cout) << name << ": starting" << endl;
+ for (int i = 0; i < 12; i++)
+ {
+ wait();
+ if ( m_state_cthread0 == ST_SUSPENDD )
+ {
+ time_stamp(cout) << name << ": ERROR should not see this" << endl;
+ }
+ else
+ {
+ time_stamp(cout) << name << ": active" << endl;
+ }
+ }
+ time_stamp(cout) << name << ": terminating" << endl;
+}
+
+void top::target_method0()
+{
+ const char* name = "target_method0";
+ static int state = 0;
+ switch( state )
+ {
+ case 0:
+ time_stamp(cout) << name << ": starting" << endl;
+ break;
+ default:
+ if ( m_state_method0 == ST_SUSPENDD )
+ {
+ time_stamp(cout) << name << ": ERROR should not see this" << endl;
+ }
+ else if ( state < 20 )
+ {
+ time_stamp(cout) << name << ": active" << endl;
+ }
+ break;
+ case 21:
+ time_stamp(cout) << name << ": terminating" << endl;
+ break;
+ }
+ state++;
+}
+
+void top::target_thread0()
+{
+ const char* name = "target_thread0";
+
+ time_stamp(cout) << name << ": starting" << endl;
+ for (int i = 0; i < 12; i++)
+ {
+ wait();
+ if ( m_state_thread0 == ST_SUSPENDD )
+ {
+ time_stamp(cout) << name << ": ERROR should not see this" << endl;
+ }
+ else
+ {
+ time_stamp(cout) << name << ": active" << endl;
+ }
+ }
+ time_stamp(cout) << name << ": terminating" << endl;
+}
+
+int sc_main (int argc, char *argv[])
+{
+ sc_core::sc_allow_process_control_corners = true;
+ sc_clock clock( "clock", 2.0, SC_NS );
+
+ top* top_p = new top("top");
+ top_p->m_clk(clock);
+
+ sc_core::sc_allow_process_control_corners = true;
+ sc_start();
+ return 0;
+}
+