Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was able to run 2 SystemC tests using the fork system call. I used the tutorial example on <a href="http://www.doulos.com/knowhow/systemc/tutorial/modules_and_processes/" rel="nofollow">doulos.com</a> and the <a href="http://code.google.com/p/googletest/" rel="nofollow">Google Test</a> framework. I was able to run the test twice, but I get an error printed out by the SystemC simulator about starting the test after calling sc_stop. However, regardless of the error, the simulator runs fine the second time around. </p> <pre><code> SystemC 2.2.0 --- Feb 24 2011 15:01:50 Copyright (c) 1996-2006 by all Contributors ALL RIGHTS RESERVED Running main() from gtest_main.cc [==========] Running 2 tests from 1 test case. [----------] Global test environment set-up. [----------] 2 tests from systemc_test [ RUN ] systemc_test.test1 Time A B F 0 s 0 0 0 0 s 0 0 1 10 ns 0 1 1 20 ns 1 0 1 30 ns 1 1 0 SystemC: simulation stopped by user. [ OK ] systemc_test.test1 (1 ms) [ RUN ] systemc_test.test2 Error: (E546) sc_start called after sc_stop has been called In file: ../../../../src/sysc/kernel/sc_simcontext.cpp:1315 [ OK ] systemc_test.test2 (2 ms) [----------] 2 tests from systemc_test (3 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (3 ms total) [ PASSED ] 2 tests. [ OK ] systemc_test.test1 (3 ms) [ RUN ] systemc_test.test2 Time A B F 0 s 0 0 0 0 s 0 0 1 10 ns 0 1 1 20 ns 1 0 1 30 ns 1 1 0 SystemC: simulation stopped by user. [ OK ] systemc_test.test2 (1 ms) [----------] 2 tests from systemc_test (4 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (4 ms total) [ PASSED ] 2 tests. [ OK ] systemc_test.test2 (1 ms) [----------] 2 tests from systemc_test (4 ms total) [----------] Global test environment tear-down [==========] 2 tests from 1 test case ran. (4 ms total) [ PASSED ] 2 tests. </code></pre> <p><strong>UPDATE:</strong> Code sample as requested:</p> <pre><code>// main_1.cxx #include "systemc.h" #include "stim.hxx" #include "exor2.hxx" #include "mon.hxx" //#include &lt;pthread.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/wait.h&gt; void run_1() { sc_signal&lt;bool&gt; ASig, BSig, FSig; sc_clock TestClk("TestClock", 10, SC_NS,0.5); stim* Stim1 = new stim("Stimulus1_1"); Stim1-&gt;A(ASig); Stim1-&gt;B(BSig); Stim1-&gt;Clk(TestClk); exor2* DUT = new exor2("exor2_1"); DUT-&gt;A(ASig); DUT-&gt;B(BSig); DUT-&gt;F(FSig); mon* Monitor1 = new mon("Monitor_1"); Monitor1-&gt;A(ASig); Monitor1-&gt;B(BSig); Monitor1-&gt;F(FSig); Monitor1-&gt;Clk(TestClk); Stim1-&gt;run(); delete Stim1; delete DUT; delete Monitor1; } bool sc_main_1() { //int rc; //pthread_t thread; //if( (rc = pthread_create( &amp;thread, NULL, &amp;run_1, NULL)) ) //{ // printf("Thread creation failed: %d\n", rc); //}; //pthread_join(thread, NULL); int pid = fork(); if(pid == 0) { run_1(); }; waitpid(pid, NULL, 0); return true; }; // main_2.cxx #include "systemc.h" #include "stim.hxx" #include "exor2.hxx" #include "mon.hxx" //#include &lt;pthread.h&gt; #include &lt;sys/types.h&gt; #include &lt;sys/wait.h&gt; void run_2() { sc_signal&lt;bool&gt; ASig, BSig, FSig; sc_clock TestClk("TestClock", 10, SC_NS,0.5); stim* Stim1 = new stim("Stimulus1_2"); Stim1-&gt;A(ASig); Stim1-&gt;B(BSig); Stim1-&gt;Clk(TestClk); exor2* DUT = new exor2("exor2_2"); DUT-&gt;A(ASig); DUT-&gt;B(BSig); DUT-&gt;F(FSig); mon* Monitor1 = new mon("Monitor_2"); Monitor1-&gt;A(ASig); Monitor1-&gt;B(BSig); Monitor1-&gt;F(FSig); Monitor1-&gt;Clk(TestClk); Stim1-&gt;run(); delete Stim1; delete DUT; delete Monitor1; } bool sc_main_2() { //int rc; //pthread_t thread; //if( (rc = pthread_create( &amp;thread, NULL, &amp;run_1, NULL)) ) //{ // printf("Thread creation failed: %d\n", rc); //}; //pthread_join(thread, NULL); int pid = fork(); if(pid == 0) { run_2(); }; waitpid(pid, NULL, 0); return true; }; // main.cxx #include "systemc.h" #include "gtest/gtest.h" extern bool sc_main_1(); extern bool sc_main_2(); TEST(systemc_test, test1) { EXPECT_TRUE(sc_main_1()); }; TEST(systemc_test, test2) { EXPECT_TRUE(sc_main_2()); }; int sc_main(int argc, char* argv[]) { std::cout &lt;&lt; "Running main() from gtest_main.cc\n"; testing::InitGoogleTest(&amp;argc, argv); RUN_ALL_TESTS(); return 0; } // stim.hxx #ifndef stim_hxx #define stim_hxx #include "systemc.h" SC_MODULE(stim) { sc_out&lt;bool&gt; A, B; sc_in&lt;bool&gt; Clk; void StimGen() { A.write(false); B.write(false); wait(); A.write(false); B.write(true); wait(); A.write(true); B.write(false); wait(); A.write(true); B.write(true); wait(); sc_stop(); } SC_CTOR(stim) { SC_THREAD(StimGen); sensitive &lt;&lt; Clk.pos(); } bool run() { sc_start(); // run forever return true; }; }; #endif // exor2.hxx #ifndef exor_hxx #define exor_hxx #include "systemc.h" #include "nand2.hxx" SC_MODULE(exor2) { sc_in&lt;bool&gt; A, B; sc_out&lt;bool&gt; F; nand2 n1, n2, n3, n4; sc_signal&lt;bool&gt; S1, S2, S3; SC_CTOR(exor2) : n1("N1"), n2("N2"), n3("N3"), n4("N4") { n1.A(A); n1.B(B); n1.F(S1); n2.A(A); n2.B(S1); n2.F(S2); n3.A(S1); n3.B(B); n3.F(S3); n4.A(S2); n4.B(S3); n4.F(F); } }; #endif // mon.hxx #ifndef mon_hxx #define mon_hxx #include "systemc.h" #include &lt;iomanip&gt; #include &lt;iostream&gt; using namespace std; SC_MODULE(mon) { sc_in&lt;bool&gt; A,B,F; sc_in&lt;bool&gt; Clk; void monitor() { cout &lt;&lt; setw(10) &lt;&lt; "Time"; cout &lt;&lt; setw(2) &lt;&lt; "A" ; cout &lt;&lt; setw(2) &lt;&lt; "B"; cout &lt;&lt; setw(2) &lt;&lt; "F" &lt;&lt; endl; while (true) { cout &lt;&lt; setw(10) &lt;&lt; sc_time_stamp(); cout &lt;&lt; setw(2) &lt;&lt; A.read(); cout &lt;&lt; setw(2) &lt;&lt; B.read(); cout &lt;&lt; setw(2) &lt;&lt; F.read() &lt;&lt; endl; wait(); // wait for 1 clock cycle } } SC_CTOR(mon) { SC_THREAD(monitor); sensitive &lt;&lt; Clk.pos(); } }; #endif </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload