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 --- .../check_writer/test15/golden/test15.log | 167 ++++++++++++++++++++ .../sc_signal/check_writer/test15/test15.cpp | 175 +++++++++++++++++++++ 2 files changed, 342 insertions(+) create mode 100644 src/systemc/tests/systemc/communication/sc_signal/check_writer/test15/golden/test15.log create mode 100644 src/systemc/tests/systemc/communication/sc_signal/check_writer/test15/test15.cpp (limited to 'src/systemc/tests/systemc/communication/sc_signal/check_writer/test15') diff --git a/src/systemc/tests/systemc/communication/sc_signal/check_writer/test15/golden/test15.log b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test15/golden/test15.log new file mode 100644 index 000000000..0a9ea351f --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test15/golden/test15.log @@ -0,0 +1,167 @@ +SystemC Simulation + +*** trigger each driver in individual delta cycles + dut.p1: 1 ns @ 1: writing dut.sig = 1 + dut.run: 1 ns @ 2: reading dut.sig = 1 + dut.p2: 1 ns @ 2: writing dut.sig = 2 + dut.run: 1 ns @ 3: reading dut.sig = 2 + dut.p3: 1 ns @ 3: writing dut.sig = 3 + dut.run: 1 ns @ 4: reading dut.sig = 3 + dut.p4: 1 ns @ 4: writing dut.sig = 1 + dut.run: 1 ns @ 5: reading dut.sig = 1 + +*** trigger 1-2-3 in the same delta cycle + dut.p1: 2 ns @ 6: writing dut.sig = 1 + dut.p2: 2 ns @ 6: writing dut.sig = 2 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p1' (sc_method_process) + second driver `dut.p2' (sc_method_process) + conflicting write in delta cycle 6 +In file: +In process: dut.p2 @ 2 ns + + dut.p3: 2 ns @ 6: writing dut.sig = 3 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p1' (sc_method_process) + second driver `dut.p3' (sc_method_process) + conflicting write in delta cycle 6 +In file: +In process: dut.p3 @ 2 ns + + dut.run: 2 ns @ 7: reading dut.sig = 1 + +*** trigger 2-3-1 in the same delta cycle + dut.p2: 3 ns @ 8: writing dut.sig = 2 + dut.p3: 3 ns @ 8: writing dut.sig = 3 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p2' (sc_method_process) + second driver `dut.p3' (sc_method_process) + conflicting write in delta cycle 8 +In file: +In process: dut.p3 @ 3 ns + + dut.p1: 3 ns @ 8: writing dut.sig = 1 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p2' (sc_method_process) + second driver `dut.p1' (sc_method_process) + conflicting write in delta cycle 8 +In file: +In process: dut.p1 @ 3 ns + + dut.run: 3 ns @ 9: reading dut.sig = 2 + +*** trigger 3-1-2 in the same delta cycle + dut.p3: 4 ns @ 10: writing dut.sig = 3 + dut.p1: 4 ns @ 10: writing dut.sig = 1 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p3' (sc_method_process) + second driver `dut.p1' (sc_method_process) + conflicting write in delta cycle 10 +In file: +In process: dut.p1 @ 4 ns + + dut.p2: 4 ns @ 10: writing dut.sig = 2 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p3' (sc_method_process) + second driver `dut.p2' (sc_method_process) + conflicting write in delta cycle 10 +In file: +In process: dut.p2 @ 4 ns + + dut.run: 4 ns @ 11: reading dut.sig = 3 + +*** trigger 1-2-1-2 in the same delta cycle + dut.p1: 5 ns @ 12: writing dut.sig = 1 + dut.p2: 5 ns @ 12: writing dut.sig = 2 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p1' (sc_method_process) + second driver `dut.p2' (sc_method_process) + conflicting write in delta cycle 12 +In file: +In process: dut.p2 @ 5 ns + + dut.p1: 5 ns @ 12: writing dut.sig = 1 + dut.p2: 5 ns @ 12: writing dut.sig = 2 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p1' (sc_method_process) + second driver `dut.p2' (sc_method_process) + conflicting write in delta cycle 12 +In file: +In process: dut.p2 @ 5 ns + + dut.run: 5 ns @ 13: reading dut.sig = 1 + +*** trigger 2-1 in the same delta cycle + dut.p2: 6 ns @ 14: writing dut.sig = 2 + dut.p1: 6 ns @ 14: writing dut.sig = 1 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p2' (sc_method_process) + second driver `dut.p1' (sc_method_process) + conflicting write in delta cycle 14 +In file: +In process: dut.p1 @ 6 ns + + dut.run: 6 ns @ 15: reading dut.sig = 2 + +*** trigger 1-3 in the same delta cycle + dut.p1: 7 ns @ 16: writing dut.sig = 1 + dut.p3: 7 ns @ 16: writing dut.sig = 3 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p1' (sc_method_process) + second driver `dut.p3' (sc_method_process) + conflicting write in delta cycle 16 +In file: +In process: dut.p3 @ 7 ns + + dut.run: 7 ns @ 17: reading dut.sig = 1 + +*** trigger 1-4-1 in the same delta cycle + dut.p1: 8 ns @ 18: writing dut.sig = 1 + dut.p4: 8 ns @ 18: writing dut.sig = 1 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p1' (sc_method_process) + second driver `dut.p4' (sc_method_process) + conflicting write in delta cycle 18 +In file: +In process: dut.p4 @ 8 ns + + dut.p1: 8 ns @ 18: writing dut.sig = 1 + dut.run: 8 ns @ 19: reading dut.sig = 1 + +*** trigger 4-1 in the same delta cycle + dut.p4: 9 ns @ 20: writing dut.sig = 1 + dut.p1: 9 ns @ 20: writing dut.sig = 1 + +Error: (E115) sc_signal cannot have more than one driver: + signal `dut.sig' (sc_signal) + first driver `dut.p4' (sc_method_process) + second driver `dut.p1' (sc_method_process) + conflicting write in delta cycle 20 +In file: +In process: dut.p1 @ 9 ns + + dut.run: 9 ns @ 21: reading dut.sig = 1 + +Program completed diff --git a/src/systemc/tests/systemc/communication/sc_signal/check_writer/test15/test15.cpp b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test15/test15.cpp new file mode 100644 index 000000000..1719abe87 --- /dev/null +++ b/src/systemc/tests/systemc/communication/sc_signal/check_writer/test15/test15.cpp @@ -0,0 +1,175 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + test15.cpp -- sc_writer_policy: check conflicts within an evaluation phase + + Original Author: Philipp A. Hartmann, Intel, 2017-05-12 + + *****************************************************************************/ + +// see https://github.com/OSCI-WG/systemc/issues/222 + +#define SC_INCLUDE_DYNAMIC_PROCESSES +#include +#include +#include + +using sc_core::SC_NS; +using sc_core::SC_ZERO_TIME; + +SC_MODULE(dut) +{ + static const int num_drivers = 4; + + SC_CTOR(dut) + : sig("sig") + { + SC_THREAD(run); + for(int id=1; id <= num_drivers; ++id) { + // first and last driver write the same values + spawn_driver( id, (id-1) % (num_drivers-1) + 1 ); + } + } + +private: + void spawn_driver(int id, int value) { + sc_assert( id > 0 && id <= num_drivers ); + sc_core::sc_spawn_options sp; + sp.set_sensitivity(&ev[id-1]); + sp.spawn_method(); + sp.dont_initialize(); + + std::stringstream nm; + nm << "p" << id; + sc_spawn( sc_bind(&dut::driver, this, value), nm.str().c_str(), &sp ); + } + + void run() { + wait(1, SC_NS); + + std::cout << "\n*** trigger each driver in individual delta cycles" << std::endl; + for(int id=1; id <= num_drivers; ++id) { + trigger(id); + wait(SC_ZERO_TIME); + log(); + } + + wait(1, SC_NS); + std::cout << "\n*** trigger 1-2-3 in the same delta cycle" << std::endl; + trigger(1); + trigger(2); // error expected + trigger(3); // error expected + wait(SC_ZERO_TIME); + log(); + + wait(1, SC_NS); + std::cout << "\n*** trigger 2-3-1 in the same delta cycle" << std::endl; + trigger(2); + trigger(3); // error expected + trigger(1); // error expected + wait(SC_ZERO_TIME); + log(); + + wait(1, SC_NS); + std::cout << "\n*** trigger 3-1-2 in the same delta cycle" << std::endl; + trigger(3); + trigger(1); // error expected + trigger(2); // error expected + wait(SC_ZERO_TIME); + log(); + + wait(1, SC_NS); + std::cout << "\n*** trigger 1-2-1-2 in the same delta cycle" << std::endl; + trigger(1); + trigger(2); // error expected + trigger(1); // NO error expected (original process) + trigger(2); // error expected + wait(SC_ZERO_TIME); + log(); + + wait(1, SC_NS); + std::cout << "\n*** trigger 2-1 in the same delta cycle" << std::endl; + trigger(2); + trigger(1); // error expected + wait(SC_ZERO_TIME); + log(); + + wait(1, SC_NS); + std::cout << "\n*** trigger 1-3 in the same delta cycle" << std::endl; + trigger(1); + trigger(3); // error expected + wait(SC_ZERO_TIME); + log(); + + wait(1, SC_NS); + std::cout << "\n*** trigger 1-4-1 in the same delta cycle" << std::endl; + trigger(1); + trigger(4); // error expected? (same value) + trigger(1); // NO error expected (original process) + wait(SC_ZERO_TIME); + log(); + + wait(1, SC_NS); + std::cout << "\n*** trigger 4-1 in the same delta cycle" << std::endl; + trigger(4); + trigger(1); // error expected? (same value) + wait(SC_ZERO_TIME); + log(); + } + + void trigger(int id) { + sc_assert( id > 0 && id <= num_drivers ); + ev[id-1].notify(); + wait(ev_schedule); + } + + void driver(int value) { + log(value); + try { + sig.write(value); + } catch (const sc_core::sc_report& msg ) { + std::cout << "\n" << msg.what() << "\n" << std::endl; + } + ev_schedule.notify(); + } + + void log(int value = -1) { + std::cout + << std::setw(8) << sc_core::sc_get_current_process_handle().name() << ": " + << std::setw(5) << sc_core::sc_time_stamp() + << " @ " << std::setw(2) << sc_core::sc_delta_count() << ": " + << ( (value!=-1) ? "writing " : "reading " ) + << sig.name() << " = " + << ( (value!=-1) ? value : sig.read() ) + << std::endl; + } + + sc_core::sc_signal sig; + sc_core::sc_event ev_schedule, ev[num_drivers]; +}; + +int sc_main( int, char*[] ) +{ + dut top("dut"); + sc_core::sc_start(); + std::cout << "\nProgram completed" << std::endl; + return 0; +} -- cgit v1.2.3