112855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES
212855Sgabeblack@google.com
312855Sgabeblack@google.com#include <systemc>
412855Sgabeblack@google.com#include <cstring>
512855Sgabeblack@google.comusing namespace sc_core;
612855Sgabeblack@google.comusing namespace sc_dt;
712855Sgabeblack@google.comusing std::cout;
812855Sgabeblack@google.comusing std::endl;
912855Sgabeblack@google.com
1012855Sgabeblack@google.com// 3) Process handle methods, including invalid and terminated process
1112855Sgabeblack@google.com
1212855Sgabeblack@google.comvoid invalid_handle_check(sc_process_handle& h)
1312855Sgabeblack@google.com{
1412855Sgabeblack@google.com
1512855Sgabeblack@google.com    sc_assert(h.valid() == false);
1612855Sgabeblack@google.com    sc_assert(strcmp(h.name(), "") == 0);
1712855Sgabeblack@google.com    sc_assert(h.proc_kind() == SC_NO_PROC_);
1812855Sgabeblack@google.com    sc_assert(h.get_process_object() == 0);
1912855Sgabeblack@google.com    std::vector<sc_object*> children = h.get_child_objects();
2012855Sgabeblack@google.com    sc_assert(children.size() == 0);
2112855Sgabeblack@google.com    sc_assert(h.get_parent_object() == 0);
2212855Sgabeblack@google.com    sc_assert(h.terminated() == false);
2312855Sgabeblack@google.com    sc_assert(h.dynamic() == false);
2412855Sgabeblack@google.com    sc_assert( !(h == h) );
2512855Sgabeblack@google.com    sc_assert(h != h);
2612855Sgabeblack@google.com
2712855Sgabeblack@google.com    cout << "There should be warning 11 messages" << endl;
2812855Sgabeblack@google.com
2912855Sgabeblack@google.com    h.disable();
3012855Sgabeblack@google.com    h.enable();
3112855Sgabeblack@google.com    h.is_unwinding();
3212855Sgabeblack@google.com    h.kill();
3312855Sgabeblack@google.com    h.reset();
3412855Sgabeblack@google.com    h.resume();
3512855Sgabeblack@google.com    h.suspend();
3612855Sgabeblack@google.com    h.sync_reset_off();
3712855Sgabeblack@google.com    h.sync_reset_on();
3812855Sgabeblack@google.com    h.terminated_event();
3912855Sgabeblack@google.com    h.throw_it(sc_user(), SC_NO_DESCENDANTS);
4012855Sgabeblack@google.com
4112855Sgabeblack@google.com    cout << "End of warning messages" << endl;
4212855Sgabeblack@google.com}
4312855Sgabeblack@google.com
4412855Sgabeblack@google.comSC_MODULE(M)
4512855Sgabeblack@google.com{
4612855Sgabeblack@google.com  sc_in_clk clk;
4712855Sgabeblack@google.com  SC_CTOR(M)
4812855Sgabeblack@google.com  {
4912855Sgabeblack@google.com    sc_process_handle h;
5012855Sgabeblack@google.com    invalid_handle_check(h);
5112855Sgabeblack@google.com
5212855Sgabeblack@google.com    SC_THREAD(T);
5312855Sgabeblack@google.com    SC_CTHREAD(CT, clk.pos());
5412855Sgabeblack@google.com    SC_METHOD(ME);
5512855Sgabeblack@google.com
5612855Sgabeblack@google.com    sc_process_handle h3 = sc_spawn(sc_bind(&M::stat_thread, this), "stat_thread");
5712855Sgabeblack@google.com    sc_spawn_options opt;
5812855Sgabeblack@google.com    opt.spawn_method();
5912855Sgabeblack@google.com    sc_process_handle h4 = sc_spawn(sc_bind(&M::stat_method, this), "stat_method", &opt);
6012855Sgabeblack@google.com
6112855Sgabeblack@google.com    std::vector<sc_object*> children = this->get_child_objects();
6212855Sgabeblack@google.com    sc_assert(children.size() == 6);
6312855Sgabeblack@google.com  }
6412855Sgabeblack@google.com  void T()
6512855Sgabeblack@google.com  {
6612855Sgabeblack@google.com    sc_process_handle h;
6712855Sgabeblack@google.com    invalid_handle_check(h);
6812855Sgabeblack@google.com
6912855Sgabeblack@google.com    sc_process_handle h2 = sc_get_current_process_handle();
7012855Sgabeblack@google.com    sc_assert(h2.valid() == true);
7112855Sgabeblack@google.com    sc_assert(strcmp(h2.name(), "top.m.T") == 0);
7212855Sgabeblack@google.com    sc_assert(h2.proc_kind() == SC_THREAD_PROC_);
7312855Sgabeblack@google.com    sc_assert(h2.get_process_object() != 0);
7412855Sgabeblack@google.com    std::vector<sc_object*> children2 = h2.get_child_objects();
7512855Sgabeblack@google.com    sc_assert(children2.size() == 0);
7612855Sgabeblack@google.com    sc_assert(h2.get_parent_object() == this);
7712855Sgabeblack@google.com    sc_assert(h2.terminated() == false);
7812855Sgabeblack@google.com    sc_assert(h2.dynamic() == false);
7912855Sgabeblack@google.com    sc_assert(h2 == h2);
8012855Sgabeblack@google.com    sc_assert(h2 != h);
8112855Sgabeblack@google.com
8212855Sgabeblack@google.com    sc_process_handle h3 = sc_spawn(sc_bind(&M::dyn_thread, this), "dyn_thread");
8312855Sgabeblack@google.com    wait(1, SC_NS);
8412855Sgabeblack@google.com
8512855Sgabeblack@google.com    if (h3.valid() == true)
8612855Sgabeblack@google.com    {
8712855Sgabeblack@google.com      sc_assert(strcmp(h3.name(), "top.m.T.dyn_thread") == 0);
8812855Sgabeblack@google.com      sc_assert(h3.proc_kind() == SC_THREAD_PROC_);
8912855Sgabeblack@google.com      sc_assert(h3.get_process_object() != 0);
9012855Sgabeblack@google.com      std::vector<sc_object*> children3 = h3.get_child_objects();
9112855Sgabeblack@google.com      sc_assert(children3.size() == 0);
9212855Sgabeblack@google.com      sc_assert(h3.get_parent_object() == sc_get_current_process_handle().get_process_object());
9312855Sgabeblack@google.com      sc_assert(h3.terminated() == true);
9412855Sgabeblack@google.com      sc_assert(h3.dynamic() == true);
9512855Sgabeblack@google.com      sc_assert(h3 == h3);
9612855Sgabeblack@google.com      sc_assert( !(h3 != h3) );
9712855Sgabeblack@google.com    }
9812855Sgabeblack@google.com
9912855Sgabeblack@google.com    sc_spawn_options opt;
10012855Sgabeblack@google.com    opt.spawn_method();
10112855Sgabeblack@google.com    sc_process_handle h4 = sc_spawn(sc_bind(&M::dyn_method, this), "dyn_method", &opt);
10212855Sgabeblack@google.com    sc_assert(h4 != h3);
10312855Sgabeblack@google.com
10412855Sgabeblack@google.com    wait(10, SC_NS);
10512855Sgabeblack@google.com    sc_stop();
10612855Sgabeblack@google.com  }
10712855Sgabeblack@google.com
10812855Sgabeblack@google.com  void stat_thread()
10912855Sgabeblack@google.com  {
11012855Sgabeblack@google.com    sc_process_handle h;
11112855Sgabeblack@google.com    invalid_handle_check(h);
11212855Sgabeblack@google.com
11312855Sgabeblack@google.com    wait(5, SC_NS);
11412855Sgabeblack@google.com
11512855Sgabeblack@google.com    sc_process_handle h3 = sc_get_current_process_handle();
11612855Sgabeblack@google.com    sc_assert(h3.valid() == true);
11712855Sgabeblack@google.com    sc_assert(strcmp(h3.name(), "top.m.stat_thread") == 0);
11812855Sgabeblack@google.com    sc_assert(h3.proc_kind() == SC_THREAD_PROC_);
11912855Sgabeblack@google.com    sc_assert(h3.get_process_object() != 0);
12012855Sgabeblack@google.com    std::vector<sc_object*> children3 = h3.get_child_objects();
12112855Sgabeblack@google.com    sc_assert(children3.size() == 0);
12212855Sgabeblack@google.com    sc_assert(h3.get_parent_object() != 0);
12312855Sgabeblack@google.com    sc_assert(h3.terminated() == false);
12412855Sgabeblack@google.com    sc_assert(h3.dynamic() == false);
12512855Sgabeblack@google.com    sc_assert(h3 == h3);
12612855Sgabeblack@google.com    sc_assert(h3 != h);
12712855Sgabeblack@google.com
12812855Sgabeblack@google.com    sc_process_handle h4;
12912855Sgabeblack@google.com    h4 = h3;
13012855Sgabeblack@google.com    sc_assert(h4 == h3);
13112855Sgabeblack@google.com    sc_assert(h4 != h);
13212855Sgabeblack@google.com  }
13312855Sgabeblack@google.com
13412855Sgabeblack@google.com  void stat_method()
13512855Sgabeblack@google.com  {
13612855Sgabeblack@google.com    sc_process_handle h;
13712855Sgabeblack@google.com    invalid_handle_check(h);
13812855Sgabeblack@google.com
13912855Sgabeblack@google.com    sc_process_handle h3 = sc_get_current_process_handle();
14012855Sgabeblack@google.com    sc_assert(h3.valid() == true);
14112855Sgabeblack@google.com    sc_assert(strcmp(h3.name(), "top.m.stat_method") == 0);
14212855Sgabeblack@google.com    sc_assert(h3.proc_kind() == SC_METHOD_PROC_);
14312855Sgabeblack@google.com    sc_assert(h3.get_process_object() != 0);
14412855Sgabeblack@google.com    std::vector<sc_object*> children3 = h3.get_child_objects();
14512855Sgabeblack@google.com    sc_assert(children3.size() == 0);
14612855Sgabeblack@google.com    sc_assert(h3.get_parent_object() != 0);
14712855Sgabeblack@google.com    sc_assert(h3.terminated() == false);
14812855Sgabeblack@google.com    sc_assert(h3.dynamic() == false);
14912855Sgabeblack@google.com    sc_assert(h3 == h3);
15012855Sgabeblack@google.com    sc_assert(h3 != h);
15112855Sgabeblack@google.com
15212855Sgabeblack@google.com    sc_process_handle h4;
15312855Sgabeblack@google.com    h4 = h3;
15412855Sgabeblack@google.com    sc_assert(h4 == h3);
15512855Sgabeblack@google.com    sc_assert(h4 != h);
15612855Sgabeblack@google.com  }
15712855Sgabeblack@google.com
15812855Sgabeblack@google.com  void dyn_thread()
15912855Sgabeblack@google.com  {
16012855Sgabeblack@google.com    sc_process_handle h;
16112855Sgabeblack@google.com    invalid_handle_check(h);
16212855Sgabeblack@google.com
16312855Sgabeblack@google.com    sc_process_handle h3 = sc_get_current_process_handle();
16412855Sgabeblack@google.com    sc_assert(h3.valid() == true);
16512855Sgabeblack@google.com    sc_assert(strcmp(h3.name(), "top.m.T.dyn_thread") == 0);
16612855Sgabeblack@google.com    sc_assert(h3.proc_kind() == SC_THREAD_PROC_);
16712855Sgabeblack@google.com    sc_assert(h3.get_process_object() != 0);
16812855Sgabeblack@google.com    std::vector<sc_object*> children3 = h3.get_child_objects();
16912855Sgabeblack@google.com    sc_assert(children3.size() == 0);
17012855Sgabeblack@google.com    sc_assert(h3.get_parent_object() != 0);
17112855Sgabeblack@google.com    sc_assert(h3.terminated() == false);
17212855Sgabeblack@google.com    sc_assert(h3.dynamic() == true);
17312855Sgabeblack@google.com    sc_assert(h3 == h3);
17412855Sgabeblack@google.com    sc_assert(h3 != h);
17512855Sgabeblack@google.com
17612855Sgabeblack@google.com    sc_process_handle h4(h3);
17712855Sgabeblack@google.com    sc_assert(h4 == h3);
17812855Sgabeblack@google.com  }
17912855Sgabeblack@google.com
18012855Sgabeblack@google.com  void dyn_method()
18112855Sgabeblack@google.com  {
18212855Sgabeblack@google.com    sc_process_handle h;
18312855Sgabeblack@google.com    invalid_handle_check(h);
18412855Sgabeblack@google.com
18512855Sgabeblack@google.com    sc_process_handle h3 = sc_get_current_process_handle();
18612855Sgabeblack@google.com    sc_assert(h3.valid() == true);
18712855Sgabeblack@google.com    sc_assert(strcmp(h3.name(), "top.m.T.dyn_method") == 0);
18812855Sgabeblack@google.com    sc_assert(h3.proc_kind() == SC_METHOD_PROC_);
18912855Sgabeblack@google.com    sc_assert(h3.get_process_object() != 0);
19012855Sgabeblack@google.com    std::vector<sc_object*> children3 = h3.get_child_objects();
19112855Sgabeblack@google.com    sc_assert(children3.size() == 0);
19212855Sgabeblack@google.com    sc_assert(h3.get_parent_object() != 0);
19312855Sgabeblack@google.com    sc_assert(h3.terminated() == false);
19412855Sgabeblack@google.com    sc_assert(h3.dynamic() == true);
19512855Sgabeblack@google.com    sc_assert(h3 == h3);
19612855Sgabeblack@google.com    sc_assert(h3 != h);
19712855Sgabeblack@google.com
19812855Sgabeblack@google.com    sc_process_handle h4(h3);
19912855Sgabeblack@google.com    sc_assert(h4 == h3);
20012855Sgabeblack@google.com  }
20112855Sgabeblack@google.com
20212855Sgabeblack@google.com  void CT()
20312855Sgabeblack@google.com  {
20412855Sgabeblack@google.com    sc_process_handle h;
20512855Sgabeblack@google.com    invalid_handle_check(h);
20612855Sgabeblack@google.com
20712855Sgabeblack@google.com    sc_process_handle h2 = sc_get_current_process_handle();
20812855Sgabeblack@google.com    sc_assert(h2.valid() == true);
20912855Sgabeblack@google.com    sc_assert(strcmp(h2.name(), "top.m.CT") == 0);
21012855Sgabeblack@google.com    sc_assert(h2.proc_kind() == SC_CTHREAD_PROC_);
21112855Sgabeblack@google.com    sc_assert(h2.get_process_object() != 0);
21212855Sgabeblack@google.com    std::vector<sc_object*> children2 = h2.get_child_objects();
21312855Sgabeblack@google.com    sc_assert(children2.size() == 0);
21412855Sgabeblack@google.com    sc_assert(h2.get_parent_object() == this);
21512855Sgabeblack@google.com    sc_assert(h2.terminated() == false);
21612855Sgabeblack@google.com    sc_assert(h2.dynamic() == false);
21712855Sgabeblack@google.com    sc_assert(h2 == h2);
21812855Sgabeblack@google.com    sc_assert(h2 != h);
21912855Sgabeblack@google.com  }
22012855Sgabeblack@google.com
22112855Sgabeblack@google.com  void ME()
22212855Sgabeblack@google.com  {
22312855Sgabeblack@google.com    sc_process_handle h;
22412855Sgabeblack@google.com    invalid_handle_check(h);
22512855Sgabeblack@google.com
22612855Sgabeblack@google.com    sc_process_handle h2 = sc_get_current_process_handle();
22712855Sgabeblack@google.com    sc_assert(h2.valid() == true);
22812855Sgabeblack@google.com    sc_assert(strcmp(h2.name(), "top.m.ME") == 0);
22912855Sgabeblack@google.com    sc_assert(h2.proc_kind() == SC_METHOD_PROC_);
23012855Sgabeblack@google.com    sc_assert(h2.get_process_object() != 0);
23112855Sgabeblack@google.com    std::vector<sc_object*> children2 = h2.get_child_objects();
23212855Sgabeblack@google.com    sc_assert(children2.size() == 0);
23312855Sgabeblack@google.com    sc_assert(h2.get_parent_object() == this);
23412855Sgabeblack@google.com    sc_assert(h2.terminated() == false);
23512855Sgabeblack@google.com    sc_assert(h2.dynamic() == false);
23612855Sgabeblack@google.com    sc_assert(h2 == h2);
23712855Sgabeblack@google.com    sc_assert(h2 != h);
23812855Sgabeblack@google.com  }
23912855Sgabeblack@google.com
24012855Sgabeblack@google.com};
24112855Sgabeblack@google.com
24212855Sgabeblack@google.comstruct Top: sc_module
24312855Sgabeblack@google.com{
24412855Sgabeblack@google.com  M *m;
24512855Sgabeblack@google.com  sc_clock clk;
24612855Sgabeblack@google.com  Top(sc_module_name)
24712855Sgabeblack@google.com  {
24812855Sgabeblack@google.com    m = new M("m");
24912855Sgabeblack@google.com    m->clk(clk);
25012855Sgabeblack@google.com  }
25112855Sgabeblack@google.com};
25212855Sgabeblack@google.com
25312855Sgabeblack@google.comint sc_main(int argc, char* argv[])
25412855Sgabeblack@google.com{
25512855Sgabeblack@google.com  cout << "Should be silent except for warning messages" << endl;
25612855Sgabeblack@google.com
25712855Sgabeblack@google.com  sc_process_handle h;
25812855Sgabeblack@google.com  invalid_handle_check(h);
25912855Sgabeblack@google.com
26012855Sgabeblack@google.com  Top top("top");
26112855Sgabeblack@google.com  sc_start();
26212855Sgabeblack@google.com
26312855Sgabeblack@google.com  cout << endl << "Success" << endl;
26412855Sgabeblack@google.com  return 0;
26512855Sgabeblack@google.com}
266