From 16fa8d7cc8c92f5ab879e4cf9c6c0bbb3567860f Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Thu, 24 May 2018 01:37:55 -0700 Subject: systemc: Import tests from the Accellera systemc distribution. Change-Id: Iad76b398949a55d768a34d027a2d8e3739953da6 Reviewed-on: https://gem5-review.googlesource.com/10845 Reviewed-by: Giacomo Travaglini Maintainer: Gabe Black --- .../tests/systemc/datatypes/misc/test03/test03.cpp | 131 +++++++++++++++++++++ 1 file changed, 131 insertions(+) create mode 100644 src/systemc/tests/systemc/datatypes/misc/test03/test03.cpp (limited to 'src/systemc/tests/systemc/datatypes/misc/test03/test03.cpp') diff --git a/src/systemc/tests/systemc/datatypes/misc/test03/test03.cpp b/src/systemc/tests/systemc/datatypes/misc/test03/test03.cpp new file mode 100644 index 000000000..b7f916347 --- /dev/null +++ b/src/systemc/tests/systemc/datatypes/misc/test03/test03.cpp @@ -0,0 +1,131 @@ +/***************************************************************************** + + Licensed to Accellera Systems Initiative Inc. (Accellera) under one or + more contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright ownership. + Accellera licenses this file to you under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with the + License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied. See the License for the specific language governing + permissions and limitations under the License. + + *****************************************************************************/ + +/***************************************************************************** + + test03.cpp -- + + Original Author: Martin Janssen, Synopsys, Inc., 2002-03-19 + + *****************************************************************************/ + +/***************************************************************************** + + MODIFICATION LOG - modifiers, enter your name, affiliation, date and + changes you are making here. + + Name, Affiliation, Date: + Description of Modification: + + *****************************************************************************/ + +// test of sc_length_param and sc_length_context and their use in the datatype +// base classes. + +#include "systemc.h" + +void +test_sc_length_param() +{ + cout << "\n*** test_sc_length_param ***" << endl; + + sc_length_param a; + cout << a << endl; + + sc_length_param b( 5 ); + cout << b << endl; + + try { + sc_length_param c( -1 ); + cout << c << endl; + } catch( sc_report x ) { + cout << "\nException caught" << endl; + cout << x.what() << endl; + } + + sc_length_param d( b ); + cout << d << endl; + + sc_dt::sc_without_context foo; + sc_length_param e( foo ); + cout << e << endl; + + e = b; + cout << e << endl; + + cout << (e == b) << endl; + cout << (e != b) << endl; + + cout << e.len() << endl; + e.len( 42 ); + cout << e.len() << endl; + + cout << e.to_string() << endl; + + e.print(); + cout << endl; + e.dump(); +} + +#define TEST_DEFAULT_CTOR(tp) \ +{ \ + cout << "\n" << #tp << endl; \ + \ + tp a; \ + cout << a.length() << endl; \ + \ + sc_length_context con1( sc_length_param( 5 ) ); \ + tp b; \ + cout << b.length() << endl; \ + \ + sc_length_context con2( sc_length_param( 42 ) ); \ + tp c; \ + cout << c.length() << endl; \ + \ + con2.end(); \ + tp d; \ + cout << d.length() << endl; \ + \ + con1.end(); \ + tp e; \ + cout << e.length() << endl; \ +} + +void +test_default_ctors() +{ + cout << "\n*** test_default_ctors ***" << endl; + + TEST_DEFAULT_CTOR(sc_bv_base); + TEST_DEFAULT_CTOR(sc_lv_base); + + TEST_DEFAULT_CTOR(sc_int_base); + TEST_DEFAULT_CTOR(sc_uint_base); + TEST_DEFAULT_CTOR(sc_signed); + TEST_DEFAULT_CTOR(sc_unsigned); +} + +int +sc_main( int, char*[] ) +{ + test_sc_length_param(); + test_default_ctors(); + + return 0; +} -- cgit v1.2.3