Move away from using the statusChange function on snoops. Clean up snooping code...
[gem5.git] / src / unittest / initest.cc
1 /*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Nathan Binkert
29 * Steve Reinhardt
30 */
31
32 #include <iostream>
33 #include <fstream>
34 #include <string>
35 #include <vector>
36
37 #include "base/inifile.hh"
38 #include "base/cprintf.hh"
39
40 using namespace std;
41
42 char *progname;
43
44 void
45 usage()
46 {
47 cout << "Usage: " << progname << " <ini file>\n";
48 exit(1);
49 }
50
51 #if 0
52 char *defines = getenv("CONFIG_DEFINES");
53 if (defines) {
54 char *c = defines;
55 while ((c = strchr(c, ' ')) != NULL) {
56 *c++ = '\0';
57 count++;
58 }
59 count++;
60 }
61
62 #endif
63
64 int
65 main(int argc, char *argv[])
66 {
67 IniFile simConfigDB;
68
69 progname = argv[0];
70
71 vector<char *> cppArgs;
72
73 vector<char *> cpp_options;
74 cpp_options.reserve(argc * 2);
75
76 for (int i = 1; i < argc; ++i) {
77 char *arg_str = argv[i];
78
79 // if arg starts with '-', parse as option,
80 // else treat it as a configuration file name and load it
81 if (arg_str[0] == '-') {
82
83 // switch on second char
84 switch (arg_str[1]) {
85 case 'D':
86 case 'U':
87 case 'I':
88 // cpp options: record & pass to cpp. Note that these
89 // cannot have spaces, i.e., '-Dname=val' is OK, but
90 // '-D name=val' is not. I don't consider this a
91 // problem, since even though gnu cpp accepts the
92 // latter, other cpp implementations do not (Tru64,
93 // for one).
94 cppArgs.push_back(arg_str);
95 break;
96
97 case '-':
98 // command-line configuration parameter:
99 // '--<section>:<parameter>=<value>'
100
101 if (!simConfigDB.add(arg_str + 2)) {
102 // parse error
103 ccprintf(cerr,
104 "Could not parse configuration argument '%s'\n"
105 "Expecting --<section>:<parameter>=<value>\n",
106 arg_str);
107 exit(0);
108 }
109 break;
110
111 default:
112 usage();
113 }
114 }
115 else {
116 // no '-', treat as config file name
117
118 if (!simConfigDB.loadCPP(arg_str, cppArgs)) {
119 cprintf("Error processing file %s\n", arg_str);
120 exit(1);
121 }
122 }
123 }
124
125 string value;
126
127 #define FIND(C, E) \
128 if (simConfigDB.find(C, E, value)) \
129 cout << ">" << value << "<\n"; \
130 else \
131 cout << "Not Found!\n"
132
133 FIND("General", "Test2");
134 FIND("Junk", "Test3");
135 FIND("Junk", "Test4");
136 FIND("General", "Test1");
137 FIND("Junk2", "test3");
138 FIND("General", "Test3");
139
140 cout << "\n";
141
142 simConfigDB.dump();
143
144 return 0;
145 }