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 --- .../odds_and_ends/golden/odds_and_ends.log | 35 ++++ .../odds_and_ends/odds_and_ends.cpp | 207 +++++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 src/systemc/tests/systemc/1666-2011-compliance/odds_and_ends/golden/odds_and_ends.log create mode 100644 src/systemc/tests/systemc/1666-2011-compliance/odds_and_ends/odds_and_ends.cpp (limited to 'src/systemc/tests/systemc/1666-2011-compliance/odds_and_ends') diff --git a/src/systemc/tests/systemc/1666-2011-compliance/odds_and_ends/golden/odds_and_ends.log b/src/systemc/tests/systemc/1666-2011-compliance/odds_and_ends/golden/odds_and_ends.log new file mode 100644 index 000000000..bb048354f --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/odds_and_ends/golden/odds_and_ends.log @@ -0,0 +1,35 @@ +SystemC Simulation +task1 or task2 completed +task1 or task2 completed +T2 at 10 ns +T2 at 20 ns +suspend at 25 ns +resume at 45 ns +T2 at 45 ns +T2 at 50 ns +T2 at 60 ns +disable at 65 ns +enable at 85 ns +T2 at 90 ns +T2 at 100 ns +reset_handler() called at 105 ns +T2 at 110 ns +T2 at 120 ns +kill_handler() called at 125 ns +Reentering sc_start at 145 ns +Reentering sc_start at 150 ns +Reentering sc_start at 150 ns +Reentering sc_start at 160 ns +Reentering sc_start at 160 ns +Reentering sc_start at 170 ns +Reentering sc_start at 170 ns +Reentering sc_start at 180 ns +Reentering sc_start at 180 ns +Reentering sc_start at 190 ns +Reentering sc_start at 190 ns +Reentering sc_start at 195 ns + +Info: /OSCI/SystemC: Simulation stopped by user. +sc_max_time() = 18446744073709551615 ps + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/odds_and_ends/odds_and_ends.cpp b/src/systemc/tests/systemc/1666-2011-compliance/odds_and_ends/odds_and_ends.cpp new file mode 100644 index 000000000..aac544b1b --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/odds_and_ends/odds_and_ends.cpp @@ -0,0 +1,207 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// odds_and_ends.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: odds_and_ends.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Quick test of new features in 1666-2011 + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include +using namespace sc_core; +using std::cout; +using std::endl; + +SC_MODULE(Top) +{ + SC_CTOR(Top) + { + SC_THREAD(gen); + SC_THREAD(T1); + h1 = sc_get_current_process_handle(); + SC_THREAD(T2); + h2 = sc_get_current_process_handle(); + + // Complete for mutex + SC_THREAD(task1); + SC_THREAD(task2); + + SC_METHOD(reset_handler); + dont_initialize(); + sensitive << h2.reset_event(); + + SC_METHOD(kill_handler); + dont_initialize(); + sensitive << h2.terminated_event(); + + SC_THREAD(T3); + + end_of_T1 = end_of_T3 = T3A_called = T3B_called = false; + } + + sc_event ev; + + sc_process_handle h1, h2; + bool end_of_T1, end_of_T3; + + void gen() + { + for (;;) + { + wait(10, SC_NS); + ev.notify(); + } + } + + void T1() + { + wait(25, SC_NS); + cout << "suspend at " << sc_time_stamp() << endl; + h2.suspend(); + wait(20, SC_NS); + cout << "resume at " << sc_time_stamp() << endl; + h2.resume(); + wait(20, SC_NS); + + cout << "disable at " << sc_time_stamp() << endl; + h2.disable(); + wait(20, SC_NS); + cout << "enable at " << sc_time_stamp() << endl; + h2.enable(); + wait(20, SC_NS); + + h2.reset(); + wait(20, SC_NS); + + h2.kill(); + wait(20, SC_NS); + + sc_pause(); + wait(50, SC_NS); + sc_stop(); + end_of_T1 = true; + } + + void T2() + { + for (;;) + { + wait(ev); + cout << "T2 at " << sc_time_stamp() << endl; + } + } + + void task1() + { + resource(); + sc_assert( sc_time_stamp() == sc_time(10, SC_NS) || sc_time_stamp() == sc_time(20, SC_NS) ); + cout << "task1 or task2 completed" << endl; + } + + void task2() + { + resource(); + sc_assert( sc_time_stamp() == sc_time(10, SC_NS) || sc_time_stamp() == sc_time(20, SC_NS) ); + cout << "task1 or task2 completed" << endl; + } + + void resource() + { + sc_mutex mut; + mut.lock(); + wait(10, SC_NS); + mut.unlock(); + } + + void reset_handler() + { + cout << "reset_handler() called at " << sc_time_stamp() << endl; + sc_assert( sc_time_stamp() == sc_time(105, SC_NS) ); + sc_assert( !sc_is_unwinding() ); + } + + void kill_handler() + { + cout << "kill_handler() called at " << sc_time_stamp() << endl; + sc_assert( sc_time_stamp() == sc_time(125, SC_NS) ); + sc_assert( !sc_is_unwinding() ); + } + + void T3() + { + wait(10, SC_NS); + SC_FORK + t3a = sc_spawn(sc_bind( &Top::T3A, this)), + t3b = sc_spawn(sc_bind( &Top::T3B, this)) + SC_JOIN + if (t3a.valid()) sc_assert( t3a.terminated() ); + if (t3b.valid()) sc_assert( t3b.terminated() ); + end_of_T3 = true; + } + + sc_process_handle t3a, t3b; + bool T3A_called; + bool T3B_called; + + void T3A() + { + sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); + wait(5, SC_NS); + T3A_called = true; + } + + void T3B() + { + sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); + wait(7, SC_NS); + T3B_called = true; + } +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + sc_start(); + + while (sc_pending_activity() && sc_get_status() != SC_STOPPED) + { + cout << "Reentering sc_start at " << sc_time_stamp() << endl; + sc_start(sc_time_to_pending_activity()); + } + + cout << "sc_max_time() = " << sc_max_time() << endl; + sc_assert( sc_get_status() == SC_STOPPED ); + + sc_assert( top.end_of_T1 ); + sc_assert( top.end_of_T3 ); + sc_assert( top.T3A_called ); + sc_assert( top.T3B_called ); + + cout << endl << "Success" << endl; + return 0; +} -- cgit v1.2.3