sc_start_starvation.cpp revision 12855:588919e0e4aa
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20// sc_start_starvation.cpp -- test for 21// 22// Original Author: John Aynsley, Doulos, Inc. 23// 24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and 25// 26// $Log: sc_start_starvation.cpp,v $ 27// Revision 1.2 2011/05/08 19:18:46 acg 28// Andy Goodrich: remove extraneous + prefixes from git diff. 29// 30 31// sc_start with event starvation policy 32// sc_pending_activity and friends 33 34#define SC_INCLUDE_DYNAMIC_PROCESSES 35 36#include <systemc> 37using namespace sc_core; 38using std::cout; 39using std::endl; 40 41SC_MODULE(Top) 42{ 43 SC_CTOR(Top) 44 { 45 SC_THREAD(T); 46 } 47 48 sc_event ev2; 49 50 void T() 51 { 52 sc_assert( sc_get_status() == SC_RUNNING ); 53 54 sc_assert( sc_pending_activity_at_current_time() == false ); 55 sc_assert( sc_pending_activity_at_future_time() == true ); 56 sc_assert( sc_time_to_pending_activity() == sc_time(250, SC_NS) ); 57 58 ev2.notify(150, SC_NS); 59 60 sc_assert( sc_pending_activity_at_current_time() == false ); 61 sc_assert( sc_pending_activity_at_future_time() == true ); 62 sc_assert( sc_time_to_pending_activity() == sc_time(150, SC_NS) ); 63 } 64}; 65 66int sc_main(int argc, char* argv[]) 67{ 68 Top top("top"); 69 70 sc_event ev; 71 ev.notify(250, SC_NS); 72 73 sc_assert( sc_pending_activity_at_current_time() == false ); 74 sc_assert( sc_pending_activity_at_future_time() == true ); 75 sc_assert( sc_pending_activity() == true ); 76 sc_assert( sc_time_to_pending_activity() == sc_time(250, SC_NS) ); 77 78 sc_assert( sc_get_status() == SC_ELABORATION ); 79 sc_assert( sc_time_stamp() == SC_ZERO_TIME ); 80 sc_start(100, SC_NS); 81 sc_assert( sc_get_status() == SC_PAUSED ); 82 sc_assert( sc_time_stamp() == sc_time(100, SC_NS) ); 83 84 sc_assert( sc_pending_activity_at_current_time() == false ); 85 sc_assert( sc_pending_activity_at_future_time() == true ); 86 sc_assert( sc_time_to_pending_activity() == sc_time(50, SC_NS) ); 87 88 sc_start(10, SC_NS, SC_RUN_TO_TIME); 89 sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); 90 sc_assert( sc_time_to_pending_activity() == sc_time(40, SC_NS) ); 91 92 sc_start(10, SC_NS, SC_EXIT_ON_STARVATION); 93 sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); 94 95 sc_start(80, SC_NS, SC_EXIT_ON_STARVATION); 96 97 sc_assert( sc_time_stamp() == sc_time(150, SC_NS) ); 98 sc_assert( sc_pending_activity_at_current_time() == false ); 99 sc_assert( sc_pending_activity_at_future_time() == true ); 100 sc_assert( sc_time_to_pending_activity() == sc_time(100, SC_NS) ); 101 102 sc_start(50, SC_NS, SC_EXIT_ON_STARVATION); 103 sc_assert( sc_time_stamp() == sc_time(150, SC_NS) ); 104 sc_assert( sc_time_to_pending_activity() == sc_time(100, SC_NS) ); 105 106 sc_start(50, SC_NS, SC_RUN_TO_TIME); 107 sc_assert( sc_time_stamp() == sc_time(200, SC_NS) ); 108 sc_assert( sc_time_to_pending_activity() == sc_time(50, SC_NS) ); 109 110 sc_start(); 111 sc_assert( sc_get_status() == SC_PAUSED ); 112 sc_assert( sc_time_stamp() == sc_time(250, SC_NS) ); 113 114 sc_assert( sc_pending_activity() == false ); 115 sc_assert( sc_time_to_pending_activity() == sc_max_time() - sc_time_stamp() ); 116 117 ev.notify(SC_ZERO_TIME); 118 119 sc_assert( sc_pending_activity_at_current_time() == true ); 120 sc_assert( sc_pending_activity_at_future_time() == false ); 121 sc_assert( sc_time_to_pending_activity() == SC_ZERO_TIME ); 122 123 sc_start(); 124 sc_assert( sc_time_stamp() == sc_time(250, SC_NS) ); 125 126 sc_assert( sc_pending_activity() == false ); 127 sc_assert( sc_time_to_pending_activity() == sc_max_time() - sc_time_stamp() ); 128 129 ev.notify(10, SC_NS); 130 131 sc_assert( sc_pending_activity() == true ); 132 sc_assert( sc_time_to_pending_activity() == sc_time(10, SC_NS) ); 133 134 sc_start(); 135 sc_assert( sc_time_stamp() == sc_time(260, SC_NS) ); 136 137 ev.notify(10, SC_NS); 138 sc_start(sc_time(100, SC_NS), SC_EXIT_ON_STARVATION); 139 sc_assert( sc_time_stamp() == sc_time(270, SC_NS) ); 140 141 ev.notify(10, SC_NS); 142 sc_start(sc_time(100, SC_NS)); // SC_RUN_TO_TIME 143 sc_assert( sc_time_stamp() == sc_time(370, SC_NS) ); 144 sc_assert( sc_get_status() == SC_PAUSED ); 145 146 ev.notify(); 147 sc_assert( sc_pending_activity() == false ); 148 149 cout << endl << "Success" << endl; 150 return 0; 151} 152