Last change
on this file since 51 was
35,
checked in by buchmann, 15 years ago
|
Code cleanup.
Add --dynamiclink option to systemcass executable.
|
File size:
1.3 KB
|
Line | |
---|
1 | #include <systemc.h> |
---|
2 | #include <iostream> |
---|
3 | #include <cstring> |
---|
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 |
---|
20 | |
---|
21 | |
---|
22 | using namespace std; |
---|
23 | |
---|
24 | static int errnum = 0; |
---|
25 | |
---|
26 | void |
---|
27 | check_time (int i) |
---|
28 | { |
---|
29 | const sc_time &t = sc_time_stamp (); |
---|
30 | CERR(i); |
---|
31 | CERR(t.to_double()); |
---|
32 | #ifdef SYSTEMCASS_SPECIFIC |
---|
33 | ASSERT((int) (t.to_double ()) == i); |
---|
34 | #else |
---|
35 | ASSERT((int) (t.to_double ()) == i * 1000); |
---|
36 | #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; |
---|
43 | #ifdef SYSTEMCASS_SPECIFIC |
---|
44 | unit = "NS"; |
---|
45 | #else |
---|
46 | if (i == 0) |
---|
47 | unit = "s"; |
---|
48 | else if (i < 1000) |
---|
49 | unit = "ns"; |
---|
50 | else |
---|
51 | unit = "ns"; |
---|
52 | #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); |
---|
57 | } |
---|
58 | |
---|
59 | int |
---|
60 | sc_main (int argc, char ** argv) |
---|
61 | { |
---|
62 | sc_clock clk ("clock"); |
---|
63 | |
---|
64 | check_time (0); |
---|
65 | sc_start (0); |
---|
66 | |
---|
67 | check_time (0); |
---|
68 | sc_start (1); |
---|
69 | check_time (1); |
---|
70 | |
---|
71 | sc_start (15); |
---|
72 | check_time (16); |
---|
73 | |
---|
74 | sc_start (7); |
---|
75 | check_time (23); |
---|
76 | |
---|
77 | sc_start (100); |
---|
78 | check_time (123); |
---|
79 | |
---|
80 | sc_start (1000); |
---|
81 | check_time (1123); |
---|
82 | cerr << "Test OK.\n"; |
---|
83 | return 0; |
---|
84 | } |
---|
85 | |
---|
Note: See
TracBrowser
for help on using the repository browser.