test01.cpp revision 12855:588919e0e4aa
14202Sbinkertn@umich.edu/***************************************************************************** 24202Sbinkertn@umich.edu 34202Sbinkertn@umich.edu Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 44202Sbinkertn@umich.edu more contributor license agreements. See the NOTICE file distributed 54202Sbinkertn@umich.edu with this work for additional information regarding copyright ownership. 64202Sbinkertn@umich.edu Accellera licenses this file to you under the Apache License, Version 2.0 74202Sbinkertn@umich.edu (the "License"); you may not use this file except in compliance with the 84202Sbinkertn@umich.edu License. You may obtain a copy of the License at 94202Sbinkertn@umich.edu 104202Sbinkertn@umich.edu http://www.apache.org/licenses/LICENSE-2.0 114202Sbinkertn@umich.edu 124202Sbinkertn@umich.edu Unless required by applicable law or agreed to in writing, software 134202Sbinkertn@umich.edu distributed under the License is distributed on an "AS IS" BASIS, 144202Sbinkertn@umich.edu WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 154202Sbinkertn@umich.edu implied. See the License for the specific language governing 164202Sbinkertn@umich.edu permissions and limitations under the License. 174202Sbinkertn@umich.edu 184202Sbinkertn@umich.edu *****************************************************************************/ 194202Sbinkertn@umich.edu 204202Sbinkertn@umich.edu/***************************************************************************** 214202Sbinkertn@umich.edu 224202Sbinkertn@umich.edu test01.cpp -- 234202Sbinkertn@umich.edu 244202Sbinkertn@umich.edu Original Author: Martin Janssen, Synopsys, Inc., 2002-02-15 254202Sbinkertn@umich.edu 264202Sbinkertn@umich.edu *****************************************************************************/ 274202Sbinkertn@umich.edu 284202Sbinkertn@umich.edu/***************************************************************************** 294202Sbinkertn@umich.edu 304202Sbinkertn@umich.edu MODIFICATION LOG - modifiers, enter your name, affiliation, date and 314202Sbinkertn@umich.edu changes you are making here. 324202Sbinkertn@umich.edu 339157Sandreas.hansson@arm.com Name, Affiliation, Date: 3410259SAndrew.Bardsley@arm.com Description of Modification: 354486Sbinkertn@umich.edu 369793Sakash.bagdia@arm.com *****************************************************************************/ 379827Sakash.bagdia@arm.com 389850Sandreas.hansson@arm.com// test of sc_time's methods 3910249Sstephan.diestelhorst@arm.com 4010268SGeoffrey.Blake@arm.com#include "systemc.h" 414486Sbinkertn@umich.edu 428774Sgblack@eecs.umich.eduvoid 434202Sbinkertn@umich.edutest_print() 444202Sbinkertn@umich.edu{ 4510458Sandreas.hansson@arm.com cout << "test_print" << endl; 4610458Sandreas.hansson@arm.com 4710458Sandreas.hansson@arm.com sc_time t1; 484202Sbinkertn@umich.edu cout << t1 << endl; 4910453SAndrew.Bardsley@arm.com 504202Sbinkertn@umich.edu uint64 v = 1230; 519983Sstever@gmail.com sc_time t2 = sc_time::from_value( v ); 5210453SAndrew.Bardsley@arm.com cout << t2 << endl; 5310453SAndrew.Bardsley@arm.com 548233Snate@binkert.org v *= 10000; 554202Sbinkertn@umich.edu sc_time t3 = sc_time::from_value( v ); 564202Sbinkertn@umich.edu cout << t3 << endl; 579342SAndreas.Sandberg@arm.com 584202Sbinkertn@umich.edu v *= 100; 594202Sbinkertn@umich.edu sc_time t4 = sc_time::from_value( v ); 6010268SGeoffrey.Blake@arm.com cout << t4 << endl; 6110259SAndrew.Bardsley@arm.com 624202Sbinkertn@umich.edu v *= 10000; 634202Sbinkertn@umich.edu sc_time t5 = sc_time::from_value( v ); 6410453SAndrew.Bardsley@arm.com cout << t5 << endl; 659793Sakash.bagdia@arm.com 669827Sakash.bagdia@arm.com v *= 100; 679850Sandreas.hansson@arm.com sc_time t6 = sc_time::from_value( v ); 6810249Sstephan.diestelhorst@arm.com cout << t6 << endl; 697768SAli.Saidi@ARM.com 709850Sandreas.hansson@arm.com v *= 10000; 719850Sandreas.hansson@arm.com sc_time t7 = sc_time::from_value( v ); 728766Sgblack@eecs.umich.edu cout << t7 << endl; 737768SAli.Saidi@ARM.com} 748766Sgblack@eecs.umich.edu 7510930Sbrandon.potter@amd.comvoid 767768SAli.Saidi@ARM.comtest_constructors() 779850Sandreas.hansson@arm.com{ 784486Sbinkertn@umich.edu cout << "test_constructors" << endl; 798335Snate@binkert.org 808335Snate@binkert.org sc_time t1; 8110458Sandreas.hansson@arm.com cout << t1 << endl; 829152Satgutier@umich.edu 838335Snate@binkert.org sc_time t2a( 0, SC_SEC ); 848335Snate@binkert.org cout << t2a << endl; 858335Snate@binkert.org 868335Snate@binkert.org sc_time t2b( 1.2345, SC_NS ); 878335Snate@binkert.org cout << t2b << endl; 888335Snate@binkert.org sc_time t2c( 1.2341, SC_NS ); 898335Snate@binkert.org cout << t2c << endl; 909733Sandreas@sandberg.pp.se 918335Snate@binkert.org sc_time t2d( 1, SC_FS ); 928335Snate@binkert.org cout << t2d << endl; 938335Snate@binkert.org 948335Snate@binkert.org sc_time t2e( -1.2345, SC_NS ); 958335Snate@binkert.org cout << t2e << endl; 968335Snate@binkert.org sc_time t2f( -1.2341, SC_NS ); 978335Snate@binkert.org cout << t2f << endl; 989793Sakash.bagdia@arm.com 999827Sakash.bagdia@arm.com char v1 = 1; 10010249Sstephan.diestelhorst@arm.com signed char v2 = 2; 101 unsigned char v3 = 3; 102 short v4 = 4; 103 unsigned short v5 = 5; 104 int v6 = 6; 105 unsigned int v7 = 7; 106 long v8 = 8; 107 unsigned long v9 = 9; 108 float v10 = 10; 109 double v11 = 11; 110 111 sc_time t2g( v1, SC_NS ); 112 cout << t2g << endl; 113 sc_time t2h( v2, SC_NS ); 114 cout << t2h << endl; 115 sc_time t2i( v3, SC_NS ); 116 cout << t2i << endl; 117 sc_time t2j( v4, SC_NS ); 118 cout << t2j << endl; 119 sc_time t2k( v5, SC_NS ); 120 cout << t2k << endl; 121 sc_time t2l( v6, SC_NS ); 122 cout << t2l << endl; 123 sc_time t2m( v7, SC_NS ); 124 cout << t2m << endl; 125 sc_time t2n( v8, SC_NS ); 126 cout << t2n << endl; 127 sc_time t2o( v9, SC_NS ); 128 cout << t2o << endl; 129 sc_time t2p( v10, SC_NS ); 130 cout << t2p << endl; 131 sc_time t2q( v11, SC_NS ); 132 cout << t2q << endl; 133 134 sc_time t3a( 0, SC_SEC ); 135 cout << t3a << endl; 136 137 sc_time t3b( 1.2341, true ); 138 cout << t3b << endl; 139 sc_time t3c( 1.2345, true ); 140 cout << t3c << endl; 141 sc_time t3d( -1.2341, true ); 142 cout << t3d << endl; 143 sc_time t3e( -1.2345, true ); 144 cout << t3e << endl; 145 146 sc_time t3f( 1.2345, false ); 147 cout << t3f << endl; 148 sc_time t3g( 1.5432, false ); 149 cout << t3g << endl; 150 sc_time t3h( -1.2345, false ); 151 cout << t3h << endl; 152 sc_time t3i( -1.5432, false ); 153 cout << t3i << endl; 154 155#if !defined( _MSC_VER ) 156 sc_time t4a( 0ull, true ); 157 cout << t4a << endl; 158 sc_time t4b( 25ull, true ); 159 cout << t4b << endl; 160 sc_time t4c( 25ull, false ); 161 cout << t4c << endl; 162#else 163 sc_time t4a( 0ui64, true ); 164 cout << t4a << endl; 165 sc_time t4b( 25ui64, true ); 166 cout << t4b << endl; 167 sc_time t4c( 25ui64, false ); 168 cout << t4c << endl; 169#endif 170 171 sc_time t5( t4c ); 172 cout << t5 << endl; 173} 174 175void 176test_assignment() 177{ 178 cout << "test_assignment" << endl; 179 180 sc_time t1; 181 182 sc_time t2; 183 t1 = t2; 184 cout << t1 << endl; 185 186 sc_time t3( 1.2345, SC_NS ); 187 t1 = t3; 188 cout << t1 << endl; 189 190 sc_time t4( -1.5432, SC_NS ); 191 t1 = t4; 192 cout << t1 << endl; 193} 194 195void 196test_conversion() 197{ 198 cout << "test_conversion" << endl; 199 200 sc_time t1; 201 cout << t1.value() << endl; 202 cout << t1.to_double() << endl; 203 cout << t1 << endl; 204 cout << t1.to_seconds() << endl; 205 206 sc_time t2( 1.2345, SC_US ); 207 cout << t2.value() << endl; 208 cout << t2.to_double() << endl; 209 cout << t2 << endl; 210 cout << t2.to_seconds() << endl; 211 212 sc_time t3( -1.5432, SC_NS ); 213 cout << t3.value() << endl; 214 cout << t3.to_double() << endl; 215 cout << t3 << endl; 216 cout << t3.to_seconds() << endl; 217} 218 219void 220test_relational() 221{ 222 cout << "test_relational" << endl; 223 224 sc_time t1; 225 sc_time t2( 1, SC_FS ); 226 sc_time t3( 1.2345, SC_NS ); 227 sc_time t4( 1.2341, SC_NS ); 228 sc_time t5( -1.5432, SC_NS ); 229 230 cout << ( t1 == t2 ) << endl; 231 cout << ( t1 != t2 ) << endl; 232 cout << ( t1 < t2 ) << endl; 233 cout << ( t1 <= t2 ) << endl; 234 cout << ( t1 > t2 ) << endl; 235 cout << ( t1 >= t2 ) << endl; 236 237 cout << ( t3 == t4 ) << endl; 238 cout << ( t3 != t4 ) << endl; 239 cout << ( t3 < t4 ) << endl; 240 cout << ( t3 <= t4 ) << endl; 241 cout << ( t3 > t4 ) << endl; 242 cout << ( t3 >= t4 ) << endl; 243 244 cout << ( t1 == t5 ) << endl; 245 cout << ( t1 != t5 ) << endl; 246 cout << ( t1 < t5 ) << endl; 247 cout << ( t1 <= t5 ) << endl; 248 cout << ( t1 > t5 ) << endl; 249 cout << ( t1 >= t5 ) << endl; 250} 251 252void 253test_arithmetic() 254{ 255 cout << "test_arithmetic" << endl; 256 257 sc_time t1; 258 sc_time t2( 1, SC_FS ); 259 sc_time t3( 1.2345, SC_NS ); 260 sc_time t4( 1.2341, SC_NS ); 261 sc_time t5( -1.5432, SC_NS ); 262 263 cout << ( t1 + t2 ) << endl; 264 cout << ( t1 + t3 ) << endl; 265 cout << ( t1 + t5 ) << endl; 266 cout << ( t3 + t2 ) << endl; 267 cout << ( t3 + t4 ) << endl; 268 cout << ( t3 + t5 ) << endl; 269 cout << ( t5 + t5 ) << endl; 270 271 cout << ( t1 - t2 ) << endl; 272 cout << ( t1 - t3 ) << endl; 273 cout << ( t1 - t5 ) << endl; 274 cout << ( t3 - t4 ) << endl; 275 cout << ( t3 - t5 ) << endl; 276 cout << ( t5 - t5 ) << endl; 277 278 cout << ( t1 * 1.2345 ) << endl; 279 cout << ( 1.2345 * t3 ) << endl; 280 cout << ( t4 * 2 ) << endl; 281 282 cout << ( t1 / 1.2345 ) << endl; 283 cout << ( t4 / 2 ) << endl; 284 cout << ( t3 / t4 ) << endl; 285 286 cout << ( t2 += t3 ) << endl; 287 cout << ( t2 -= t4 ) << endl; 288 cout << ( t2 *= 1.2345 ) << endl; 289 cout << ( t2 /= 2 ) << endl; 290} 291 292void 293test_SC_ZERO_TIME() 294{ 295 cout << "test_SC_ZERO_TIME" << endl; 296 297 cout << SC_ZERO_TIME << endl; 298} 299 300int 301sc_main( int, char*[] ) 302{ 303#if defined(_MSC_VER) && _MSC_VER < 1900 304 _set_output_format(_TWO_DIGIT_EXPONENT); 305#endif 306 test_print(); 307 test_constructors(); 308 test_assignment(); 309 test_conversion(); 310 test_relational(); 311 test_arithmetic(); 312 test_SC_ZERO_TIME(); 313 314 return 0; 315} 316