112855Sgabeblack@google.com/***************************************************************************** 212855Sgabeblack@google.com 312855Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412855Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512855Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612855Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712855Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812855Sgabeblack@google.com License. You may obtain a copy of the License at 912855Sgabeblack@google.com 1012855Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112855Sgabeblack@google.com 1212855Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312855Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412855Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512855Sgabeblack@google.com implied. See the License for the specific language governing 1612855Sgabeblack@google.com permissions and limitations under the License. 1712855Sgabeblack@google.com 1812855Sgabeblack@google.com *****************************************************************************/ 1912855Sgabeblack@google.com 2012855Sgabeblack@google.com// named_events.cpp -- test for 2112855Sgabeblack@google.com// 2212855Sgabeblack@google.com// Original Author: John Aynsley, Doulos, Inc. 2312855Sgabeblack@google.com// 2412855Sgabeblack@google.com// MODIFICATION LOG - modifiers, enter your name, affiliation, date and 2512855Sgabeblack@google.com// 2612855Sgabeblack@google.com// $Log: named_events.cpp,v $ 2712855Sgabeblack@google.com// Revision 1.2 2011/05/08 19:18:46 acg 2812855Sgabeblack@google.com// Andy Goodrich: remove extraneous + prefixes from git diff. 2912855Sgabeblack@google.com// 3012855Sgabeblack@google.com 3112855Sgabeblack@google.com// Hierarchically named events 3212855Sgabeblack@google.com 3312855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES 3412855Sgabeblack@google.com 3512855Sgabeblack@google.com#include <systemc> 3612855Sgabeblack@google.com 3712855Sgabeblack@google.comusing namespace sc_core; 3812855Sgabeblack@google.comusing std::cout; 3912855Sgabeblack@google.comusing std::endl; 4012855Sgabeblack@google.com 4112855Sgabeblack@google.comstruct Object: sc_object 4212855Sgabeblack@google.com{ 4312855Sgabeblack@google.com Object(const char* n) 4412855Sgabeblack@google.com : sc_object(n) 4512855Sgabeblack@google.com , ev((std::string(n) + "_ev").c_str()) {} 4612855Sgabeblack@google.com 4712855Sgabeblack@google.com sc_event ev; // Parent of event is containing module or process instance 4812855Sgabeblack@google.com}; 4912855Sgabeblack@google.com 5012855Sgabeblack@google.comstruct Top: sc_module 5112855Sgabeblack@google.com{ 5212855Sgabeblack@google.com sc_event ev1, ev2; 5312855Sgabeblack@google.com Object *obj; 5412855Sgabeblack@google.com sc_signal<int> sig; // Kernel events should not be hierarchically named 5512855Sgabeblack@google.com sc_fifo<int> fifo; // Kernel events should not be hierarchically named 5612855Sgabeblack@google.com sc_semaphore sema; // Kernel events should not be hierarchically named 5712855Sgabeblack@google.com sc_mutex mut; // Kernel events should not be hierarchically named 5812855Sgabeblack@google.com 5912855Sgabeblack@google.com bool T_done; 6012855Sgabeblack@google.com 6112855Sgabeblack@google.com Top(sc_module_name _name) 6212855Sgabeblack@google.com : ev2("ev2") 6312855Sgabeblack@google.com , sig("sig") 6412855Sgabeblack@google.com , sema(1) 6512855Sgabeblack@google.com , T_done(false) 6612855Sgabeblack@google.com { 6712855Sgabeblack@google.com 6812855Sgabeblack@google.com sc_assert( ev1.in_hierarchy() ); 6912855Sgabeblack@google.com sc_assert( ev1.get_parent_object() == this ); 7012855Sgabeblack@google.com sc_assert( std::string(ev1.name()).substr(0,9) == "top.event" ); 7112855Sgabeblack@google.com sc_assert( std::string(ev1.basename()).substr(0,5) == "event" ); 7212855Sgabeblack@google.com 7312855Sgabeblack@google.com sc_assert( ev2.in_hierarchy() ); 7412855Sgabeblack@google.com sc_assert( ev2.get_parent_object() == this ); 7512855Sgabeblack@google.com sc_assert( std::string(ev2.name()) == "top.ev2" ); 7612855Sgabeblack@google.com sc_assert( std::string(ev2.basename()) == "ev2" ); 7712855Sgabeblack@google.com 7812855Sgabeblack@google.com sc_assert( sc_find_event("top.ev2") == &ev2 ); 7912855Sgabeblack@google.com 8012855Sgabeblack@google.com std::vector<sc_event*> vec = this->get_child_events(); 8112855Sgabeblack@google.com sc_assert( vec.size() == 2 ); 8212855Sgabeblack@google.com 8312855Sgabeblack@google.com sc_process_handle dummy_handle; 8412855Sgabeblack@google.com sc_assert( dummy_handle.get_child_events().size() == 0 ); 8512855Sgabeblack@google.com sc_assert( std::string(dummy_handle.name()) == ""); 8612855Sgabeblack@google.com 8712855Sgabeblack@google.com obj = new Object("obj"); 8812855Sgabeblack@google.com vec = obj->get_child_events(); // Should return empty vector 8912855Sgabeblack@google.com sc_assert( vec.size() == 0 ); 9012855Sgabeblack@google.com 9112855Sgabeblack@google.com vec = this->get_child_events(); 9212855Sgabeblack@google.com sc_assert( vec.size() == 3 ); 9312855Sgabeblack@google.com 9412855Sgabeblack@google.com sc_assert( sc_find_event("top.obj_ev") == &obj->ev ); 9512855Sgabeblack@google.com 9612855Sgabeblack@google.com Object obj2("ev2"); // Name clash 9712855Sgabeblack@google.com 9812855Sgabeblack@google.com vec = this->get_child_events(); 9912855Sgabeblack@google.com sc_assert( vec.size() == 4 ); 10012855Sgabeblack@google.com 10112855Sgabeblack@google.com SC_THREAD(T); 10212855Sgabeblack@google.com } 10312855Sgabeblack@google.com 10412855Sgabeblack@google.com void T() 10512855Sgabeblack@google.com { 10612855Sgabeblack@google.com sc_event ev1("local1"); 10712855Sgabeblack@google.com sc_event ev2("local2"); 10812855Sgabeblack@google.com 10912855Sgabeblack@google.com sc_process_handle handle = sc_get_current_process_handle(); 11012855Sgabeblack@google.com std::string proc_name = handle.name(); 11112855Sgabeblack@google.com 11212855Sgabeblack@google.com sc_assert( ev1.in_hierarchy() ); 11312855Sgabeblack@google.com sc_assert( ev1.get_parent_object() == handle.get_process_object() ); 11412855Sgabeblack@google.com sc_assert( std::string(ev1.name()) == proc_name + ".local1" ); 11512855Sgabeblack@google.com sc_assert( std::string(ev1.basename()) == "local1" ); 11612855Sgabeblack@google.com sc_assert( sc_hierarchical_name_exists(ev1.name()) ); 11712855Sgabeblack@google.com 11812855Sgabeblack@google.com sc_assert( ev2.in_hierarchy() ); 11912855Sgabeblack@google.com sc_assert( ev2.get_parent_object() == handle.get_process_object() ); 12012855Sgabeblack@google.com sc_assert( std::string(ev2.name()) == proc_name + ".local2" ); 12112855Sgabeblack@google.com sc_assert( std::string(ev2.basename()) == "local2" ); 12212855Sgabeblack@google.com sc_assert( sc_hierarchical_name_exists(ev2.name()) ); 12312855Sgabeblack@google.com 12412855Sgabeblack@google.com std::vector<sc_event*> vec = handle.get_child_events(); 12512855Sgabeblack@google.com sc_assert( vec.size() == 2 ); 12612855Sgabeblack@google.com sc_assert( vec[0] == &ev1 ); 12712855Sgabeblack@google.com sc_assert( vec[1] == &ev2 ); 12812855Sgabeblack@google.com 12912855Sgabeblack@google.com sc_assert( sc_find_event(ev1.name()) == &ev1 ); 13012855Sgabeblack@google.com sc_assert( sc_find_event(ev2.name()) == &ev2 ); 13112855Sgabeblack@google.com 13212855Sgabeblack@google.com T_done = true; 13312855Sgabeblack@google.com } 13412855Sgabeblack@google.com 13512855Sgabeblack@google.com SC_HAS_PROCESS(Top); 13612855Sgabeblack@google.com}; 13712855Sgabeblack@google.com 13812855Sgabeblack@google.comint sc_main(int argc, char* argv[]) 13912855Sgabeblack@google.com{ 14012855Sgabeblack@google.com std::vector<sc_object*> vec_o; 14112855Sgabeblack@google.com vec_o = sc_get_top_level_objects(); 14212855Sgabeblack@google.com sc_assert( vec_o.size() == 0 ); 14312855Sgabeblack@google.com 14412855Sgabeblack@google.com std::vector<sc_event*> vec_e; 14512855Sgabeblack@google.com vec_e = sc_get_top_level_events(); 14612855Sgabeblack@google.com sc_assert( vec_e.size() == 0 ); 14712855Sgabeblack@google.com 14812855Sgabeblack@google.com sc_event ev("foo"); 14912855Sgabeblack@google.com 15012855Sgabeblack@google.com sc_assert( ev.in_hierarchy() ); 15112855Sgabeblack@google.com sc_assert( ev.get_parent_object() == 0 ); 15212855Sgabeblack@google.com sc_assert( std::string(ev.name()) == "foo" ); 15312855Sgabeblack@google.com sc_assert( std::string(ev.basename()) == "foo" ); 15412855Sgabeblack@google.com sc_assert( sc_hierarchical_name_exists("foo") ); 15512855Sgabeblack@google.com 15612855Sgabeblack@google.com vec_o = sc_get_top_level_objects(); 15712855Sgabeblack@google.com sc_assert( vec_o.size() == 0 ); 15812855Sgabeblack@google.com vec_e = sc_get_top_level_events(); 15912855Sgabeblack@google.com sc_assert( vec_e.size() == 1 ); 16012855Sgabeblack@google.com sc_assert( vec_e[0] == &ev ); 16112855Sgabeblack@google.com sc_assert( std::string(vec_e[0]->name()) == "foo" ); 16212855Sgabeblack@google.com 16312855Sgabeblack@google.com sc_assert( sc_find_event("foo") == &ev ); 16412855Sgabeblack@google.com 16512855Sgabeblack@google.com Top top("top"); 16612855Sgabeblack@google.com sc_assert( sc_hierarchical_name_exists("top") ); 16712855Sgabeblack@google.com sc_assert( sc_hierarchical_name_exists("top.ev2") ); 16812855Sgabeblack@google.com sc_assert( sc_hierarchical_name_exists("top.sig") ); 16912855Sgabeblack@google.com sc_assert( sc_hierarchical_name_exists("top.obj") ); 17012855Sgabeblack@google.com sc_assert( sc_hierarchical_name_exists("top.obj_ev") ); 17112855Sgabeblack@google.com sc_assert( !sc_hierarchical_name_exists("woowoo") ); 17212855Sgabeblack@google.com sc_assert( !sc_hierarchical_name_exists("top.woowoo") ); 17312855Sgabeblack@google.com 17412855Sgabeblack@google.com sc_event ev2; 17512855Sgabeblack@google.com 17612855Sgabeblack@google.com sc_assert( ev2.in_hierarchy() ); 17712855Sgabeblack@google.com sc_assert( ev2.get_parent_object() == 0 ); 17812855Sgabeblack@google.com sc_assert( std::string(ev2.name()).substr(0,5) == "event" ); 17912855Sgabeblack@google.com sc_assert( std::string(ev2.basename()).substr(0,5) == "event" ); 18012855Sgabeblack@google.com sc_assert( sc_hierarchical_name_exists(ev2.name()) ); 18112855Sgabeblack@google.com 18212855Sgabeblack@google.com vec_e = sc_get_top_level_events(); 18312855Sgabeblack@google.com sc_assert( vec_e.size() == 2); 18412855Sgabeblack@google.com 18512855Sgabeblack@google.com sc_event ev3("top"); // Name clash 18612855Sgabeblack@google.com vec_e = sc_get_top_level_events(); 18712855Sgabeblack@google.com sc_assert( vec_e.size() == 3); 18812855Sgabeblack@google.com vec_o = sc_get_top_level_objects(); 18912855Sgabeblack@google.com sc_assert( vec_o.size() == 1 ); 19012855Sgabeblack@google.com 19112855Sgabeblack@google.com sc_assert( sc_find_event(ev3.name()) == &ev3 ); 19212855Sgabeblack@google.com 19312855Sgabeblack@google.com sc_signal<bool> sig; // Kernel events should not be hierarchically named 19412855Sgabeblack@google.com vec_e = sc_get_top_level_events(); 19512855Sgabeblack@google.com sc_assert( vec_e.size() == 3 ); 19612855Sgabeblack@google.com vec_o = sc_get_top_level_objects(); 19712855Sgabeblack@google.com sc_assert( vec_o.size() == 2 ); 19812855Sgabeblack@google.com 19912855Sgabeblack@google.com sc_start(); 20012855Sgabeblack@google.com 20112855Sgabeblack@google.com sc_assert( top.T_done ); 20212855Sgabeblack@google.com 20312855Sgabeblack@google.com cout << endl << "There should be two name clashes reported above" << endl; 20412855Sgabeblack@google.com cout << endl << "Success" << endl; 20512855Sgabeblack@google.com return 0; 20612855Sgabeblack@google.com} 20712855Sgabeblack@google.com 208