source: trunk/IPs/systemC/Environment/Data/selftest/main.cpp @ 134

Last change on this file since 134 was 134, checked in by rosiere, 15 years ago

1) valgrind fix
2) debug file on/off

  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1#include <iostream>
2#include "../include/Data.h"
3
4using namespace std;
5using namespace environment;
6using namespace environment::data;
7
8#define TEST(x,y)                               \
9  {                                             \
10    cout << "Line " << __LINE__ << " : ";       \
11    if (x==y)                                   \
12      {                                         \
13        cout << "Test OK" << endl;              \
14      }                                         \
15    else                                        \
16      {                                         \
17        cout << "Test KO" << endl;              \
18        exit (EXIT_FAILURE);                    \
19      }                                         \
20  } while (0)
21   
22
23
24#ifdef SYSTEMC
25int sc_main (int argc, char * argv[])
26#else
27int    main (int argc, char * argv[])
28#endif
29{
30  cout << "<main> Begin" << endl;
31
32  {
33//     Segment * seg1 = new Segment ();
34   
35//     TEST(seg1->getType     (), TYPE_TARGET_MEMORY);
36//     TEST(seg1->getIndex    (), 0);
37//     TEST(seg1->getBase     (), 0);
38//     TEST(seg1->getSize     (), 0);
39//     TEST(seg1->getUncached (), false);
40   
41//     seg1->define_target(TYPE_TARGET_SIM2OS,4);
42//     TEST(seg1->getType     (), TYPE_TARGET_SIM2OS);
43//     TEST(seg1->getIndex    (), 4);
44   
45//     cout << *seg1 << endl;
46   
47    SEGMENT_TABLE_ENTRY * entry = new SEGMENT_TABLE_ENTRY("entry", 0x100, 0x1024, 21, 7, true);
48   
49    Segment * seg2 = new Segment (entry);
50   
51    cout << *seg2 << endl;
52   
53    TEST(seg2->test(0x100, 0x0   ), true);
54    TEST(seg2->test(0x100, 0x1024), true);
55    TEST(seg2->test(0x100, 0x1025), false);
56   
57    char * str = new char [10];
58   
59    str [0] = 'k';
60    str [1] = 'a';
61    str [2] = 'n';
62    str [3] = 'e';
63    str [4] = 'd';
64    str [5] = 'e';
65    str [6] = 'a';
66    str [7] = 'd';
67   
68    seg2->write(0x200,8,str);
69   
70    for (uint32_t i=0; i<10; i++)
71      str [i] = '.';
72   
73    for (uint32_t i=0; i<10; i++)
74      cout << str [i];
75    cout << endl;
76   
77    str [0] = 'i';
78    str [1] = 's';
79    str [2] = 'b';
80    str [3] = 'a';
81    str [4] = 'c';
82    str [5] = 'k';
83   
84    seg2->write(0x204,6,str);
85
86    for (uint32_t i=0; i<10; i++)
87      str [i] = '.';
88   
89    seg2->read(0x200,10,str);
90   
91    for (uint32_t i=0; i<10; i++)
92      cout << str [i];
93    cout << endl;
94 
95    Entity * entity1 = new Entity (false);
96    Entity * entity2 = new Entity (true, seg2);
97   
98    cout << *entity1 << endl;
99    cout << *entity2 << endl; 
100   
101    delete    entity2;
102    delete    entity1;
103    delete [] str;
104    delete    seg2;
105    delete    entry;
106//     delete    seg1;
107  }
108
109  {
110    SOCLIB_SEGMENT_TABLE * segtable = new SOCLIB_SEGMENT_TABLE;
111    segtable->setMSBNumber    (8);
112    segtable->setDefaultTarget(0,0);
113   
114    //shared data segment
115   
116    const int TEXT_BASE          = 0x0;
117    const int DATA_CACHED_BASE   = 0x10000000;
118    const int DATA_UNCACHED_BASE = 0x40000000;
119   
120    const int TEXT_SIZE          = 0x4000;
121    const int DATA_CACHED_SIZE   = 0x4000;
122    const int DATA_UNCACHED_SIZE = 0x4000;
123   
124    // Add a segment   :name        , address of base    , size               , global index , local index, uncache
125    segtable->addSegment("text"      , TEXT_BASE          , TEXT_SIZE          , 0            ,0           , false);
126    segtable->addSegment("data"      , DATA_CACHED_BASE   , DATA_CACHED_SIZE   , 0            ,0           , false);
127    segtable->addSegment("data_unc"  , DATA_UNCACHED_BASE , DATA_UNCACHED_SIZE , 0            ,0           , true );
128   
129    segtable->print();
130
131    Parameters * param = new Parameters (16,0,0,segtable);
132   
133    Data * data = new Data ("my_data", param);
134
135    cout << *data << endl;
136   
137    const char * filename = "selftest/data/soft.x";
138    const char * sections_text  []  = {".text",NULL}; 
139    const char * sections_data  []  = {".data",".rodata",".bss",".sdata",".sbss", NULL}; 
140
141    data->init("text"   , filename, sections_text);
142    data->init("data"   , filename, sections_data);
143
144    char * str = new char [8];
145   
146    data->read(0x100,8,str);
147   
148    cout << hex;
149    for (uint32_t i=0; i<8; i++)
150      {
151        if (i==4)
152          cout << endl;
153        cout << std::setw(2) << std::setfill('0') << ((static_cast<uint32_t>(str [i]))&0xff);
154      }
155    cout << dec << endl;
156
157    str [0] = 0xde;
158    str [1] = 0xad;
159    str [2] = 0xbe;
160    str [3] = 0xef;
161    str [4] = 0xba;
162    str [5] = 0xbe;
163    str [6] = 0xbe;
164    str [7] = 0xef;
165
166    data->write(0x104,8,str);
167
168    data->read(0x100,8,str);
169   
170    cout << hex;
171    for (uint32_t i=0; i<8; i++)
172      {
173        if (i==4)
174          cout << endl;
175        cout << std::setw(2) << std::setfill('0') << ((static_cast<uint32_t>(str [i]))&0xff);
176      }
177    cout << dec << endl;
178
179    data->read(0x108,8,str);
180   
181    cout << hex;
182    for (uint32_t i=0; i<8; i++)
183      {
184        if (i==4)
185          cout << endl;
186        cout << std::setw(2) << std::setfill('0') << ((static_cast<uint32_t>(str [i]))&0xff);
187      }
188    cout << dec << endl;
189
190    delete [] str;
191    delete data;
192    delete param;
193    delete segtable;
194  }
195  cout << "<main> End" << endl;
196 
197  return EXIT_SUCCESS;
198}
Note: See TracBrowser for help on using the repository browser.