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/test01/golden/test01.log | 25 +++++ .../communication/sc_export/test01/test01.cpp | 75 +++++++++++++++ .../sc_export/test02/golden/test02.log | 4 + .../communication/sc_export/test02/test02.cpp | 20 ++++ .../sc_export/test03/golden/test03.log | 4 + .../communication/sc_export/test03/test03.cpp | 86 +++++++++++++++++ .../sc_export/test04/golden/test04.log | 4 + .../communication/sc_export/test04/test04.cpp | 17 ++++ .../sc_export/test05/golden/test05.log | 51 ++++++++++ .../communication/sc_export/test05/test05.cpp | 106 +++++++++++++++++++++ 10 files changed, 392 insertions(+) create mode 100644 src/systemc/tests/systemc/communication/sc_export/test01/golden/test01.log create mode 100644 src/systemc/tests/systemc/communication/sc_export/test01/test01.cpp create mode 100644 src/systemc/tests/systemc/communication/sc_export/test02/golden/test02.log create mode 100644 src/systemc/tests/systemc/communication/sc_export/test02/test02.cpp 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 create mode 100644 src/systemc/tests/systemc/communication/sc_export/test04/golden/test04.log create mode 100644 src/systemc/tests/systemc/communication/sc_export/test04/test04.cpp create mode 100644 src/systemc/tests/systemc/communication/sc_export/test05/golden/test05.log create mode 100644 src/systemc/tests/systemc/communication/sc_export/test05/test05.cpp (limited to 'src/systemc/tests/systemc/communication/sc_export') diff --git a/src/systemc/tests/systemc/communication/sc_export/test01/golden/test01.log b/src/systemc/tests/systemc/communication/sc_export/test01/golden/test01.log new file mode 100644 index 000000000..19836dbfb --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_export/test01/golden/test01.log @@ -0,0 +1,25 @@ +SystemC Simulation +READ_LEAF: change 0 +TOP: change 0 +TOP: change 1 +READ_LEAF: change 1 +TOP: change 2 +READ_LEAF: change 2 +TOP: change 3 +READ_LEAF: change 3 +TOP: change 4 +READ_LEAF: change 4 +TOP: change 5 +READ_LEAF: change 5 +TOP: change 6 +READ_LEAF: change 6 +TOP: change 7 +READ_LEAF: change 7 +TOP: change 8 +READ_LEAF: change 8 +TOP: change 9 +READ_LEAF: change 9 +TOP: change 10 +READ_LEAF: change 10 +TOP: change 11 +READ_LEAF: change 11 diff --git a/src/systemc/tests/systemc/communication/sc_export/test01/test01.cpp b/src/systemc/tests/systemc/communication/sc_export/test01/test01.cpp new file mode 100644 index 000000000..9b2388421 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_export/test01/test01.cpp @@ -0,0 +1,75 @@ +#include "systemc.h" + +SC_MODULE(READ_LEAF) +{ + SC_CTOR(READ_LEAF) + { + SC_METHOD(delta); + sensitive << in; + } + void delta() + { + cout << "READ_LEAF: change " << (int)in->read() << endl; + } + sc_in > in; +}; + +SC_MODULE(WRITE_LEAF) +{ + SC_CTOR(WRITE_LEAF) : out("out"), clk("clk") + { + my_export(out); + SC_METHOD(sync) + sensitive << clk.pos(); + } + void sync() + { + out = out.read() + 1; + } + sc_signal > out; + sc_export > > my_export; + sc_in_clk clk; +}; + +SC_MODULE(MIDDLE) +{ + SC_CTOR(MIDDLE) : reader("reader"), writer("writer") + { + writer.clk(clk); // Bind clk going down the module hierarchy. + my_port(writer.my_export); // Bind my_port coming up the module hierarchy. + reader.in(my_port); // Bind my_port going down the module hierarchy. + } + sc_in_clk clk; + sc_export > > my_port; + READ_LEAF reader; + WRITE_LEAF writer; +}; + +SC_MODULE(TOP) +{ + SC_CTOR(TOP) : down("down") + { + down.clk(clk); // Bind clk going down the module hierarchy. + in(down.my_port); // Bind in coming up the module hierarchy. + SC_METHOD(delta); + sensitive << in; + } + void delta() + { + cout << "TOP: change " << (int)in.read() << endl; + } + sc_in_clk clk; + sc_in > in; + MIDDLE down; +}; + +int sc_main(int argc, char* arg[]) +{ + sc_clock clock; + TOP top("top"); + top.clk(clock); + + sc_start(10, SC_NS); + return 0; +} + diff --git a/src/systemc/tests/systemc/communication/sc_export/test02/golden/test02.log b/src/systemc/tests/systemc/communication/sc_export/test02/golden/test02.log new file mode 100644 index 000000000..b2a9f1c81 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_export/test02/golden/test02.log @@ -0,0 +1,4 @@ +SystemC Simulation + +Error: (E120) sc_export instance has no interface: x.export_1 +In file: diff --git a/src/systemc/tests/systemc/communication/sc_export/test02/test02.cpp b/src/systemc/tests/systemc/communication/sc_export/test02/test02.cpp new file mode 100644 index 000000000..f044fc741 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_export/test02/test02.cpp @@ -0,0 +1,20 @@ +#include "systemc.h" + +SC_MODULE(X) +{ + SC_CTOR(X) + { + a(b); + } + sc_export > a; + sc_export > b; +}; + +int sc_main(int argc, char* argv[]) +{ + sc_clock clock; + X x("x"); + + sc_start(1, SC_NS); + return 0; +} 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; +} diff --git a/src/systemc/tests/systemc/communication/sc_export/test04/golden/test04.log b/src/systemc/tests/systemc/communication/sc_export/test04/golden/test04.log new file mode 100644 index 000000000..df6df8478 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_export/test04/golden/test04.log @@ -0,0 +1,4 @@ +SystemC Simulation + +Error: (E109) complete binding failed: export not bound: export 'x.a' (sc_export) +In file: diff --git a/src/systemc/tests/systemc/communication/sc_export/test04/test04.cpp b/src/systemc/tests/systemc/communication/sc_export/test04/test04.cpp new file mode 100644 index 000000000..6a2b21421 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_export/test04/test04.cpp @@ -0,0 +1,17 @@ +#include "systemc.h" + +SC_MODULE(X) +{ + SC_CTOR(X) : a("a") + { + } + sc_export > a; +}; + +int sc_main(int argc, char* argv[]) +{ + X x("x"); + + sc_start(1, SC_NS); + return 0; +} diff --git a/src/systemc/tests/systemc/communication/sc_export/test05/golden/test05.log b/src/systemc/tests/systemc/communication/sc_export/test05/golden/test05.log new file mode 100644 index 000000000..a736ca05c --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_export/test05/golden/test05.log @@ -0,0 +1,51 @@ +SystemC Simulation +0 s: 0 +1 ns: 0 +2 ns: 0 +3 ns: 0 +4 ns: 1 +5 ns: 2 +6 ns: 3 +7 ns: 4 +8 ns: 5 +9 ns: 6 +10 ns: 7 +11 ns: 8 +12 ns: 9 +13 ns: 10 +14 ns: 11 +15 ns: 12 +16 ns: 13 +17 ns: 14 +18 ns: 15 +19 ns: 16 +20 ns: 17 +21 ns: 18 +22 ns: 19 +23 ns: 20 +24 ns: 21 +25 ns: 22 +26 ns: 23 +27 ns: 24 +28 ns: 25 +29 ns: 26 +30 ns: 27 +31 ns: 28 +32 ns: 29 +33 ns: 30 +34 ns: 31 +35 ns: 32 +36 ns: 33 +37 ns: 34 +38 ns: 35 +39 ns: 36 +40 ns: 37 +41 ns: 38 +42 ns: 39 +43 ns: 40 +44 ns: 41 +45 ns: 42 +46 ns: 43 +47 ns: 44 +48 ns: 45 +49 ns: 46 diff --git a/src/systemc/tests/systemc/communication/sc_export/test05/test05.cpp b/src/systemc/tests/systemc/communication/sc_export/test05/test05.cpp new file mode 100644 index 000000000..f1e38c862 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_export/test05/test05.cpp @@ -0,0 +1,106 @@ +#include "systemc.h" + +typedef sc_biguint<121> atom; // Value to be pipe delayed. + +//============================================================================== +// esc_dpipe - DELAY PIPELINE FOR AN ARBITRARY CLASS: +//============================================================================== +template +SC_MODULE(esc_dpipe) { + public: + typedef sc_export > in; // To pipe port type. + typedef sc_export > out; // From pipe port type. + + public: + SC_CTOR(esc_dpipe) + { + m_in(m_pipe[0]); + m_out(m_pipe[N-1]); + SC_METHOD(rachet); + sensitive << m_clk.pos(); + } + + protected: + void rachet() + { + for ( int i = N-1; i > 0; i-- ) + { + m_pipe[i].write(m_pipe[i-1].read()); + } + } + + public: + sc_in_clk m_clk; // Pipe synchronization. + in m_in; // Input to delay pipe. + out m_out; // Output from delay pipe. + + protected: + sc_signal m_pipe[N]; // Pipeline stages. +}; + + +// Testbench reader of values from the pipe: + +SC_MODULE(Reader) +{ + SC_CTOR(Reader) + { + SC_METHOD(extract) + sensitive << m_clk.pos(); + dont_initialize(); + } + + void extract() + { + cout << sc_time_stamp() << ": " << m_from_pipe.read() << endl; + } + + sc_in_clk m_clk; // Module synchronization. + sc_in m_from_pipe; // Output from delay pipe. +}; + + + +// Testbench writer of values to the pipe: + +SC_MODULE(Writer) +{ + SC_CTOR(Writer) + { + SC_METHOD(insert) + sensitive << m_clk.pos(); + m_counter = 0; + } + + void insert() + { + m_to_pipe.write(m_counter); + m_counter++; + } + + sc_in_clk m_clk; // Module synchronization. + atom m_counter; // Write value. + sc_inout m_to_pipe; // Input for delay pipe. +}; + +// Main program + +int sc_main(int argc, char* argv[]) +{ + sc_clock clock; + esc_dpipe delay("pipe"); + Reader reader("reader"); + Writer writer("writer"); + + delay.m_clk(clock); + + reader.m_clk(clock); + reader.m_from_pipe(delay.m_out); + + writer.m_clk(clock); + writer.m_to_pipe(delay.m_in); + + sc_start(50, SC_NS); + + return 0; +} -- cgit v1.2.3