diff options
author | Gabe Black <gabeblack@google.com> | 2018-05-24 01:37:55 -0700 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-08-08 10:09:54 +0000 |
commit | 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f (patch) | |
tree | 7b6faaacb4574a555e561534aa4a8508c0624c32 /src/systemc/tests/systemc/1666-2011-compliance | |
parent | 7235d3b5211d0ba8f528d930a4c1e7ad62eec51a (diff) | |
download | gem5-16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f.tar.xz |
systemc: Import tests from the Accellera systemc distribution.
Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6
Reviewed-on: https://gem5-review.googlesource.com/10845
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Maintainer: Gabe Black <gabeblack@google.com>
Diffstat (limited to 'src/systemc/tests/systemc/1666-2011-compliance')
78 files changed, 10258 insertions, 0 deletions
diff --git a/src/systemc/tests/systemc/1666-2011-compliance/async_reset/async_reset.cpp b/src/systemc/tests/systemc/1666-2011-compliance/async_reset/async_reset.cpp new file mode 100644 index 000000000..d7d8d9ba8 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/async_reset/async_reset.cpp @@ -0,0 +1,661 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// async_reset.cpp +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: async_reset.cpp,v $ +// Revision 1.3 2011/05/08 19:18:45 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// async_reset_signal_is + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + : count(0) + { + clk_port.bind(clk); + + SC_THREAD(ctrl); + + SC_CTHREAD(CT, clk_port.value_changed()); + async_reset_signal_is(areset, true); + ct = sc_get_current_process_handle(); + + sc_spawn_options opt; + opt.async_reset_signal_is(areset, true); + t = sc_spawn(sc_bind(&Top::T, this), "T", &opt); + + opt.spawn_method(); + opt.dont_initialize(); + opt.set_sensitivity( &clk ); + m = sc_spawn(sc_bind(&Top::M, this), "M", &opt); + + SC_CTHREAD(CT2, clk_port.pos()) + async_reset_signal_is(areset1, true); + async_reset_signal_is(areset2, true); + async_reset_signal_is(areset3, true); + reset_signal_is(sreset1, true); + reset_signal_is(sreset2, true); + reset_signal_is(sreset3, true); + ct2 = sc_get_current_process_handle(); + ct2.disable(); + + SC_THREAD(T2) + sensitive << clk_port.pos(); + async_reset_signal_is(areset1, true); + async_reset_signal_is(areset2, true); + async_reset_signal_is(areset3, true); + reset_signal_is(sreset1, true); + reset_signal_is(sreset2, true); + reset_signal_is(sreset3, true); + t2 = sc_get_current_process_handle(); + t2.disable(); + + clk.write(false); + areset.write(false); + + f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0; + f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0; + f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0; + f30 = f31 = f32 = f33 = f34 = f35 = f36 = f37 = f38 = f39 = 0; + f40 = f41 = f42 = f43 = f44 = f45 = f46 = f47 = f48 = f49 = 0; + f50 = f51 = f52 = f53 = f54 = f55 = f56 = f57 = f58 = f59 = 0; + f60 = f61 = f62 = f63 = f64 = f65 = f66 = f67 = f68 = f69 = 0; + f70 = f71 = f72 = f73 = f74 = f75 = f76 = f77 = f78 = f79 = 0; + f80 = f81 = f82 = f83 = f84 = f85 = f86 = f87 = f88 = f89 = 0; + } + + sc_signal<bool> clk; + sc_in<bool> clk_port; + sc_signal<bool> areset; + sc_signal<bool> areset1, areset2, areset3, sreset1, sreset2, sreset3; + + sc_process_handle ct, t, m, ct2, t2; + int count; + + int f1, f2, f3, f4, f5, f6, f7, f8, f9; + int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19; + int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29; + int f30, f31, f32, f33, f34, f35, f36, f37, f38, f39; + int f40, f41, f42, f43, f44, f45, f46, f47, f48, f49; + int f50, f51, f52, f53, f54, f55, f56, f57, f58, f59; + int f60, f61, f62, f63, f64, f65, f66, f67, f68, f69; + int f70, f71, f72, f73, f74, f75, f76, f77, f78, f79; + int f80, f81, f82, f83, f84, f85, f86, f87, f88, f89; + + void ctrl() + { + sc_assert( sc_delta_count() == 0 ); + clock(); + wait(SC_ZERO_TIME); + wait(SC_ZERO_TIME); + + count = 1; + clock(); + wait(1, SC_NS); + + count = 2; + clock(); + wait(10, SC_NS); + + count = 3; + clock(); + wait(sc_time(20, SC_NS) - sc_time_stamp()); + + count = 4; + areset.write(true); + wait(1, SC_NS); + + count = 5; + areset.write(false); + wait(1, SC_NS); + + count = 6; + clock(); + wait(sc_time(30, SC_NS) - sc_time_stamp()); + + count = 7; + areset.write(true); + wait(1, SC_NS); + + count = 8; + clock(); // Clocked while asynch reset is active + wait(1, SC_NS); + + count = 9; + clock(); + wait(1, SC_NS); + + count = 10; + areset.write(false); + wait(1, SC_NS); + + count = 11; + areset.write(true); + wait(1, SC_NS); + + count = 12; + areset.write(false); + wait(sc_time(40, SC_NS) - sc_time_stamp()); + + count = 13; + sync_reset_on(); + wait(1, SC_NS); + + count = 14; + clock(); + wait(1, SC_NS); + + count = 15; + sync_reset_off(); + wait(sc_time(50, SC_NS) - sc_time_stamp()); + + count = 16; + disable(); + wait(1, SC_NS); + + count = 17; + clock(); + wait(1, SC_NS); + + count = 18; + sync_reset_on(); + clock(); + wait(1, SC_NS); + + count = 19; + enable(); + clock(); + wait(1, SC_NS); + + count = 20; + sync_reset_off(); + clock(); + wait(sc_time(60, SC_NS) - sc_time_stamp()); + + count = 21; + disable(); + wait(1, SC_NS); + + count = 22; + areset.write(true); + wait(1, SC_NS); + + count = 23; + clock(); + wait(1, SC_NS); + + count = 24; + areset.write(false); + wait(1, SC_NS); + + count = 25; + clock(); + wait(1, SC_NS); + + count = 26; + areset.write(true); + wait(1, SC_NS); + + count = 27; + enable(); + wait(1, SC_NS); + + count = 28; + clock(); + wait(1, SC_NS); + + count = 29; + areset.write(false); + wait(sc_time(100, SC_NS) - sc_time_stamp()); + + count = 30; + ct.disable(); + t.disable(); + m.disable(); + + // Test multiple resets + ct2.enable(); + t2.enable(); + clock2(); + + count = 31; + clock2(); + + count = 32; + sreset1.write(1); + clock2(); + + count = 33; + sreset2.write(1); + sreset3.write(1); + clock2(); + + count = 34; + sreset1.write(0); + sreset2.write(0); + clock2(); + + count = 35; + sreset3.write(0); + clock2(); + + count = 36; + areset1.write(1); + areset2.write(1); + areset3.write(1); + wait(SC_ZERO_TIME); + + count = 37; + clock2(); + + count = 38; + sreset1.write(1); + sreset2.write(1); + sreset3.write(1); + ct2.sync_reset_on(); + t2.sync_reset_on(); + clock2(); + + count = 39; + areset1.write(0); + areset2.write(0); + areset3.write(0); + sreset1.write(0); + sreset2.write(0); + sreset3.write(0); + clock2(); + + count = 40; + ct2.sync_reset_off(); + t2.sync_reset_off(); + clock2(); + + count = 41; + sreset2.write(1); + ct2.sync_reset_on(); + t2.sync_reset_on(); + clock2(); + + count = 42; + areset2.write(1); + wait(SC_ZERO_TIME); + + count = 43; + clock2(); + + count = 44; + sreset2.write(0); + ct2.sync_reset_off(); + t2.sync_reset_off(); + clock2(); + + count = 45; + areset1.write(0); + areset2.write(0); + areset3.write(0); + sreset1.write(0); + sreset2.write(0); + sreset3.write(0); + clock2(); + + count = 46; + ct2.reset(); + t2.reset(); + wait(SC_ZERO_TIME); + + count = 47; + clock2(); + } + + void CT() + { + //cout << "CT() called at " << sc_time_stamp() << endl; + switch (count) + { + case 0: sc_assert( sc_delta_count() == 1 ); f1=1; break; + case 4: sc_assert( sc_time_stamp() == sc_time(20, SC_NS) ); f2=1; break; + case 7: sc_assert( sc_time_stamp() == sc_time(30, SC_NS) ); f3=1; break; + case 8: sc_assert( sc_time_stamp() == sc_time(31, SC_NS) ); f4=1; break; + case 9: sc_assert( sc_time_stamp() == sc_time(32, SC_NS) ); f5=1; break; + case 11: sc_assert( sc_time_stamp() == sc_time(34, SC_NS) ); f6=1; break; + case 14: sc_assert( sc_time_stamp() == sc_time(41, SC_NS) ); f7=1; break; + case 19: sc_assert( sc_time_stamp() == sc_time(53, SC_NS) ); f8=1; break; + case 22: sc_assert( sc_time_stamp() == sc_time(61, SC_NS) ); f9=1; break; + case 26: sc_assert( sc_time_stamp() == sc_time(65, SC_NS) ); f11=1; break; + case 28: sc_assert( sc_time_stamp() == sc_time(67, SC_NS) ); f12=1; break; + default: sc_assert( false ); break; + } + while (true) + { + wait(); + //cout << "CT() awoke at " << sc_time_stamp() << endl; + + switch (count) + { + case 1: sc_assert( sc_delta_count() == 3 ); f13=1; break; + case 2: sc_assert( sc_time_stamp() == sc_time(1, SC_NS) ); f14=1; break; + case 3: sc_assert( sc_time_stamp() == sc_time(11, SC_NS) ); f15=1; break; + case 6: sc_assert( sc_time_stamp() == sc_time(22, SC_NS) ); f16=1; break; + case 20: sc_assert( sc_time_stamp() == sc_time(54, SC_NS) ); f17=1; break; + default: sc_assert( false ); break; + } + + } + } + + void T() + { + //cout << "T() called at " << sc_time_stamp() << endl; + switch (count) + { + case 0: sc_assert( sc_delta_count() == 0 ); f18=1; break; + case 4: sc_assert( sc_time_stamp() == sc_time(20, SC_NS) ); f19=1; break; + case 7: sc_assert( sc_time_stamp() == sc_time(30, SC_NS) ); f20=1; break; + case 8: sc_assert( sc_time_stamp() == sc_time(31, SC_NS) ); f21=1; break; + case 9: sc_assert( sc_time_stamp() == sc_time(32, SC_NS) ); f22=1; break; + case 11: sc_assert( sc_time_stamp() == sc_time(34, SC_NS) ); f23=1; break; + case 14: sc_assert( sc_time_stamp() == sc_time(41, SC_NS) ); f24=1; break; + case 19: sc_assert( sc_time_stamp() == sc_time(53, SC_NS) ); f25=1; break; + case 22: sc_assert( sc_time_stamp() == sc_time(61, SC_NS) ); f26=1; break; + case 26: sc_assert( sc_time_stamp() == sc_time(65, SC_NS) ); f28=1; break; + case 28: sc_assert( sc_time_stamp() == sc_time(67, SC_NS) ); f29=1; break; + default: sc_assert( false ); break; + } + while (true) + { + wait(clk.default_event()); + //cout << "T() awoke at " << sc_time_stamp() << endl; + + switch (count) + { + case 0: sc_assert( sc_delta_count() == 1 ); f30=1; break; + case 1: sc_assert( sc_delta_count() == 3 ); f31=1; break; + case 2: sc_assert( sc_time_stamp() == sc_time(1, SC_NS) ); f32=1; break; + case 3: sc_assert( sc_time_stamp() == sc_time(11, SC_NS) ); f33=1; break; + case 6: sc_assert( sc_time_stamp() == sc_time(22, SC_NS) ); f34=1; break; + case 20: sc_assert( sc_time_stamp() == sc_time(54, SC_NS) ); f35=1; break; + default: sc_assert( false ); break; + } + + } + } + + void M() + { + //cout << "M() called at " << sc_time_stamp() << endl; + switch (count) + { + case 0: sc_assert( sc_delta_count() == 1 ); f36=1; break; + case 1: sc_assert( sc_delta_count() == 3 ); f37=1; break; + case 2: sc_assert( sc_time_stamp() == sc_time(1, SC_NS) ); f38=1; break; + case 3: sc_assert( sc_time_stamp() == sc_time(11, SC_NS) ); f39=1; break; + case 4: sc_assert( sc_time_stamp() == sc_time(20, SC_NS) ); f83=1; break; + case 6: sc_assert( sc_time_stamp() == sc_time(22, SC_NS) ); f40=1; break; + case 7: sc_assert( sc_time_stamp() == sc_time(30, SC_NS) ); f84=1; break; + case 8: sc_assert( sc_time_stamp() == sc_time(31, SC_NS) ); f41=1; break; + case 9: sc_assert( sc_time_stamp() == sc_time(32, SC_NS) ); f42=1; break; + case 11: sc_assert( sc_time_stamp() == sc_time(34, SC_NS) ); f85=1; break; + case 14: sc_assert( sc_time_stamp() == sc_time(41, SC_NS) ); f43=1; break; + case 19: sc_assert( sc_time_stamp() == sc_time(53, SC_NS) ); f44=1; break; + case 20: sc_assert( sc_time_stamp() == sc_time(54, SC_NS) ); f45=1; break; + case 22: sc_assert( sc_time_stamp() == sc_time(61, SC_NS) ); f26=1; break; + case 26: sc_assert( sc_time_stamp() == sc_time(65, SC_NS) ); f86=1; break; + case 28: sc_assert( sc_time_stamp() == sc_time(67, SC_NS) ); f46=1; break; + default: sc_assert( false ); break; + } + } + + void CT2() + { + //cout << "CT2() called at " << sc_time_stamp() << endl; + switch (count) + { + case 30: sc_assert( sc_time_stamp() == sc_time(105, SC_NS) ); f47=1; break; + case 32: sc_assert( sc_time_stamp() == sc_time(125, SC_NS) ); f51=1; break; + case 33: sc_assert( sc_time_stamp() == sc_time(135, SC_NS) ); f53=1; break; + case 34: sc_assert( sc_time_stamp() == sc_time(145, SC_NS) ); f55=1; break; + case 36: sc_assert( sc_time_stamp() == sc_time(160, SC_NS) ); f59=1; break; + case 37: sc_assert( sc_time_stamp() == sc_time(165, SC_NS) ); f61=1; break; + case 38: sc_assert( sc_time_stamp() == sc_time(175, SC_NS) ); f63=1; break; + case 39: sc_assert( sc_time_stamp() == sc_time(185, SC_NS) ); f65=1; break; + case 41: sc_assert( sc_time_stamp() == sc_time(205, SC_NS) ); f69=1; break; + case 42: sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); f71=1; break; + case 43: sc_assert( sc_time_stamp() == sc_time(215, SC_NS) ); f73=1; break; + case 44: sc_assert( sc_time_stamp() == sc_time(225, SC_NS) ); f75=1; break; + case 46: sc_assert( sc_time_stamp() == sc_time(240, SC_NS) ); f79=1; break; + default: sc_assert( false ); break; + } + while (true) + { + wait(); + //cout << "CT2() awoke at " << sc_time_stamp() << endl; + switch (count) + { + case 31: sc_assert( sc_time_stamp() == sc_time(115, SC_NS) ); f49=1; break; + case 35: sc_assert( sc_time_stamp() == sc_time(155, SC_NS) ); f57=1; break; + case 40: sc_assert( sc_time_stamp() == sc_time(195, SC_NS) ); f67=1; break; + case 45: sc_assert( sc_time_stamp() == sc_time(235, SC_NS) ); f77=1; break; + case 47: sc_assert( sc_time_stamp() == sc_time(245, SC_NS) ); f81=1; break; + default: sc_assert( false ); break; + } + } + } + + void T2() + { + //cout << "T2() called at " << sc_time_stamp() << endl; + switch (count) + { + case 30: sc_assert( sc_time_stamp() == sc_time(105, SC_NS) ); f48=1; break; + case 32: sc_assert( sc_time_stamp() == sc_time(125, SC_NS) ); f52=1; break; + case 33: sc_assert( sc_time_stamp() == sc_time(135, SC_NS) ); f54=1; break; + case 34: sc_assert( sc_time_stamp() == sc_time(145, SC_NS) ); f56=1; break; + case 36: sc_assert( sc_time_stamp() == sc_time(160, SC_NS) ); f60=1; break; + case 37: sc_assert( sc_time_stamp() == sc_time(165, SC_NS) ); f62=1; break; + case 38: sc_assert( sc_time_stamp() == sc_time(175, SC_NS) ); f64=1; break; + case 39: sc_assert( sc_time_stamp() == sc_time(185, SC_NS) ); f66=1; break; + case 41: sc_assert( sc_time_stamp() == sc_time(205, SC_NS) ); f70=1; break; + case 42: sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); f72=1; break; + case 43: sc_assert( sc_time_stamp() == sc_time(215, SC_NS) ); f74=1; break; + case 44: sc_assert( sc_time_stamp() == sc_time(225, SC_NS) ); f76=1; break; + case 46: sc_assert( sc_time_stamp() == sc_time(240, SC_NS) ); f80=1; break; + default: sc_assert( false ); break; + } + while (true) + { + wait(); + //cout << "T2() awoke at " << sc_time_stamp() << endl; + switch (count) + { + case 31: sc_assert( sc_time_stamp() == sc_time(115, SC_NS) ); f50=1; break; + case 35: sc_assert( sc_time_stamp() == sc_time(155, SC_NS) ); f58=1; break; + case 40: sc_assert( sc_time_stamp() == sc_time(195, SC_NS) ); f68=1; break; + case 45: sc_assert( sc_time_stamp() == sc_time(235, SC_NS) ); f78=1; break; + case 47: sc_assert( sc_time_stamp() == sc_time(245, SC_NS) ); f82=1; break; + default: sc_assert( false ); break; + } + } + } + + void clock() + { + clk.write( !clk.read() ); + } + + void clock2() + { + clk.write(0); + wait(5, SC_NS); + clk.write(1); + wait(5, SC_NS); + } + + void suspend() + { + ct.suspend(); + t.suspend(); + m.suspend(); + } + + void resume() + { + ct.resume(); + t.resume(); + m.resume(); + } + + void disable() + { + ct.disable(); + t.disable(); + m.disable(); + } + + void enable() + { + ct.enable(); + t.enable(); + m.enable(); + } + + void sync_reset_on() + { + ct.sync_reset_on(); + t.sync_reset_on(); + m.sync_reset_on(); + } + + void sync_reset_off() + { + ct.sync_reset_off(); + t.sync_reset_off(); + m.sync_reset_off(); + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert(top.f1); + sc_assert(top.f2); + sc_assert(top.f3); + sc_assert(top.f4); + sc_assert(top.f5); + sc_assert(top.f6); + sc_assert(top.f7); + sc_assert(top.f8); + sc_assert(top.f9); + sc_assert(top.f11); + sc_assert(top.f12); + sc_assert(top.f13); + sc_assert(top.f14); + sc_assert(top.f15); + sc_assert(top.f16); + sc_assert(top.f17); + sc_assert(top.f18); + sc_assert(top.f19); + sc_assert(top.f20); + sc_assert(top.f21); + sc_assert(top.f22); + sc_assert(top.f23); + sc_assert(top.f24); + sc_assert(top.f25); + sc_assert(top.f26); + sc_assert(top.f28); + sc_assert(top.f29); + sc_assert(top.f30); + sc_assert(top.f31); + sc_assert(top.f32); + sc_assert(top.f33); + sc_assert(top.f34); + sc_assert(top.f35); + sc_assert(top.f36); + sc_assert(top.f37); + sc_assert(top.f38); + sc_assert(top.f39); + sc_assert(top.f40); + sc_assert(top.f41); + sc_assert(top.f42); + sc_assert(top.f43); + sc_assert(top.f44); + sc_assert(top.f45); + sc_assert(top.f46); + sc_assert(top.f47); + sc_assert(top.f48); + sc_assert(top.f49); + sc_assert(top.f50); + sc_assert(top.f51); + sc_assert(top.f52); + sc_assert(top.f53); + sc_assert(top.f54); + sc_assert(top.f55); + sc_assert(top.f56); + sc_assert(top.f57); + sc_assert(top.f58); + sc_assert(top.f59); + sc_assert(top.f60); + sc_assert(top.f61); + sc_assert(top.f62); + sc_assert(top.f63); + sc_assert(top.f64); + sc_assert(top.f65); + sc_assert(top.f66); + sc_assert(top.f67); + sc_assert(top.f68); + sc_assert(top.f69); + sc_assert(top.f70); + sc_assert(top.f71); + sc_assert(top.f72); + sc_assert(top.f73); + sc_assert(top.f74); + sc_assert(top.f75); + sc_assert(top.f76); + sc_assert(top.f77); + sc_assert(top.f78); + sc_assert(top.f79); + sc_assert(top.f80); + sc_assert(top.f81); + sc_assert(top.f82); + sc_assert(top.f83); + sc_assert(top.f84); + sc_assert(top.f85); + sc_assert(top.f86); + + cout << endl << "Success" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/1666-2011-compliance/async_reset/golden/async_reset.log b/src/systemc/tests/systemc/1666-2011-compliance/async_reset/golden/async_reset.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/async_reset/golden/async_reset.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/async_reset_port/async_reset_port.cpp b/src/systemc/tests/systemc/1666-2011-compliance/async_reset_port/async_reset_port.cpp new file mode 100644 index 000000000..4828f9bb6 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/async_reset_port/async_reset_port.cpp @@ -0,0 +1,372 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// async_reset_port.cpp -- +// +// Original Author: John Aynsley, Doulos Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: async_reset_port.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// async_reset_signal_is + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> +using namespace sc_core; +using std::cout; +using std::endl; + +struct M: sc_module +{ + sc_in<bool> clk; + + sc_in<bool> sreset1; + sc_inout<bool> sreset2; + sc_out<bool> sreset3; + + sc_in<bool> areset1; + sc_inout<bool> areset2; + sc_out<bool> areset3; + + M(sc_module_name _name) + : count(0) + { + SC_CTHREAD(CT1, clk); + reset_signal_is(sreset1, false); + ct1 = sc_get_current_process_handle(); + + SC_CTHREAD(CT2, clk); + reset_signal_is(sreset2, false); + ct2 = sc_get_current_process_handle(); + + SC_CTHREAD(CT3, clk); + reset_signal_is(sreset3, false); + ct3 = sc_get_current_process_handle(); + + SC_CTHREAD(CT4, clk); + async_reset_signal_is(areset1, false); + ct4 = sc_get_current_process_handle(); + + SC_CTHREAD(CT5, clk); + async_reset_signal_is(areset2, false); + ct5 = sc_get_current_process_handle(); + + SC_CTHREAD(CT6, clk); + async_reset_signal_is(areset3, false); + ct6 = sc_get_current_process_handle(); + + f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0; + f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0; + f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0; + f30 = f31 = f32 = f33 = f34 = f35 = f36 = f37 = f38 = f39 = 0; + } + + int count; + sc_process_handle ct1, ct2, ct3, ct4, ct5, ct6; + + int f1, f2, f3, f4, f5, f6, f7, f8, f9; + int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19; + int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29; + int f30, f31, f32, f33, f34, f35, f36, f37, f38, f39; + + void CT1() + { + if (count == 2) { sc_assert(sc_time_stamp() == sc_time( 15, SC_NS)); f1 = 1; } + if (count == 17) { sc_assert(false); } + if (count == 18) { sc_assert(sc_time_stamp() == sc_time(135, SC_NS)); f16 = 1; } + if (count == 19) { sc_assert(sc_time_stamp() == sc_time(145, SC_NS)); f25 = 1; } + while (true) + { + wait(); + if (count == 16) { sc_assert(sc_time_stamp() == sc_time(125, SC_NS)); f10 = 1; } + if (count == 20) { sc_assert(sc_time_stamp() == sc_time(155, SC_NS)); f31 = 1; } + } + } + + void CT2() + { + if (count == 4) { sc_assert(sc_time_stamp() == sc_time( 35, SC_NS)); f2 = 1; } + if (count == 17) { sc_assert(false); } + if (count == 18) { sc_assert(sc_time_stamp() == sc_time(135, SC_NS)); f17 = 1; } + if (count == 19) { sc_assert(sc_time_stamp() == sc_time(145, SC_NS)); f26 = 1; } + while (true) + { + wait(); + if (count == 16) { sc_assert(sc_time_stamp() == sc_time(125, SC_NS)); f11 = 1; } + if (count == 20) { sc_assert(sc_time_stamp() == sc_time(155, SC_NS)); f32 = 1; } + } + } + + void CT3() + { + if (count == 6) { sc_assert(sc_time_stamp() == sc_time( 55, SC_NS)); f3 = 1; } + if (count == 17) { sc_assert(false); } + if (count == 18) { sc_assert(sc_time_stamp() == sc_time(135, SC_NS)); f18 = 1; } + if (count == 19) { sc_assert(sc_time_stamp() == sc_time(145, SC_NS)); f27 = 1; } + while (true) + { + wait(); + if (count == 16) { sc_assert(sc_time_stamp() == sc_time(125, SC_NS)); f12 = 1; } + if (count == 20) { sc_assert(sc_time_stamp() == sc_time(155, SC_NS)); f33 = 1; } + } + } + + void CT4() + { + if (count == 8) { sc_assert(sc_time_stamp() == sc_time( 70, SC_NS)); f4 = 1; } + if (count == 9) { sc_assert(sc_time_stamp() == sc_time( 75, SC_NS)); f5 = 1; } + if (count == 17) { sc_assert(sc_time_stamp() == sc_time(130, SC_NS)); f19 = 1; } + if (count == 18) { sc_assert(sc_time_stamp() == sc_time(135, SC_NS)); f22 = 1; } + if (count == 19) { sc_assert(sc_time_stamp() == sc_time(145, SC_NS)); f28 = 1; } + while (true) + { + wait(); + if (count == 16) { sc_assert(sc_time_stamp() == sc_time(125, SC_NS)); f13 = 1; } + if (count == 20) { sc_assert(sc_time_stamp() == sc_time(155, SC_NS)); f34 = 1; } + } + } + + void CT5() + { + if (count == 11) { sc_assert(sc_time_stamp() == sc_time( 90, SC_NS)); f6 = 1; } + if (count == 12) { sc_assert(sc_time_stamp() == sc_time( 95, SC_NS)); f7 = 1; } + if (count == 17) { sc_assert(sc_time_stamp() == sc_time(130, SC_NS)); f20 = 1; } + if (count == 18) { sc_assert(sc_time_stamp() == sc_time(135, SC_NS)); f23 = 1; } + if (count == 19) { sc_assert(sc_time_stamp() == sc_time(145, SC_NS)); f29 = 1; } + while (true) + { + wait(); + if (count == 16) { sc_assert(sc_time_stamp() == sc_time(125, SC_NS)); f14 = 1; } + if (count == 20) { sc_assert(sc_time_stamp() == sc_time(155, SC_NS)); f35 = 1; } + } + } + + void CT6() + { + if (count == 14) { sc_assert(sc_time_stamp() == sc_time(110, SC_NS)); f8 = 1; } + if (count == 15) { sc_assert(sc_time_stamp() == sc_time(115, SC_NS)); f9 = 1; } + if (count == 17) { sc_assert(sc_time_stamp() == sc_time(130, SC_NS)); f21 = 1; } + if (count == 18) { sc_assert(sc_time_stamp() == sc_time(135, SC_NS)); f24 = 1; } + if (count == 19) { sc_assert(sc_time_stamp() == sc_time(145, SC_NS)); f30 = 1; } + while (true) + { + try { + wait(); + } + catch (const sc_unwind_exception& e) { + sc_assert( e.is_reset() ); + sc_assert( sc_is_unwinding() ); + if (count == 14) { sc_assert(sc_time_stamp() == sc_time(110, SC_NS)); f37 = 1; } + if (count == 17) { sc_assert(sc_time_stamp() == sc_time(130, SC_NS)); f38 = 1; } + throw e; + } + if (count == 16) { sc_assert(sc_time_stamp() == sc_time(125, SC_NS)); f15 = 1; } + if (count == 20) { sc_assert(sc_time_stamp() == sc_time(155, SC_NS)); f36 = 1; } + } + } + + SC_HAS_PROCESS(M); +}; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + m = new M("m"); + m->clk(clk); + m->sreset1(sreset1); + m->sreset2(sreset2); + m->sreset3(sreset3); + m->areset1(areset1); + m->areset2(areset2); + m->areset3(areset3); + + SC_THREAD(ctrl); + + // Resets are all active-low + sreset1.write(1); + sreset2.write(1); + sreset3.write(1); + areset1.write(1); + areset2.write(1); + areset3.write(1); + } + + M* m; + + sc_signal<bool> clk; + + sc_signal<bool> sreset1; + sc_signal<bool> sreset2; + sc_signal<bool> sreset3; + + sc_signal<bool> areset1; + sc_signal<bool> areset2; + sc_signal<bool> areset3; + + void ctrl() + { + m->count = 1; + clock(); + + m->count = 2; + sreset1.write(0); + clock(); + + m->count = 3; + sreset1.write(1); + clock(); + + m->count = 4; + sreset2.write(0); + clock(); + + m->count = 5; + sreset2.write(1); + clock(); + + m->count = 6; + sreset3.write(0); + clock(); + + m->count = 7; + sreset3.write(1); + clock(); + + m->count = 8; + areset1.write(0); + wait(SC_ZERO_TIME); + + m->count = 9; + clock(); + + m->count = 10; + areset1.write(1); + clock(); + + m->count = 11; + areset2.write(0); + wait(SC_ZERO_TIME); + + m->count = 12; + clock(); + + m->count = 13; + areset2.write(1); + clock(); + + m->count = 14; + areset3.write(0); + wait(SC_ZERO_TIME); + + m->count = 15; + clock(); + + m->count = 16; + areset3.write(1); + clock(); + + m->count = 17; + sreset1.write(0); + sreset2.write(0); + sreset3.write(0); + areset1.write(0); + areset2.write(0); + areset3.write(0); + wait(SC_ZERO_TIME); + + m->count = 18; + clock(); + + m->count = 19; + clock(); + + m->count = 20; + sreset1.write(1); + sreset2.write(1); + sreset3.write(1); + areset1.write(1); + areset2.write(1); + areset3.write(1); + clock(); + } + + void clock() + { + clk.write(0); + wait(5, SC_NS); + clk.write(1); + wait(5, SC_NS); + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert(top.m->f1); + sc_assert(top.m->f2); + sc_assert(top.m->f3); + sc_assert(top.m->f4); + sc_assert(top.m->f5); + sc_assert(top.m->f6); + sc_assert(top.m->f7); + sc_assert(top.m->f8); + sc_assert(top.m->f9); + sc_assert(top.m->f10); + sc_assert(top.m->f11); + sc_assert(top.m->f12); + sc_assert(top.m->f13); + sc_assert(top.m->f14); + sc_assert(top.m->f15); + sc_assert(top.m->f16); + sc_assert(top.m->f17); + sc_assert(top.m->f18); + sc_assert(top.m->f19); + sc_assert(top.m->f20); + sc_assert(top.m->f21); + sc_assert(top.m->f22); + sc_assert(top.m->f23); + sc_assert(top.m->f24); + sc_assert(top.m->f25); + sc_assert(top.m->f26); + sc_assert(top.m->f28); + sc_assert(top.m->f29); + sc_assert(top.m->f30); + sc_assert(top.m->f31); + sc_assert(top.m->f32); + sc_assert(top.m->f33); + sc_assert(top.m->f34); + sc_assert(top.m->f35); + sc_assert(top.m->f36); + sc_assert(top.m->f37); + sc_assert(top.m->f38); + + cout << endl << "Success" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/1666-2011-compliance/async_reset_port/golden/async_reset_port.log b/src/systemc/tests/systemc/1666-2011-compliance/async_reset_port/golden/async_reset_port.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/async_reset_port/golden/async_reset_port.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/child_proc_control/child_proc_control.cpp b/src/systemc/tests/systemc/1666-2011-compliance/child_proc_control/child_proc_control.cpp new file mode 100644 index 000000000..1c80be921 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/child_proc_control/child_proc_control.cpp @@ -0,0 +1,217 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// child_proc_control.cpp -- test for +// +// Original Author: John Aynsley, Doulos Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: child_proc_control.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Process control methods applied to child processes + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + : count(0) + , n(155) + , proc_count(0) + { + SC_THREAD(ctrl); + SC_THREAD(observer); + + f0 = f1 = 0; + + given_birth = new bool[n]; + + c0 = new int[n]; + c1 = new int[n]; + c2 = new int[n]; + c3 = new int[n]; + c4 = new int[n]; + c5 = new int[n]; + + for (int i = 0; i < n; i++) + { + given_birth[i] = false; + c0[i] = c1[i] = c2[i] = c3[i] = c4[i] = c5[i] = 0; + } + } + + int count; + int f0, f1; + const int n; + int proc_count; + bool *given_birth; + int *c0, *c1, *c2, *c3 ,*c4, *c5; + + sc_event ev; + sc_process_handle ph; + sc_event_and_list reset_event_list; + sc_event_and_list terminated_event_list; + + void ctrl() + { + count = 1; + ph = sc_spawn(sc_bind(&Top::parent_proc, this)); + wait(10, SC_NS); + + count = 2; + ph.reset(SC_INCLUDE_DESCENDANTS); + wait(10, SC_NS); + + count = 3; + ev.notify(); + wait(10, SC_NS); + + count = 4; + ph.suspend(SC_INCLUDE_DESCENDANTS); + wait(10, SC_NS); + + count = 5; + ev.notify(); + wait(10, SC_NS); + + count = 6; + ph.resume(SC_INCLUDE_DESCENDANTS); + wait(10, SC_NS); + + count = 7; + ph.kill(SC_INCLUDE_DESCENDANTS); + wait(10, SC_NS); + } + + void observer() + { + wait(SC_ZERO_TIME); + + wait(reset_event_list); + sc_assert(sc_time_stamp() == sc_time(10, SC_NS)); + f0 = 1; + + wait(terminated_event_list); + sc_assert(sc_time_stamp() == sc_time(60, SC_NS)); + f1 = 1; + } + + void parent_proc() + { + sc_process_handle h; + int level = 2; + for (int i = 0; i < 5; i++) + { + if (proc_count < n) + { + h = sc_spawn(sc_bind(&Top::child_proc, this, proc_count++, level)); + reset_event_list &= h.reset_event(); + terminated_event_list &= h.terminated_event(); + } + } + } + + void child_proc(int i, int level) + { + //cout << "Child " << i << " called at " << sc_time_stamp() << endl; + if (level > 0) + if ( !given_birth[i] ) + { + sc_process_handle h; + for (int j = 0; j < 5; j++) + { + if (proc_count < n) + { + h = sc_spawn(sc_bind(&Top::child_proc, this, proc_count++, level-1)); + reset_event_list &= h.reset_event(); + terminated_event_list &= h.terminated_event(); + given_birth[i] = true; + } + } + } + switch(count) + { + case 1: sc_assert(sc_time_stamp() == sc_time( 0, SC_NS)); c0[i] = 1; break; + case 2: sc_assert(sc_time_stamp() == sc_time(10, SC_NS)); c2[i] = 1; break; + default: sc_assert(false); break; + } + while(true) + { + try { + wait(ev); + } + catch (const sc_unwind_exception& e) { + switch(count) + { + case 2: sc_assert(sc_time_stamp() == sc_time(10, SC_NS)); + sc_assert( e.is_reset() ); c1[i] = 1; break; + case 7: sc_assert(sc_time_stamp() == sc_time(60, SC_NS)); + sc_assert( !e.is_reset() ); c5[i] = 1; break; + default: sc_assert(false); break; + } + sc_assert( sc_is_unwinding() ); + throw e; + } + switch(count) + { + case 3: sc_assert(sc_time_stamp() == sc_time(20, SC_NS)); c3[i] = 1; break; + case 6: sc_assert(sc_time_stamp() == sc_time(50, SC_NS)); c4[i] = 1; break; + default: sc_assert(false); break; + } + } + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.proc_count == top.n ); + + sc_assert( top.f0 ); + sc_assert( top.f1 ); + + for (int i = 0; i < top.n; i++) + { + sc_assert( top.c0[i] ); + sc_assert( top.c1[i] ); + sc_assert( top.c2[i] ); + sc_assert( top.c3[i] ); + sc_assert( top.c4[i] ); + sc_assert( top.c5[i] ); + } + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/child_proc_control/golden/child_proc_control.log b/src/systemc/tests/systemc/1666-2011-compliance/child_proc_control/golden/child_proc_control.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/child_proc_control/golden/child_proc_control.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/disable_enable/disable_enable.cpp b/src/systemc/tests/systemc/1666-2011-compliance/disable_enable/disable_enable.cpp new file mode 100644 index 000000000..1302e7e7e --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/disable_enable/disable_enable.cpp @@ -0,0 +1,135 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// disable_enable.cpp -- test for +// +// Original Author: John Aynsley, Doulos Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: disable_enable.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// disable() should take effect only the next evaluation phase + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using namespace std; + +struct Top: sc_module +{ + Top(sc_module_name _name) + : count(0) + { + SC_THREAD(control); + SC_THREAD(target); + t = sc_get_current_process_handle(); + + f0 = f1 = f2 = f3 = f4 = f5 = 0; + } + + sc_process_handle t; + sc_event ev; + int count; + int f0, f1, f2, f3, f4, f5; + + void control() + { + wait(SC_ZERO_TIME); + + count = 1; + ev.notify(); + wait(10, SC_NS); + + count = 2; + ev.notify(); + t.disable(); + wait(SC_ZERO_TIME); + + count = 3; + ev.notify(); + wait(SC_ZERO_TIME); + + count = 4; + t.enable(); + ev.notify(); + wait(10, SC_NS); + + count = 5; + t.disable(); + t.reset(); + wait(10, SC_NS); + + count = 6; + t.reset(); + wait(10, SC_NS); + + sc_stop(); + } + + void target() + { + //cout << "Target called at " << sc_time_stamp() << " with count = " << count << endl; + switch(count) + { + case 0: sc_assert(sc_time_stamp() == sc_time( 0, SC_NS)); f0 = 1; break; + case 5: sc_assert(sc_time_stamp() == sc_time(20, SC_NS)); f4 = 1; break; + case 6: sc_assert(sc_time_stamp() == sc_time(30, SC_NS)); f5 = 1; break; + default: sc_assert(false); + } + for (;;) + { + wait(ev); + //cout << "Target awoke at " << sc_time_stamp() << " with count = " << count << endl; + switch(count) + { + case 1: sc_assert(sc_time_stamp() == sc_time( 0, SC_NS)); f1 = 1; break; + case 2: sc_assert(sc_time_stamp() == sc_time(10, SC_NS)); f2 = 1; break; + case 4: sc_assert(sc_time_stamp() == sc_time(10, SC_NS)); f3 = 1; break; + default: sc_assert(false); + } + } + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f0 ); + sc_assert( top.f1 ); + sc_assert( top.f2 ); + sc_assert( top.f3 ); + sc_assert( top.f4 ); + sc_assert( top.f5 ); + /* + */ + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/disable_enable/golden/disable_enable.log b/src/systemc/tests/systemc/1666-2011-compliance/disable_enable/golden/disable_enable.log new file mode 100644 index 000000000..cdf4578d6 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/disable_enable/golden/disable_enable.log @@ -0,0 +1,5 @@ +SystemC Simulation + +Info: /OSCI/SystemC: Simulation stopped by user. + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/event_list/event_list.cpp b/src/systemc/tests/systemc/1666-2011-compliance/event_list/event_list.cpp new file mode 100644 index 000000000..a3617ff60 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/event_list/event_list.cpp @@ -0,0 +1,318 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// event_list.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: event_list.cpp,v $ +// Revision 1.3 2011/09/05 21:23:30 acg +// Philipp A. Hartmann: eliminate compiler warnings. +// +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Event lists. A thread waits on a list of events built dynamically from a multiport + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Mod: sc_module +{ + sc_port<sc_signal_in_if<int>, 0> p; // Multiport + + Mod(sc_module_name _name) + { + SC_THREAD(T1); + SC_THREAD(T2); + } + + void T1() + { + for (;;) + { + wait(all_events()); + cout << "M::T1 awoke with " << p[0]->read() << p[1]->read() << p[2]->read() + << " at " << sc_time_stamp() << " on list" << endl; + } + } + void T2() + { + for (;;) + { + wait( p[0]->default_event() | p[1]->default_event() ); + cout << "M::T2 awoke with " << p[0]->read() << p[1]->read() << p[2]->read() + << " at " << sc_time_stamp() << " on list" << endl; + } + } + sc_event_or_list all_events() const + { + sc_assert( p.size() == 3 ); + + sc_event_or_list or_list; + for (int i = 0; i < p.size(); i++) + or_list |= p[i]->default_event(); + + sc_assert( or_list.size() == 3 ); + return or_list; + } + + SC_HAS_PROCESS(Mod); +}; + +struct Top: sc_module +{ + Top(sc_module_name _name) + : finished(false) + , count(0) + { + m = new Mod("m"); + m->p.bind(sig1); + m->p.bind(sig2); + m->p.bind(sig3); + SC_THREAD(T); + SC_METHOD(M); + } + + ~Top() + { + sc_assert( finished ); + sc_assert( count == 4 ); + sc_assert( sc_get_status() == SC_PAUSED ); + sc_assert( sc_is_running() == true ); + cout << "~T() called" << endl; + } + + sc_signal<int> sig1, sig2, sig3; + Mod* m; + + sc_event e1, e2, e3, e4; + bool finished; + + void T() + { + sig1.write(0); + sig2.write(0); + sig3.write(0); + + wait(10, SC_NS); + sig1.write(1); + wait(10, SC_NS); + sig1.write(2); + + wait(10, SC_NS); + sig2.write(1); + wait(10, SC_NS); + sig2.write(2); + + wait(10, SC_NS); + sig3.write(1); + wait(10, SC_NS); + sig3.write(2); + + sc_time start; + start = sc_time_stamp(); + + e1.notify(10, SC_NS); + e2.notify(20, SC_NS); + + sc_event_and_list list1 = e1 & e2; + sc_assert( list1.size() == 2 ); + + wait( list1 ); + cout << "Awoke at " << sc_time_stamp() << endl; + sc_assert( sc_time_stamp() - start == sc_time(20, SC_NS) ); + + start = sc_time_stamp(); + e1.notify(11, SC_NS); + e2.notify(21, SC_NS); + + sc_event_and_list list2; + list2 &= e1; + list2 &= e2; + sc_assert( list2.size() == 2 ); + + wait( list2); + cout << "Awoke at " << sc_time_stamp() << endl; + sc_assert( sc_time_stamp() - start == sc_time(21, SC_NS) ); + + start = sc_time_stamp(); + e1.notify(14, SC_NS); + e2.notify(24, SC_NS); + + sc_event_and_list list3 = list2 & e2; + sc_assert( list3.size() == 2 ); + + wait( list3 ); + cout << "Awoke at " << sc_time_stamp() << endl; + sc_assert( sc_time_stamp() - start == sc_time(24, SC_NS) ); + + start = sc_time_stamp(); + e1.notify(100, SC_NS); + e2.notify(200, SC_NS); + + sc_event_and_list list4; + list4 = list3 & e2; + sc_assert( list4.size() == 2 ); + wait( list4 ); + cout << "Awoke at " << sc_time_stamp() << endl; + sc_assert( sc_time_stamp() - start == sc_time(200, SC_NS) ); + + start = sc_time_stamp(); + e1.notify(101, SC_NS); + e2.notify(202, SC_NS); + + sc_event_and_list list5 = list3 & list4; + sc_assert( list5.size() == 2 ); + wait( list5 ); + cout << "Awoke at " << sc_time_stamp() << endl; + sc_assert( sc_time_stamp() - start == sc_time(202, SC_NS) ); + + sc_event_and_list list6 = e1; + sc_assert( list6.size() == 1 ); + + start = sc_time_stamp(); + e1.notify(500, SC_NS); + wait(list6); + sc_assert( sc_time_stamp() - start == sc_time(500, SC_NS) ); + + + start = sc_time_stamp(); + e1.notify(1000, SC_NS); + wait(e1 | e2 | e3); + cout << "Awoke at " << sc_time_stamp() << endl; + sc_assert( sc_time_stamp() - start == sc_time(1000, SC_NS) ); + + start = sc_time_stamp(); + e1.notify(1002, SC_NS); + e2.notify(1001, SC_NS); + e3.notify(1000, SC_NS); + + wait(e1 & e2 & e3); + cout << "Awoke at " << sc_time_stamp() << endl; + sc_assert( sc_time_stamp() - start == sc_time(1002, SC_NS) ); + + start = sc_time_stamp(); + e1.notify(2000, SC_NS); + + sc_event_or_list list7; + list7 = e1 | e2; + list7 = list7 | e3; + list7 |= e4; + wait(list7); + cout << "Awoke at " << sc_time_stamp() << endl; + sc_assert( sc_time_stamp() - start == sc_time(2000, SC_NS) ); + + start = sc_time_stamp(); + e1.notify(3000, SC_NS); + list7 = e2 | e3; + list7 = e1 | list7; + wait(list7); + cout << "Awoke at " << sc_time_stamp() << endl; + sc_assert( sc_time_stamp() - start == sc_time(3000, SC_NS) ); + + list1 = e1; + list2 = e2; + e1.notify(SC_ZERO_TIME); + wait(list1); + e2.notify(SC_ZERO_TIME); + wait(list2); + + list1.swap(list2); + + e1.notify(SC_ZERO_TIME); + wait(list2); + e2.notify(SC_ZERO_TIME); + wait(list1); + + finished = true; + } + + sc_event v1, v2, v3, v4; + sc_event_or_list or_list1, or_list2; + sc_event_and_list and_list1, and_list2; + int count; + + void M() + { + switch (count) + { + case 0: + { + sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); + or_list1 = v1 | v2; + or_list2 = v3 | v4; + v2.notify(10, SC_NS); + next_trigger(or_list1 | or_list2); + break; + } + case 1: + { + sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); + and_list1 = v1 & v2; + and_list2 = v3 & v4; + v1.notify(1, SC_NS); + v2.notify(2, SC_NS); + v3.notify(3, SC_NS); + v4.notify(4, SC_NS); + next_trigger(and_list1 & and_list2); + break; + } + case 2: + { + sc_assert( sc_time_stamp() == sc_time(14, SC_NS) ); + and_list1 = v1 & v2 & v2 & v1; + sc_assert( and_list1.size() == 2 ); + v1.notify(1, SC_NS); + v2.notify(2, SC_NS); + next_trigger(and_list1); + break; + } + case 3: + { + sc_assert( sc_time_stamp() == sc_time(16, SC_NS) ); + break; + } + } + ++count; + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( sc_get_status() == SC_PAUSED ); + sc_assert( sc_is_running() ); + sc_assert( sc_pending_activity() == false ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/event_list/golden/event_list.log b/src/systemc/tests/systemc/1666-2011-compliance/event_list/golden/event_list.log new file mode 100644 index 000000000..91fb861d7 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/event_list/golden/event_list.log @@ -0,0 +1,23 @@ +SystemC Simulation +M::T1 awoke with 100 at 10 ns on list +M::T2 awoke with 100 at 10 ns on list +M::T1 awoke with 200 at 20 ns on list +M::T2 awoke with 200 at 20 ns on list +M::T1 awoke with 210 at 30 ns on list +M::T2 awoke with 210 at 30 ns on list +M::T1 awoke with 220 at 40 ns on list +M::T2 awoke with 220 at 40 ns on list +M::T1 awoke with 221 at 50 ns on list +M::T1 awoke with 222 at 60 ns on list +Awoke at 80 ns +Awoke at 101 ns +Awoke at 125 ns +Awoke at 325 ns +Awoke at 527 ns +Awoke at 2027 ns +Awoke at 3029 ns +Awoke at 5029 ns +Awoke at 8029 ns + +Success +~T() called diff --git a/src/systemc/tests/systemc/1666-2011-compliance/immed_self_notif/golden/immed_self_notif.log b/src/systemc/tests/systemc/1666-2011-compliance/immed_self_notif/golden/immed_self_notif.log new file mode 100644 index 000000000..994878d96 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/immed_self_notif/golden/immed_self_notif.log @@ -0,0 +1,7 @@ +SystemC Simulation + +Warning: (W536) immediate self-notification ignored as of IEEE 1666-2011: top.M1 +In file: <removed by verify.pl> +In process: top.M1 @ 0 s + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/immed_self_notif/immed_self_notif.cpp b/src/systemc/tests/systemc/1666-2011-compliance/immed_self_notif/immed_self_notif.cpp new file mode 100644 index 000000000..d29582a38 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/immed_self_notif/immed_self_notif.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. + + *****************************************************************************/ + +// immed_self_notif.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: immed_self_notif.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Change to the semantics of immediate self-notification to match Verilog semantics + +#define SC_INCLUDE_DYNAMIC_PROCESSES +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(T1); + sensitive << ev1; + + SC_THREAD(T2); + sensitive << ev1; + + SC_THREAD(T3); + + SC_THREAD(T4); + sensitive << ev3; + + SC_METHOD(M1); + sensitive << ev5; + + SC_METHOD(M2); + + SC_METHOD(M3); + + SC_THREAD(yield_test); + + end_of_t2 = false; + m1_run = false; + m2_run = false; + m3_run = false; + first_yield = true; + yield_count = 0; + yield_test_run = false; + } + + sc_event ev1, ev2, ev3, ev4, ev5, ev6, ev7; + bool end_of_t2; + bool m1_run; + bool m2_run; + bool m3_run; + + sc_event yield_event_1, yield_event_2; + bool first_yield; + int yield_count; + bool yield_test_run; + + void T1() + { + wait(SC_ZERO_TIME); + ev1.notify(); + sc_assert( sc_delta_count() == 1 ); + wait(ev1); + sc_assert( false ); + } + + void T2() + { + wait(ev1); + sc_assert( sc_delta_count() == 1 ); + end_of_t2 = true; + } + + void T3() + { + wait(SC_ZERO_TIME); + ev2.notify(); + sc_assert( sc_delta_count() == 1 ); + wait(ev2); + sc_assert( false ); + } + + void T4() + { + wait(SC_ZERO_TIME); + ev3.notify(); + sc_assert( sc_delta_count() == 1 ); + wait(ev4); + sc_assert( false ); + } + + void M1() + { + sc_assert( !m1_run ); + ev5.notify(); + m1_run = true; + } + + void M2() + { + sc_assert( !m2_run ); + ev6.notify(); + next_trigger(ev6); + m2_run = true; + } + + void M3() + { + sc_assert( !m3_run ); + next_trigger(ev7); + ev7.notify(); + m3_run = true; + } + + void yield_test() + { + sc_assert( sc_delta_count() == 0 ); + wait(SC_ZERO_TIME); + sc_assert( sc_delta_count() == 1 ); + + yield(); + sc_spawn(sc_bind( &Top::yield_test_child, this)); + yield(); + sc_spawn(sc_bind( &Top::yield_test_child, this)); + yield(); + + sc_assert( sc_delta_count() == 1 ); + wait(1, SC_MS); + unsigned int delta_count = sc_delta_count(); + + yield(); + sc_spawn(sc_bind( &Top::yield_test_child, this)); + yield(); + sc_spawn(sc_bind( &Top::yield_test_child, this)); + yield(); + + sc_assert( sc_delta_count() == delta_count ); + yield_test_run = true; + } + + void yield_test_child() + { + yield(); + } + + void yield() + { + ++yield_count; + if (first_yield) + { + sc_spawn(sc_bind(&Top::yield_helper, this)); + first_yield = false; + } + else + yield_event_1.notify(); + wait(yield_event_2); + } + + void yield_helper() + { + yield_event_2.notify(); + while (true) + { + wait(yield_event_1); + yield_event_2.notify(); + } + } + + SC_HAS_PROCESS(Top); +}; + + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.end_of_t2 ); + sc_assert( top.m1_run ); + sc_assert( top.m2_run ); + sc_assert( top.m3_run ); + sc_assert( top.first_yield == false ); + sc_assert( top.yield_count == 10 ); + sc_assert( top.yield_test_run ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/include_descendants/golden/include_descendants.log b/src/systemc/tests/systemc/1666-2011-compliance/include_descendants/golden/include_descendants.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/include_descendants/golden/include_descendants.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/include_descendants/include_descendants.cpp b/src/systemc/tests/systemc/1666-2011-compliance/include_descendants/include_descendants.cpp new file mode 100644 index 000000000..3a9306d04 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/include_descendants/include_descendants.cpp @@ -0,0 +1,328 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// include_descendants.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: include_descendants.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Process control methods include_descendants argument + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(calling); + + SC_THREAD(target1); + t1 = sc_get_current_process_handle(); + + SC_THREAD(target4); + t4 = sc_get_current_process_handle(); + + SC_THREAD(target7); + t7 = sc_get_current_process_handle(); + + count = 0; + f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = f10 = 0; + f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = 0; + } + + sc_process_handle t1, ch2, ch3, t4, ch5, ch6, t7, ch8, ch9; + sc_process_handle gch10, gch11, gch12, gch13; + sc_event ev; + int count; + int f1, f2, f3, f4, f5, f6, f7, f8, f9, f10; + int f11, f12, f13, f14, f15, f16, f17, f18; + + std::exception ex; + + void calling() + { + wait(SC_ZERO_TIME); + + count = 1; + t1.suspend(SC_INCLUDE_DESCENDANTS); + ev.notify(5, SC_NS); + wait(10, SC_NS); + + count = 2; + t1.resume(SC_INCLUDE_DESCENDANTS); + wait(10, SC_NS); + + count = 3; + t1.disable(SC_INCLUDE_DESCENDANTS); + ev.notify(5, SC_NS); + wait(10, SC_NS); + + count = 4; + t1.enable(SC_INCLUDE_DESCENDANTS); + wait(10, SC_NS); + + count = 5; + ev.notify(); + wait(10, SC_NS); + + count = 6; + t1.sync_reset_on(SC_INCLUDE_DESCENDANTS); + wait(10, SC_NS); + + count = 7; + ev.notify(); + wait(10, SC_NS); + + count = 8; + t1.sync_reset_off(SC_INCLUDE_DESCENDANTS); + wait(sc_time(110, SC_NS) - sc_time_stamp()); + + count = 10; + t4.reset(SC_INCLUDE_DESCENDANTS); + wait(sc_time(210, SC_NS) - sc_time_stamp()); + + t7.throw_it(ex, SC_INCLUDE_DESCENDANTS); + } + + void target1() + { + sc_assert(count == 0); + ch2 = sc_spawn(sc_bind(&Top::child2, this)); + ch3 = sc_spawn(sc_bind(&Top::child3, this)); + wait(ch2.terminated_event() & ch3.terminated_event()); + f5 = 1; + } + + void child2() + { + if (count == 0) // Initialization + { + wait(ev); + sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); + wait(ev); + sc_assert(count == 5); + sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); + f1 = 1; + wait(ev); + } + else if (count == 7) // Sync reset + { + sc_assert( sc_time_stamp() == sc_time(60, SC_NS) ); + f3 = 1; + wait(20, SC_NS); + } + } + + void child3() + { + if (count == 0) // Initialization + { + wait(ev); + sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); + wait(ev); + sc_assert(count == 5); + sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); + f2 = 1; + wait(ev); + } + else if (count == 7) // Sync reset + { + sc_assert( sc_time_stamp() == sc_time(60, SC_NS) ); + f4 = 1; + wait(20, SC_NS); + } + } + + void target4() + { + if (count == 0) + { + wait(100, SC_NS); + count = 9; + ch5 = sc_spawn(sc_bind(&Top::child5, this)); + ch6 = sc_spawn(sc_bind(&Top::child6, this)); + } + else // Hard reset + { + sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); + f11 = 1; + } + wait(ch5.terminated_event() & ch6.terminated_event()); + f6 = 1; + } + + void child5() + { + switch (count) + { + case 9: sc_assert( sc_time_stamp() == sc_time(100, SC_NS) ); f7=1; break; + case 10: sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); f8=1; break; + default: sc_assert( false ); break; + } + wait(20, SC_NS); + } + + void child6() + { + switch (count) + { + case 9: sc_assert( sc_time_stamp() == sc_time(100, SC_NS) ); f9=1; break; + case 10: sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); f10=1; break; + default: sc_assert( false ); break; + } + wait(20, SC_NS); + } + + void target7() + { + wait(200, SC_NS); + count = 11; + ch8 = sc_spawn(sc_bind(&Top::child8, this)); + ch9 = sc_spawn(sc_bind(&Top::child9, this)); + try { + wait(20, SC_NS); + } + catch (std::exception e) { + sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); + } + wait(ch8.terminated_event() & ch9.terminated_event()); + sc_assert( sc_time_stamp() == sc_time(214, SC_NS) ); + f12 = 1; + } + + void child8() + { + gch10 = sc_spawn(sc_bind(&Top::grandchild10, this)); + gch11 = sc_spawn(sc_bind(&Top::grandchild11, this)); + try { + wait(20, SC_NS); + } + catch (std::exception e) { + f13 = 1; + sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); + } + wait(gch10.terminated_event() & gch11.terminated_event()); + } + + void child9() + { + gch12 = sc_spawn(sc_bind(&Top::grandchild12, this)); + gch13 = sc_spawn(sc_bind(&Top::grandchild13, this)); + try { + wait(20, SC_NS); + } + catch (std::exception e) { + f14 = 1; + sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); + } + wait(gch12.terminated_event() & gch13.terminated_event()); + } + + void grandchild10() + { + try { + wait(20, SC_NS); + } + catch (std::exception e) { + f15 = 1; + sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); + } + wait(1, SC_NS); + } + + void grandchild11() + { + try { + wait(20, SC_NS); + } + catch (std::exception e) { + f16 = 1; + sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); + } + wait(4, SC_NS); + } + + void grandchild12() + { + try { + wait(20, SC_NS); + } + catch (std::exception e) { + f17 = 1; + sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); + } + wait(2, SC_NS); + } + + void grandchild13() + { + try { + wait(20, SC_NS); + } + catch (std::exception e) { + f18 = 1; + sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); + } + wait(3, SC_NS); + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f1 ); + sc_assert( top.f2 ); + sc_assert( top.f3 ); + sc_assert( top.f4 ); + sc_assert( top.f5 ); + sc_assert( top.f6 ); + sc_assert( top.f7 ); + sc_assert( top.f8 ); + sc_assert( top.f9 ); + sc_assert( top.f10 ); + sc_assert( top.f11 ); + sc_assert( top.f12 ); + sc_assert( top.f13 ); + sc_assert( top.f14 ); + sc_assert( top.f15 ); + sc_assert( top.f16 ); + sc_assert( top.f17 ); + sc_assert( top.f18 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/kill_reset/golden/kill_reset.log b/src/systemc/tests/systemc/1666-2011-compliance/kill_reset/golden/kill_reset.log new file mode 100644 index 000000000..e9e5e75ef --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/kill_reset/golden/kill_reset.log @@ -0,0 +1,17 @@ +SystemC Simulation +Target called/reset at 0 s +Target awoke at 10 ns +Target awoke at 20 ns +sc_unwind_exception caught by target +Target called/reset at 25 ns +Target awoke at 30 ns +sc_unwind_exception caught by target +sc_unwind_exception caught by ticker +sc_unwind_exception caught by victim +sc_unwind_exception caught by bystander +sc_unwind_exception caught by second_bystander +sc_unwind_exception caught by third_bystander + +Info: /OSCI/SystemC: Simulation stopped by user. + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/kill_reset/kill_reset.cpp b/src/systemc/tests/systemc/1666-2011-compliance/kill_reset/kill_reset.cpp new file mode 100644 index 000000000..208e5bb2d --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/kill_reset/kill_reset.cpp @@ -0,0 +1,270 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// kill_reset.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: kill_reset.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Reset and kill a thread process, including nested kills and resets + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct M3: sc_module +{ + M3(sc_module_name _name) + { + SC_THREAD(ticker); + k = sc_get_current_process_handle(); + + SC_THREAD(calling); + + SC_THREAD(target); + t = sc_get_current_process_handle(); + + SC_THREAD(victim); + v = sc_get_current_process_handle(); + + SC_THREAD(bystander); + b = sc_get_current_process_handle(); + + SC_THREAD(second_bystander); + b2 = sc_get_current_process_handle(); + + SC_THREAD(third_bystander); + b3 = sc_get_current_process_handle(); + + killing_over = false; + third_bystander_knocked_over = false; + } + + sc_process_handle t, k, v, b, b2, b3; + sc_event ev; + int count; + bool killing_over; + bool third_bystander_knocked_over; + + void ticker() + { + for (;;) + { + try { + wait(10, SC_NS); + ev.notify(); + sc_assert( !sc_is_unwinding() ); + } + catch (const sc_unwind_exception& ex) + { + // ticker process killed by target + cout << "sc_unwind_exception caught by ticker" << endl; + sc_assert( !ex.is_reset() ); + sc_assert( count == 1 ); + sc_assert( !killing_over ); + sc_assert( t.is_unwinding() ); + sc_assert( sc_is_unwinding() ); + + v.kill(); + throw ex; + } + } + } + + void calling() + { + wait(15, SC_NS); + // Target runs at time 10 NS due to notification + sc_assert( count == 1 ); + // The victim awakes every 1ns + sc_assert( sc_time_to_pending_activity() <= sc_time(1, SC_NS) ); + + wait(10, SC_NS); + // Target runs again at time 20 NS due to notification + sc_assert( count == 2 ); + + t.reset(); + // Target reset immediately at time 25 NS + sc_assert( count == 0 ); + + wait(10, SC_NS); + // Target runs again at time 30 NS due to notification + sc_assert( count == 1 ); + + t.kill(); + sc_assert( !killing_over ); + killing_over = true; + + // Target killed immediately at time 35 NS + if (t.valid()) + sc_assert( t.terminated() ); + if (k.valid()) + sc_assert( k.terminated() ); + if (v.valid()) + sc_assert( v.terminated() ); + sc_assert( b.valid() && !b.terminated() ); + sc_assert( b2.valid() && !b2.terminated() ); + if (b3.valid()) + sc_assert( b3.terminated() ); + + sc_stop(); + } + + void target() + { + cout << "Target called/reset at " << sc_time_stamp() << endl; + count = 0; + for (;;) + { + try { + wait(ev); + cout << "Target awoke at " << sc_time_stamp() << endl; + ++count; + } + catch (const sc_unwind_exception& ex) + { + cout << "sc_unwind_exception caught by target" << endl; + if (count == 2) + sc_assert( ex.is_reset() ); + else if (count == 1) + { + sc_assert( !ex.is_reset() ); + sc_assert( !killing_over ); + k.kill(); + } + else + sc_assert( false ); + throw ex; + } + } + } + + void victim() + { + try { + while (true) + { + wait(1, SC_NS); + sc_assert( !sc_is_unwinding() ); + } + } + catch (const sc_unwind_exception& ex) + { + cout << "sc_unwind_exception caught by victim" << endl; + sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); + sc_assert( ex.is_reset() == false ); + sc_assert( !killing_over ); + sc_assert( v.is_unwinding() ); + sc_assert( sc_is_unwinding() ); + + b.reset(); + throw ex; + } + } + + void bystander() // Gets reset by victim + { + for (;;) + { + try { + wait(ev); + } + catch (const sc_unwind_exception& ex) { + cout << "sc_unwind_exception caught by bystander" << endl; + sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); + sc_assert( ex.is_reset() == true ); + sc_assert( !killing_over ); + sc_assert( v.is_unwinding() ); // sic + sc_assert( sc_is_unwinding() ); + + b2.reset(); + throw ex; + } + } + } + + void second_bystander() // Gets reset by bystander + { + for (;;) + { + try { + wait(ev); + } + catch (const sc_unwind_exception& ex) { + cout << "sc_unwind_exception caught by second_bystander" << endl; + sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); + sc_assert( ex.is_reset() == true ); + sc_assert( !killing_over ); + sc_assert( v.is_unwinding() ); // sic + sc_assert( b.is_unwinding() ); // sic + sc_assert( sc_is_unwinding() ); + + b3.kill(); + throw ex; + } + } + } + + void third_bystander() // Gets killed by second bystander + { + for (;;) + { + try { + wait(ev); + } + catch (const sc_unwind_exception& ex) { + cout << "sc_unwind_exception caught by third_bystander" << endl; + sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); + sc_assert( !ex.is_reset() == true ); + sc_assert( !killing_over ); + sc_assert( v.is_unwinding() ); // sic + sc_assert( b.is_unwinding() ); // sic + sc_assert( b2.is_unwinding() ); // sic + sc_assert( sc_is_unwinding() ); + + third_bystander_knocked_over = true; + throw ex; + } + } + } + + SC_HAS_PROCESS(M3); +}; + +int sc_main(int argc, char* argv[]) +{ + M3 m("m"); + sc_assert( sc_pending_activity() == false ); + sc_assert( sc_time_to_pending_activity() == sc_max_time() ); + + sc_start(); + sc_assert( m.third_bystander_knocked_over ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/late_reset_bug/golden/late_reset_bug.log b/src/systemc/tests/systemc/1666-2011-compliance/late_reset_bug/golden/late_reset_bug.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/late_reset_bug/golden/late_reset_bug.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/late_reset_bug/late_reset_bug.cpp b/src/systemc/tests/systemc/1666-2011-compliance/late_reset_bug/late_reset_bug.cpp new file mode 100644 index 000000000..9ec572ff5 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/late_reset_bug/late_reset_bug.cpp @@ -0,0 +1,90 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// late_reset_bug.cpp -- test for +// +// Original Author: John Aynsley, Doulus +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// + +// + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(control); + + SC_METHOD(target); + sensitive << ev; + dont_initialize(); + target_handle = sc_get_current_process_handle(); + + count = 0; + f0 = f1 = 0; + } + + sc_event ev; + sc_process_handle target_handle; + int count; + int f0, f1; + + void control() + { + count = 0; + wait(10, SC_NS); + + count = 1; + target_handle.reset(); + + count = 2; + f1 = 1; + } + + void target() + { + sc_assert( count == 1 ); // FAILS !!!!!! + f0 = 1; + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f0 ); + sc_assert( top.f1 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/living_children/golden/living_children.log b/src/systemc/tests/systemc/1666-2011-compliance/living_children/golden/living_children.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/living_children/golden/living_children.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/living_children/living_children.cpp b/src/systemc/tests/systemc/1666-2011-compliance/living_children/living_children.cpp new file mode 100644 index 000000000..e67218770 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/living_children/living_children.cpp @@ -0,0 +1,107 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// living_children.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: living_children.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Not invaliding handles to processes with living children + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + t1 = sc_spawn(sc_bind(&Top::T1, this)); + } + + sc_process_handle t1, t2a, t2b; + + void T1() + { + wait(1, SC_NS); + t2a = sc_spawn(sc_bind(&Top::T2, this)); + t2b = sc_spawn(sc_bind(&Top::T2, this)); + wait(1, SC_NS); + sc_assert( t2a.valid() ); + sc_assert( t2b.valid() ); + + std::vector<sc_object*> children = t1.get_child_objects(); + sc_assert( children.size() == 2); + + sc_event_and_list and_list = t2a.terminated_event() & t2b.terminated_event(); + wait( and_list ); + + sc_assert( t2a.valid() ); + sc_assert( t2a.terminated() ); + sc_assert( t2b.valid() ); + sc_assert( t2b.terminated() ); + sc_assert( sc_time_stamp() == sc_time(3, SC_NS) ); + } + + void T2() + { + wait(2, SC_NS); + sc_process_handle t3 = sc_spawn(sc_bind(&Top::T3, this)); + wait(SC_ZERO_TIME); + sc_assert( t3.valid() ); + + sc_process_handle me = sc_get_current_process_handle(); + sc_assert( me.get_parent_object() ); // Parent handle shall still be valid + std::vector<sc_object*> children = me.get_child_objects(); + sc_assert( children.size() == 1); + + std::vector<sc_event*> my_events = me.get_child_events(); + sc_assert( my_events.size() == 0 ); + } + + void T3() + { + wait(3, SC_NS); + sc_process_handle me = sc_get_current_process_handle(); + sc_assert( me.get_parent_object() ); // Parent handle shall still be valid + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/living_dead_bug/golden/living_dead_bug.log b/src/systemc/tests/systemc/1666-2011-compliance/living_dead_bug/golden/living_dead_bug.log new file mode 100644 index 000000000..09402b72c --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/living_dead_bug/golden/living_dead_bug.log @@ -0,0 +1,10 @@ +SystemC Simulation + +Warning: (W558) disable() or dont_initialize() called on process with no static sensitivity, it will be orphaned: top.target +In file: <removed by verify.pl> + +Warning: (W558) disable() or dont_initialize() called on process with no static sensitivity, it will be orphaned: top.control.dyn_target +In file: <removed by verify.pl> +In process: top.control @ 0 s + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/living_dead_bug/living_dead_bug.cpp b/src/systemc/tests/systemc/1666-2011-compliance/living_dead_bug/living_dead_bug.cpp new file mode 100644 index 000000000..921ddd5bb --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/living_dead_bug/living_dead_bug.cpp @@ -0,0 +1,88 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// living_dead_bug.cpp -- test for +// +// Original Author: John Aynsley, Doulus +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// + +// + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(control); + + SC_THREAD(target); + dont_initialize(); + target_handle = sc_get_current_process_handle(); + + f0 = f1 = 0; + } + + sc_process_handle target_handle; + int f0, f1; + + void control() + { + // create another (orphaned) instance of "target" + { + sc_spawn_options opt; + opt.dont_initialize(); + sc_spawn( sc_bind( &Top::target, this ), "dyn_target", &opt ); + } + + wait(10, SC_NS); + f0 = 1; + target_handle.kill(); + f1 = 1; + } + + void target() + { + sc_assert( false ); // FAILS!!!!!! + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f0 ); + sc_assert( top.f1 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/method_suspends_itself/golden/method_suspends_itself.log b/src/systemc/tests/systemc/1666-2011-compliance/method_suspends_itself/golden/method_suspends_itself.log new file mode 100644 index 000000000..cdf4578d6 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/method_suspends_itself/golden/method_suspends_itself.log @@ -0,0 +1,5 @@ +SystemC Simulation + +Info: /OSCI/SystemC: Simulation stopped by user. + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/method_suspends_itself/method_suspends_itself.cpp b/src/systemc/tests/systemc/1666-2011-compliance/method_suspends_itself/method_suspends_itself.cpp new file mode 100644 index 000000000..26dce0530 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/method_suspends_itself/method_suspends_itself.cpp @@ -0,0 +1,429 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// method_suspends_itself.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: method_suspends_itself.cpp,v $ +// Revision 1.3 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Method process uses suspends, resumes, disables, and enables itself + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(ticker); + SC_THREAD(calling); + + SC_METHOD(target); + sensitive << ev; + dont_initialize(); + t = sc_get_current_process_handle(); + + suspend_target = false; + resume_target = false; + disable_target = false; + enable_target = false; + dynamic_sensitivity = false; + f0 = f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0; + f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0; + f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0; + } + + sc_process_handle t; + sc_event ev, ev2; + bool suspend_target; + bool resume_target; + bool disable_target; + bool enable_target; + bool dynamic_sensitivity; + int count; + int f0, f1, f2, f3, f4, f5, f6, f7, f8, f9; + int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19; + int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29; + + void ticker() + { + for (;;) + { + wait(10, SC_NS); + ev.notify(); + } + } + + void calling() + { + count = 1; + wait(15, SC_NS); + // Target runs at 10 NS + + count = 2; + suspend_target = true; + wait(10, SC_NS); + // Target runs at 20 NS and suspends itself + + count = 3; + suspend_target = false; + wait(10, SC_NS); + // Target does not run at 30 NS + + count = 4; + t.resume(); + // Target runs at 35 NS + + wait(10, SC_NS); + // Target runs at 40 NS + + count = 6; + suspend_target = true; + resume_target = true; + wait(10, SC_NS); + // Target runs at 50 NS + + count = 7; + resume_target = true; + wait(10, SC_NS); + // Double resume at 60 NS + + count = 8; + suspend_target = true; + resume_target = false; + wait(10, SC_NS); + // Target runs at 70 NS + + count = 9; + wait(10, SC_NS); + // Double suspend + // Target does not run at 80 NS + + count = 10; + suspend_target = false; + resume_target = false; + t.resume(); + // Target runs at 85 NS + + wait(10, SC_NS); + // Target runs at 90 NS + sc_assert( count == 11 ); + + count = 12; + t.suspend(); + wait(10, SC_NS); + // Target does not run at 100 NS + + count = 13; + t.resume(); + // Target runs at 105 NS + + wait(10, SC_NS); + // Target runs at 110 NS + sc_assert( count == 14 ); + + count = 15; + t.disable(); + wait(10, SC_NS); + // Target does not run at 120 NS + + count = 16; + wait(10, SC_NS); + // Target does not run at 130 NS + + count = 17; + t.disable(); + // Double disable + wait(10, SC_NS); + // Target does not run at 140 NS + + count = 18; + t.enable(); + wait(10, SC_NS); + // Target runs at 150 NS + + count = 19; + t.enable(); + // Double enable + wait(10, SC_NS); + // Target runs at 160 NS + + count = 20; + disable_target = true; + wait(10, SC_NS); + // Target runs at 170 and disables itself + + count = 21; + disable_target = false; + wait(10, SC_NS); + // Target does not run at 180 + + count = 22; + enable_target = true; + wait(10, SC_NS); + // Target does not run at 190 + + count = 23; + wait(10, SC_NS); + // Failed to enable it itself, so still does not run at 200 + + count = 24; + enable_target = false; + t.enable(); + wait(10, SC_NS); + // Target runs at 210 + + count = 25; + disable_target = true; + enable_target = true; + wait(10, SC_NS); + // Target runs at 220 and calls disable -> enable + + count = 26; + disable_target = false; + enable_target = false; + wait(10, SC_NS); + // Target runs at 230 + + count = 27; + t.suspend(); + wait(10, SC_NS); + // Target does not run at 240 + + count = 28; + t.enable(); + wait(10, SC_NS); + // Has no effect - still suspended at 250 + + count = 29; + t.disable(); + wait(10, SC_NS); + // Both disabled and suspended at 260 + + count = 30; + t.enable(); + wait(10, SC_NS); + // Enabled but still suspended + + count = 31; + t.resume(); + // Target resumed at 275 NS + wait(SC_ZERO_TIME); + + count = 311; + wait(10, SC_NS); + + count = 32; + t.disable(); + wait(10, SC_NS); + // Disabled at 290 NS + + count = 33; + t.resume(); + wait(10, SC_NS); + // Still disabled at 300 NS + + count = 34; + t.suspend(); + wait(10, SC_NS); + // Both disabled and suspended at 310 + + count = 35; + t.enable(); + wait(10, SC_NS); + // Remains suspended at 320 + + count = 36; + t.resume(); + wait(10, SC_NS); + // Resumed at 325 NS and runs at 330 + sc_assert( count == 37 ); + + count = 38; + suspend_target = true; + resume_target = true; + disable_target = true; + enable_target = true; + wait(10, SC_NS); + // Runs at 340 + + count = 39; + suspend_target = true; + resume_target = false; + disable_target = true; + enable_target = true; + wait(10, SC_NS); + // Runs at 350, when it suspends + + count = 40; + suspend_target = false; + wait(10, SC_NS); + // Suspended at 360 + + count = 41; + t.resume(); + wait(10, SC_NS); + // Runs at 365 and 370 + sc_assert( count == 42 ); + + sc_assert( t.valid() ); + sc_assert( t.terminated() == false ); + sc_assert( t.dynamic() == false ); + sc_assert( t.get_parent_object() == this ); + sc_assert( t.get_process_object() != 0 ); + + count = 43; + t.reset(); + wait(SC_ZERO_TIME); + + count = 44; + dynamic_sensitivity = true; + wait(10, SC_NS); + // Runs at 380 + + count = 45; + ev2.notify(); + wait(1, SC_NS); + + count = 46; + ev2.notify(); + wait(sc_time(400, SC_NS) - sc_time_stamp()); + + count = 47; + dynamic_sensitivity = false; + t.sync_reset_on(); // Still dynamically sensitive to ev2 + ev2.notify(); // Clears dynamic sensitivity, restores static sensitivity + + count = 48; + wait(10, SC_NS); + + count = 49; + t.kill(); + + if (t.valid()) + sc_assert( t.terminated() ); + + sc_stop(); + } + + void target() + { + //cout << "Target called at " << sc_time_stamp() << " count = " << count << endl; + switch (count) + { + case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); f0=1; break; + case 2: sc_assert( sc_time_stamp() == sc_time(20, SC_NS) ); f1=1; break; + case 4: sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); count = 5; f2=1; break; + case 5: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); f3=1; break; + case 6: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); f4=1; break; + case 7: sc_assert( sc_time_stamp() == sc_time(60, SC_NS) ); f5=1; break; + case 8: sc_assert( sc_time_stamp() == sc_time(70, SC_NS) ); f6=1; break; + case 10: sc_assert( sc_time_stamp() == sc_time(85, SC_NS) ); count = 11; f7=1; break; + case 11: sc_assert( sc_time_stamp() == sc_time(90, SC_NS) ); f8=1; break; + case 13: sc_assert( sc_time_stamp() == sc_time(105, SC_NS) ); count = 14; f9=1; break; + case 14: sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); f10=1; break; + case 18: sc_assert( sc_time_stamp() == sc_time(150, SC_NS) ); f11=1; break; + case 19: sc_assert( sc_time_stamp() == sc_time(160, SC_NS) ); f12=1; break; + case 20: sc_assert( sc_time_stamp() == sc_time(170, SC_NS) ); f13=1; break; + case 24: sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); f14=1; break; + case 25: sc_assert( sc_time_stamp() == sc_time(220, SC_NS) ); f15=1; break; + case 26: sc_assert( sc_time_stamp() == sc_time(230, SC_NS) ); f16=1; break; + case 31: sc_assert( sc_time_stamp() == sc_time(275, SC_NS) ); f17=1; break; + case 311:sc_assert( sc_time_stamp() == sc_time(280, SC_NS) ); f18=1; break; + case 36: sc_assert( sc_time_stamp() == sc_time(325, SC_NS) ); count = 37; f19=1; break; + case 37: sc_assert( sc_time_stamp() == sc_time(330, SC_NS) ); f20=1; break; + case 38: sc_assert( sc_time_stamp() == sc_time(340, SC_NS) ); f21=1; break; + case 39: sc_assert( sc_time_stamp() == sc_time(350, SC_NS) ); f22=1; break; + case 41: sc_assert( sc_time_stamp() == sc_time(365, SC_NS) ); count = 42; f23=1; break; + case 42: sc_assert( sc_time_stamp() == sc_time(370, SC_NS) ); f24=1; break; + case 43: sc_assert( sc_time_stamp() == sc_time(375, SC_NS) ); f29=1; break; //////// + case 44: sc_assert( sc_time_stamp() == sc_time(380, SC_NS) ); f25=1; break; + case 45: sc_assert( sc_time_stamp() == sc_time(385, SC_NS) ); f26=1; break; + case 46: sc_assert( sc_time_stamp() == sc_time(386, SC_NS) ); f27=1; break; + case 48: sc_assert( sc_time_stamp() == sc_time(400, SC_NS) ); f28=1; break; + default: sc_assert( false ); break; + } + + if (suspend_target) + t.suspend(); + if (resume_target) + t.resume(); + if (disable_target) + t.disable(); + if (enable_target) + t.enable(); + if (dynamic_sensitivity) + next_trigger(ev2); + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f0 ); + sc_assert( top.f1 ); + sc_assert( top.f2 ); + sc_assert( top.f3 ); + sc_assert( top.f4 ); + sc_assert( top.f5 ); + sc_assert( top.f6 ); + sc_assert( top.f7 ); + sc_assert( top.f8 ); + sc_assert( top.f9 ); + sc_assert( top.f10 ); + sc_assert( top.f11 ); + sc_assert( top.f12 ); + sc_assert( top.f13 ); + sc_assert( top.f14 ); + sc_assert( top.f15 ); + sc_assert( top.f16 ); + sc_assert( top.f17 ); + sc_assert( top.f18 ); + sc_assert( top.f19 ); + sc_assert( top.f20 ); + sc_assert( top.f21 ); + sc_assert( top.f22 ); + sc_assert( top.f23 ); + sc_assert( top.f24 ); + sc_assert( top.f25 ); + sc_assert( top.f26 ); + sc_assert( top.f27 ); + sc_assert( top.f28 ); + sc_assert( top.f29 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/method_with_reset/golden/method_with_reset.log b/src/systemc/tests/systemc/1666-2011-compliance/method_with_reset/golden/method_with_reset.log new file mode 100644 index 000000000..0d5dc4ebb --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/method_with_reset/golden/method_with_reset.log @@ -0,0 +1,5 @@ +SystemC Simulation + +Error: (E521) immediate notification is not allowed during update phase or elaboration +In file: <removed by verify.pl> +In process: top.ctrl.m3 @ 520 ns diff --git a/src/systemc/tests/systemc/1666-2011-compliance/method_with_reset/method_with_reset.cpp b/src/systemc/tests/systemc/1666-2011-compliance/method_with_reset/method_with_reset.cpp new file mode 100644 index 000000000..aafd3f61d --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/method_with_reset/method_with_reset.cpp @@ -0,0 +1,446 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// method_with_reset.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: method_with_reset.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Method processes with sync and async resets, reset_event, sc_event_or_list + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + : clk("clk") + , count(0) + { + SC_THREAD(ctrl); + + SC_METHOD(method_sync_reset); + sensitive << clk.posedge_event(); + reset_signal_is(reset, true); + dont_initialize(); + m1 = sc_get_current_process_handle(); + + SC_METHOD(method_async_reset); + sensitive << clk.posedge_event(); + async_reset_signal_is(reset, true); + dont_initialize(); + m2 = sc_get_current_process_handle(); + + f0 = f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0; + f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0; + f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0; + f30 = f31 = f32 = f33 = f34 = f35 = f36 = f37 = f38 = f39 = 0; + f40 = f41 = f42 = f43 = f44 = f45 = f46 = f47 = f48 = f49 = 0; + f50 = f51 = f52 = f53 = f54 = f55 = f56 = f57 = f58 = f59 = 0; + } + + sc_process_handle m1, m2, m3, m4, m5, m6; + sc_signal<bool> clk, reset, sreset, areset; + int count; + int f0, f1, f2, f3, f4, f5, f6, f7, f8, f9; + int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19; + int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29; + int f30, f31, f32, f33, f34, f35, f36, f37, f38, f39; + int f40, f41, f42, f43, f44, f45, f46, f47, f48, f49; + int f50, f51, f52, f53, f54, f55, f56, f57, f58, f59; + + void ctrl() + { + count = 1; + reset.write(false); + sreset.write(false); + areset.write(false); + clk.write(false); + wait(10, SC_NS); + + count = 2; + reset.write(true); + wait(10, SC_NS); + + count = 3; + reset.write(false); + wait(10, SC_NS); + + count = 4; + reset.write(true); + wait(10, SC_NS); + + count = 5; + clk.write(true); + wait(10, SC_NS); + + count = 6; + clk.write(false); + wait(10, SC_NS); + + count = 7; + reset.write(false); + wait(10, SC_NS); + + count = 8; + clk.write(true); + wait(10, SC_NS); + + count = 9; + clk.write(false); + wait(10, SC_NS); + + count = 10; + clk.write(true); + wait(10, SC_NS); + + count = 11; + reset.write(true); + wait(10, SC_NS); + + count = 12; + reset.write(false); + wait(10, SC_NS); + + count = 13; + reset.write(true); + wait(10, SC_NS); + + count = 14; + clk.write(false); + wait(sc_time(200, SC_NS) - sc_time_stamp()); + + count = 15; + clk.write(true); + wait(10, SC_NS); + + count = 16; + clk.write(false); + wait(10, SC_NS); + + count = 17; + clk.write(true); + wait(10, SC_NS); + + count = 18; + reset.write(false); + wait(10, SC_NS); + + count = 19; + reset.write(true); + wait(10, SC_NS); + + count = 20; + reset.write(false); + wait(10, SC_NS); + + count = 21; + clk.write(false); + wait(sc_time(300, SC_NS) - sc_time_stamp()); + + count = 22; + clk.write(true); + wait(10, SC_NS); + + count = 23; + clk.write(false); + m1.disable(); + m2.disable(); + + sc_spawn_options opt3; + opt3.spawn_method(); + opt3.set_sensitivity( &clk.posedge_event() ); + opt3.reset_signal_is(sreset, true); + opt3.async_reset_signal_is(areset, true); + m3 = sc_spawn(sc_bind( &Top::spawned_method, this ), "m3", &opt3); + + sc_spawn_options opt4; + opt4.spawn_method(); + opt4.set_sensitivity( &m3.reset_event() ); + opt4.dont_initialize(); + m4 = sc_spawn(sc_bind( &Top::reset_handler, this), "m4", &opt4); + + sc_spawn_options opt5; + opt5.spawn_method(); + m5 = sc_spawn(sc_bind( &Top::reset_or_terminated_handler, this), "m5", &opt5); + + std::vector<sc_event*> vec = this->get_child_events(); + sc_assert( vec.size() == 0 ); + wait(10, SC_NS); + + m6 = sc_spawn(sc_bind( &Top::multiple_reset_handler, this) ); + + count = 24; + clk.write(true); + wait(10, SC_NS); + + count = 25; + clk.write(false); + wait(10, SC_NS); + + count = 26; + sreset.write(true); + wait(10, SC_NS); + + count = 27; + clk.write(true); + wait(sc_time(500, SC_NS) - sc_time_stamp()); + + count = 28; + clk.write(false); + sreset.write(false); + wait(10, SC_NS); + + count = 29; + m3.reset(); + wait(10, SC_NS); + + count = 30; + areset.write(true); + wait(10, SC_NS); + + count = 31; + areset.write(false); + wait(10, SC_NS); + + count = 32; + areset.write(true); + wait(10, SC_NS); + + count = 33; + clk.write(true); + wait(10, SC_NS); + + count = 34; + clk.write(false); + wait(10, SC_NS); + + count = 35; + areset.write(false); + wait(sc_time(600, SC_NS) - sc_time_stamp()); + + count = 36; + m3.kill(); + wait(10, SC_NS); + + count = 37; + m1.reset(); + wait(10, SC_NS); + + count = 38; + m2.reset(); + wait(10, SC_NS); + + + } + + void method_sync_reset() + { + if (reset) + switch (count) + { + case 5: sc_assert( sc_time_stamp() == sc_time( 40, SC_NS) ); f0=1; break; + case 15: sc_assert( sc_time_stamp() == sc_time(200, SC_NS) ); f3=1; break; + case 17: sc_assert( sc_time_stamp() == sc_time(220, SC_NS) ); f4=1; break; + default: sc_assert( false ); + } + else + switch (count) + { + case 8: sc_assert( sc_time_stamp() == sc_time( 70, SC_NS) ); f1=1; break; + case 10: sc_assert( sc_time_stamp() == sc_time( 90, SC_NS) ); f2=1; break; + case 22: sc_assert( sc_time_stamp() == sc_time(300, SC_NS) ); f5=1; break; + case 37: sc_assert( sc_time_stamp() == sc_time(610, SC_NS) ); f55=1; break; + default: sc_assert( false ); + } + } + + void method_async_reset() + { + if (reset) + switch (count) + { + case 2: sc_assert( sc_time_stamp() == sc_time( 10, SC_NS) ); f10=1; break; + case 4: sc_assert( sc_time_stamp() == sc_time( 30, SC_NS) ); f11=1; break; + case 5: sc_assert( sc_time_stamp() == sc_time( 40, SC_NS) ); f12=1; break; + case 11: sc_assert( sc_time_stamp() == sc_time(100, SC_NS) ); f15=1; break; + case 13: sc_assert( sc_time_stamp() == sc_time(120, SC_NS) ); f16=1; break; + case 15: sc_assert( sc_time_stamp() == sc_time(200, SC_NS) ); f17=1; break; + case 17: sc_assert( sc_time_stamp() == sc_time(220, SC_NS) ); f18=1; break; + case 19: sc_assert( sc_time_stamp() == sc_time(240, SC_NS) ); f19=1; break; + default: sc_assert( false ); + } + else + switch (count) + { + case 8: sc_assert( sc_time_stamp() == sc_time( 70, SC_NS) ); f13=1; break; + case 10: sc_assert( sc_time_stamp() == sc_time( 90, SC_NS) ); f14=1; break; + case 22: sc_assert( sc_time_stamp() == sc_time(300, SC_NS) ); f20=1; break; + case 38: sc_assert( sc_time_stamp() == sc_time(620, SC_NS) ); f57=1; break; + default: sc_assert( false ); + } + } + + void spawned_method() + { + switch (count) + { + case 23: sc_assert( sc_time_stamp() == sc_time(310, SC_NS) ); f30=1; break; + case 24: sc_assert( sc_time_stamp() == sc_time(320, SC_NS) ); f31=1; break; + case 27: sc_assert( sc_time_stamp() == sc_time(350, SC_NS) ); f32=1; break; + case 29: sc_assert( sc_time_stamp() == sc_time(510, SC_NS) ); f34=1; break; + case 30: sc_assert( sc_time_stamp() == sc_time(520, SC_NS) ); f36=1; break; + case 32: sc_assert( sc_time_stamp() == sc_time(540, SC_NS) ); f38=1; break; + case 33: sc_assert( sc_time_stamp() == sc_time(550, SC_NS) ); f40=1; break; + default: sc_assert( false ); + } + } + + void reset_handler() + { + switch (count) + { + case 27: sc_assert( sc_time_stamp() == sc_time(350, SC_NS) ); f33=1; break; + case 29: sc_assert( sc_time_stamp() == sc_time(510, SC_NS) ); f35=1; break; + case 30: sc_assert( sc_time_stamp() == sc_time(520, SC_NS) ); f37=1; break; + case 32: sc_assert( sc_time_stamp() == sc_time(540, SC_NS) ); f39=1; break; + case 33: sc_assert( sc_time_stamp() == sc_time(550, SC_NS) ); f41=1; break; + default: sc_assert( false ); + } + } + + sc_event_or_list event_list; + + void reset_or_terminated_handler() + { + switch (count) + { + case 23: sc_assert( sc_time_stamp() == sc_time(310, SC_NS) ); f42=1; break; + case 27: sc_assert( sc_time_stamp() == sc_time(350, SC_NS) ); f43=1; break; + case 29: sc_assert( sc_time_stamp() == sc_time(510, SC_NS) ); f44=1; break; + case 30: sc_assert( sc_time_stamp() == sc_time(520, SC_NS) ); f45=1; break; + case 32: sc_assert( sc_time_stamp() == sc_time(540, SC_NS) ); f46=1; break; + case 33: sc_assert( sc_time_stamp() == sc_time(550, SC_NS) ); f47=1; break; + case 36: sc_assert( sc_time_stamp() == sc_time(600, SC_NS) ); f48=1; break; + default: sc_assert( false ); + } + event_list = m3.reset_event() | m3.terminated_event(); + next_trigger(event_list); + } + + void multiple_reset_handler() + { + sc_event_or_list or_list; + or_list |= m1.reset_event(); + or_list |= m2.reset_event(); + or_list |= m3.reset_event(); + or_list |= m4.reset_event(); + or_list |= m5.reset_event(); + + while (true) + { + wait(or_list); + switch (count) + { + case 27: sc_assert( sc_time_stamp() == sc_time(350, SC_NS) ); f50=1; break; + case 29: sc_assert( sc_time_stamp() == sc_time(510, SC_NS) ); f51=1; break; + case 30: sc_assert( sc_time_stamp() == sc_time(520, SC_NS) ); f52=1; break; + case 32: sc_assert( sc_time_stamp() == sc_time(540, SC_NS) ); f53=1; break; + case 33: sc_assert( sc_time_stamp() == sc_time(550, SC_NS) ); f54=1; break; + case 37: sc_assert( sc_time_stamp() == sc_time(610, SC_NS) ); f56=1; break; + case 38: sc_assert( sc_time_stamp() == sc_time(620, SC_NS) ); f58=1; break; + default: sc_assert( false ); + } + } + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + sc_allow_process_control_corners = true; // Andy's hack to switch on async_reset with method + + Top top("top"); + + sc_start(); + + sc_assert( top.f0 ); + sc_assert( top.f1 ); + sc_assert( top.f2 ); + sc_assert( top.f3 ); + sc_assert( top.f4 ); + sc_assert( top.f5 ); + sc_assert( top.f10 ); + sc_assert( top.f11 ); + sc_assert( top.f12 ); + sc_assert( top.f13 ); + sc_assert( top.f14 ); + sc_assert( top.f15 ); + sc_assert( top.f16 ); + sc_assert( top.f17 ); + sc_assert( top.f18 ); + sc_assert( top.f19 ); + sc_assert( top.f20 ); + + sc_assert( top.f30 ); + sc_assert( top.f31 ); + sc_assert( top.f32 ); + sc_assert( top.f33 ); + sc_assert( top.f34 ); + sc_assert( top.f35 ); + sc_assert( top.f36 ); + sc_assert( top.f37 ); + sc_assert( top.f38 ); + sc_assert( top.f39 ); + sc_assert( top.f40 ); + sc_assert( top.f41 ); + sc_assert( top.f42 ); + sc_assert( top.f43 ); + sc_assert( top.f44 ); + sc_assert( top.f45 ); + sc_assert( top.f46 ); + sc_assert( top.f47 ); + sc_assert( top.f48 ); + + sc_assert( top.f50 ); + sc_assert( top.f51 ); + sc_assert( top.f52 ); + sc_assert( top.f53 ); + sc_assert( top.f54 ); + sc_assert( top.f55 ); + sc_assert( top.f56 ); + sc_assert( top.f57 ); + sc_assert( top.f58 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/mixed_child_procs/golden/mixed_child_procs.log b/src/systemc/tests/systemc/1666-2011-compliance/mixed_child_procs/golden/mixed_child_procs.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/mixed_child_procs/golden/mixed_child_procs.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/mixed_child_procs/mixed_child_procs.cpp b/src/systemc/tests/systemc/1666-2011-compliance/mixed_child_procs/mixed_child_procs.cpp new file mode 100644 index 000000000..58b185c13 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/mixed_child_procs/mixed_child_procs.cpp @@ -0,0 +1,214 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// mixed_child_procs.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: mixed_child_procs.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Process control methods applied where child process tree contains +// a mixture of method and thread processes + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +#include <string> +using std::string; + +struct Top: sc_module +{ + Top(sc_module_name _name) + : count(0) + , index(0) + , n(30) + { + SC_THREAD(ctrl); + + opt.spawn_method(); + opt.set_sensitivity( &ev ); + + given_birth = new bool[n]; + + f0 = new int[n]; + f1 = new int[n]; + f2 = new int[n]; + f3 = new int[n]; + f4 = new int[n]; + f5 = new int[n]; + + for (int i = 0; i < n; i++) + { + given_birth[i] = false; + + f0[i] = 0; + f1[i] = 0; + f2[i] = 0; + f3[i] = 0; + f4[i] = 0; + f5[i] = 0; + } + + t = sc_spawn(sc_bind(&Top::child_thread, this, index++, 3)); + m = sc_spawn(sc_bind(&Top::child_method, this, index++, 3), "m", &opt); + } + + sc_spawn_options opt; + sc_process_handle t, m; + std::exception ex; + int count; + int index; + const int n; + int *f0, *f1, *f2, *f3, *f4, *f5; + bool *given_birth; + + sc_event ev; + + void ctrl() + { + wait(10, SC_NS); + + count = 1; + ev.notify(); + wait(10, SC_NS); + + count = 2; + t.throw_it(ex, SC_INCLUDE_DESCENDANTS); + m.throw_it(ex, SC_INCLUDE_DESCENDANTS); + wait(10, SC_NS); + + count = 3; + t.sync_reset_on(SC_INCLUDE_DESCENDANTS); + m.sync_reset_on(SC_INCLUDE_DESCENDANTS); + wait(10, SC_NS); + + count = 4; + ev.notify(); + wait(10, SC_NS); + + count = 5; + t.sync_reset_off(SC_INCLUDE_DESCENDANTS); + m.sync_reset_off(SC_INCLUDE_DESCENDANTS); + wait(10, SC_NS); + + count = 6; + ev.notify(); + wait(10, SC_NS); + } + + void child_thread(int i, int level) + { + //cout << "child_thread " << i << " at level " << level << " called at " << sc_time_stamp() << endl; + if (level > 0 && !given_birth[i]) + { + sc_spawn(sc_bind(&Top::child_thread, this, index++, level-1)); + sc_spawn(sc_bind(&Top::child_method, this, index++, level-1), "h", &opt); + given_birth[i] = true; + } + switch(count) + { + case 0: f0[i]=1; break; + case 4: f4[i]=1; break; + default: sc_assert(false); break; + } + while(true) + { + try { + wait(ev); + //cout << "child_thread " << i << " at level " << level << " awoke at " << sc_time_stamp() << endl; + switch(count) + { + case 1: f1[i]=1; break; + case 6: f5[i]=1; break; + default: sc_assert(false); break; + } + } + catch (const std::exception& e) { + //cout << "child_thread " << i << " at level " << level << " caught at " << sc_time_stamp() << endl; + switch(count) + { + case 2: f2[i]=1; break; + case 4: f3[i]=1; throw static_cast<const sc_unwind_exception&>(e); + default: sc_assert(false); break; + } + } + } + } + + void child_method(int i, int level) + { + //cout << "child_method " << i << " at level " << level << " at " << sc_time_stamp() << endl; + if (level > 0 && !given_birth[i]) + { + sc_spawn(sc_bind(&Top::child_thread, this, index++, level-1)); + sc_spawn(sc_bind(&Top::child_method, this, index++, level-1), "m", &opt); + given_birth[i] = true; + } + switch(count) + { + case 0: f0[i]=2; break; + case 1: sc_assert(sc_time_stamp() == sc_time(10, SC_NS)); f1[i]=1; break; + case 4: f4[i]=1; break; + case 6: f5[i]=1; break; + default: sc_assert(false); break; + } + next_trigger(ev); + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + sc_report_handler::set_actions(SC_WARNING, SC_DO_NOTHING); + + Top top("top"); + + sc_start(); + + sc_assert( top.index == top.n ); + + for (int i = 0; i < top.n; i++) + { + sc_assert( top.f0[i] ); + sc_assert( top.f1[i] ); + + if (top.f0[i] == 1) // i.e. a thread process + { + sc_assert( top.f2[i] ); + sc_assert( top.f3[i] ); + } + sc_assert( top.f4[i] ); + sc_assert( top.f5[i] ); + } + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/named_events/golden/named_events.log b/src/systemc/tests/systemc/1666-2011-compliance/named_events/golden/named_events.log new file mode 100644 index 000000000..254874664 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/named_events/golden/named_events.log @@ -0,0 +1,11 @@ +SystemC Simulation + +Warning: (W505) object already exists: top.ev2. Latter declaration will be renamed to top.ev2_0 +In file: <removed by verify.pl> + +Warning: (W505) object already exists: top. Latter declaration will be renamed to top_0 +In file: <removed by verify.pl> + +There should be two name clashes reported above + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/named_events/named_events.cpp b/src/systemc/tests/systemc/1666-2011-compliance/named_events/named_events.cpp new file mode 100644 index 000000000..c655cbb62 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/named_events/named_events.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. + + *****************************************************************************/ + +// named_events.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: named_events.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Hierarchically named events + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Object: sc_object +{ + Object(const char* n) + : sc_object(n) + , ev((std::string(n) + "_ev").c_str()) {} + + sc_event ev; // Parent of event is containing module or process instance +}; + +struct Top: sc_module +{ + sc_event ev1, ev2; + Object *obj; + sc_signal<int> sig; // Kernel events should not be hierarchically named + sc_fifo<int> fifo; // Kernel events should not be hierarchically named + sc_semaphore sema; // Kernel events should not be hierarchically named + sc_mutex mut; // Kernel events should not be hierarchically named + + bool T_done; + + Top(sc_module_name _name) + : ev2("ev2") + , sig("sig") + , sema(1) + , T_done(false) + { + + sc_assert( ev1.in_hierarchy() ); + sc_assert( ev1.get_parent_object() == this ); + sc_assert( std::string(ev1.name()).substr(0,9) == "top.event" ); + sc_assert( std::string(ev1.basename()).substr(0,5) == "event" ); + + sc_assert( ev2.in_hierarchy() ); + sc_assert( ev2.get_parent_object() == this ); + sc_assert( std::string(ev2.name()) == "top.ev2" ); + sc_assert( std::string(ev2.basename()) == "ev2" ); + + sc_assert( sc_find_event("top.ev2") == &ev2 ); + + std::vector<sc_event*> vec = this->get_child_events(); + sc_assert( vec.size() == 2 ); + + sc_process_handle dummy_handle; + sc_assert( dummy_handle.get_child_events().size() == 0 ); + sc_assert( std::string(dummy_handle.name()) == ""); + + obj = new Object("obj"); + vec = obj->get_child_events(); // Should return empty vector + sc_assert( vec.size() == 0 ); + + vec = this->get_child_events(); + sc_assert( vec.size() == 3 ); + + sc_assert( sc_find_event("top.obj_ev") == &obj->ev ); + + Object obj2("ev2"); // Name clash + + vec = this->get_child_events(); + sc_assert( vec.size() == 4 ); + + SC_THREAD(T); + } + + void T() + { + sc_event ev1("local1"); + sc_event ev2("local2"); + + sc_process_handle handle = sc_get_current_process_handle(); + std::string proc_name = handle.name(); + + sc_assert( ev1.in_hierarchy() ); + sc_assert( ev1.get_parent_object() == handle.get_process_object() ); + sc_assert( std::string(ev1.name()) == proc_name + ".local1" ); + sc_assert( std::string(ev1.basename()) == "local1" ); + sc_assert( sc_hierarchical_name_exists(ev1.name()) ); + + sc_assert( ev2.in_hierarchy() ); + sc_assert( ev2.get_parent_object() == handle.get_process_object() ); + sc_assert( std::string(ev2.name()) == proc_name + ".local2" ); + sc_assert( std::string(ev2.basename()) == "local2" ); + sc_assert( sc_hierarchical_name_exists(ev2.name()) ); + + std::vector<sc_event*> vec = handle.get_child_events(); + sc_assert( vec.size() == 2 ); + sc_assert( vec[0] == &ev1 ); + sc_assert( vec[1] == &ev2 ); + + sc_assert( sc_find_event(ev1.name()) == &ev1 ); + sc_assert( sc_find_event(ev2.name()) == &ev2 ); + + T_done = true; + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + std::vector<sc_object*> vec_o; + vec_o = sc_get_top_level_objects(); + sc_assert( vec_o.size() == 0 ); + + std::vector<sc_event*> vec_e; + vec_e = sc_get_top_level_events(); + sc_assert( vec_e.size() == 0 ); + + sc_event ev("foo"); + + sc_assert( ev.in_hierarchy() ); + sc_assert( ev.get_parent_object() == 0 ); + sc_assert( std::string(ev.name()) == "foo" ); + sc_assert( std::string(ev.basename()) == "foo" ); + sc_assert( sc_hierarchical_name_exists("foo") ); + + vec_o = sc_get_top_level_objects(); + sc_assert( vec_o.size() == 0 ); + vec_e = sc_get_top_level_events(); + sc_assert( vec_e.size() == 1 ); + sc_assert( vec_e[0] == &ev ); + sc_assert( std::string(vec_e[0]->name()) == "foo" ); + + sc_assert( sc_find_event("foo") == &ev ); + + Top top("top"); + sc_assert( sc_hierarchical_name_exists("top") ); + sc_assert( sc_hierarchical_name_exists("top.ev2") ); + sc_assert( sc_hierarchical_name_exists("top.sig") ); + sc_assert( sc_hierarchical_name_exists("top.obj") ); + sc_assert( sc_hierarchical_name_exists("top.obj_ev") ); + sc_assert( !sc_hierarchical_name_exists("woowoo") ); + sc_assert( !sc_hierarchical_name_exists("top.woowoo") ); + + sc_event ev2; + + sc_assert( ev2.in_hierarchy() ); + sc_assert( ev2.get_parent_object() == 0 ); + sc_assert( std::string(ev2.name()).substr(0,5) == "event" ); + sc_assert( std::string(ev2.basename()).substr(0,5) == "event" ); + sc_assert( sc_hierarchical_name_exists(ev2.name()) ); + + vec_e = sc_get_top_level_events(); + sc_assert( vec_e.size() == 2); + + sc_event ev3("top"); // Name clash + vec_e = sc_get_top_level_events(); + sc_assert( vec_e.size() == 3); + vec_o = sc_get_top_level_objects(); + sc_assert( vec_o.size() == 1 ); + + sc_assert( sc_find_event(ev3.name()) == &ev3 ); + + sc_signal<bool> sig; // Kernel events should not be hierarchically named + vec_e = sc_get_top_level_events(); + sc_assert( vec_e.size() == 3 ); + vec_o = sc_get_top_level_objects(); + sc_assert( vec_o.size() == 2 ); + + sc_start(); + + sc_assert( top.T_done ); + + cout << endl << "There should be two name clashes reported above" << endl; + cout << endl << "Success" << endl; + return 0; +} + 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 <systemc> +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; +} diff --git a/src/systemc/tests/systemc/1666-2011-compliance/old_event_bug/golden/old_event_bug.log b/src/systemc/tests/systemc/1666-2011-compliance/old_event_bug/golden/old_event_bug.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/old_event_bug/golden/old_event_bug.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/old_event_bug/old_event_bug.cpp b/src/systemc/tests/systemc/1666-2011-compliance/old_event_bug/old_event_bug.cpp new file mode 100644 index 000000000..e776ceb00 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/old_event_bug/old_event_bug.cpp @@ -0,0 +1,147 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// old_event_bug.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: old_event_bug.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Longstanding bug when checking for events in signals + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + : counti(0) + , countb(0) + , reached_the_end(false) + { + SC_THREAD(T); + + SC_METHOD(MI); + sensitive << sigi; + dont_initialize(); + + SC_METHOD(MB); + sensitive << sigb; + dont_initialize(); + + sigi.write(0); + sigb.write(false); + sigi_dummy.write(0); + sigb_dummy.write(false); + } + + int counti; + int countb; + bool reached_the_end; + + sc_signal<int> sigi; + sc_signal<bool> sigb; + + sc_signal<int> sigi_dummy; + sc_signal<bool> sigb_dummy; + + void T() + { + sc_assert( sigi.event() == false ); + sc_assert( sigb.event() == false ); + sc_assert( sigb.posedge() == false ); + sc_assert( sigb.negedge() == false ); + + sigi.write(1); + wait(sigi.value_changed_event()); + sc_assert( sigi.event() ); + + sigb.write(true); + wait(sigb.value_changed_event()); + sc_assert( sigb.event() ); + sc_assert( sigb.posedge() ); + sc_assert( sigb.negedge() == false ); + + wait(1, SC_NS); + + sc_assert( sigi.event() == false ); + sc_assert( sigb.event() == false ); + + sigi.write(2); + sigb.write(false); + + wait(1, SC_NS); + + sc_assert( sigi.event() == false ); + sc_assert( sigb.event() == false ); + sc_assert( sigb.posedge() == false ); + sc_assert( sigb.negedge() == false ); + + sigi_dummy.write(1); + sigb_dummy.write(true); + + wait(1, SC_NS); + + sc_assert( sigi_dummy.event() == false ); + sc_assert( sigb_dummy.event() == false ); + sc_assert( sigb_dummy.posedge() == false ); + sc_assert( sigb_dummy.negedge() == false ); + + reached_the_end = true; + } + + void MI() + { + sc_assert( sigi.event() ); + ++counti; + } + + void MB() + { + sc_assert( sigb.event() ); + ++countb; + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.counti == 2 ); + sc_assert( top.countb == 2 ); + sc_assert( top.reached_the_end ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/overkill_bug/golden/overkill_bug.log b/src/systemc/tests/systemc/1666-2011-compliance/overkill_bug/golden/overkill_bug.log new file mode 100644 index 000000000..1b72448a0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/overkill_bug/golden/overkill_bug.log @@ -0,0 +1,7 @@ +SystemC Simulation + +Warning: (W540) kill/reset ignored during unwinding: top.target +In file: <removed by verify.pl> +In process: top.target @ 10 ns + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/overkill_bug/overkill_bug.cpp b/src/systemc/tests/systemc/1666-2011-compliance/overkill_bug/overkill_bug.cpp new file mode 100644 index 000000000..b66f4955f --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/overkill_bug/overkill_bug.cpp @@ -0,0 +1,88 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// overkill_bug.cpp -- test for +// +// Original Author: John Aynsley, Doulus +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// + +// + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(target); + target_handle = sc_get_current_process_handle(); + f0 = 0; + } + + struct bomb + { + sc_process_handle h; + + bomb(sc_process_handle _h) + { + h = _h; + } + + ~bomb() + { + h.kill(); // Aborts !!!!!! + } + }; + + sc_process_handle target_handle; + int f0; + + void target() + { + bomb local_obj(target_handle); + + wait(10, SC_NS); + + f0 = 1; + target_handle.kill(); + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f0 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl/golden/proc_ctrl.log b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl/golden/proc_ctrl.log new file mode 100644 index 000000000..cdf4578d6 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl/golden/proc_ctrl.log @@ -0,0 +1,5 @@ +SystemC Simulation + +Info: /OSCI/SystemC: Simulation stopped by user. + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl/proc_ctrl.cpp b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl/proc_ctrl.cpp new file mode 100644 index 000000000..b8e9f2569 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl/proc_ctrl.cpp @@ -0,0 +1,295 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ +
+// proc_ctrl.cpp -- test for
+//
+// Original Author: John Aynsley, Doulos, Inc.
+//
+// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
+//
+// $Log: proc_ctrl.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +//
+
+// Basic functionality of process control methods
+
+#define SC_INCLUDE_DYNAMIC_PROCESSES
+
+#include <systemc>
+using sc_core::sc_process_handle;
+using sc_core::sc_event;
+using sc_core::sc_get_current_process_handle;
+using sc_core::SC_NS;
+using sc_core::sc_time;
+using sc_core::sc_time_stamp;
+using sc_core::sc_stop;
+using sc_core::sc_unwind_exception;
+using sc_core::sc_is_unwinding;
+using sc_core::sc_start;
+using sc_core::SC_ZERO_TIME;
+using std::cout;
+using std::endl;
+
+SC_MODULE(Top)
+{
+ SC_CTOR(Top)
+ : count(0)
+ {
+ SC_METHOD(gen);
+ sensitive << ev;
+
+ SC_THREAD(ctrl);
+
+ SC_THREAD(target);
+ t1 = sc_get_current_process_handle();
+
+ f0 = f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0;
+ f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0;
+ f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0;
+ }
+
+ sc_process_handle t1, t2;
+ sc_event ev;
+ int count;
+ int f0, f1, f2, f3, f4, f5, f6, f7, f8, f9;
+ int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19;
+ int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29;
+
+ void gen()
+ {
+ ev.notify(10, SC_NS);
+ }
+
+ void ctrl()
+ {
+ wait(SC_ZERO_TIME);
+
+ count = 1;
+ wait(15, SC_NS);
+
+ count = 2;
+ t1.suspend();
+ wait(20, SC_NS);
+
+ count = 3;
+ t1.reset(); // Reset takes priority over suspend
+ wait(20, SC_NS);
+
+ count = 4;
+ t1.reset(); // Reset takes priority over suspend
+ wait(20, SC_NS);
+
+ count = 5;
+ t1.resume();
+ wait(SC_ZERO_TIME);
+
+ count = 6;
+ wait(10, SC_NS);
+
+ count = 7;
+ wait(10, SC_NS);
+
+ count = 8;
+ t1.reset();
+
+ count = 9;
+ wait(10, SC_NS);
+
+ count = 10;
+ wait(10, SC_NS);
+
+ count = 11;
+ t1.disable();
+ wait(20, SC_NS);
+
+ count = 12;
+ t1.reset(); // Reset takes priority over enable
+
+ count = 13;
+ wait(20, SC_NS);
+
+ count = 14;
+ t1.reset(); // Reset takes priority over enable
+
+ count = 15;
+ wait(20, SC_NS);
+
+ count = 16;
+ t1.enable();
+ wait(SC_ZERO_TIME);
+
+ count = 17;
+ wait(10, SC_NS);
+
+ count = 18;
+ wait(10, SC_NS);
+
+ count = 19;
+ t1.disable();
+ wait(SC_ZERO_TIME);
+
+ count = 20;
+ wait(20, SC_NS);
+
+ count = 21;
+ t1.suspend();
+ wait(20, SC_NS);
+
+ count = 22;
+ t1.enable();
+ wait(SC_ZERO_TIME);
+
+ count = 23;
+ wait(20, SC_NS);
+
+ count = 24;
+ t1.resume();
+ wait(SC_ZERO_TIME);
+
+ count = 25;
+ wait(10, SC_NS);
+
+ count = 26;
+ wait(10, SC_NS);
+
+ count = 27;
+ t1.suspend();
+
+ count = 28;
+ wait(20, SC_NS);
+
+ count = 29;
+ t1.kill(); // kill takes priority over suspend
+ wait(20, SC_NS);
+
+ count = 30;
+ t1.resume();
+ wait(20, SC_NS);
+
+ count = 31;
+ sc_assert( !sc_is_unwinding() );
+ if (t1.valid())
+ sc_assert( !t1.is_unwinding() );
+
+ sc_stop();
+ }
+
+ void target()
+ {
+ sc_assert( !sc_is_unwinding() );
+
+ switch(count)
+ {
+ case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f1=1; break;
+ case 3: sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); f3=1; break;
+ case 4: sc_assert( sc_time_stamp() == sc_time(55, SC_NS) ); f4=1; break;
+ case 8: sc_assert( sc_time_stamp() == sc_time(95, SC_NS) ); f8=1; break;
+ case 12: sc_assert( sc_time_stamp() == sc_time(135, SC_NS) ); f11=1; break;
+ case 14: sc_assert( sc_time_stamp() == sc_time(155, SC_NS) ); f12=1; break;
+ default: sc_assert( false ); break;
+ }
+
+ for(;;)
+ {
+ try {
+ wait(ev);
+
+ switch(count)
+ {
+ case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); f2=1; break;
+ case 5: sc_assert( sc_time_stamp() == sc_time(75, SC_NS) ); f5=1; break;
+ case 6: sc_assert( sc_time_stamp() == sc_time(80, SC_NS) ); f6=1; break;
+ case 7: sc_assert( sc_time_stamp() == sc_time(90, SC_NS) ); f7=1; break;
+ case 9: sc_assert( sc_time_stamp() == sc_time(100, SC_NS) ); f9=1; break;
+ case 10: sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); f10=1; break;
+ case 17: sc_assert( sc_time_stamp() == sc_time(180, SC_NS) ); f13=1; break;
+ case 18: sc_assert( sc_time_stamp() == sc_time(190, SC_NS) ); f14=1; break;
+ case 24: sc_assert( sc_time_stamp() == sc_time(255, SC_NS) ); f15=1; break;
+ case 25: sc_assert( sc_time_stamp() == sc_time(260, SC_NS) ); f16=1; break;
+ case 26: sc_assert( sc_time_stamp() == sc_time(270, SC_NS) ); f17=1; break;
+ default: sc_assert( false ); break;
+ }
+
+ }
+ catch (const sc_unwind_exception& e)
+ {
+ sc_assert( sc_is_unwinding() );
+
+ if (count == 29)
+ {
+ sc_assert( e.is_reset() == false ); f24=1;
+ }
+ switch(count)
+ {
+ case 3: sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); f18=1; break;
+ case 4: sc_assert( sc_time_stamp() == sc_time(55, SC_NS) ); f19=1; break;
+ case 8: sc_assert( sc_time_stamp() == sc_time(95, SC_NS) ); f20=1; break;
+ case 12: sc_assert( sc_time_stamp() == sc_time(135, SC_NS) ); f21=1; break;
+ case 14: sc_assert( sc_time_stamp() == sc_time(155, SC_NS) ); f22=1; break;
+ case 29: sc_assert( sc_time_stamp() == sc_time(295, SC_NS) ); f23=1; break;
+ default: sc_assert( false ); break;
+ }
+
+ throw e;
+ }
+ }
+ }
+};
+
+int sc_main(int argc, char* argv[])
+{
+ Top top("top");
+ sc_start();
+
+ sc_assert(top.f1);
+ sc_assert(top.f2);
+ sc_assert(top.f3);
+ sc_assert(top.f4);
+ sc_assert(top.f5);
+ sc_assert(top.f6);
+ sc_assert(top.f7);
+ sc_assert(top.f8);
+ sc_assert(top.f9);
+ sc_assert(top.f10);
+ sc_assert(top.f11);
+ sc_assert(top.f12);
+ sc_assert(top.f13);
+ sc_assert(top.f14);
+ sc_assert(top.f15);
+ sc_assert(top.f16);
+ sc_assert(top.f17);
+ sc_assert(top.f18);
+ sc_assert(top.f19);
+ sc_assert(top.f20);
+ sc_assert(top.f21);
+ sc_assert(top.f22);
+ sc_assert(top.f23);
+ sc_assert(top.f24);
+ /*
+ sc_assert(top.f25);
+ sc_assert(top.f26);
+ sc_assert(top.f27);
+ sc_assert(top.f28);
+ sc_assert(top.f29);
+ */
+
+ cout << endl << "Success" << endl;
+ return 0;
+}
diff --git a/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_elab/golden/proc_ctrl_elab.log b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_elab/golden/proc_ctrl_elab.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_elab/golden/proc_ctrl_elab.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_elab/proc_ctrl_elab.cpp b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_elab/proc_ctrl_elab.cpp new file mode 100644 index 000000000..a89120921 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_elab/proc_ctrl_elab.cpp @@ -0,0 +1,534 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ +
+// proc_ctrl_elab.cpp -- test for
+//
+// Original Author: John Aynsley, Doulos, Inc.
+//
+// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
+//
+// $Log: proc_ctrl_elab.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +//
+
+// Calling process control methods during elaboration
+
+#define SC_INCLUDE_DYNAMIC_PROCESSES
+
+#include "systemc.h"
+
+SC_MODULE(Top)
+{
+ SC_CTOR(Top)
+ : caught_throw_it(0)
+ , caught_reset(0)
+ , caught_kill(0)
+
+ , target_suspend_1_called(false)
+ , target_suspend_2_called(false)
+ , target_suspend_3_called(false)
+ , target_suspend_4_called(false)
+ , target_suspend_5_called(false)
+
+ , target_disable_1_called(false)
+ , target_disable_2_called(false)
+ , target_disable_2_called_again(false)
+ , target_disable_3_called(false)
+ , target_disable_4_called(false)
+ , target_disable_5_called(false)
+
+ , target_sync_reset_1_called(false)
+ , target_sync_reset_2_called(false)
+ , target_sync_reset_3_called(false)
+ , target_sync_reset_4_called(false)
+
+ , reset_1_count(0)
+ , reset_2_count(0)
+ , reset_3_count(0)
+ , reset_4_count(0)
+ {
+ SC_THREAD(ctrl);
+
+ SC_THREAD(target_suspend_1);
+ sensitive << ev;
+ ts1 = sc_get_current_process_handle();
+
+ SC_THREAD(target_suspend_2);
+ dont_initialize();
+ sensitive << ev;
+ ts2 = sc_get_current_process_handle();
+
+ SC_THREAD(target_suspend_3);
+ dont_initialize();
+ sensitive << ev;
+ ts3 = sc_get_current_process_handle();
+
+ SC_THREAD(target_suspend_4);
+ dont_initialize();
+ sensitive << ev;
+ ts4 = sc_get_current_process_handle();
+ ts4.suspend();
+
+ SC_THREAD(target_suspend_5);
+ dont_initialize();
+ sensitive << ev;
+ ts5 = sc_get_current_process_handle();
+ ts5.suspend();
+ ts5.resume();
+
+ SC_THREAD(target_disable_1);
+ sensitive << dummy_ev;
+ td1 = sc_get_current_process_handle();
+
+ SC_THREAD(target_disable_2);
+ sensitive << ev;
+ td2 = sc_get_current_process_handle();
+
+ SC_THREAD(target_disable_3);
+ td3 = sc_get_current_process_handle();
+
+ SC_THREAD(target_disable_4);
+ dont_initialize();
+ sensitive << ev;
+ td4 = sc_get_current_process_handle();
+ td4.disable();
+
+ SC_THREAD(target_disable_5);
+ dont_initialize();
+ sensitive << ev;
+ td5 = sc_get_current_process_handle();
+ td5.disable();
+ td5.enable();
+ td5.sync_reset_on();
+ td5.sync_reset_off();
+
+ SC_THREAD(target_sync_reset_1);
+ sensitive << ev;
+ tr1 = sc_get_current_process_handle();
+
+ SC_THREAD(target_sync_reset_2);
+ sensitive << ev;
+ tr2 = sc_get_current_process_handle();
+
+ SC_THREAD(target_sync_reset_3);
+ dont_initialize();
+ sensitive << ev;
+ tr3 = sc_get_current_process_handle();
+
+ SC_THREAD(target_sync_reset_4);
+ dont_initialize();
+ sensitive << ev;
+ tr4 = sc_get_current_process_handle();
+ tr4.sync_reset_on();
+
+ try {
+ ts2.throw_it(ex);
+ sc_assert( false );
+ }
+ catch (std::exception e) {
+ ++caught_throw_it;
+ }
+
+ try {
+ ts2.reset();
+ sc_assert( false );
+ }
+ catch (std::exception e) {
+ ++caught_reset;
+ }
+
+ try {
+ ts2.kill();
+ sc_assert( false );
+ }
+ catch (std::exception e) {
+ ++caught_kill;
+ }
+ }
+
+ void before_end_of_elaboration()
+ {
+ ts1.suspend();
+ ts2.suspend();
+ ts3.suspend();
+
+ td1.disable();
+ td2.disable();
+ td3.disable();
+
+ tr1.sync_reset_on();
+ tr2.sync_reset_on();
+ tr3.sync_reset_on();
+
+ try {
+ ts2.throw_it(ex);
+ sc_assert( false );
+ }
+ catch (std::exception e) {
+ ++caught_throw_it;
+ }
+
+ try {
+ ts2.reset();
+ sc_assert( false );
+ }
+ catch (std::exception e) {
+ ++caught_reset;
+ }
+
+ try {
+ ts2.kill();
+ sc_assert( false );
+ }
+ catch (std::exception e) {
+ ++caught_kill;
+ }
+ }
+
+ void start_of_simulation()
+ {
+ td3.enable();
+ tr3.sync_reset_off();
+
+ try {
+ ts2.throw_it(ex);
+ sc_assert( false );
+ }
+ catch (std::exception e) {
+ ++caught_throw_it;
+ }
+
+ try {
+ ts2.reset();
+ sc_assert( false );
+ }
+ catch (std::exception e) {
+ ++caught_reset;
+ }
+
+ try {
+ ts2.kill();
+ sc_assert( false );
+ }
+ catch (std::exception e) {
+ ++caught_kill;
+ }
+ }
+
+ sc_event ev, dummy_ev;
+
+ std::exception ex;
+
+ sc_process_handle ts1;
+ sc_process_handle ts2;
+ sc_process_handle ts3;
+ sc_process_handle ts4;
+ sc_process_handle ts5;
+
+ sc_process_handle td1;
+ sc_process_handle td2;
+ sc_process_handle td3;
+ sc_process_handle td4;
+ sc_process_handle td5;
+
+ sc_process_handle tr1;
+ sc_process_handle tr2;
+ sc_process_handle tr3;
+ sc_process_handle tr4;
+
+ int caught_throw_it;
+ int caught_reset;
+ int caught_kill;
+
+ bool target_suspend_1_called;
+ bool target_suspend_2_called;
+ bool target_suspend_3_called;
+ bool target_suspend_4_called;
+ bool target_suspend_5_called;
+
+ bool target_disable_1_called;
+ bool target_disable_2_called;
+ bool target_disable_2_called_again;
+ bool target_disable_3_called;
+ bool target_disable_4_called;
+ bool target_disable_5_called;
+
+ bool target_sync_reset_1_called;
+ bool target_sync_reset_2_called;
+ bool target_sync_reset_3_called;
+ bool target_sync_reset_4_called;
+
+ int reset_1_count;
+ int reset_2_count;
+ int reset_3_count;
+ int reset_4_count;
+
+ void ctrl()
+ {
+ ts3.resume();
+
+ wait(10, SC_NS);
+ ts1.resume();
+ ev.notify();
+
+ wait(10, SC_NS);
+ ts2.resume();
+ tr2.sync_reset_off();
+ tr4.sync_reset_off();
+
+ wait(10, SC_NS);
+ td2.enable();
+
+ wait(10, SC_NS);
+ ev.notify();
+
+ wait(10, SC_NS);
+ ev.notify();
+ td2.disable();
+
+ wait(10, SC_NS);
+ td4.enable();
+ ts4.resume();
+ ev.notify();
+ }
+
+ void target_suspend_1()
+ {
+ sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
+ target_suspend_1_called = true;
+ }
+
+ void target_suspend_2()
+ {
+ sc_assert( sc_time_stamp() == sc_time(20, SC_NS) );
+ target_suspend_2_called = true;
+ }
+
+ void target_suspend_3()
+ {
+ sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
+ target_suspend_3_called = true;
+ }
+
+ void target_suspend_4()
+ {
+ sc_assert( sc_time_stamp() == sc_time(60, SC_NS) );
+ target_suspend_4_called = true;
+ }
+
+ void target_suspend_5()
+ {
+ sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
+ target_suspend_5_called = true;
+ ts5.suspend();
+ }
+
+ void target_disable_1()
+ {
+ sc_assert( false );
+ target_disable_1_called = true;
+ }
+
+ void target_disable_2()
+ {
+ sc_assert( sc_time_stamp() == sc_time(40, SC_NS) );
+ target_disable_2_called = true;
+ wait(); // on ev
+
+ sc_assert( sc_time_stamp() == sc_time(50, SC_NS) );
+ target_disable_2_called_again = true;
+ }
+
+ void target_disable_3()
+ {
+ sc_assert( sc_time_stamp() == sc_time(0, SC_NS) );
+ sc_assert( sc_delta_count() == 0 );
+ target_disable_3_called = true;
+ }
+
+ void target_disable_4()
+ {
+ sc_assert( sc_time_stamp() == sc_time(60, SC_NS) );
+ target_disable_4_called = true;
+ }
+
+ void target_disable_5()
+ {
+ sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
+ target_disable_5_called = true;
+ td5.disable();
+ }
+
+ void target_sync_reset_1()
+ {
+ switch (reset_1_count)
+ {
+ case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) );
+ sc_assert( sc_delta_count() == 0 );
+ break;
+ case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
+ break;
+ case 2: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) );
+ break;
+ case 3: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) );
+ target_sync_reset_1_called = true;
+ break;
+ }
+ ++reset_1_count;
+
+ while (true)
+ {
+ wait();
+ sc_assert( false );
+ }
+ }
+
+ void target_sync_reset_2()
+ {
+ switch (reset_2_count)
+ {
+ case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) );
+ sc_assert( sc_delta_count() == 0 );
+ break;
+ case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
+ break;
+ case 2: sc_assert( false );
+ break;
+ case 3: sc_assert( false );
+ break;
+ }
+ ++reset_2_count;
+
+ while (true)
+ {
+ wait();
+
+ switch (reset_2_count)
+ {
+ case 0: sc_assert( false );
+ break;
+ case 1: sc_assert( false );
+ break;
+ case 2: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) );
+ break;
+ case 3: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) );
+ target_sync_reset_2_called = true;
+ break;
+ }
+ ++reset_2_count;
+
+ }
+ }
+
+ void target_sync_reset_3()
+ {
+ switch (reset_3_count)
+ {
+ case 0: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
+ break;
+ case 1: sc_assert( false );
+ break;
+ case 2: sc_assert( false );
+ break;
+ }
+ ++reset_3_count;
+
+ while (true)
+ {
+ wait();
+
+ switch (reset_3_count)
+ {
+ case 0: sc_assert( false );
+ break;
+ case 1: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) );
+ break;
+ case 2: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) );
+ target_sync_reset_3_called = true;
+ break;
+ }
+ ++reset_3_count;
+
+ }
+ }
+
+ void target_sync_reset_4()
+ {
+ switch (reset_4_count)
+ {
+ case 0: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
+ break;
+ case 1: sc_assert( false );
+ break;
+ case 2: sc_assert( false );
+ break;
+ }
+ ++reset_4_count;
+
+ while (true)
+ {
+ wait();
+
+ switch (reset_4_count)
+ {
+ case 0: sc_assert( false );
+ break;
+ case 1: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) );
+ break;
+ case 2: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) );
+ target_sync_reset_4_called = true;
+ break;
+ }
+ ++reset_4_count;
+
+ }
+ }
+};
+
+int sc_main(int argc, char* argv[])
+{
+ Top top("top");
+ sc_start();
+
+ sc_assert( top.caught_throw_it == 3 );
+ sc_assert( top.caught_reset == 3 );
+ sc_assert( top.caught_kill == 3 );
+
+ sc_assert( top.target_suspend_1_called );
+ sc_assert( top.target_suspend_2_called );
+ sc_assert( top.target_suspend_3_called );
+ sc_assert( top.target_suspend_4_called );
+ sc_assert( top.target_suspend_5_called );
+
+ sc_assert( !top.target_disable_1_called );
+ sc_assert( top.target_disable_2_called );
+ sc_assert( top.target_disable_2_called_again );
+ sc_assert( top.target_disable_3_called );
+ sc_assert( top.target_disable_4_called );
+ sc_assert( top.target_disable_5_called );
+
+ sc_assert( top.target_sync_reset_1_called );
+ sc_assert( top.target_sync_reset_2_called );
+ sc_assert( top.target_sync_reset_3_called );
+ sc_assert( top.target_sync_reset_4_called );
+
+ cout << endl << "Success" << endl;
+ return 0;
+}
diff --git a/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_immed/golden/proc_ctrl_immed.log b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_immed/golden/proc_ctrl_immed.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_immed/golden/proc_ctrl_immed.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_immed/proc_ctrl_immed.cpp b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_immed/proc_ctrl_immed.cpp new file mode 100644 index 000000000..69a607198 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_immed/proc_ctrl_immed.cpp @@ -0,0 +1,413 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// proc_ctrl_immed.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: proc_ctrl_immed.cpp,v $ +// Revision 1.3 2011/09/01 15:47:15 acg +// John Aynsley: correction for immediate method invocation on reset. +// +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Process control methods executed immediately in same eval phase + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + : count(0), reset_count(0) + { + SC_THREAD(ctrl); + SC_THREAD(target_thread); + t = sc_get_current_process_handle(); + + SC_METHOD(target_method); + sensitive << ev; + dont_initialize(); + m = sc_get_current_process_handle(); + m.disable(); + + SC_METHOD(thread_reset_handler); + sensitive << t.reset_event(); + dont_initialize(); + + SC_METHOD(method_reset_handler); + sensitive << m.reset_event(); + dont_initialize(); + + SC_METHOD(thread_terminated_handler); + sensitive << t.terminated_event(); + dont_initialize(); + + SC_METHOD(method_terminated_handler); + sensitive << m.terminated_event(); + dont_initialize(); + + SC_METHOD(yield_helper_method); + sensitive << yield_event_1; + dont_initialize(); + + f0 = f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0; + f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0; + f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0; + f30 = f31 = f32 = f33 = f34 = f35 = f36 = f37 = f38 = f39 = 0; + } + + sc_event yield_event_1, yield_event_2, target_awoke_event; + int count, reset_count; + int f0, f1, f2, f3, f4, f5, f6, f7, f8, f9; + int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19; + int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29; + int f30, f31, f32, f33, f34, f35, f36, f37, f38, f39; + + sc_event ev; + sc_process_handle t, m; + std::exception ex; + + void ctrl() + { + wait(SC_ZERO_TIME); + sc_assert( sc_delta_count() == 1 ); + + count = 1; + ev.notify(); + wait(target_awoke_event); + + count = 2; + ev.notify(); + t.suspend(); + yield(); + + count = 2; + t.resume(); + wait(target_awoke_event); + + count = 3; + ev.notify(); + t.disable(); + wait(target_awoke_event); + + count = 4; + ev.notify(); + yield(); + + count = 5; + t.enable(); + yield(); + + count = 6; + ev.notify(); + wait(target_awoke_event); + + count = 7; + t.suspend(); + ev.notify(); + yield(); + + count = 8; + t.resume(); + wait(target_awoke_event); + + count = 9; + reset_count = 9; + t.sync_reset_on(); + ev.notify(); + wait(target_awoke_event); + + count = 10; + reset_count = 10; + ev.notify(); + wait(target_awoke_event); + + count = 11; + t.sync_reset_off(); + ev.notify(); + wait(target_awoke_event); + + count = 12; + t.resume(); + t.enable(); + t.sync_reset_off(); + yield(); + + count = 13; + ev.notify(); + wait(target_awoke_event); + + count = 14; + reset_count = 14; + t.reset(); + + count = 15; + ev.notify(); + wait(target_awoke_event); + + count = 16; + reset_count = 16; + t.reset(); + + count = 17; + t.throw_it(ex); + + count = 18; + t.kill(); + yield(); + + count = 19; + m.enable(); + ev.notify(); + wait(target_awoke_event); + + count = 20; + ev.notify(); + m.suspend(); + yield(); + + count = 21; + m.resume(); + wait(target_awoke_event); + + count = 22; + m.suspend(); + ev.notify(); + yield(); + + count = 23; + m.resume(); + wait(target_awoke_event); + + count = 24; + m.suspend(); + ev.notify(); + + count = 25; + m.resume(); + wait(target_awoke_event); + + count = 26; + reset_count = 26; + m.sync_reset_on(); + ev.notify(); + wait(target_awoke_event); + + count = 27; + m.disable(); + ev.notify(); + yield(); + + count = 28; + reset_count = 28; + m.enable(); + ev.notify(); + wait(target_awoke_event); + + count = 29; + m.sync_reset_off(); + m.enable(); + m.resume(); + yield(); + + count = 30; + reset_count = 30; + m.reset(); + + count = 31; + m.kill(); + yield(); + + sc_assert( sc_delta_count() == 1 ); + f27 = 1; + } + + void target_thread() + { + switch (count) + { + case 0: f0=1; break; + case 9: f7=1; break; + case 10: f9=1; break; + case 14: f13=1; break; + case 16: f16=1; break; + default: sc_assert(false); break; + } + while (true) + { + try { + target_awoke_event.notify(); + wait(ev); + } + catch (const std::exception& e) { + switch (count) + { + case 9: sc_assert(sc_is_unwinding()); f6=1; break; + case 10: sc_assert(sc_is_unwinding()); f8=1; break; + case 14: sc_assert(sc_is_unwinding()); f12=1; break; + case 16: sc_assert(sc_is_unwinding()); f15=1; break; + case 17: sc_assert( !sc_is_unwinding() ); f17=1; break; + case 18: sc_assert(sc_is_unwinding()); f19=1; break; + default: sc_assert(false); break; + } + if ( sc_is_unwinding() ) + throw dynamic_cast<const sc_unwind_exception&>(e); + } + switch (count) + { + case 1: f1=1; break; + case 2: f2=1; break; + case 3: f3=1; break; + case 6: f4=1; break; + case 8: f5=1; break; + case 11: f10=1; break; + case 13: f11=1; break; + case 15: f14=1; break; + case 17: f18=1; break; + default: sc_assert(false); break; + } + } + } + + void target_method() + { + switch (count) + { + case 19: f20=1; break; + case 21: f21=1; break; + case 23: f22=1; break; + case 25: f23=1; break; + case 26: f24=1; break; + case 28: f25=1; break; + case 30: f26=1; break; + default: sc_assert(false); break; + } + target_awoke_event.notify(); + } + + void thread_reset_handler() + { + switch (reset_count) + { + case 9: f30=1; break; + case 10: f31=1; break; + case 14: f32=1; break; + case 16: f33=1; break; + default: sc_assert(false); break; + } + } + + void method_reset_handler() + { + switch (reset_count) + { + case 26: f34=1; break; + case 28: f35=1; break; + case 30: f36=1; break; + default: sc_assert(false); break; + } + } + + void thread_terminated_handler() + { + sc_assert(count == 18); + sc_assert(sc_delta_count() == 1); + f37 = 1; + } + + void method_terminated_handler() + { + sc_assert(count == 31); + sc_assert(sc_delta_count() == 1); + f38 = 1; + } + + void yield() + { + yield_event_1.notify(); + wait(yield_event_2); + } + + void yield_helper_method() + { + yield_event_2.notify(); + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f0 ); + sc_assert( top.f1 ); + sc_assert( top.f2 ); + sc_assert( top.f3 ); + sc_assert( top.f4 ); + sc_assert( top.f5 ); + sc_assert( top.f6 ); + sc_assert( top.f7 ); + sc_assert( top.f8 ); + sc_assert( top.f9 ); + sc_assert( top.f10 ); + sc_assert( top.f11 ); + sc_assert( top.f12 ); + sc_assert( top.f13 ); + sc_assert( top.f14 ); + sc_assert( top.f15 ); + sc_assert( top.f16 ); + sc_assert( top.f17 ); + sc_assert( top.f18 ); + sc_assert( top.f19 ); + sc_assert( top.f20 ); + sc_assert( top.f21 ); + sc_assert( top.f22 ); + sc_assert( top.f23 ); + sc_assert( top.f24 ); + sc_assert( top.f25 ); + sc_assert( top.f26 ); + sc_assert( top.f27 ); + + sc_assert( top.f30 ); + sc_assert( top.f31 ); + sc_assert( top.f32 ); + sc_assert( top.f33 ); + sc_assert( top.f34 ); + sc_assert( top.f35 ); + sc_assert( top.f36 ); + sc_assert( top.f37 ); + sc_assert( top.f38 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_priority/golden/proc_ctrl_priority.log b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_priority/golden/proc_ctrl_priority.log new file mode 100644 index 000000000..cdf4578d6 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_priority/golden/proc_ctrl_priority.log @@ -0,0 +1,5 @@ +SystemC Simulation + +Info: /OSCI/SystemC: Simulation stopped by user. + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_priority/proc_ctrl_priority.cpp b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_priority/proc_ctrl_priority.cpp new file mode 100644 index 000000000..1f8c9d71a --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_priority/proc_ctrl_priority.cpp @@ -0,0 +1,377 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// proc_ctrl_priority.cpp -- test for +// +// Original Author: John Aynsley, Doulus +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: proc_ctrl_priority.cpp,v $ +// Revision 1.3 2011/09/05 21:23:35 acg +// Philipp A. Hartmann: eliminate compiler warnings. +// +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Priority of process control methods suspend, disable, sync_reset_on, reset + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(calling); + + SC_THREAD(target); + t = sc_get_current_process_handle(); + + count = 0; + f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0; + f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0; + f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0; + } + + sc_process_handle t; + sc_event ev; + int count; + bool target_awoke; + int f1, f2, f3, f4, f5, f6, f7, f8, f9; + int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19; + int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29; + + void calling() + { + count = 0; + wait(SC_ZERO_TIME); + + count = 1; + ev.notify(5, SC_NS); + wait(10, SC_NS); + + count = 2; + ev.notify(5, SC_NS); + t.disable(); + wait(10, SC_NS); + + count = 3; + ev.notify(5, SC_NS); + t.disable(); + t.disable(); // Dummy + t.resume(); + t.resume(); + t.sync_reset_off(); // Dummy + t.sync_reset_off(); // Dummy + wait(10, SC_NS); + + count = 4; + ev.notify(5, SC_NS); + t.enable(); + wait(10, SC_NS); + + count = 5; + ev.notify(5, SC_NS); + t.enable(); // Dummy + t.enable(); // Dummy + t.sync_reset_off(); // Dummy + t.sync_reset_off(); // Dummy + wait(10, SC_NS); + + count = 6; + ev.notify(5, SC_NS); + t.reset(); + wait(SC_ZERO_TIME); + + count = 7; + wait(sc_time(100, SC_NS) - sc_time_stamp()); + + count = 8; + ev.notify(5, SC_NS); + t.disable(); + wait(10, SC_NS); + + count = 9; + ev.notify(5, SC_NS); + t.reset(); + wait(10, SC_NS); + + count = 10; + ev.notify(5, SC_NS); + t.reset(); + wait(10, SC_NS); + + count = 11; + ev.notify(5, SC_NS); + t.enable(); + wait(sc_time(200, SC_NS) - sc_time_stamp()); + + count = 12; + ev.notify(5, SC_NS); + t.suspend(); + wait(10, SC_NS); + + count = 13; + t.suspend(); // Dummy + t.suspend(); // Dummy + t.enable(); // Dummy + t.enable(); // Dummy + t.sync_reset_off(); // Dummy + t.sync_reset_off(); // Dummy + wait(10, SC_NS); + + count = 14; + t.resume(); + wait(10, SC_NS); + + count = 15; + ev.notify(5, SC_NS); + t.resume(); // Dummy + t.resume(); // Dummy + t.enable(); // Dummy + t.enable(); // Dummy + t.sync_reset_off(); // Dummy + t.sync_reset_off(); // Dummy + wait(10, SC_NS); + + count = 16; + ev.notify(); + t.resume(); // Dummy + t.resume(); // Dummy + t.disable(); // Dummy + t.disable(); // Dummy + t.enable(); // Dummy + t.enable(); // Dummy + t.suspend(); + wait(10, SC_NS); + + count = 17; + t.suspend(); // Dummy + t.suspend(); // Dummy + t.enable(); // Dummy + t.enable(); // Dummy + t.sync_reset_off(); // Dummy + t.sync_reset_off(); // Dummy + wait(10, SC_NS); + + count = 18; + t.resume(); + wait(sc_time(300, SC_NS) - sc_time_stamp()); + + count = 19; + ev.notify(); + ev.notify(5, SC_NS); + t.disable(); + t.disable(); // Dummy + wait(5, SC_NS); + t.disable(); // Dummy + t.resume(); + t.resume(); + wait(5, SC_NS); + + count = 20; + ev.notify(5, SC_NS); + t.enable(); + t.enable(); // Dummy + wait(SC_ZERO_TIME); + + count = 21; + wait(10, SC_NS); + + count = 22; + ev.notify(5, SC_NS); + t.suspend(); + wait(10, SC_NS); + + count = 23; + t.reset(); + ev.notify(5, SC_NS); + wait(10, SC_NS); + + count = 24; + t.reset(); + ev.notify(5, SC_NS); + wait(10, SC_NS); + + count = 25; + t.resume(); + wait(sc_time(400, SC_NS) - sc_time_stamp()); + + count = 26; + ev.notify(); + t.reset(); + wait(10, SC_NS); + + count = 27; + ev.notify(); + t.suspend(); + wait(10, SC_NS); + + count = 28; + t.reset(); + wait(10, SC_NS); + t.resume(); + + wait(sc_time(500, SC_NS) - sc_time_stamp()); + + count = 29; + t.sync_reset_on(); + t.sync_reset_on(); // Dummy + wait(10, SC_NS); + + count = 30; + ev.notify(); + wait(10, SC_NS); + + count = 31; + t.resume(); // Dummy + t.resume(); // Dummy + t.enable(); // Dummy + t.enable(); // Dummy + t.sync_reset_on(); // Dummy + t.sync_reset_on(); // Dummy + wait(10, SC_NS); + + count = 32; + ev.notify(); + wait(10, SC_NS); + + count = 33; + ev.notify(); + t.disable(); + wait(10, SC_NS); + + count = 34; + ev.notify(); + wait(10, SC_NS); + + count = 35; + t.enable(); + ev.notify(); + wait(10, SC_NS); + + count = 36; + t.disable(); + t.disable(); // Dummy + ev.notify(); + ev.notify(); // Dummy + wait(10, SC_NS); + + count = 37; + t.sync_reset_off(); + t.sync_reset_off(); // Dummy + wait(10, SC_NS); + + count = 38; + t.enable(); + wait(10, SC_NS); + + count = 39; + ev.notify(); + wait(sc_time(700, SC_NS) - sc_time_stamp()); + + sc_stop(); + } + + void target() + { + switch (count) + { + case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f1=1; break; + case 6: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); f5=1; break; + case 9: sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); f7=1; break; + case 10: sc_assert( sc_time_stamp() == sc_time(120, SC_NS) ); f8=1; break; + case 23: sc_assert( sc_time_stamp() == sc_time(330, SC_NS) ); f15=1; break; + case 24: sc_assert( sc_time_stamp() == sc_time(340, SC_NS) ); f16=1; break; + case 26: sc_assert( sc_time_stamp() == sc_time(400, SC_NS) ); f18=1; break; + case 28: sc_assert( sc_time_stamp() == sc_time(420, SC_NS) ); f19=1; break; + case 30: sc_assert( sc_time_stamp() == sc_time(510, SC_NS) ); f20=1; break; + case 32: sc_assert( sc_time_stamp() == sc_time(530, SC_NS) ); f21=1; break; + case 33: sc_assert( sc_time_stamp() == sc_time(540, SC_NS) ); f22=1; break; + case 35: sc_assert( sc_time_stamp() == sc_time(560, SC_NS) ); f23=1; break; + default: sc_assert( false ); break; + } + + for (;;) + { + wait(ev); + switch (count) + { + case 1: sc_assert( sc_time_stamp() == sc_time(5, SC_NS) ); f2=1; break; + case 4: sc_assert( sc_time_stamp() == sc_time(35, SC_NS) ); f3=1; break; + case 5: sc_assert( sc_time_stamp() == sc_time(45, SC_NS) ); f4=1; break; + case 7: sc_assert( sc_time_stamp() == sc_time(55, SC_NS) ); f6=1; break; + case 11: sc_assert( sc_time_stamp() == sc_time(135, SC_NS) ); f9=1; break; + case 14: sc_assert( sc_time_stamp() == sc_time(220, SC_NS) ); f10=1; break; + case 15: sc_assert( sc_time_stamp() == sc_time(235, SC_NS) ); f11=1; break; + case 18: sc_assert( sc_time_stamp() == sc_time(260, SC_NS) ); f12=1; break; + case 19: sc_assert( sc_time_stamp() == sc_time(300, SC_NS) ); f13=1; break; + case 21: sc_assert( sc_time_stamp() == sc_time(315, SC_NS) ); f14=1; break; + case 25: sc_assert( sc_time_stamp() == sc_time(350, SC_NS) ); f17=1; break; + case 39: sc_assert( sc_time_stamp() == sc_time(600, SC_NS) ); f24=1; break; + default: sc_assert( false ); break; + } + } + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f1 ); + sc_assert( top.f2 ); + sc_assert( top.f3 ); + sc_assert( top.f4 ); + sc_assert( top.f5 ); + sc_assert( top.f6 ); + sc_assert( top.f7 ); + sc_assert( top.f8 ); + sc_assert( top.f9 ); + sc_assert( top.f10 ); + sc_assert( top.f11 ); + sc_assert( top.f12 ); + sc_assert( top.f13 ); + sc_assert( top.f14 ); + sc_assert( top.f15 ); + sc_assert( top.f16 ); + sc_assert( top.f17 ); + sc_assert( top.f18 ); + sc_assert( top.f19 ); + sc_assert( top.f20 ); + sc_assert( top.f21 ); + sc_assert( top.f22 ); + sc_assert( top.f23 ); + sc_assert( top.f24 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_timeout/golden/proc_ctrl_timeout.log b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_timeout/golden/proc_ctrl_timeout.log new file mode 100644 index 000000000..cdf4578d6 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_timeout/golden/proc_ctrl_timeout.log @@ -0,0 +1,5 @@ +SystemC Simulation + +Info: /OSCI/SystemC: Simulation stopped by user. + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_timeout/proc_ctrl_timeout.cpp b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_timeout/proc_ctrl_timeout.cpp new file mode 100644 index 000000000..060ff3ac1 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_timeout/proc_ctrl_timeout.cpp @@ -0,0 +1,340 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// proc_ctrl_timeout.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: proc_ctrl_timeout.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Process control methods interacting with time-out and event lists + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(calling); + + SC_THREAD(target1); + t1 = sc_get_current_process_handle(); + + SC_METHOD(target2); + t2 = sc_get_current_process_handle(); + + SC_THREAD(target3); + t3 = sc_get_current_process_handle(); + + SC_METHOD(target4); + t4 = sc_get_current_process_handle(); + + SC_METHOD(target5); + t5 = sc_get_current_process_handle(); + t5.disable(); + sensitive << ev4; + + count = 0; + f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = f10 = 0; + f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0; + f20 = f21 = f22 = 0; + } + + sc_process_handle t1, t2, t3, t4, t5; + sc_event ev1, ev2, ev3, ev4; + int count; + int f1, f2, f3, f4, f5, f6, f7, f8, f9, f10; + int f11, f12, f13, f14, f15, f16, f17, f18, f19; + int f20, f21, f22; + + void calling() + { + wait(SC_ZERO_TIME); + count = 1; + wait(15, SC_NS); + + count = 2; + try { + t1.disable(); + sc_assert(false); + } + catch (sc_exception ex) { + //cout << "Exception caught at " << sc_time_stamp() << endl; + f7 = 1; + } + + try { + t2.disable(); + sc_assert(false); + } + catch (sc_exception ex) { + //cout << "Exception caught at " << sc_time_stamp() << endl; + f8 = 1; + } + wait(SC_ZERO_TIME); + t1.kill(); + t2.kill(); + ev1.notify(); + wait(sc_time(100, SC_NS) - sc_time_stamp()); + + count = 6; + t3.disable(); + t4.disable(); + wait(10, SC_NS); + + ev2.notify(); + wait(10, SC_NS); + + t3.enable(); + t4.enable(); + wait(10, SC_NS); + + ev3.notify(); + wait(10, SC_NS); + + ev2.notify(); + wait(sc_time(200, SC_NS) - sc_time_stamp()); + + count = 7; + ev1.notify(); + wait(10, SC_NS); + + t3.suspend(); + t4.suspend(); + wait(10, SC_NS); + + ev2.notify(); + wait(10, SC_NS); + + t3.resume(); + t4.resume(); + wait(10, SC_NS); + + ev3.notify(); + wait(sc_time(300, SC_NS) - sc_time_stamp()); + + count = 8; + ev1.notify(); + wait(10, SC_NS); + + ev2.notify(); + wait(10, SC_NS); + + t3.reset(); + count = 9; + wait(10, SC_NS); + + ev3.notify(); + wait(10, SC_NS); + + ev1.notify(); + wait(10, SC_NS); + + ev2.notify(); + wait(sc_time(400, SC_NS) - sc_time_stamp()); + t3.disable(); + t4.disable(); + + // Now target5 + count = 9; + t5.enable(); + ev4.notify(); + wait(SC_ZERO_TIME); + + count = 10; + ev3.notify(3, SC_NS); + ev2.notify(2, SC_NS); + ev1.notify(1, SC_NS); + wait(10, SC_NS); + + count = 11; + t5.reset(); // On reset, dynamic sensit is cleared, then target is called again + wait(SC_ZERO_TIME); + + count = 12; + ev3.notify(3, SC_NS); + ev2.notify(2, SC_NS); + ev1.notify(1, SC_NS); + wait(10, SC_NS); + + count = 13; + ev4.notify(); + wait(SC_ZERO_TIME); + + count = 14; + try { + t5.disable(); // Disabling a process waiting on a time-out + } + catch (sc_exception ex) { + //cout << "Exception caught at " << sc_time_stamp() << endl; + f21 = 1; + } + wait(sc_time(500, SC_NS) - sc_time_stamp()); + + count = 15; + t5.reset(); + wait(10, SC_NS); + + count = 16; + ev4.notify(); + wait(10, SC_NS); + + sc_stop(); + } + + void target1() + { + //cout << "target1() called at " << sc_time_stamp() << " count = " << count << endl; + switch (count) + { + case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f1=1; break; + default: sc_assert( false ); break; + } + + for (;;) + { + wait(10, SC_NS); + //cout << "target1() awoke at " << sc_time_stamp() << " count = " << count << endl; + switch (count) + { + case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); f5=1; break; + default: sc_assert( false ); break; + } + } + } + + void target2() + { + //cout << "target2() called at " << sc_time_stamp() << " count = " << count << endl; + switch (count) + { + case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f2=1; break; + case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); f6=1; break; + default: sc_assert( false ); break; + } + next_trigger(10, SC_NS); + } + + void target3() + { + //cout << "target3() called at " << sc_time_stamp() << " count = " << count << endl; + switch (count) + { + case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f3=1; break; + case 8: sc_assert( sc_time_stamp() == sc_time(320, SC_NS) ); f13=1; break; + default: sc_assert( false ); break; + } + + for (;;) + { + wait(ev1 & ev2 & ev3); + //cout << "target3() awoke at " << sc_time_stamp() << " count = " << count << endl; + switch (count) + { + case 6: sc_assert( sc_time_stamp() == sc_time(140, SC_NS) ); f9=1; break; + case 7: sc_assert( sc_time_stamp() == sc_time(240, SC_NS) ); f11=1; break; + case 9: sc_assert( sc_time_stamp() == sc_time(350, SC_NS) ); f15=1; break; + default: sc_assert( false ); break; + } + } + } + + void target4() + { + //cout << "target4() called at " << sc_time_stamp() << " count = " << count << endl; + switch (count) + { + case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f4=1; break; + case 6: sc_assert( sc_time_stamp() == sc_time(140, SC_NS) ); f10=1; break; + case 7: sc_assert( sc_time_stamp() == sc_time(240, SC_NS) ); f12=1; break; + case 9: sc_assert( sc_time_stamp() == sc_time(330, SC_NS) ); f14=1; break; + default: sc_assert( false ); break; + } + next_trigger(ev1 & ev2 & ev3); + } + + void target5() + { + //cout << "target5() called at " << sc_time_stamp() << " count = " << count << endl; + switch (count) + { + case 9: sc_assert( sc_time_stamp() == sc_time(400, SC_NS) ); f16=1; break; + case 10: sc_assert( sc_time_stamp() == sc_time(403, SC_NS) ); f17=1; break; + case 11: sc_assert( sc_time_stamp() == sc_time(410, SC_NS) ); f18=1; break; + case 12: sc_assert( sc_time_stamp() == sc_time(413, SC_NS) ); f19=1; break; + case 14: sc_assert( sc_time_stamp() == sc_time(424, SC_NS) ); break; + case 15: sc_assert( sc_time_stamp() == sc_time(500, SC_NS) ); f20=1; break; + case 16: sc_assert( sc_time_stamp() == sc_time(510, SC_NS) ); f22=1; break; + default: sc_assert( false ); break; + } + if (count < 12) + next_trigger(ev1 & ev2 & ev3); + else if (count == 12) + next_trigger(11, SC_NS, ev3); + else if (count > 12) + next_trigger(); + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f1 ); + sc_assert( top.f2 ); + sc_assert( top.f3 ); + sc_assert( top.f4 ); + sc_assert( top.f5 ); + sc_assert( top.f6 ); + sc_assert( top.f7 ); + sc_assert( top.f8 ); + sc_assert( top.f9 ); + sc_assert( top.f10 ); + sc_assert( top.f11 ); + sc_assert( top.f12 ); + sc_assert( top.f13 ); + sc_assert( top.f14 ); + sc_assert( top.f15 ); + sc_assert( top.f16 ); + sc_assert( top.f17 ); + sc_assert( top.f18 ); + sc_assert( top.f19 ); + sc_assert( top.f20 ); + sc_assert( top.f21 ); + sc_assert( top.f22 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/recursive_kill_bug/golden/recursive_kill_bug.log b/src/systemc/tests/systemc/1666-2011-compliance/recursive_kill_bug/golden/recursive_kill_bug.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/recursive_kill_bug/golden/recursive_kill_bug.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/recursive_kill_bug/recursive_kill_bug.cpp b/src/systemc/tests/systemc/1666-2011-compliance/recursive_kill_bug/recursive_kill_bug.cpp new file mode 100644 index 000000000..50ed7d537 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/recursive_kill_bug/recursive_kill_bug.cpp @@ -0,0 +1,124 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// recursive_kill_bug.cpp -- test for +// +// Original Author: John Aynsley, Doulus +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// + +// + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(control); + + SC_METHOD(caller); + sensitive << ev; + dont_initialize(); + caller_handle = sc_get_current_process_handle(); + + SC_THREAD(target); + target_handle = sc_get_current_process_handle(); + + count = 0; + f0 = f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0; + } + + struct bomb + { + sc_process_handle h; + + bomb(sc_process_handle _h) + { + h = _h; + } + + ~bomb() + { + h.kill(); + } + }; + + sc_process_handle caller_handle; + sc_process_handle target_handle; + int count; + int f0, f1, f2, f3, f4, f5, f6, f7, f8, f9; + sc_event ev; + + void control() + { + count = 0; + wait(10, SC_NS); + + count = 1; + ev.notify(); + } + + void caller() + { + f0 = 1; + target_handle.kill(); + sc_assert( false ); // FAILS !!!!!! + } + + void target() + { + bomb local_obj(caller_handle); + sc_assert( count == 0 ); + f1 = 1; + try { + wait(20, SC_NS); + } + catch (const sc_unwind_exception& e) { + sc_assert( count == 1 ); + sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); + f2 = 1; + throw e; + } + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f0 ); + sc_assert( top.f1 ); + sc_assert( top.f2 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_delta_count/golden/sc_delta_count.log b/src/systemc/tests/systemc/1666-2011-compliance/sc_delta_count/golden/sc_delta_count.log new file mode 100644 index 000000000..4a4355f1f --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_delta_count/golden/sc_delta_count.log @@ -0,0 +1,25 @@ +SystemC Simulation +M() awoke at 0 s +M() awoke at 0 s +M() awoke at 0 s +M() awoke at 1 ns +M() awoke at 2 ns +M() awoke at 5 ns +M() awoke at 6 ns +M() awoke at 7 ns +M() awoke at 8 ns + +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: <removed by verify.pl> + +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: <removed by verify.pl> +M() awoke at 9 ns +M() awoke at 10 ns +M() awoke at 12 ns +M() awoke at 12 ns +M() awoke at 13 ns + +Info: /OSCI/SystemC: Simulation stopped by user. + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_delta_count/sc_delta_count.cpp b/src/systemc/tests/systemc/1666-2011-compliance/sc_delta_count/sc_delta_count.cpp new file mode 100644 index 000000000..ad8622e03 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_delta_count/sc_delta_count.cpp @@ -0,0 +1,250 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// sc_delta_count.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: sc_delta_count.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// sc_delta_count, including notifications across pauses + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + + SC_THREAD(T); + + SC_METHOD(M); + sensitive << ev << ev2 << ev3; + dont_initialize(); + m = sc_get_current_process_handle(); + + sc_assert( sc_delta_count() == 0 ); + count = 0; + reached_end = false; + } + + void start_of_simulation() + { + sc_assert( sc_delta_count() == 0 ); + } + + sc_process_handle m; + sc_event ev, ev2, ev3; + int count; + sc_time last_time; + bool reached_end; + + void T() + { + sc_assert( sc_delta_count() == 0 ); + + count = 1; + ev.notify(); + wait(SC_ZERO_TIME); + sc_assert( sc_delta_count() == 1 ); + + count = 2; + ev.notify(); + wait(SC_ZERO_TIME); + sc_assert( sc_delta_count() == 2 ); + + count = 3; + ev.notify(SC_ZERO_TIME); + wait(SC_ZERO_TIME); + sc_assert( sc_delta_count() == 3 ); + + count = 4; + ev.notify(1, SC_NS); + wait(SC_ZERO_TIME); + sc_assert( sc_delta_count() == 4 ); + + count = 5; + wait(1, SC_NS); + ev.notify(1, SC_NS); + sc_assert( sc_delta_count() == 5 ); + + count = 6; + wait(2, SC_NS); + sc_assert( sc_delta_count() == 7 ); + + count = 7; + m.disable(); + ev.notify(1, SC_NS); + wait(2, SC_NS); + sc_assert( sc_delta_count() == 8 ); + + count = 8; + m.enable(); + ev .notify(); + ev2.notify(1, SC_NS); + ev3.notify(2, SC_NS); + wait(3, SC_NS); + sc_assert( sc_delta_count() == 11 ); + + count = 9; + last_time = sc_time_stamp(); + sc_pause(); // 1st pause + wait(ev); + sc_assert( sc_delta_count() == 12 ); + + count = 10; + last_time = sc_time_stamp(); + sc_pause(); // 2nd pause + wait(ev); + sc_assert( sc_delta_count() == 13 ); + + count = 11; + last_time = sc_time_stamp(); + sc_pause(); // 3rd pause + wait(ev); + sc_assert( sc_delta_count() == 14 ); + + count = 12; + last_time = sc_time_stamp(); + sc_pause(); // 4th pause + wait(ev); + sc_assert( sc_delta_count() == 15 ); + + count = 13; + last_time = sc_time_stamp(); + sc_pause(); // 5th pause + wait(ev); + sc_assert( sc_delta_count() == 16 ); + + count = 14; + wait(ev); + sc_assert( sc_delta_count() == 17 ); + + last_time = sc_time_stamp(); + reached_end = true; + sc_stop(); + } + + void M() + { + cout << "M() awoke at " << sc_time_stamp() << endl; + switch (count) + { + case 0: sc_assert( false ); break; + case 1: sc_assert( sc_delta_count() == 0 ); break; + case 2: sc_assert( sc_delta_count() == 1 ); break; + case 3: sc_assert( sc_delta_count() == 3 ); break; + case 4: sc_assert( false ); break; + case 5: sc_assert( sc_delta_count() == 5 ); break; + case 6: sc_assert( sc_delta_count() == 6 ); break; + case 7: sc_assert( false ); break; + case 8: sc_assert( sc_delta_count() == 8 || + sc_delta_count() == 9 || + sc_delta_count() == 10 ); break; + case 9: sc_assert( sc_delta_count() == 12 ); break; + case 10: sc_assert( sc_delta_count() == 13 ); break; + case 11: sc_assert( sc_delta_count() == 14 ); break; + case 12: sc_assert( sc_delta_count() == 15 ); break; + case 13: sc_assert( sc_delta_count() == 16 ); break; + case 14: sc_assert( sc_delta_count() == 17 ); break; + } + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + sc_assert( sc_delta_count() == 0 ); + + Top top("top"); + + sc_start(); + + sc_assert( sc_delta_count() == 12 ); + sc_assert( sc_get_status() == SC_PAUSED ); + top.ev.notify(); // Wake from 1st pause on immed notification + + sc_start(); + sc_assert( sc_delta_count() == 13 ); + sc_assert( sc_get_status() == SC_PAUSED ); + sc_assert( sc_pending_activity_at_current_time() == false ); + sc_assert( sc_pending_activity_at_future_time() == false ); + + sc_start(SC_ZERO_TIME); + sc_assert( sc_delta_count() == 13 ); + + sc_assert( sc_get_status() == SC_PAUSED ); + sc_start(SC_ZERO_TIME); + sc_assert( sc_delta_count() == 13 ); + sc_assert( top.last_time == sc_time_stamp() ); + + sc_start(1, SC_NS); + sc_assert( sc_delta_count() == 13 ); + sc_assert( top.count == 10 ); + // sc_assert( top.last_time == sc_time_stamp() ); + + top.ev.notify(SC_ZERO_TIME); // Wake from 2nd pause on delta notification + sc_start(1, SC_NS); + sc_assert( sc_delta_count() == 14 ); + sc_assert( top.last_time == sc_time_stamp() ); + + top.ev.notify(1, SC_NS); // Wake from 3rd pause on timed notification + sc_start(2, SC_NS); + sc_assert( sc_delta_count() == 15 ); + sc_assert( top.last_time == sc_time_stamp() ); + + top.ev.notify(2, SC_NS); // Future notification beyond the subsequent start + sc_assert( sc_pending_activity_at_current_time() == false ); + sc_assert( sc_pending_activity_at_future_time() == true ); + sc_start(1, SC_NS); + sc_assert( sc_delta_count() == 15 ); + + sc_start(); + sc_assert( sc_delta_count() == 16 ); + sc_assert( top.last_time == sc_time_stamp() ); + + top.ev.notify(); // Wake from 5th pause on immed notification + sc_start(SC_ZERO_TIME); + sc_assert( sc_delta_count() == 17 ); + sc_assert( top.last_time == sc_time_stamp() ); + + sc_assert( sc_get_status() == SC_PAUSED ); + + top.ev.notify(1, SC_NS); // Future notification before calling sc_stop + sc_start(2, SC_NS); + + sc_assert( sc_get_status() == SC_STOPPED ); + sc_assert( sc_end_of_simulation_invoked() ); + sc_assert( top.last_time == sc_time_stamp() ); + sc_assert( top.reached_end ); + + cout << endl << "Success" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_pause/golden/sc_pause.log b/src/systemc/tests/systemc/1666-2011-compliance/sc_pause/golden/sc_pause.log new file mode 100644 index 000000000..dcbcdcb48 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_pause/golden/sc_pause.log @@ -0,0 +1,29 @@ +SystemC Simulation +sc_get_status() == SC_ELABORATION ELAB +sc_get_status() == SC_ELABORATION CTOR in top +sc_get_status() == SC_BEFORE_END_OF_ELABORATION before_end_of_elaboration in top +sc_get_status() == SC_BEFORE_END_OF_ELABORATION CTOR in top.m +sc_get_status() == SC_BEFORE_END_OF_ELABORATION before_end_of_elaboration in top.m +sc_get_status() == SC_END_OF_ELABORATION end_of_elaboration in top +sc_get_status() == SC_END_OF_ELABORATION end_of_elaboration in top.m +sc_get_status() == SC_START_OF_SIMULATION start_of_simulation in top +sc_get_status() == SC_START_OF_SIMULATION start_of_simulation in top.m +sc_get_status() == SC_RUNNING METHOD in top +sc_get_status() == SC_RUNNING PROCESS in top +on_timed_event() awoke +sc_get_status() == SC_RUNNING METHOD in top +sc_get_status() == SC_RUNNING PROCESS after sc_pause in top +sc_get_status() == SC_PAUSED PAUSED +sc_get_status() == SC_RUNNING PROCESS after sc_pause in top +sc_get_status() == SC_PAUSED PAUSED +on_immed_event() awoke +spawned_while_paused() awoke +on_delta_event() awoke +sc_get_status() == SC_RUNNING PROCESS after sc_stop() in top + +Info: /OSCI/SystemC: Simulation stopped by user. +sc_get_status() == SC_END_OF_SIMULATION end_of_simulation in top +sc_get_status() == SC_END_OF_SIMULATION end_of_simulation in top.m +sc_get_status() == SC_STOPPED STOPPED + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_pause/sc_pause.cpp b/src/systemc/tests/systemc/1666-2011-compliance/sc_pause/sc_pause.cpp new file mode 100644 index 000000000..2f7ebd930 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_pause/sc_pause.cpp @@ -0,0 +1,348 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// sc_pause.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: sc_pause.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// sc_pause, sc_get_status, sc_is_running + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> +using namespace sc_core; +using std::cout; +using std::endl; +using std::hex; + +struct my_interface: virtual sc_interface +{ + virtual void schedule_events_while_paused() = 0; +}; + +struct M: sc_module, private my_interface +{ + sc_export<my_interface> xport; + + SC_CTOR(M) + { + cout << "sc_get_status() == " << hex << sc_get_status() << " CTOR in " << name() << endl; + sc_assert( sc_get_status() == SC_BEFORE_END_OF_ELABORATION ); + sc_assert( sc_is_running() == false ); + + xport.bind(*this); + + sc_spawn(sc_bind(&M::T, this)); + + SC_THREAD(on_immed_event); + SC_THREAD(on_delta_event); + SC_THREAD(on_timed_event); + } + + sc_signal<int> sig1, sig2, sig3, sig4; + sc_event immed_event; + sc_event delta_event; + sc_event timed_event; + + void before_end_of_elaboration() + { + cout << "sc_get_status() == " << hex << sc_get_status() << " before_end_of_elaboration in " << name() << endl; + sc_assert( sc_get_status() == SC_BEFORE_END_OF_ELABORATION ); + sc_assert( sc_is_running() == false ); + sig1.write(1); + timed_event.notify(1234, SC_NS); + sc_pause(); // Should be ignored + } + + void end_of_elaboration() + { + cout << "sc_get_status() == " << hex << sc_get_status() << " end_of_elaboration in " << name() << endl; + sc_assert( sc_get_status() == SC_END_OF_ELABORATION ); + sc_assert( sc_is_running() == false ); + sig2.write(2); + sc_pause(); // Should be ignored + } + + void start_of_simulation() + { + cout << "sc_get_status() == " << hex << sc_get_status() << " start_of_simulation in " << name() << endl; + sc_assert( sc_get_status() == SC_START_OF_SIMULATION ); + sc_assert( sc_is_running() == false ); + sig3.write(3); + sig4.write(0); + sc_pause(); // Should be ignored + } + + void end_of_simulation() + { + cout << "sc_get_status() == " << hex << sc_get_status() << " end_of_simulation in " << name() << endl;; + sc_assert( sc_get_status() == SC_END_OF_SIMULATION ); + sc_assert( sc_is_running() == false ); + } + + void T() + { + sc_assert( sig1.read() == 1 ); + sc_assert( sig2.read() == 2 ); + sc_assert( sig3.read() == 3 ); + } + + void on_immed_event() + { + wait(immed_event); + cout << "on_immed_event() awoke\n"; + + // Should run in 1st eval phase after pause + sc_assert( sig4.read() == 0 ); + } + + void on_delta_event() + { + wait(delta_event); + cout << "on_delta_event() awoke\n"; + + // Should run in 2nd eval phase after pause + sc_assert( sig4.read() == 4 ); + } + + void on_timed_event() + { + wait(timed_event); + cout << "on_timed_event() awoke\n"; + + sc_assert( sig1.read() == 1 ); + sc_assert( sig2.read() == 2 ); + sc_assert( sig3.read() == 3 ); + sc_assert( sig4.read() == 0 ); + sc_assert( sc_time_stamp() == sc_time(1234, SC_NS) ); + } + +private: + + void schedule_events_while_paused() + { + sig4.write(4); + immed_event.notify(); + delta_event.notify(SC_ZERO_TIME); + + // Should be able to instantiate an sc_object while paused + mut = new sc_mutex("mut"); + sem = new sc_semaphore("sem", 1); + } + + sc_mutex* mut; + sc_semaphore* sem; +}; + +SC_MODULE(Top) +{ + SC_CTOR(Top) + { + cout << "sc_get_status() == " << hex << sc_get_status() << " CTOR in " << name() << endl; + sc_assert( sc_get_status() == SC_ELABORATION ); + sc_assert( sc_is_running() == false ); + SC_THREAD(T); + + sc_spawn_options opt; + opt.spawn_method(); + opt.set_sensitivity( &timed_ev ); + opt.set_sensitivity( &delta_ev ); + opt.dont_initialize(); + sc_spawn(sc_bind(&Top::ev_handler, this), "ev_handler", &opt); + + SC_METHOD(immed_ev_handler); + sensitive << immed_ev; + dont_initialize(); + + immed_ev_delta = 0; + sc_assert( sc_delta_count() == 0 ); + } + + ~Top() + { + sc_assert( sc_get_status() == SC_STOPPED ); + sc_assert( sc_is_running() == false ); + } + + M* m; + sc_event timed_ev; + sc_event delta_ev; + sc_event immed_ev; + unsigned immed_ev_delta; + sc_signal<int> sig; + + void before_end_of_elaboration() + { + cout << "sc_get_status() == " << hex << sc_get_status() << " before_end_of_elaboration in " << name() << endl; + sc_assert( sc_get_status() == SC_BEFORE_END_OF_ELABORATION ); + sc_assert( sc_is_running() == false ); + + m = new M("m"); + } + + void end_of_elaboration() + { + cout << "sc_get_status() == " << hex << sc_get_status() << " end_of_elaboration in " << name() << endl; + sc_assert( sc_get_status() == SC_END_OF_ELABORATION ); + sc_assert( sc_is_running() == false ); + } + + void start_of_simulation() + { + cout << "sc_get_status() == " << hex << sc_get_status() << " start_of_simulation in " << name() << endl; + sc_assert( sc_get_status() == SC_START_OF_SIMULATION ); + sc_assert( sc_is_running() == false ); + } + + void end_of_simulation() + { + cout << "sc_get_status() == " << hex << sc_get_status() << " end_of_simulation in " << name() << endl; + sc_assert( sc_get_status() == SC_END_OF_SIMULATION ); + sc_assert( sc_is_running() == false ); + sc_assert( immed_ev_delta == 999 ); + } + + void T() + { + cout << "sc_get_status() == " << hex << sc_get_status() << " PROCESS in " << name() << endl; + sc_assert( sc_delta_count() == 0 ); + sc_assert( sig.read() == 42 ); + sc_assert( sc_get_status() == SC_RUNNING ); + sc_assert( sc_is_running() == true ); + wait(timed_ev); + sc_assert( sc_time_stamp() == sc_time(42, SC_US) ); + sc_assert( sc_get_status() == SC_RUNNING ); + sc_assert( sc_is_running() == true ); + + sc_pause(); + cout << "sc_get_status() == " << hex << sc_get_status() << " PROCESS after sc_pause in " << name() << endl; + sc_assert( sc_time_stamp() == sc_time(42, SC_US) ); + sc_assert( sc_get_status() == SC_RUNNING ); + sc_assert( sc_is_running() == true ); + wait(SC_ZERO_TIME); + sc_assert( sc_get_status() == SC_RUNNING ); + sc_assert( sc_is_running() == true ); + + sc_pause(); + cout << "sc_get_status() == " << hex << sc_get_status() << " PROCESS after sc_pause in " << name() << endl; + sc_assert( sc_time_stamp() == sc_time(42, SC_US) ); + sc_assert( sc_get_status() == SC_RUNNING ); + sc_assert( sc_is_running() == true ); + wait(2, SC_US); + sc_assert( sc_time_stamp() == sc_time(44, SC_US) ); + sc_assert( sc_get_status() == SC_RUNNING ); + sc_assert( sc_is_running() == true ); + + sc_stop(); + cout << "sc_get_status() == " << hex << sc_get_status() << " PROCESS after sc_stop() in " << name() << endl;; + sc_assert( sc_time_stamp() == sc_time(44, SC_US) ); + sc_assert( sc_get_status() == SC_RUNNING ); + sc_assert( sc_is_running() == true ); + + sc_pause(); + sc_assert( sc_get_status() == SC_RUNNING ); + } + + void ev_handler() + { + cout << "sc_get_status() == " << hex << sc_get_status() << " METHOD in " << name() << endl; + sc_assert( sc_get_status() == SC_RUNNING ); + sc_assert( sig.read() == 42 ); + + static bool first = true; + if (first) + { + sc_assert( sc_time_stamp() == SC_ZERO_TIME ); + first = false; + } + else + sc_assert( sc_time_stamp() == sc_time(42, SC_US) ); + } + + void immed_ev_handler() + { + sc_assert( sc_time_stamp() == sc_time(42, SC_US) ); + sc_assert( sc_delta_count() == immed_ev_delta ); + immed_ev_delta = 999; + } +}; + +void spawned_while_paused() +{ + cout << "spawned_while_paused() awoke" << endl; + sc_assert( sc_time_stamp() == sc_time(42, SC_US) ); + sc_assert( sc_get_status() == SC_RUNNING ); + sc_assert( sc_pending_activity() == true ); +} + +int sc_main(int argc, char* argv[]) +{ + sc_assert( sc_delta_count() == 0 ); + cout << "sc_get_status() == " << hex << sc_get_status() << " ELAB" << endl; + sc_assert( sc_get_status() == SC_ELABORATION ); + sc_assert( sc_is_running() == false ); + Top top("top"); + + sc_pause(); // Should be ignored + + // Schedule some update requests and events + top.sig.write(42); + top.timed_ev.notify(42, SC_US); + top.delta_ev.notify(SC_ZERO_TIME); + sc_assert( sc_get_status() == SC_ELABORATION ); + sc_assert( sc_delta_count() == 0 ); + + sc_start(); + cout << "sc_get_status() == " << hex << sc_get_status() << " PAUSED" << endl; + sc_assert( sc_get_status() == SC_PAUSED ); + sc_assert( sc_is_running() == true ); + sc_assert( sc_time_stamp() == sc_time(42, SC_US) ); + + sc_start(1, SC_US); + cout << "sc_get_status() == " << hex << sc_get_status() << " PAUSED" << endl; + sc_assert( sc_get_status() == SC_PAUSED ); + sc_assert( sc_is_running() == true ); + sc_assert( sc_time_stamp() == sc_time(42, SC_US) ); + + // Schedule an immediate notification + top.immed_ev.notify(); + top.immed_ev_delta = sc_delta_count(); + + // IMC while paused + top.m->xport->schedule_events_while_paused(); + + sc_process_handle h = sc_spawn(&spawned_while_paused); + sc_assert( h.valid() ); + + sc_start(); + cout << "sc_get_status() == " << hex << sc_get_status() << " STOPPED" << endl; + sc_assert( sc_get_status() == SC_STOPPED ); + sc_assert( sc_is_running() == false ); + sc_assert( sc_time_stamp() == sc_time(44, SC_US) ); + + cout << endl << "Success" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_process_handle_less_than/golden/sc_process_handle_less_than.log b/src/systemc/tests/systemc/1666-2011-compliance/sc_process_handle_less_than/golden/sc_process_handle_less_than.log new file mode 100644 index 000000000..3574ecaa6 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_process_handle_less_than/golden/sc_process_handle_less_than.log @@ -0,0 +1,5 @@ +SystemC Simulation +T2 completed +T1 completed + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_process_handle_less_than/sc_process_handle_less_than.cpp b/src/systemc/tests/systemc/1666-2011-compliance/sc_process_handle_less_than/sc_process_handle_less_than.cpp new file mode 100644 index 000000000..300bd4bac --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_process_handle_less_than/sc_process_handle_less_than.cpp @@ -0,0 +1,180 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// sc_process_handle_less_than.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: sc_process_handle_less_than.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// sc_process_handle::operator< and swap + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> +#include <map> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(T1); + SC_THREAD(T2); + } + + void T1() + { + sc_process_handle a, b; // Two empty handles + sc_assert( !a.valid() && !b.valid() ); // Both are invalid + sc_assert( a != b ); + sc_assert( !(a < b) && !(b < a) ); + + a = sc_spawn(sc_bind(&Top::f, this)); + b = sc_spawn(sc_bind(&Top::f, this)); + + sc_assert( a != b ); + sc_assert( (a < b) || (b < a) ); // Two handles to different processes + + sc_process_handle c = b; + + sc_assert( b == c ); + sc_assert( !(b < c) && !(c < b) ); // Two handles to the same process + + std::map<sc_process_handle, int> m; + m[a] = 1; + m[b] = 2; + m[c] = 3; + + sc_assert( m.size() == 2 ); + sc_assert( m[a] == 1 ); + sc_assert( m[b] == 3 ); + sc_assert( m[c] == 3 ); + + a.swap(b); + sc_assert( m[a] == 3 ); + sc_assert( m[b] == 1 ); + sc_assert( m[c] == 3 ); + b.swap(a); + + wait( a.terminated_event() & b.terminated_event() ); + + sc_assert( (a < b) || (b < a) ); // Same ordering whether handles are valid or not + + if ( b.valid() ) // Handles may or may not have been invalidated + sc_assert( b == c ); + else + sc_assert( b != c ); + + sc_assert( b.valid() == c.valid() ); // Invalidation is consistent + sc_assert( !(b < c) && !(c < b) ); // Two handles to the same process, whether valid or not + sc_assert( c.terminated() ); + + sc_process_handle d = a; + m[d] = 4; + + sc_assert( m.size() == 2 ); + sc_assert( m[a] == 4 ); + sc_assert( m[b] == 3 ); + sc_assert( m[c] == 3 ); + sc_assert( m[d] == 4 ); + + sc_process_handle e; + m[e] = 5; + + sc_assert( m.size() == 3 ); + sc_assert( m[a] == 4 ); + sc_assert( m[b] == 3 ); + sc_assert( m[c] == 3 ); + sc_assert( m[d] == 4 ); + sc_assert( m[e] == 5 ); + + sc_process_handle f; + m[f] = 6; + + sc_assert( m.size() == 3 ); + sc_assert( m[a] == 4 ); + sc_assert( m[b] == 3 ); + sc_assert( m[c] == 3 ); + sc_assert( m[d] == 4 ); + sc_assert( m[e] == 6 ); + sc_assert( m[f] == 6 ); + + sc_process_handle g; + m[g] = 7; + + sc_assert( m.size() == 3 ); + sc_assert( m[a] == 4 ); + sc_assert( m[b] == 3 ); + sc_assert( m[c] == 3 ); + sc_assert( m[d] == 4 ); + sc_assert( m[e] == 7 ); + sc_assert( m[f] == 7 ); + sc_assert( m[g] == 7 ); + + g = sc_spawn(sc_bind(&Top::f, this)); + m[g] = 8; + + sc_assert( m.size() == 4 ); + sc_assert( m[a] == 4 ); + sc_assert( m[b] == 3 ); + sc_assert( m[c] == 3 ); + sc_assert( m[d] == 4 ); + sc_assert( m[e] == 7 ); + sc_assert( m[f] == 7 ); + sc_assert( m[g] == 8 ); + + cout << "T1 completed" << endl; + } + + void T2() + { + sc_process_handle a, b = sc_get_current_process_handle(); + sc_assert( b.valid() ); + + a.swap( b ); + sc_assert( a == sc_get_current_process_handle() ); + sc_assert( !b.valid() ); + + cout << "T2 completed" << endl; + } + + void f() {} + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_start_bug/golden/sc_start_bug.log b/src/systemc/tests/systemc/1666-2011-compliance/sc_start_bug/golden/sc_start_bug.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_start_bug/golden/sc_start_bug.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_start_bug/sc_start_bug.cpp b/src/systemc/tests/systemc/1666-2011-compliance/sc_start_bug/sc_start_bug.cpp new file mode 100644 index 000000000..c69289e66 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_start_bug/sc_start_bug.cpp @@ -0,0 +1,79 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// sc_start_bug.cpp +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(T1); + SC_THREAD(T2); + } + + void T1() + { + sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); + wait(15, SC_NS); + sc_assert( sc_time_stamp() == sc_time(15, SC_NS) ); + sc_pause(); + } + + void T2() + { + sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); + wait(30, SC_NS); + sc_assert( sc_time_stamp() == sc_time(30, SC_NS) ); + sc_pause(); + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(10, SC_NS, SC_RUN_TO_TIME); + sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); + + sc_start(10, SC_NS, SC_RUN_TO_TIME); + sc_assert( sc_time_stamp() == sc_time(15, SC_NS) ); + + sc_start(10, SC_NS, SC_RUN_TO_TIME); + sc_assert( sc_time_stamp() == sc_time(25, SC_NS) ); + + sc_start(10, SC_NS, SC_RUN_TO_TIME); + sc_assert( sc_time_stamp() == sc_time(30, SC_NS) ); + + cout << endl << "Success" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_start_starvation/golden/sc_start_starvation.log b/src/systemc/tests/systemc/1666-2011-compliance/sc_start_starvation/golden/sc_start_starvation.log new file mode 100644 index 000000000..ae3e71658 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_start_starvation/golden/sc_start_starvation.log @@ -0,0 +1,12 @@ +SystemC Simulation + +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: <removed by verify.pl> + +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: <removed by verify.pl> + +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: <removed by verify.pl> + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_start_starvation/sc_start_starvation.cpp b/src/systemc/tests/systemc/1666-2011-compliance/sc_start_starvation/sc_start_starvation.cpp new file mode 100644 index 000000000..d279c4364 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_start_starvation/sc_start_starvation.cpp @@ -0,0 +1,151 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// sc_start_starvation.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: sc_start_starvation.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// sc_start with event starvation policy +// sc_pending_activity and friends + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> +using namespace sc_core; +using std::cout; +using std::endl; + +SC_MODULE(Top) +{ + SC_CTOR(Top) + { + SC_THREAD(T); + } + + sc_event ev2; + + void T() + { + sc_assert( sc_get_status() == SC_RUNNING ); + + sc_assert( sc_pending_activity_at_current_time() == false ); + sc_assert( sc_pending_activity_at_future_time() == true ); + sc_assert( sc_time_to_pending_activity() == sc_time(250, SC_NS) ); + + ev2.notify(150, SC_NS); + + sc_assert( sc_pending_activity_at_current_time() == false ); + sc_assert( sc_pending_activity_at_future_time() == true ); + sc_assert( sc_time_to_pending_activity() == sc_time(150, SC_NS) ); + } +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_event ev; + ev.notify(250, SC_NS); + + sc_assert( sc_pending_activity_at_current_time() == false ); + sc_assert( sc_pending_activity_at_future_time() == true ); + sc_assert( sc_pending_activity() == true ); + sc_assert( sc_time_to_pending_activity() == sc_time(250, SC_NS) ); + + sc_assert( sc_get_status() == SC_ELABORATION ); + sc_assert( sc_time_stamp() == SC_ZERO_TIME ); + sc_start(100, SC_NS); + sc_assert( sc_get_status() == SC_PAUSED ); + sc_assert( sc_time_stamp() == sc_time(100, SC_NS) ); + + sc_assert( sc_pending_activity_at_current_time() == false ); + sc_assert( sc_pending_activity_at_future_time() == true ); + sc_assert( sc_time_to_pending_activity() == sc_time(50, SC_NS) ); + + sc_start(10, SC_NS, SC_RUN_TO_TIME); + sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); + sc_assert( sc_time_to_pending_activity() == sc_time(40, SC_NS) ); + + sc_start(10, SC_NS, SC_EXIT_ON_STARVATION); + sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); + + sc_start(80, SC_NS, SC_EXIT_ON_STARVATION); + + sc_assert( sc_time_stamp() == sc_time(150, SC_NS) ); + sc_assert( sc_pending_activity_at_current_time() == false ); + sc_assert( sc_pending_activity_at_future_time() == true ); + sc_assert( sc_time_to_pending_activity() == sc_time(100, SC_NS) ); + + sc_start(50, SC_NS, SC_EXIT_ON_STARVATION); + sc_assert( sc_time_stamp() == sc_time(150, SC_NS) ); + sc_assert( sc_time_to_pending_activity() == sc_time(100, SC_NS) ); + + sc_start(50, SC_NS, SC_RUN_TO_TIME); + sc_assert( sc_time_stamp() == sc_time(200, SC_NS) ); + sc_assert( sc_time_to_pending_activity() == sc_time(50, SC_NS) ); + + sc_start(); + sc_assert( sc_get_status() == SC_PAUSED ); + sc_assert( sc_time_stamp() == sc_time(250, SC_NS) ); + + sc_assert( sc_pending_activity() == false ); + sc_assert( sc_time_to_pending_activity() == sc_max_time() - sc_time_stamp() ); + + ev.notify(SC_ZERO_TIME); + + sc_assert( sc_pending_activity_at_current_time() == true ); + sc_assert( sc_pending_activity_at_future_time() == false ); + sc_assert( sc_time_to_pending_activity() == SC_ZERO_TIME ); + + sc_start(); + sc_assert( sc_time_stamp() == sc_time(250, SC_NS) ); + + sc_assert( sc_pending_activity() == false ); + sc_assert( sc_time_to_pending_activity() == sc_max_time() - sc_time_stamp() ); + + ev.notify(10, SC_NS); + + sc_assert( sc_pending_activity() == true ); + sc_assert( sc_time_to_pending_activity() == sc_time(10, SC_NS) ); + + sc_start(); + sc_assert( sc_time_stamp() == sc_time(260, SC_NS) ); + + ev.notify(10, SC_NS); + sc_start(sc_time(100, SC_NS), SC_EXIT_ON_STARVATION); + sc_assert( sc_time_stamp() == sc_time(270, SC_NS) ); + + ev.notify(10, SC_NS); + sc_start(sc_time(100, SC_NS)); // SC_RUN_TO_TIME + sc_assert( sc_time_stamp() == sc_time(370, SC_NS) ); + sc_assert( sc_get_status() == SC_PAUSED ); + + ev.notify(); + sc_assert( sc_pending_activity() == false ); + + cout << endl << "Success" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_vector/golden/sc_vector.log b/src/systemc/tests/systemc/1666-2011-compliance/sc_vector/golden/sc_vector.log new file mode 100644 index 000000000..c2d510c75 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_vector/golden/sc_vector.log @@ -0,0 +1,40 @@ +SystemC Simulation +Called method() in top.m1.target_vec_0 at 10 ns +Called method() in top.m1.target_vec_1 at 10 ns +Called method() in top.m3.targets_0 at 10 ns +Called method() in top.m1.target_vec_3 at 10 ns +Called method() in top.m3.target_vec_2 at 10 ns +Called method() in top.m3.target_vec_1 at 10 ns +Called method() in top.m3.target_vec_0 at 10 ns +Called method() in top.m2.targets_0 at 10 ns +Called method() in top.m2.target_vec_3 at 10 ns +Called method() in top.m2.target_vec_2 at 10 ns +Called method() in top.m2.target_vec_1 at 10 ns +Called method() in top.m2.target_vec_0 at 10 ns +Called method() in top.m1.targets_0 at 10 ns +Called method() in top.m3.target_vec_3 at 10 ns +Called method() in top.m1.target_vec_2 at 10 ns +Called method() in top.m1.targets_1 at 20 ns +Called method() in top.m2.targets_1 at 20 ns +Called method() in top.m3.targets_1 at 20 ns +Top:0100 +Called method() in top.m3.targets_2 at 30 ns +Called method() in top.m2.targets_2 at 30 ns +Called method() in top.m1.targets_2 at 30 ns +Top:0120 +Called method() in top.m1.targets_3 at 40 ns +Called method() in top.m2.targets_3 at 40 ns +Called method() in top.m3.targets_3 at 40 ns +Top:0123 +Top:4123 +Top:4523 +Top:4563 +Top:4567 +Top:8567 +Top:8967 +vec_obj[0].name() = top.T2.vec_obj_0 +vec_obj[1].name() = top.T2.vec_obj_1 +vec_obj[2].name() = top.T2.vec_obj_2 +vec_obj[3].name() = top.T2.vec_obj_3 + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_vector/sc_vector.cpp b/src/systemc/tests/systemc/1666-2011-compliance/sc_vector/sc_vector.cpp new file mode 100644 index 000000000..21628e93d --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_vector/sc_vector.cpp @@ -0,0 +1,380 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// sc_vector.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: sc_vector.cpp,v $ +// Revision 1.3 2011/07/24 16:04:12 acg +// Philipp A. Hartmann: remove assert() that does not test the correct thing. +// +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// sc_vector + +#define SC_INCLUDE_DYNAMIC_PROCESSES +#include <systemc> +#include <cstring> + +using namespace sc_core; +using std::cout; +using std::endl; +using std::string; + +struct Sub: sc_module +{ + sc_inout<int> p; + + Sub(sc_module_name) + { + SC_THREAD(T); + } + + void T() + { + for (;;) + { + wait(p.default_event()); + } + } + + SC_HAS_PROCESS(Sub); +}; + + +struct my_module: sc_module +{ + my_module(sc_module_name n, string weird_arg ) + { + sc_assert( weird_arg == "The Creator" || weird_arg == "WeIrD_aRg" ); + } +}; + + +struct my_object: sc_object +{ + my_object() : sc_object() {} + my_object(const char* c) : sc_object(c) {} +}; + + +struct i_f: virtual sc_interface +{ + virtual void method() = 0; +}; + + +struct Initiator: sc_module +{ + sc_vector<sc_port<i_f> > ports; + + Initiator(sc_module_name) + : ports("ports", 4) + { + SC_THREAD(T); + } + + void T() + { + for (unsigned int i = 0; i < ports.size(); i++) // Use method size() with vector + { + wait(10, SC_NS); + ports[i]->method(); // Use operator[] with vector + } + } + SC_HAS_PROCESS(Initiator); +}; + + +struct Initiator1: sc_module +{ + sc_port<i_f> port; + + Initiator1(sc_module_name) + : port("port") + { + SC_THREAD(T); + } + + void T() + { + wait(10, SC_NS); + port->method(); + } + SC_HAS_PROCESS(Initiator1); +}; + + +struct Target: public sc_module, private i_f +{ + sc_export<i_f> xp; + + Target(sc_module_name) + : xp("xp") + { + xp.bind( *this ); + } + + virtual void method() { + cout << "Called method() in " << name() << " at " << sc_time_stamp() << endl; + } +}; + + +typedef sc_vector<sc_inout<int> > port_type; + +struct M: sc_module +{ + port_type ports; // Vector-of-ports + + sc_vector<Sub> kids; // Vector-of-modules, each with a port p + sc_vector<Sub> kids2; + sc_vector<sc_signal<int> > sigs2; + sc_vector<sc_signal<int> > sigs3; + + int dim; + + Initiator* initiator; + sc_vector<Target> targets; + + sc_vector<Initiator1> initiator_vec; + sc_vector<Target> target_vec; + + + sc_vector<my_module> my_vec_of_modules; + + struct my_module_creator + { + my_module_creator( string arg ) : weird_arg(arg) {} + + my_module* operator() (const char* name, size_t) + { + return new my_module(name, weird_arg ); + } + string weird_arg; + }; + + sc_vector<my_module> my_vec_of_modules2; + + // If creator is not a function object, it could be a function + my_module* my_module_creator_func( const char* name, size_t i ) + { + creator_func_called = true; + return new my_module( name, "WeIrD_aRg" ); + } + + bool creator_func_called; + + + M(sc_module_name _name, int N) + : ports("ports", N) + , kids("kids") // Construct the vector with name seed "kids" + , kids2("kids2", 8) + , sigs2("sigs2", 4) + , sigs3("sigs3", 4) + , dim(N) + , targets("targets", N) + , initiator_vec("initiator_vec", N) + , target_vec("target_vec", N) + , my_vec_of_modules("my_vec_of_modules") + , creator_func_called(false) + { + //vec.init(N); // Alternative initialization (instead of passing N to ctor) + kids.init(N); + + sc_assert( ports.size() == static_cast<unsigned int>(N) ); + sc_assert( kids.size() == static_cast<unsigned int>(N) ); + + // Using vector view to create vector-of-ports + sc_assemble_vector(kids, &Sub::p).bind( ports ); + + for (unsigned int i = 0; i < kids.size(); i++) + { + sc_assert( kids[i].p.get_interface() == ports[i].get_interface() ); + } + + initiator = new Initiator("initiator"); + + // Using vector view to create vector-of-exports + initiator->ports.bind( sc_assemble_vector(targets, &Target::xp) ); + + // Double whammy + sc_assemble_vector(initiator_vec, &Initiator1::port).bind( sc_assemble_vector(target_vec, &Target::xp) ); + + // sc_vector_view has no public constructors, though it is copyable + sc_vector_assembly< Initiator1, sc_port<i_f> > assembly = sc_assemble_vector(initiator_vec, &Initiator1::port); + + sc_assert( &*(assembly.begin()) == &(*initiator_vec.begin()).port ); + // sc_assert( &*(assembly.end()) == &(*initiator_vec.end()).port ); + sc_assert( assembly.size() == initiator_vec.size() ); + for (unsigned int i = 0; i < assembly.size(); i++) + { + sc_assert( &assembly[i] == &initiator_vec[i].port ); + sc_assert( &assembly.at(i) == &initiator_vec[i].port ); + } + + std::vector<sc_object*> elements; + + // sc_vector_view (aka sc_vector_assembly) acts as a proxy for sc_vector + // It has begin() end() size() operator[] bind() etc + + elements = assembly.get_elements(); + for ( unsigned i = 0; i < elements.size(); i++ ) + if ( elements[i] ) + sc_assert( elements[i] == &initiator_vec[i].port ); + + elements = ports.get_elements(); + for ( unsigned i = 0; i < elements.size(); i++ ) + if ( elements[i] ) + sc_assert( elements[i] == &ports[i] ); + + elements = sc_assemble_vector(initiator_vec, &Initiator1::port).get_elements(); + for ( unsigned i = 0; i < elements.size(); i++ ) + if ( elements[i] ) + sc_assert( elements[i] == &initiator_vec[i].port ); + + // Additional method to support a vector iterator as an offset + sc_assemble_vector(kids2, &Sub::p).bind( sigs2.begin(), sigs2.end(), kids2.begin()); + sc_assemble_vector(kids2, &Sub::p).bind( sigs3.begin(), sigs3.end(), kids2.begin() + 4 ); + + // Construct elements of sc_vector, passing through ctor arguments to user-defined sc_module + my_vec_of_modules.init(N, my_module_creator("The Creator")); + + // Alternatively, instead of a function object pass in a function + my_vec_of_modules2.init(N, sc_bind( &M::my_module_creator_func, this, sc_unnamed::_1, sc_unnamed::_2 ) ); + + // Well-formedness check on creator function call + my_module_creator foo("The Creator"); + const char* nm = "foo"; + unsigned int idx = 0; + my_module* next = foo( (const char*)nm, (sc_vector<my_module>::size_type)idx ); + char buf[80]; + strcpy(buf, this->name()); + strcat(buf, ".foo"); + sc_assert( strcmp(next->name(), buf) == 0 ); + delete next; + + SC_THREAD(T); + } + + void T() + { + int j = 0; + for (int i = 0; i < 10; i++) + { + wait(10, SC_NS); + ports[i % dim].write((j++) % 10); // Use operator[] with vector + } + } + + SC_HAS_PROCESS(M); +}; + +struct Top: sc_module +{ + sc_vector<sc_signal<int> > sigs; // Vector-of-signals + sc_vector<sc_signal<int> > more_sigs; // Vector-of-signals + sc_vector<sc_signal<int> > hi_sigs; // Vector-of-signals + sc_vector<sc_signal<int> > lo_sigs; // Vector-of-signals + + M *m1, *m2, *m3; + + Top(sc_module_name _name) + : sigs("sigs", 4) + , more_sigs("more_sigs", 4) + , hi_sigs("hi_sigs", 2) + , lo_sigs("lo_sigs", 2) + { + m1 = new M("m1", 4); + m2 = new M("m2", 4); + m3 = new M("m3", 4); + + for (int i = 0; i < 4; i++) + m1->ports[i].bind( sigs[i] ); // Using operator[] with a vector + + port_type::iterator it = m2->ports.bind( more_sigs ); // Vector-to-vector bind + sc_assert( (it - m2->ports.begin()) == 4 ); + + // Bind upper half of ports vector to hi_sigs + it = m3->ports.bind( hi_sigs.begin(), hi_sigs.end() ); + sc_assert( (it - m3->ports.begin()) == 2 ); + + // Bind lower half of ports vector to lo_sigs + it = m3->ports.bind( lo_sigs.begin(), lo_sigs.end(), it); + sc_assert( (it - m3->ports.begin()) == 4 ); + + SC_THREAD(T); + SC_THREAD(T2); + } + + void T() + { + sc_event_or_list list; + for (int i = 0; i < 4; i++) + list |= sigs[i].default_event(); + for (;;) + { + wait(list); + cout << "Top:" << sigs[0] << sigs[1] << sigs[2] << sigs[3] << endl; + } + } + + + void T2() + { + wait(10, SC_US); + + // Create sc_vector during simulation + sc_vector<my_object> vec_obj("vec_obj", 4); + sc_assert( vec_obj.size() == 4 ); + for (unsigned int i = 0; i < vec_obj.size(); i++) + cout << "vec_obj[" << i << "].name() = " << vec_obj[i].name() << endl; + + sc_object* proc = sc_get_current_process_handle().get_process_object(); + std::vector<sc_object*> children = proc->get_child_objects(); + + sc_assert( children.size() == 5 ); // sc_vector itself + 4 X my_object + } + + SC_HAS_PROCESS(Top); +}; + + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + std::vector<sc_object*> children = top.get_child_objects(); + sc_assert( children.size() == 21 ); // sc_vectors themselves are sc_objects + + sc_start(); + + sc_assert( top.m1->creator_func_called ); + sc_assert( top.m2->creator_func_called ); + sc_assert( top.m3->creator_func_called ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_verbosity/golden/sc_verbosity.log b/src/systemc/tests/systemc/1666-2011-compliance/sc_verbosity/golden/sc_verbosity.log new file mode 100644 index 000000000..45b0a71ce --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_verbosity/golden/sc_verbosity.log @@ -0,0 +1,51 @@ +SystemC Simulation + +Info: DEFAULT: verbosity=SC_NONE + +Info: DEFAULT: verbosity=SC_LOW + +Info: DEFAULT: verbosity=SC_MEDIUM + +Info: SC_NONE: verbosity=SC_NONE + +Info: SC_MEDIUM: verbosity=SC_NONE + +Info: SC_MEDIUM: verbosity=SC_LOW + +Info: SC_MEDIUM: verbosity=SC_MEDIUM + +Info: SC_FULL: verbosity=SC_NONE + +Info: SC_FULL: verbosity=SC_LOW + +Info: SC_FULL: verbosity=SC_MEDIUM + +Info: SC_FULL: verbosity=SC_HIGH + +Info: SC_FULL: verbosity=SC_FULL + +Info: SC_LOW: verbosity=SC_NONE + +Info: SC_LOW: verbosity=SC_LOW + +Info: SC_HIGH: verbosity=SC_NONE + +Info: SC_HIGH: verbosity=SC_LOW + +Info: SC_HIGH: verbosity=SC_MEDIUM + +Info: SC_HIGH: verbosity=SC_HIGH + +Info: SC_DEBUG: verbosity=SC_NONE + +Info: SC_DEBUG: verbosity=SC_LOW + +Info: SC_DEBUG: verbosity=SC_MEDIUM + +Info: SC_DEBUG: verbosity=SC_HIGH + +Info: SC_DEBUG: verbosity=SC_FULL + +Info: SC_DEBUG: verbosity=SC_DEBUG + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_verbosity/sc_verbosity.cpp b/src/systemc/tests/systemc/1666-2011-compliance/sc_verbosity/sc_verbosity.cpp new file mode 100644 index 000000000..dfb7633d5 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_verbosity/sc_verbosity.cpp @@ -0,0 +1,109 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// sc_verbosity.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: sc_verbosity.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Verbosity level + +#include <systemc> +using namespace sc_core; +using std::cout; +using std::endl; + + +void report_with_verbosity(const char* msg_type) +{ + SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_NONE", SC_NONE); + SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_LOW", SC_LOW); + SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_MEDIUM", SC_MEDIUM); + SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_HIGH", SC_HIGH); + SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_FULL", SC_FULL); + SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_DEBUG", SC_DEBUG); +} + + +SC_MODULE(Top) +{ + SC_CTOR(Top) + { + report_with_verbosity("DEFAULT"); + + sc_report_handler::set_verbosity_level( SC_NONE ); + report_with_verbosity("SC_NONE"); + sc_assert( sc_report_handler::get_verbosity_level() == 0 ); + + sc_report_handler::set_verbosity_level( SC_MEDIUM ); + report_with_verbosity("SC_MEDIUM"); + sc_assert( sc_report_handler::get_verbosity_level() == 200 ); + + sc_report_handler::set_verbosity_level( SC_FULL ); + report_with_verbosity("SC_FULL"); + sc_assert( sc_report_handler::get_verbosity_level() == 400 ); + + SC_THREAD(T); + + f = 0; + } + + int f; + + void T() + { + sc_report_handler::set_verbosity_level( SC_LOW ); + report_with_verbosity("SC_LOW"); + sc_assert( sc_report_handler::get_verbosity_level() == 100 ); + + sc_report_handler::set_verbosity_level( SC_HIGH ); + report_with_verbosity("SC_HIGH"); + sc_assert( sc_report_handler::get_verbosity_level() == 300 ); + + sc_report_handler::set_verbosity_level( SC_DEBUG ); + report_with_verbosity("SC_DEBUG"); + sc_assert( sc_report_handler::get_verbosity_level() == 500 ); + + try { + SC_REPORT_ERROR("msg_type", "msg"); + } + catch (const sc_report& e) { + sc_assert( e.get_verbosity() == SC_MEDIUM ); + f = 1; + } + } + +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + sc_start(); + + sc_assert( top.f ); + + cout << endl << "Success" << endl; + return 0; +} diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_writer_policy/golden/sc_writer_policy.log b/src/systemc/tests/systemc/1666-2011-compliance/sc_writer_policy/golden/sc_writer_policy.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_writer_policy/golden/sc_writer_policy.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sc_writer_policy/sc_writer_policy.cpp b/src/systemc/tests/systemc/1666-2011-compliance/sc_writer_policy/sc_writer_policy.cpp new file mode 100644 index 000000000..fccd8fa60 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sc_writer_policy/sc_writer_policy.cpp @@ -0,0 +1,321 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// sc_writer_policy.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: sc_writer_policy.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// sc_writer_policy template argument of class sc_signal + +#define SC_INCLUDE_DYNAMIC_PROCESSES +#include <systemc> + +using namespace sc_core; +using namespace sc_dt; +using std::cout; +using std::endl; +using std::string; + + +struct M: sc_module +{ + sc_inout<bool> port; + + sc_time delay; + sc_signal<int> one_sig; + sc_signal<int, SC_MANY_WRITERS> many_sig; + + bool first_run; + int g0, g1, g2, g3; + + M(sc_module_name _name, sc_time _delay) + : port("port") + , delay(_delay) + , first_run(true) + { + sc_assert( one_sig.get_writer_policy() == SC_ONE_WRITER ); + sc_assert( many_sig.get_writer_policy() == SC_MANY_WRITERS ); + + SC_THREAD(T); + SC_METHOD(method_process_1); + SC_METHOD(method_process_2); + + one_sig.write(-1); + many_sig.write(-1); + + g0 = g1 = g2 = g3 = 0; + } + + void end_of_elaboration() + { + sc_assert( port->get_writer_policy() == SC_MANY_WRITERS ); + one_sig.write(1); + many_sig.write(1); + g0 = 1; + } + + void start_of_simulation() + { + one_sig.write(2); + many_sig.write(2); + g1 = 1; + } + + void T() + { + wait(delay); + port.write(true); + g2 = 1; + } + + void method_process_1() + { + one_sig.write(3); + many_sig.write(3); + } + + void method_process_2() + { + if (first_run) + { + first_run = false; + next_trigger(SC_ZERO_TIME); + } + else + { + try { + one_sig = 4; + } + catch (const std::exception& e) { + g3 = 1; + } + many_sig.write(4); + } + } + + SC_HAS_PROCESS(M); +}; + +struct Top: sc_module +{ + M *m1; + M *m2; + + sc_signal<bool,SC_MANY_WRITERS> many_sig_1; + sc_signal<int,SC_MANY_WRITERS> many_sig_2; + sc_signal<int,SC_ONE_WRITER> one_sig_1; + sc_signal<int> one_sig_2; + + sc_buffer<sc_logic, SC_MANY_WRITERS> buffy; + + sc_signal_resolved resolved; + sc_signal_rv<2> rv; + + Top(sc_module_name _name) + : many_sig_1("many_sig_1") + , many_sig_2("many_sig_2") + , one_sig_1("one_sig_1") + , buffy("buffy") + , resolved("resolved") + , rv("rv") + { + m1 = new M("m1", sc_time(1, SC_PS)); + m2 = new M("m2", sc_time(2, SC_PS)); + + m1->port.bind(many_sig_1); + m2->port.bind(many_sig_1); + + SC_THREAD(T1); + SC_THREAD(T2); + sc_spawn(sc_bind(&Top::T3, this)); + + sc_assert( many_sig_1.get_writer_policy() == SC_MANY_WRITERS ); + sc_assert( many_sig_2.get_writer_policy() == SC_MANY_WRITERS ); + sc_assert( one_sig_1 .get_writer_policy() == SC_ONE_WRITER ); + sc_assert( one_sig_2 .get_writer_policy() == SC_ONE_WRITER ); + sc_assert( buffy .get_writer_policy() == SC_MANY_WRITERS ); + sc_assert( resolved .get_writer_policy() == SC_MANY_WRITERS ); + sc_assert( rv .get_writer_policy() == SC_MANY_WRITERS ); + + one_sig_1 = 0; + buffy = SC_LOGIC_X; + resolved = SC_LOGIC_Z; + rv = sc_lv<2>("ZZ"); + + // Writes outside of a process should not count as manyple writers + many_sig_1.write(true); + many_sig_2.write(0); + one_sig_1.write(0); + one_sig_2.write(0); + buffy.write(SC_LOGIC_0); + + f0 = f1 = f2 = f3 = f4 = f5 = 0; + + } + + int f0, f1, f2, f3, f4, f5; + + void T1() + { + resolved = SC_LOGIC_0; + rv = sc_lv<2>("01"); + + // Attempt to write SC_ONE_WRITER signal from >1 process should fail + try { + one_sig_1 = 1; + } + catch (const std::exception& e) { + f3 = 1; + } + + try { + one_sig_2 = 1; + } + catch (const std::exception& e) { + f4 = 1; + } + wait(1, SC_PS); + + // Attempt to write SC_MANY_WRITER signal from >1 process IN SAME DELTA should fail + try { + many_sig_2.write(3); + } + catch (const std::exception& e) { + f5 = 1; + } + wait(3, SC_PS); + + many_sig_2.write(6); + buffy = SC_LOGIC_0; + + wait(many_sig_2.default_event()); + f0 = 1; + } + + void T2() + { + resolved = SC_LOGIC_1; + rv = sc_lv<2>("10"); + + try { + one_sig_1 = 2; + } + catch (const std::exception& e) { + f3 = 1; + } + + try { + one_sig_2 = 2; + } + catch (const std::exception& e) { + f4 = 1; + } + wait(1, SC_PS); + + try { + many_sig_2.write(4); + } + catch (const std::exception& e) { + f5 = 1; + } + wait(4, SC_PS); + + many_sig_2.write(7); + buffy = SC_LOGIC_1; + + wait(many_sig_2.default_event()); + f1 = 1; + } + + void T3() + { + resolved = SC_LOGIC_Z; + rv = sc_lv<2>("ZZ"); + + try { + one_sig_1 = 3; + } + catch (const std::exception& e) { + f3 = 1; + } + + try { + one_sig_2 = 3; + } + catch (const std::exception& e) { + f4 = 1; + } + wait(1, SC_PS); + + try { + many_sig_2.write(5); + } + catch (const std::exception& e) { + f5 = 1; + } + wait(5, SC_PS); + + many_sig_2.write(8); + buffy = SC_LOGIC_0; + + wait(many_sig_2.default_event()); + f2 = 1; + + sc_assert( resolved.read() == SC_LOGIC_X ); + sc_assert( rv.read() == sc_lv<2>("XX") ); + sc_assert( many_sig_2.read() == 8 ); + sc_assert( buffy.read() == SC_LOGIC_0 ); + } + + SC_HAS_PROCESS(Top); +}; + + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + sc_start(); + + sc_assert( top.f0 ); + sc_assert( top.f1 ); + sc_assert( top.f2 ); + sc_assert( top.f3 ); + sc_assert( top.f4 ); + sc_assert( top.f5 ); + + sc_assert( top.m1->g0 ); + sc_assert( top.m2->g0 ); + sc_assert( top.m1->g1 ); + sc_assert( top.m2->g1 ); + sc_assert( top.m1->g2 ); + sc_assert( top.m2->g2 ); + sc_assert( top.m1->g3 ); + sc_assert( top.m2->g3 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/self_reset_bug/golden/self_reset_bug.log b/src/systemc/tests/systemc/1666-2011-compliance/self_reset_bug/golden/self_reset_bug.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/self_reset_bug/golden/self_reset_bug.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/self_reset_bug/self_reset_bug.cpp b/src/systemc/tests/systemc/1666-2011-compliance/self_reset_bug/self_reset_bug.cpp new file mode 100644 index 000000000..a56a140b9 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/self_reset_bug/self_reset_bug.cpp @@ -0,0 +1,98 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// self_reset_bug.cpp -- test for +// +// Original Author: John Aynsley, Doulus +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// + +// + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_METHOD(target); + target_handle = sc_get_current_process_handle(); + + count = 0; + f0 = f1 = f2 = f3 = 0; + } + + sc_process_handle target_handle; + int count; + int f0, f1, f2, f3; + + void target() + { + switch (count) + { + case 0: + f0 = 1; + count = 1; + next_trigger(10, SC_NS); + break; + + case 1: + f1 = 1; + count = 2; + target_handle.reset(); + break; + + case 2: + f2 = 1; + count = 3; + target_handle.reset(); + break; + + case 3: + f3 = 1; + count = 4; + break; + } + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f0 ); + sc_assert( top.f1 ); + sc_assert( top.f2 ); + sc_assert( top.f3 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/golden/stepwise_simulation.log b/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/golden/stepwise_simulation.log new file mode 100644 index 000000000..e16fcee9d --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/golden/stepwise_simulation.log @@ -0,0 +1,42 @@ +SystemC Simulation + ----- running for delta + -- stopped at - 0 s - delta: 0 + ----- running for 10 ns + --- No-op start (warning) - +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: <removed by verify.pl> + -- stopped at - 10 ns - delta: 0 + ----- running for delta +`echo.do_print' triggered at 10 ns - delta: 0 + -- stopped at - 10 ns - delta: 1 + ----- running for 5 ns + --- No-op start (warning) - +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: <removed by verify.pl> + -- stopped at - 15 ns - delta: 1 + ----- running for delta +`echo.do_print' triggered at 15 ns - delta: 1 + -- stopped at - 15 ns - delta: 2 + ----- running for delta +`echo.do_print' triggered at 15 ns - delta: 2 + -- stopped at - 15 ns - delta: 3 + ----- running for 5 ns + --- No-op start (warning) - +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: <removed by verify.pl> + -- stopped at - 20 ns - delta: 3 + ----- running for delta +`echo.do_print' triggered at 20 ns - delta: 3 + -- stopped at - 20 ns - delta: 4 + ----- running for 5 ns + --- No-op start (warning) - +Warning: (W571) no activity or clock movement for sc_start() invocation +In file: <removed by verify.pl> + -- stopped at - 25 ns - delta: 4 + ----- running for delta +`echo.do_print' triggered at 25 ns - delta: 4 + -- stopped at - 25 ns - delta: 5 + ----- running for delta +`echo.do_print' triggered at 25 ns - delta: 5 + -- stopped at - 25 ns - delta: 6 +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/stepwise_simulation.cpp b/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/stepwise_simulation.cpp new file mode 100644 index 000000000..4a480e352 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/stepwise_simulation/stepwise_simulation.cpp @@ -0,0 +1,165 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +/***************************************************************************** + + stepwise_simulation.cpp -- Test step-wise simulation + + Original Author: Philipp A. Hartmann, OFFIS, 2011-01-21 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +#include <systemc.h> + +const int num_events = 2; +const sc_time delay( 10, SC_NS ); + +//#define EXPLICIT_DELTA // should not modify the trace +#define DELAYED_EVENTS + +SC_MODULE(echo) +{ + sc_event ev[num_events]; + SC_CTOR(echo) + : self_trigger(3) + { + SC_METHOD(do_print); +# ifdef DELAYED_EVENTS + dont_initialize(); +# endif + for( int i=0; i<num_events; ++i ) + sensitive << ev[i]; + } + + void do_print() + { + std::cout << "`" << sc_get_current_process_handle().name() + << "' triggered at " << sc_time_stamp() + << " - delta: " << sc_delta_count() + << std::endl; + + if( --self_trigger > 1 ) + next_trigger( delay/2 ); + else if( self_trigger == 1 ) + next_trigger( SC_ZERO_TIME ); + else + self_trigger = 3; + + } + int self_trigger; +}; + +void do_step( sc_time const & step ) +{ + sc_dt::uint64 delta = sc_delta_count(); + static bool start_delta = ( delta == 0 ) && ( step == SC_ZERO_TIME ); + std::cout + << " ----- running for " + << ( ( step == SC_ZERO_TIME ) ? "delta" : step.to_string() ) + << std::endl; + + sc_time start = sc_time_stamp(); + if( step > SC_ZERO_TIME ) + { + std::cout << " --- No-op start (warning) - "; + sc_start( step / 2, SC_EXIT_ON_STARVATION ); + sc_assert( start == sc_time_stamp() ); + + sc_start( step / 2, SC_RUN_TO_TIME ); + sc_assert( start + step / 2 == sc_time_stamp() ); + + sc_start( step / 2 ); // complete step + } + else + { + sc_start( SC_ZERO_TIME ); + } + sc_assert( start + step == sc_time_stamp() ); + + std::cout + << " -- stopped at - " + << sc_time_stamp() << " - delta: " << sc_delta_count() + << std::endl; + + // delta has only increased, when a delta has been run + sc_assert( sc_delta_count() + == delta + ( !start_delta && step == SC_ZERO_TIME ) ); + start_delta = false; +} + +int sc_main(int, char*[]) +{ + sc_assert( !sc_pending_activity() ); + sc_assert( sc_time_to_pending_activity() + == sc_max_time() - sc_time_stamp() ); + + sc_signal<bool> toggle("toggle"); + echo dut("echo"); + + // notify future events + for( int i=0; i<num_events; ++i ) + dut.ev[i].notify( (i+1) * delay ); + + sc_assert( sc_pending_activity_at_future_time() ); + sc_assert( sc_time_to_pending_activity() == delay ); + + do_step( SC_ZERO_TIME ); // elaborate + + while( sc_pending_activity() ) + { + sc_assert( sc_pending_activity_at_current_time() + || sc_time_to_pending_activity() > SC_ZERO_TIME ); + + sc_assert( sc_pending_activity_at_future_time() + || sc_time_to_pending_activity() == SC_ZERO_TIME ); + + // run single (time) step + do_step( sc_time_to_pending_activity() ); + +# ifdef EXPLICIT_DELTA + // run remaining current deltas (optional) + while( sc_pending_activity_at_current_time() ) { + sc_assert( sc_time_to_pending_activity() == SC_ZERO_TIME ); + do_step( SC_ZERO_TIME ); + } +# endif // EXPLICIT_DELTA + } + + // force one empty evaluate (w/ non-empty update) + toggle.write( !toggle.read() ); + sc_assert( sc_pending_activity_at_current_time() ); + sc_start( SC_ZERO_TIME ); + + sc_assert( !sc_pending_activity() ); + sc_assert( sc_time_to_pending_activity() + == sc_max_time() - sc_time_stamp() ); + + std::cout << "Success" << std::endl; + return 0; +} diff --git a/src/systemc/tests/systemc/1666-2011-compliance/suspend_resume/golden/suspend_resume.log b/src/systemc/tests/systemc/1666-2011-compliance/suspend_resume/golden/suspend_resume.log new file mode 100644 index 000000000..5e04aadb4 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/suspend_resume/golden/suspend_resume.log @@ -0,0 +1,9 @@ +SystemC Simulation +Target awoke at 10 ns +Target awoke at 25 ns +Target awoke at 30 ns +Target awoke at 50 ns + +Info: /OSCI/SystemC: Simulation stopped by user. + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/suspend_resume/suspend_resume.cpp b/src/systemc/tests/systemc/1666-2011-compliance/suspend_resume/suspend_resume.cpp new file mode 100644 index 000000000..5f03444fd --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/suspend_resume/suspend_resume.cpp @@ -0,0 +1,110 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// suspend_resume.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: suspend_resume.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct M1: sc_module +{ + M1(sc_module_name _name) + { + SC_THREAD(ticker); + SC_THREAD(calling); + SC_THREAD(target); + t = sc_get_current_process_handle(); + } + + sc_process_handle t; + sc_event ev; + + void ticker() + { + for (;;) + { + wait(10, SC_NS); + ev.notify(); + } + } + + void calling() + { + wait(15, SC_NS); + // Target runs at time 10 NS due to notification + + t.suspend(); + wait(10, SC_NS); + // Target does not run at time 20 NS while suspended + + t.resume(); + // Target runs at time 25 NS when resume is called + + wait(10, SC_NS); + // Target runs at time 30 NS due to notification + + t.disable(); + wait(10, SC_NS); + // Target does not run at time 40 NS while disabled + + t.enable(); + // Target does not run at time 45 NS when enable is called + + wait(10, SC_NS); + // Target runs at time 50 NS due to notification + + sc_stop(); + } + + void target() + { + for (;;) + { + wait(ev); + cout << "Target awoke at " << sc_time_stamp() << endl; + } + } + + SC_HAS_PROCESS(M1); +}; + +int sc_main(int argc, char* argv[]) +{ + M1 m("m"); + + sc_start(); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sync_reset/golden/sync_reset.log b/src/systemc/tests/systemc/1666-2011-compliance/sync_reset/golden/sync_reset.log new file mode 100644 index 000000000..cdf4578d6 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sync_reset/golden/sync_reset.log @@ -0,0 +1,5 @@ +SystemC Simulation + +Info: /OSCI/SystemC: Simulation stopped by user. + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/sync_reset/sync_reset.cpp b/src/systemc/tests/systemc/1666-2011-compliance/sync_reset/sync_reset.cpp new file mode 100644 index 000000000..4cbcc6030 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/sync_reset/sync_reset.cpp @@ -0,0 +1,425 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// sync_reset.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: sync_reset.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// sync_reset_on/off + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct M2: sc_module +{ + M2(sc_module_name _name) + { + SC_THREAD(ticker); + SC_THREAD(calling); + SC_THREAD(target1); + t1 = sc_get_current_process_handle(); + + sc_spawn_options opt; + opt.spawn_method(); + opt.dont_initialize(); + opt.set_sensitivity( &t1.reset_event() ); + sc_spawn(sc_bind( &M2::reset_handler, this ), "reset_handler", &opt); + + SC_THREAD(target2); + t2 = sc_get_current_process_handle(); + + SC_METHOD(target3); + sensitive << ev; + t3 = sc_get_current_process_handle(); + + count = 1; + f0 = f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0; + f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0; + f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0; + f30 = f31 = f32 = f33 = f34 = f35 = f36 = f37 = f38 = f39 = 0; + f40 = f41 = f42 = f43 = f44 = f45 = f46 = f47 = f48 = f49 = 0; + } + + sc_process_handle t1, t2, t3; + sc_event ev; + int count; + + int f0, f1, f2, f3, f4, f5, f6, f7, f8, f9; + int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19; + int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29; + int f30, f31, f32, f33, f34, f35, f36, f37, f38, f39; + int f40, f41, f42, f43, f44, f45, f46, f47, f48, f49; + + void ticker() + { + for (;;) + { + wait(10, SC_NS); + sc_assert( !sc_is_unwinding() ); + ev.notify(); + } + } + + void calling() + { + count = 1; + wait(15, SC_NS); + // Target runs at 10 NS + + count = 2; + t1.sync_reset_on(); + // Target does not run at 15 NS + + wait(10, SC_NS); + // Target is reset at 20 NS + + count = 3; + wait(10, SC_NS); + // Target is reset again at 30 NS + + count = 4; + t1.sync_reset_off(); + // Target does not run at 35 NS + + wait(10, SC_NS); + // Target runs at 40 NS + + count = 5; + t1.sync_reset_off(); + // Double sync_reset_off + + wait(10, SC_NS); + // Target runs at 50 NS + + count = 6; + t1.sync_reset_on(); + t1.disable(); + wait(10, SC_NS); + // Target does not run at 60 NS + + count = 7; + t1.enable(); + // Target does not run at 65 NS + wait(10, SC_NS); + // Target reset at 70 NS + + count = 8; + t1.disable(); + wait(10, SC_NS); + // Target does not run at 80 NS + + count = 9; + t1.sync_reset_off(); + wait(10, SC_NS); + // Target still disabled at 90 NS + + count = 10; + t1.enable(); + wait(10, SC_NS); + // Target runs at 100 NS + + count = 11; + t1.suspend(); + wait(10, SC_NS); + // Target does not run at 110 NS + + count = 12; + wait(10, SC_NS); + // Target still suspended at 120 NS + + count = 13; + t1.resume(); + // Target runs at 125 NS + wait(1, SC_NS); + + count = 14; + wait(9, SC_NS); + // Target runs again at 130 NS + + count = 15; + t1.sync_reset_on(); + // Double sync_reset_on + wait(10, SC_NS); + // Target reset at 140 NS + + count = 16; + t1.sync_reset_off(); + wait(10, SC_NS); + // Target runs at 150 NS + + count = 17; + t1.sync_reset_off(); + wait(10, SC_NS); + // Target runs at 160 NS + + count = 18; + t1.sync_reset_on(); + wait(10, SC_NS); + // Target reset at 170 NS + + count = 19; + t1.reset(); + // Target reset at 175 NS + wait(SC_ZERO_TIME); + + count = 20; + wait(1, SC_NS); + t1.reset(); + // Target reset at 176 NS + + count = 21; + t1.reset(); + // Target reset at 176 NS + wait(1, SC_NS); + + count = 22; + wait(8, SC_NS); + // Target reset at 180 NS + + count = 23; + wait(10, SC_NS); + // Target reset at 190 NS + + count = 24; + t1.sync_reset_off(); + wait(10, SC_NS); + // Target runs at 200 NS + + count = 25; + wait(10, SC_NS); + // Target runs at 210 NS + + count = 26; + t1.reset(); + wait(SC_ZERO_TIME); + // Target reset at 215 + + t1.disable(); // Close it down + wait(sc_time(300, SC_NS) - sc_time_stamp()); + + count = 27; + t2.resume(); + wait(SC_ZERO_TIME); + + count = 28; + wait(15, SC_NS); + + count = 29; + t2.sync_reset_on(); + wait(10, SC_NS); + + t2.sync_reset_off(); + t2.suspend(); + wait(sc_time(405, SC_NS) - sc_time_stamp()); + + count = 30; + t3.resume(); + wait(SC_ZERO_TIME); + + count = 31; + wait(10, SC_NS); + + count = 32; + t3.sync_reset_on(); + wait(10, SC_NS); + + sc_stop(); + } + + void target1() + { + //cout << "Target1 called/reset at " << sc_time_stamp() << " count = " << count << endl; + switch (count) + { + case 1: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); f0=1; break; + case 2: sc_assert( sc_time_stamp() == sc_time(20, SC_NS) ); f1=1; break; + case 3: sc_assert( sc_time_stamp() == sc_time(30, SC_NS) ); f2=1; break; + case 7: sc_assert( sc_time_stamp() == sc_time(70, SC_NS) ); f3=1; break; + case 15: sc_assert( sc_time_stamp() == sc_time(140, SC_NS) ); f4=1; break; + case 18: sc_assert( sc_time_stamp() == sc_time(170, SC_NS) ); f5=1; break; + case 19: sc_assert( sc_time_stamp() == sc_time(175, SC_NS) ); f6=1; break; + case 20: sc_assert( sc_time_stamp() == sc_time(176, SC_NS) ); f7=1; break; + case 21: sc_assert( sc_time_stamp() == sc_time(176, SC_NS) ); f8=1; break; + case 22: sc_assert( sc_time_stamp() == sc_time(180, SC_NS) ); f9=1; break; + case 23: sc_assert( sc_time_stamp() == sc_time(190, SC_NS) ); f10=1; break; + case 26: sc_assert( sc_time_stamp() == sc_time(215, SC_NS) ); f11=1; break; + default: sc_assert( false ); break; + } + + for (;;) + { + try { + wait(ev); + //cout << "Target1 awoke at " << sc_time_stamp() << " count = " << count << endl; + sc_assert( !sc_is_unwinding() ); + switch (count) + { + case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); f12=1; break; + case 4: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); f13=1; break; + case 5: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); f14=1; break; + case 10: sc_assert( sc_time_stamp() == sc_time(100, SC_NS) ); f15=1; break; + case 13: sc_assert( sc_time_stamp() == sc_time(125, SC_NS) ); f16=1; break; + case 14: sc_assert( sc_time_stamp() == sc_time(130, SC_NS) ); f17=1; break; + case 16: sc_assert( sc_time_stamp() == sc_time(150, SC_NS) ); f18=1; break; + case 17: sc_assert( sc_time_stamp() == sc_time(160, SC_NS) ); f19=1; break; + case 24: sc_assert( sc_time_stamp() == sc_time(200, SC_NS) ); f20=1; break; + case 25: sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); f21=1; break; + default: sc_assert( false ); break; + } + } + catch (const sc_unwind_exception& ex) { + sc_assert( sc_is_unwinding() ); + sc_assert( ex.is_reset() ); + throw ex; + } + } + } + + void reset_handler() + { + //cout << "reset_handler awoke at " << sc_time_stamp() << " count = " << count << endl; + sc_assert( !sc_is_unwinding() ); + switch (count) + { + case 2: sc_assert( sc_time_stamp() == sc_time(20, SC_NS) ); f22=1; break; + case 3: sc_assert( sc_time_stamp() == sc_time(30, SC_NS) ); f23=1; break; + case 7: sc_assert( sc_time_stamp() == sc_time(70, SC_NS) ); f24=1; break; + case 15: sc_assert( sc_time_stamp() == sc_time(140, SC_NS) ); f27=1; break;; + case 18: sc_assert( sc_time_stamp() == sc_time(170, SC_NS) ); f28=1; break; + case 19: sc_assert( sc_time_stamp() == sc_time(175, SC_NS) ); f29=1; break; + case 21: sc_assert( sc_time_stamp() == sc_time(176, SC_NS) ); f31=1; break; + case 22: sc_assert( sc_time_stamp() == sc_time(180, SC_NS) ); f32=1; break; + case 23: sc_assert( sc_time_stamp() == sc_time(190, SC_NS) ); f33=1; break; + case 26: sc_assert( sc_time_stamp() == sc_time(215, SC_NS) ); f34=1; break; + default: sc_assert( false ); break; + } + } + + void target2() + { + if (sc_delta_count() == 0) + t2.suspend(); // Hack to work around not being able to call suspend during elab + + switch (count) + { + case 27: sc_assert( sc_time_stamp() == sc_time(300, SC_NS) ); f35=1; break; + case 29: sc_assert( sc_time_stamp() == sc_time(320, SC_NS) ); f37=1; break; + default: sc_assert( false ); break; + } + while(1) + { + try { + wait(10, SC_NS); + } + catch (const sc_unwind_exception& e) { + switch (count) + { + case 29: sc_assert( sc_time_stamp() == sc_time(320, SC_NS) ); f38=1; break; + default: sc_assert( false ); break; + } + throw e; + } + switch (count) + { + case 28: sc_assert( sc_time_stamp() == sc_time(310, SC_NS) ); f36=1; break; + default: sc_assert( false ); break; + } + } + } + + void target3() + { + if (sc_delta_count() == 0) + t3.suspend(); // Hack to work around not being able to call suspend during elab + + switch (count) + { + case 1: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); break; + case 30: sc_assert( sc_time_stamp() == sc_time(405, SC_NS) ); f39=1; break; + case 31: sc_assert( sc_time_stamp() == sc_time(410, SC_NS) ); f40=1; break; + case 32: sc_assert( sc_time_stamp() == sc_time(420, SC_NS) ); f41=1; break; + default: sc_assert( false ); break; + } + } + + SC_HAS_PROCESS(M2); +}; + +int sc_main(int argc, char* argv[]) +{ + M2 m("m"); + + sc_start(); + + sc_assert(m.f0); + sc_assert(m.f1); + sc_assert(m.f2); + sc_assert(m.f3); + sc_assert(m.f4); + sc_assert(m.f5); + sc_assert(m.f6); + sc_assert(m.f7); + sc_assert(m.f8); + sc_assert(m.f9); + sc_assert(m.f10); + sc_assert(m.f11); + sc_assert(m.f12); + sc_assert(m.f13); + sc_assert(m.f14); + sc_assert(m.f15); + sc_assert(m.f16); + sc_assert(m.f17); + sc_assert(m.f18); + sc_assert(m.f19); + sc_assert(m.f20); + sc_assert(m.f21); + sc_assert(m.f22); + sc_assert(m.f23); + sc_assert(m.f24); + sc_assert(m.f27); + sc_assert(m.f28); + sc_assert(m.f29); + sc_assert(m.f31); + sc_assert(m.f32); + sc_assert(m.f33); + sc_assert(m.f34); + sc_assert(m.f35); + sc_assert(m.f36); + sc_assert(m.f37); + sc_assert(m.f38); + sc_assert(m.f39); + sc_assert(m.f40); + sc_assert(m.f41); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/throw_it/golden/throw_it.log b/src/systemc/tests/systemc/1666-2011-compliance/throw_it/golden/throw_it.log new file mode 100644 index 000000000..3ff513536 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/throw_it/golden/throw_it.log @@ -0,0 +1,11 @@ +SystemC Simulation + +Warning: (W556) throw_it on method/non-running process is being ignored : top.target4 +In file: <removed by verify.pl> +In process: top.target4 @ 0 s + +Warning: (W556) throw_it on method/non-running process is being ignored : top.target4 +In file: <removed by verify.pl> +In process: top.calling @ 20 ns + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/throw_it/throw_it.cpp b/src/systemc/tests/systemc/1666-2011-compliance/throw_it/throw_it.cpp new file mode 100644 index 000000000..6417758bc --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/throw_it/throw_it.cpp @@ -0,0 +1,378 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// throw_it.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: throw_it.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Process control method throw_it + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct Top: sc_module +{ + Top(sc_module_name _name) + { + SC_THREAD(calling); + + SC_THREAD(target1); + t1 = sc_get_current_process_handle(); + + SC_THREAD(target2); + t2 = sc_get_current_process_handle(); + + SC_THREAD(target3); + t3 = sc_get_current_process_handle(); + + SC_METHOD(target4); + t4 = sc_get_current_process_handle(); + + SC_THREAD(target5); + async_reset_signal_is(areset, true); + sensitive << ev; + t5 = sc_get_current_process_handle(); + t5.disable(); + + count = 0; + f0 = f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0; + f10 = f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = f19 = 0; + f20 = f21 = f22 = f23 = f24 = f25 = f26 = f27 = f28 = f29 = 0; + } + + sc_process_handle t1, t2, t3, t4, t5; + sc_event ev; + sc_signal<bool> areset; + int count; + int f0, f1, f2, f3, f4, f5, f6, f7, f8, f9; + int f10, f11, f12, f13, f14, f15, f16, f17, f18, f19; + int f20, f21, f22, f23, f24, f25, f26, f27, f28, f29; + + std::exception ex; + + void start_of_simulation() + { + try { + t1.throw_it(ex); + } + catch (std::exception ex) { + f1 = 1; + sc_assert( t1.valid() ); + sc_assert( !t1.terminated() ); + } + } + + void calling() + { + wait(SC_ZERO_TIME); + + count = 1; + ev.notify(5, SC_NS); + wait(10, SC_NS); + + count = 2; + t1.throw_it(ex); + sc_assert( t1.valid() ); + sc_assert( !t1.terminated() ); + sc_assert(f4); + wait(10, SC_NS); + + count = 3; + t4.throw_it(ex); // Throw exception in method process + sc_assert( t4.valid() ); + sc_assert( !t4.terminated() ); + wait(sc_time(200, SC_NS) - sc_time_stamp()); + + count = 4; + t1.suspend(); + ev.notify(5, SC_NS); + wait(10, SC_NS); + + count = 5; + t1.throw_it(ex); + wait(10, SC_NS); + + count = 6; + t1.throw_it(ex); + sc_assert( t1.valid() ); + sc_assert( !t1.terminated() ); + wait(10, SC_NS); + + count = 7; + t1.resume(); + wait(sc_time(300, SC_NS) - sc_time_stamp()); + + count = 8; + t1.disable(); + ev.notify(5, SC_NS); + wait(10, SC_NS); + + count = 9; + t1.throw_it(ex); + wait(10, SC_NS); + + count = 10; + t1.throw_it(ex); + wait(10, SC_NS); + + count = 11; + t1.enable(); + wait(sc_time(400, SC_NS) - sc_time_stamp()); + + count = 12; + t1.sync_reset_on(); + ev.notify(5, SC_NS); + wait(10, SC_NS); + wait(sc_time(400, SC_NS) - sc_time_stamp()); + + count = 13; + t1.throw_it(ex); + wait(10, SC_NS); + + count = 14; + t1.throw_it(ex); + wait(10, SC_NS); + + count = 15; + t1.sync_reset_off(); + wait(sc_time(500, SC_NS) - sc_time_stamp()); + + count = 16; + ev.notify(); + t1.throw_it(ex); + wait(10, SC_NS); + + count = 17; + t1.reset(); + wait(sc_time(600, SC_NS) - sc_time_stamp()); + + count = 18; + t1.disable(); + t5.enable(); + areset.write(false); + wait(10, SC_NS); + + count = 19; + ev.notify(); + wait(10, SC_NS); + + count = 20; + ev.notify(); + wait(10, SC_NS); + + count = 21; + areset.write(true); + wait(10, SC_NS); + + count = 22; + t5.throw_it(ex); + wait(10, SC_NS); + + count = 23; + ev.notify(); + wait(10, SC_NS); + + count = 24; + t5.throw_it(ex); + wait(10, SC_NS); + + count = 25; + areset.write(false); + wait(sc_time(700, SC_NS) - sc_time_stamp()); + + count = 26; + ev.notify(); + wait(10, SC_NS); + // async_reset_signal_is ? + } + + void target1() // Target for throw_it from calling() + { + switch (count) + { + case 0: sc_assert( sc_time_stamp() == sc_time( 0, SC_NS) ); f2=1; break; + case 12: sc_assert( sc_time_stamp() == sc_time(405, SC_NS) ); f13=1; break; + case 17: sc_assert( sc_time_stamp() == sc_time(510, SC_NS) ); f19=1; break; + default: sc_assert( false ); break; + } + + for (;;) + { + try { + wait(ev); + switch (count) + { + case 1: sc_assert( sc_time_stamp() == sc_time(5, SC_NS) ); f3=1; break; + case 7: sc_assert( sc_time_stamp() == sc_time(230, SC_NS) ); f9=1; break; + default: sc_assert( false ); break; + } + } + catch (const std::exception& ex) { + switch (count) + { + case 2: sc_assert( !sc_is_unwinding() ); + sc_assert( sc_time_stamp() == sc_time( 10, SC_NS) ); f4=1; break; + case 5: sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); f7=1; break; + case 6: sc_assert( sc_time_stamp() == sc_time(220, SC_NS) ); f8=1; break; + case 9: sc_assert( sc_time_stamp() == sc_time(310, SC_NS) ); f10=1; break; + case 10: sc_assert( sc_time_stamp() == sc_time(320, SC_NS) ); f11=1; break; + case 12: sc_assert( sc_is_unwinding() ); + sc_assert( sc_time_stamp() == sc_time(405, SC_NS) ); f12=1; + throw dynamic_cast<const sc_unwind_exception&>(ex); + case 13: sc_assert( !sc_is_unwinding() ); + sc_assert( sc_time_stamp() == sc_time(410, SC_NS) ); f14=1; break; + case 14: sc_assert( sc_time_stamp() == sc_time(420, SC_NS) ); f15=1; break; + case 16: sc_assert( sc_time_stamp() == sc_time(500, SC_NS) ); f16=1; break; + case 17: sc_assert( sc_is_unwinding() ); + sc_assert( sc_time_stamp() == sc_time(510, SC_NS) ); f18=1; + throw dynamic_cast<const sc_unwind_exception&>(ex); + default: sc_assert( false ); break; + } + } + } + } + + void target2() + { + wait(100, SC_NS); + try { + t2.throw_it(ex); // Process throws an exception to itself + sc_assert( false ); + } + catch (std::exception ex) { + sc_assert( t2.valid() ); + sc_assert( !t2.terminated() ); + f5 = 1; + t3.throw_it(ex); + } + } + + void target3() // Target for throw_it from target2() + { + try { + wait(1, SC_US); + } + catch (std::exception ex) { + sc_assert( t3.valid() ); + sc_assert( !t3.terminated() ); + f6 = 1; + } + } + + void target4() // SC_METHOD, target for throw_it from calling() + { + t4.throw_it(ex); // Method process throws exception to itself + if (count != 0) + sc_assert( false ); + } + + void target5() // Target for throw_it from calling() + async_reset_signal + { + switch (count) + { + case 19: sc_assert( sc_time_stamp() == sc_time(610, SC_NS) ); f20=1; break; + case 21: sc_assert( sc_time_stamp() == sc_time(630, SC_NS) ); f23=1; break; + case 23: sc_assert( sc_time_stamp() == sc_time(650, SC_NS) ); f26=1; break; + default: sc_assert( false ); break; + } + + for (;;) + { + try { + wait(); + + switch (count) + { + case 20: sc_assert( sc_time_stamp() == sc_time(620, SC_NS) ); f21=1; break; + case 26: sc_assert( sc_time_stamp() == sc_time(700, SC_NS) ); f28=1; break; + default: sc_assert( false ); break; + } + } + catch (const std::exception& ex) { + switch (count) + { + case 21: sc_assert( sc_is_unwinding() ); + sc_assert( sc_time_stamp() == sc_time(630, SC_NS) ); f22=1; + throw dynamic_cast<const sc_unwind_exception&>(ex); + case 22: sc_assert( !sc_is_unwinding() ); + sc_assert( sc_time_stamp() == sc_time(640, SC_NS) ); f24=1; break; + case 23: sc_assert( sc_is_unwinding() ); + sc_assert( sc_time_stamp() == sc_time(650, SC_NS) ); f25=1; + throw dynamic_cast<const sc_unwind_exception&>(ex); + case 24: sc_assert( !sc_is_unwinding() ); + sc_assert( sc_time_stamp() == sc_time(660, SC_NS) ); f27=1; break; + default: sc_assert( false ); break; + } + } + } + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.f1 ); + sc_assert( top.f2 ); + sc_assert( top.f3 ); + sc_assert( top.f4 ); + sc_assert( top.f5 ); + sc_assert( top.f6 ); + sc_assert( top.f7 ); + sc_assert( top.f8 ); + sc_assert( top.f9 ); + sc_assert( top.f10 ); + sc_assert( top.f11 ); + sc_assert( top.f12 ); + sc_assert( top.f13 ); + sc_assert( top.f14 ); + sc_assert( top.f15 ); + sc_assert( top.f16 ); + sc_assert( top.f18 ); + sc_assert( top.f19 ); + sc_assert( top.f20 ); + sc_assert( top.f21 ); + sc_assert( top.f22 ); + sc_assert( top.f23 ); + sc_assert( top.f24 ); + sc_assert( top.f25 ); + sc_assert( top.f26 ); + sc_assert( top.f27 ); + sc_assert( top.f28 ); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/version_macros/golden/version_macros.log b/src/systemc/tests/systemc/1666-2011-compliance/version_macros/golden/version_macros.log new file mode 100644 index 000000000..147d986bf --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/version_macros/golden/version_macros.log @@ -0,0 +1,4 @@ +SystemC Simulation +IEEE_1666_SYSTEMC = 201101 + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/version_macros/version_macros.cpp b/src/systemc/tests/systemc/1666-2011-compliance/version_macros/version_macros.cpp new file mode 100644 index 000000000..9b84c265b --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/version_macros/version_macros.cpp @@ -0,0 +1,66 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// version_macros.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: version_macros.cpp,v $ +// Revision 1.4 2011/05/16 17:17:43 acg +// Andy Goodrich: update test to mask information that changes by SystemC +// revision. +// +// Revision 1.3 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Process control method throw_it + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +int sc_main(int argc, char* argv[]) +{ + sc_assert( SC_VERSION_MAJOR == sc_version_major ); + sc_assert( SC_VERSION_MINOR == sc_version_minor ); + sc_assert( SC_VERSION_PATCH == sc_version_patch ); + sc_assert( SC_VERSION_ORIGINATOR == sc_version_originator ); + sc_assert( SC_VERSION_RELEASE_DATE == sc_version_release_date ); + sc_assert( SC_VERSION_PRERELEASE == sc_version_prerelease ); + sc_assert( SC_IS_PRERELEASE == sc_is_prerelease ); + sc_assert( SC_VERSION == sc_version_string ); + sc_assert( sc_release() == sc_version_string ); + sc_assert( SC_COPYRIGHT == sc_copyright_string ); + sc_assert( sc_copyright() == sc_copyright_string ); + + cout << "IEEE_1666_SYSTEMC = " << IEEE_1666_SYSTEMC << endl; + + //sc_start(); + + cout << endl << "Success" << endl; + return 0; +} + diff --git a/src/systemc/tests/systemc/1666-2011-compliance/virtual_bind/golden/virtual_bind.log b/src/systemc/tests/systemc/1666-2011-compliance/virtual_bind/golden/virtual_bind.log new file mode 100644 index 000000000..7ced375b0 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/virtual_bind/golden/virtual_bind.log @@ -0,0 +1,3 @@ +SystemC Simulation + +Success diff --git a/src/systemc/tests/systemc/1666-2011-compliance/virtual_bind/virtual_bind.cpp b/src/systemc/tests/systemc/1666-2011-compliance/virtual_bind/virtual_bind.cpp new file mode 100644 index 000000000..4be25a357 --- /dev/null +++ b/src/systemc/tests/systemc/1666-2011-compliance/virtual_bind/virtual_bind.cpp @@ -0,0 +1,157 @@ +/***************************************************************************** + + 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. + + *****************************************************************************/ + +// virtual_bind.cpp -- test for +// +// Original Author: John Aynsley, Doulos, Inc. +// +// MODIFICATION LOG - modifiers, enter your name, affiliation, date and +// +// $Log: virtual_bind.cpp,v $ +// Revision 1.2 2011/05/08 19:18:46 acg +// Andy Goodrich: remove extraneous + prefixes from git diff. +// + +// Process control method throw_it + +#define SC_INCLUDE_DYNAMIC_PROCESSES + +#include <systemc> + +using namespace sc_core; +using std::cout; +using std::endl; + +struct i_f: virtual sc_interface +{ + virtual void meth() = 0; +}; + +struct Chan: i_f, sc_module +{ + int f1; + Chan(sc_module_name _name) + { + f1 = 0; + } + virtual void meth() { f1 = 1; } +}; + +struct my_port: sc_port<i_f> +{ + void bind(i_f& _if) + { + sc_assert(false); + } +}; + +struct extended_port: my_port +{ + int f2; + extended_port() { f2 = 0; } + + void bind(i_f& _if) + { + sc_port<i_f>::bind(_if); + f2 = 1; + } +}; + +struct my_export: sc_export<i_f> +{ + void bind(i_f& _if) + { + sc_assert(false); + } +}; + +struct extended_export: my_export +{ + int f3; + extended_export() { f3 = 0; } + + void bind(i_f& _if) + { + sc_export<i_f>::bind(_if); + f3 = 1; + } +}; + +struct Child: sc_module +{ + extended_port p; + extended_export xp; + + Chan chan; + + Child(sc_module_name _name) + : chan("chan") + { + my_export* mxp = static_cast<my_export*>( &xp ); + mxp->bind(chan); // bind should be virtual + SC_THREAD(T); + } + + void T() + { + p->meth(); + } + + SC_HAS_PROCESS(Child); +}; + +struct Top: sc_module +{ + Child *child; + Chan chan; + + Top(sc_module_name _name) + : chan("chan") + { + child = new Child("child"); + extended_port* ep = &(child->p); + my_port* mp = static_cast<my_port*>(ep); + mp->bind(chan); // bind should be virtual + + SC_THREAD(T); + } + + void T() + { + child->xp->meth(); + } + + SC_HAS_PROCESS(Top); +}; + +int sc_main(int argc, char* argv[]) +{ + Top top("top"); + + sc_start(); + + sc_assert( top.chan.f1 ); + sc_assert( top.child->chan.f1 ); + sc_assert( top.child->p.f2 ); + sc_assert( top.child->xp.f3 ); + + cout << endl << "Success" << endl; + return 0; +} + |