source: sources/test_regression/16062005a/system.cpp @ 55

Last change on this file since 55 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: 3.3 KB
Line 
1
2#include <iostream>
3#include <fstream>
4#include <vector>
5
6#include "systemc.h"
7#include "test.h"
8
9
10using namespace std;
11
12struct D : sc_module {
13    D(sc_module_name) {}
14};
15
16
17
18struct C : sc_module {
19    C(sc_module_name) {}
20};
21
22
23struct B : sc_module {
24    D d1;
25    D d2;
26    C c;
27    B(sc_module_name) : d1("d1"), d2("d2"), c("c") {}
28};
29
30
31struct A : sc_module {
32    B b;
33    C c;
34    A(sc_module_name) : b("b"), c("c") {}
35};
36
37
38struct top_level1 : sc_module {
39    A a;
40    D d;
41    top_level1(sc_module_name) : a("a"), d("d") {}
42};
43
44
45struct top_level2 : sc_module {
46    B b1;
47    B b2;
48    C c;
49    top_level2(sc_module_name) : b1("b1"), b2("b2"), c("c") {}
50};
51
52
53void dump_hierarchy(ostream & o, sc_object * obj) {
54    const vector<sc_object *> & children = obj->get_child_objects();
55    for (unsigned i = 0; i < children.size(); i++) {
56        if (children[i]) {
57            dump_hierarchy(o, children[i]);
58        }
59    }
60    o << obj->name() << " " << obj->kind() << endl;
61}
62
63
64void dump_hierarchy (ostream & o, const vector<sc_object *> & obj_list) {
65    for (unsigned i = 0; i < obj_list.size(); i++) {
66        dump_hierarchy(o, obj_list[i]);
67    }
68}
69
70
71int sc_main (int argc, char ** argv) {
72    if (argc < 2) {
73        cerr << "Usage : " << argv[0] << " <filename>\n";
74        exit(-1);
75    }
76
77    sc_clock clk("clock");
78    top_level1 top1("top1");
79    top_level2 top2("top2");
80
81    ofstream o;
82    o.open(argv[1],ios::out | ios::trunc);
83    if (!o.is_open()) {
84        cerr << "Unable to open '" << argv[1] << "'.\n";
85        return 1;
86    }
87
88    sc_start(sc_time(0, sc_core::SC_NS));
89    dump_hierarchy(o, sc_get_top_level_objects());
90
91    ASSERT(sc_find_object("top2.b1"    ) == &top2.b1    );
92    ASSERT(sc_find_object("top2.b1.d1" ) == &top2.b1.d1 );
93    ASSERT(sc_find_object("top2.b1.d2" ) == &top2.b1.d2 );
94    ASSERT(sc_find_object("top2.b1.c"  ) == &top2.b1.);
95    ASSERT(sc_find_object("top2.b2"    ) == &top2.b2    );
96    ASSERT(sc_find_object("top2.c"     ) == &top2.c     );
97    ASSERT(sc_find_object("top1.a"     ) == &top1.a     );
98    ASSERT(sc_find_object("top1.d"     ) == &top1.d     ); 
99    ASSERT(sc_find_object("top1.a.b"   ) == &top1.a.b   );
100    ASSERT(sc_find_object("top1.a.b.d1") == &top1.a.b.d1);
101    ASSERT(sc_find_object("top1.a.b.d2") == &top1.a.b.d2);
102    ASSERT(sc_find_object("top1.a.b.c" ) == &top1.a.b.c );
103    ASSERT(sc_find_object("top1.a.c"   ) == &top1.a.c   ); 
104    ASSERT(sc_find_object("top1.c"     ) == NULL        );
105    ASSERT(sc_find_object("top1"       )->get_parent_object() == NULL);
106    ASSERT(sc_find_object("top1.a"     )->get_parent_object() == &top1);
107    ASSERT(sc_find_object("top1.a.b"   )->get_parent_object() == &top1.a);
108    ASSERT(sc_find_object("top1.a.b.d2")->get_parent_object() == &top1.a.b);
109    ASSERT(sc_find_object("top1.d"     )->get_parent_object() == &top1);
110    ASSERT(sc_find_object("top2.b1"    )->get_parent_object() == &top2);
111    ASSERT(sc_find_object("top2.b2"    )->get_parent_object() == &top2);
112    ASSERT(sc_find_object("top2.c"     )->get_parent_object() == &top2);
113    ASSERT(sc_find_object("top2.b1.c"  )->get_parent_object() == &top2.b1);
114
115    o.close();
116
117    return 0;
118}
119
120
121/*
122# Local Variables:
123# tab-width: 4;
124# c-basic-offset: 4;
125# c-file-offsets:((innamespace . 0)(inline-open . 0));
126# indent-tabs-mode: nil;
127# End:
128#
129# vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
130*/
131
Note: See TracBrowser for help on using the repository browser.