Changeset 55 for sources/test_regression/28102005/system.cpp
- Timestamp:
- May 28, 2013, 11:17:14 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/test_regression/28102005/system.cpp
r35 r55 1 #include <systemc.h> 1 2 2 #include <iostream> 3 3 #include <cstring> 4 4 5 #define ASSERT(x) \ 6 { errnum++; \ 7 if (!(x)) \ 8 { \ 9 cerr << "ASSERT : " #x "\n"; \ 10 exit (errnum); \ 11 } \ 12 } 13 14 #ifdef DEBUG 15 #define CERR(x) \ 16 { cerr << "" #x " = " << x << "\n"; } 17 #else 18 #define CERR(x) 19 #endif 5 #include "systemc.h" 6 #include "test.h" 20 7 21 8 22 9 using namespace std; 23 10 24 static int errnum = 0;25 11 26 void 27 check_time (int i) 28 { 29 const sc_time &t = sc_time_stamp (); 30 CERR(i); 31 CERR(t.to_double()); 12 void check_time(int i) { 13 const sc_time & t = sc_time_stamp(); 14 cout << i << endl; 15 32 16 #ifdef SYSTEMCASS_SPECIFIC 33 ASSERT((int) (t.to_double()) == i);17 ASSERT((int) (t.to_double()) == i); 34 18 #else 35 ASSERT((int) (t.to_double()) == i * 1000);19 ASSERT((int) (t.to_double()) == i * 1000); 36 20 #endif 37 CERR(t.to_seconds ()); 38 double seconds = t.to_seconds()*1000000000; 39 CERR(seconds); 40 ASSERT(((int)seconds) == i); 41 char s[256]; 42 const char *unit; 21 22 cout << t.to_seconds() << endl; 23 double seconds = t.to_seconds() * 1000000000; 24 cout << seconds << endl; 25 ASSERT(((int) seconds) == i); 26 char s[256]; 27 const char * unit; 28 43 29 #ifdef SYSTEMCASS_SPECIFIC 44 unit = "NS";30 unit = "NS"; 45 31 #else 46 if (i == 0)47 unit = "s";48 else if (i < 1000)49 unit = "ns";50 else51 unit = "ns";32 if (i == 0) { 33 unit = "s"; 34 } 35 else { 36 unit = "ns"; 37 } 52 38 #endif 53 sprintf (s, "%d %s", i,unit); 54 CERR(s);55 CERR(t.to_string()); 56 ASSERT(strcmp (t.to_string ().c_str(), s)== 0);39 40 sprintf(s, "%d %s", i, unit); 41 42 ASSERT(strcmp(t.to_string().c_str(), s) == 0); 57 43 } 58 44 59 int60 sc_main (int argc, char ** argv)61 {62 sc_clock clk ("clock");63 45 64 check_time (0); 65 sc_start (0);46 int sc_main (int argc, char ** argv) { 47 sc_clock clk("clock"); 66 48 67 check_time (0); 68 sc_start (1); 69 check_time (1); 49 check_time(0); 50 sc_start(sc_time(0, sc_core::SC_NS)); 70 51 71 sc_start (15); 72 check_time (16); 52 check_time(0); 53 sc_start(sc_time(1, sc_core::SC_NS)); 54 check_time(1); 73 55 74 sc_start (7);75 check_time (23);56 sc_start(sc_time(15, sc_core::SC_NS)); 57 check_time(16); 76 58 77 sc_start (100);78 check_time (123);59 sc_start(sc_time(7, sc_core::SC_NS)); 60 check_time(23); 79 61 80 sc_start (1000); 81 check_time (1123); 82 cerr << "Test OK.\n"; 83 return 0; 62 sc_start(sc_time(100, sc_core::SC_NS)); 63 check_time(123); 64 65 sc_start(sc_time(1000, sc_core::SC_NS)); 66 check_time(1123); 67 68 return 0; 84 69 } 85 70 71 72 /* 73 # Local Variables: 74 # tab-width: 4; 75 # c-basic-offset: 4; 76 # c-file-offsets:((innamespace . 0)(inline-open . 0)); 77 # indent-tabs-mode: nil; 78 # End: 79 # 80 # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 81 */ 82
Note: See TracChangeset
for help on using the changeset viewer.