Last change
on this file since 56 was
55,
checked in by meunier, 11 years ago
|
Tried to clean the test_regression directory:
- Code formatting
- Supressed warnings
- Made comprehensible outputs
- Factorized Makefiles
There's still a lot to do (many tests don't pass for either good or bad reasons)
|
File size:
2.0 KB
|
Line | |
---|
1 | |
---|
2 | |
---|
3 | #include <iostream> |
---|
4 | |
---|
5 | #include "systemc.h" |
---|
6 | #include "test.h" |
---|
7 | |
---|
8 | using namespace std; |
---|
9 | |
---|
10 | |
---|
11 | struct observer : sc_module { |
---|
12 | sc_in_clk clk; |
---|
13 | |
---|
14 | sc_in<int> i; |
---|
15 | |
---|
16 | void f() {} |
---|
17 | |
---|
18 | SC_HAS_PROCESS(observer); |
---|
19 | observer(sc_module_name) : clk("clk"), i("i") { |
---|
20 | SC_METHOD(f); |
---|
21 | sensitive << clk.pos(); |
---|
22 | dont_initialize(); |
---|
23 | } |
---|
24 | |
---|
25 | }; |
---|
26 | |
---|
27 | |
---|
28 | struct generator : sc_module { |
---|
29 | sc_in_clk clk; |
---|
30 | |
---|
31 | sc_out<int> o; |
---|
32 | sc_in<int> i; |
---|
33 | |
---|
34 | void f() { |
---|
35 | int t = (int) (sc_time_stamp ().to_double()); |
---|
36 | o.write(t); |
---|
37 | } |
---|
38 | |
---|
39 | SC_HAS_PROCESS(generator); |
---|
40 | generator(sc_module_name) : clk ("clk"), o("o") { |
---|
41 | SC_METHOD(f); |
---|
42 | sensitive << clk.neg(); |
---|
43 | dont_initialize(); |
---|
44 | #ifdef SYSTEMCASS_SPECIFIC |
---|
45 | o(i); |
---|
46 | #endif |
---|
47 | } |
---|
48 | |
---|
49 | }; |
---|
50 | |
---|
51 | |
---|
52 | |
---|
53 | struct top_level : sc_module { |
---|
54 | sc_in_clk clk; |
---|
55 | |
---|
56 | sc_out<int> o; |
---|
57 | sc_in <int> i; |
---|
58 | |
---|
59 | generator g; |
---|
60 | observer obs1, obs2; |
---|
61 | |
---|
62 | SC_HAS_PROCESS(top_level); |
---|
63 | top_level(sc_module_name) : |
---|
64 | clk ("clk"), |
---|
65 | o("o"), |
---|
66 | i("i"), |
---|
67 | g("generator"), |
---|
68 | obs1("observer1"), |
---|
69 | obs2("observer2") { |
---|
70 | g.clk(clk); |
---|
71 | obs1.clk(clk); |
---|
72 | obs2.clk(clk); |
---|
73 | |
---|
74 | g.i(i); |
---|
75 | g.o(o); |
---|
76 | obs1.i(o); |
---|
77 | obs2.i(o); |
---|
78 | |
---|
79 | #ifdef SYSTEMCASS_SPECIFIC |
---|
80 | o (i); |
---|
81 | g.o(obs1.i); // <----- wrong declaration that needs detection |
---|
82 | #endif |
---|
83 | } |
---|
84 | }; |
---|
85 | |
---|
86 | |
---|
87 | int sc_main (int argc, char ** argv) { |
---|
88 | sc_clock clk("top_clk"); |
---|
89 | sc_signal<int> out("top_out"); |
---|
90 | sc_signal<int> in ("top_in"); |
---|
91 | |
---|
92 | top_level t("top_level"); |
---|
93 | |
---|
94 | t.clk(clk); |
---|
95 | t.o(out); |
---|
96 | t.i(in); |
---|
97 | |
---|
98 | sc_start(sc_time(0, sc_core::SC_NS)); |
---|
99 | |
---|
100 | /* simulation */ |
---|
101 | int i = 0; |
---|
102 | while (i++ < 5) { |
---|
103 | sc_start(sc_time(1, sc_core::SC_NS)); |
---|
104 | ASSERT(out.read() == t.obs1.i.read()); |
---|
105 | ASSERT(out.read() == t.obs2.i.read()); |
---|
106 | } |
---|
107 | |
---|
108 | cout << "OK" << endl; |
---|
109 | return 0; |
---|
110 | } |
---|
111 | |
---|
112 | |
---|
113 | /* |
---|
114 | # Local Variables: |
---|
115 | # tab-width: 4; |
---|
116 | # c-basic-offset: 4; |
---|
117 | # c-file-offsets:((innamespace . 0)(inline-open . 0)); |
---|
118 | # indent-tabs-mode: nil; |
---|
119 | # End: |
---|
120 | # |
---|
121 | # vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
122 | */ |
---|
123 | |
---|
Note: See
TracBrowser
for help on using the repository browser.