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 --- .../sc_export/test03/golden/test03.log | 4 + .../communication/sc_export/test03/test03.cpp | 86 ++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 src/systemc/tests/systemc/communication/sc_export/test03/golden/test03.log create mode 100644 src/systemc/tests/systemc/communication/sc_export/test03/test03.cpp (limited to 'src/systemc/tests/systemc/communication/sc_export/test03') diff --git a/src/systemc/tests/systemc/communication/sc_export/test03/golden/test03.log b/src/systemc/tests/systemc/communication/sc_export/test03/golden/test03.log new file mode 100644 index 000000000..3de4cda83 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_export/test03/golden/test03.log @@ -0,0 +1,4 @@ +SystemC Simulation +10 ns In Channel run() +17 ns In Channel run() +20 ns In Channel run() diff --git a/src/systemc/tests/systemc/communication/sc_export/test03/test03.cpp b/src/systemc/tests/systemc/communication/sc_export/test03/test03.cpp new file mode 100644 index 000000000..9da2e4934 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_export/test03/test03.cpp @@ -0,0 +1,86 @@ +#include "systemc.h" + +// Interface +class C_if : virtual public sc_interface +{ +public: + virtual void run() = 0; +}; + +// Channel +class C : public C_if, public sc_channel +{ +public: + SC_CTOR(C) { } + virtual void run() + { + cout << sc_time_stamp() << " In Channel run() " << endl; + } +}; + +// --- D: export channel C through IFP -------- +SC_MODULE( D ) +{ + sc_export IFP; + + SC_CTOR( D ) + : IFP("IFP"), // explicit name + m_C("C") + { + IFP( m_C ); // bind sc_export->interface by name + } + private: + C m_C; // channel +}; + +// --- E: module with two interface-ports --- +SC_MODULE( E ) +{ + private: + C m_C; + D m_D; + + public: + sc_export IFP1; + sc_export IFP2; + + SC_CTOR( E ) + : m_C("C"), + m_D("D"), + IFP1("IFP1") + { + IFP1( m_C ); + IFP2( m_D.IFP ); // bind sc_export->sc_export by name + IFP1.get_interface(); // just to see whether it compiles + } +}; + +// Module X connected to the channels through E +SC_MODULE( X ) +{ + sc_port P1; + sc_port P2; + SC_CTOR(X) { + SC_THREAD(run); + } + void run() { + wait(10, SC_NS); + P1->run(); + wait(10, SC_NS); + P2->run(); + } +}; + +int sc_main(int argc, char** argv) { + E the_E("E"); + X the_X("X"); + // port->IFP + the_X.P1( the_E.IFP1 ); + the_X.P2( the_E.IFP2 ); + + sc_start(17, SC_NS); + the_E.IFP1->run(); // testing the operator-> of sc_export + sc_start(50, SC_NS); + + return 0; +} -- cgit v1.2.3