summaryrefslogtreecommitdiff
path: root/src/unittest/stattest.cc
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2011-04-15 10:45:11 -0700
committerNathan Binkert <nate@binkert.org>2011-04-15 10:45:11 -0700
commit915f49ae9255372267aabe06e8c28c1fab8e43a5 (patch)
treec705ede98e96b8119c49a62d7ebec677a7de435d /src/unittest/stattest.cc
parent8c97726266a83fda31f8a68860157f195d7466ea (diff)
downloadgem5-915f49ae9255372267aabe06e8c28c1fab8e43a5.tar.xz
unittest: Make unit tests capable of using swig and python, convert stattest
Diffstat (limited to 'src/unittest/stattest.cc')
-rw-r--r--src/unittest/stattest.cc116
1 files changed, 32 insertions, 84 deletions
diff --git a/src/unittest/stattest.cc b/src/unittest/stattest.cc
index e7654ae5b..c5e39888d 100644
--- a/src/unittest/stattest.cc
+++ b/src/unittest/stattest.cc
@@ -32,8 +32,6 @@
#include <iostream>
#include <string>
-#include "base/stats/mysql.hh"
-#include "base/stats/text.hh"
#include "base/cprintf.hh"
#include "base/misc.hh"
#include "base/statistics.hh"
@@ -41,6 +39,13 @@
#include "sim/core.hh"
#include "sim/stat_control.hh"
+// override the default main() code for this unittest
+const char *m5MainCommands[] = {
+ "import m5.stattestmain",
+ "m5.stattestmain.main()",
+ 0 // sentinel is required
+};
+
using namespace std;
using namespace Stats;
@@ -55,67 +60,8 @@ class TestClass {
double operator()() { return 9.7; }
};
-const char *progname = "";
-
-void
-usage()
+struct StatTest
{
- panic("incorrect usage.\n"
- "usage:\n"
- "\t%s [-t [-c] [-d]]\n", progname);
-}
-
-int
-main(int argc, char *argv[])
-{
- bool descriptions = false;
- bool text = false;
-
-#if USE_MYSQL
- string mysql_name;
- string mysql_db;
- string mysql_host;
- string mysql_user = "binkertn";
- string mysql_passwd;
-#endif
-
- char c;
- progname = argv[0];
- while ((c = getopt(argc, argv, "cD:dh:P:p:s:tu:")) != -1) {
- switch (c) {
- case 'd':
- descriptions = true;
- break;
- case 't':
- text = true;
- break;
-#if USE_MYSQL
- case 'D':
- mysql_db = optarg;
- break;
- case 'h':
- mysql_host = optarg;
- break;
- case 'P':
- mysql_passwd = optarg;
- break;
- case 's':
- mysql_name = optarg;
- break;
- case 'u':
- mysql_user = optarg;
- break;
-#endif
- default:
- usage();
- }
- }
-
- if (!text && descriptions)
- usage();
-
- initSimStats();
-
Scalar s1;
Scalar s2;
Average s3;
@@ -153,6 +99,26 @@ main(int argc, char *argv[])
Formula f4;
Formula f5;
+ void run();
+ void init();
+};
+
+StatTest __stattest;
+void
+stattest_init()
+{
+ __stattest.init();
+}
+
+void
+stattest_run()
+{
+ __stattest.run();
+}
+
+void
+StatTest::init()
+{
cprintf("sizeof(Scalar) = %d\n", sizeof(Scalar));
cprintf("sizeof(Vector) = %d\n", sizeof(Vector));
cprintf("sizeof(Distribution) = %d\n", sizeof(Distribution));
@@ -386,10 +352,11 @@ main(int argc, char *argv[])
f4 += constant(10.0);
f4 += s5[3];
f5 = constant(1);
+}
- enable();
- reset();
-
+void
+StatTest::run()
+{
s16[1][0] = 1;
s16[0][1] = 3;
s16[0][0] = 2;
@@ -656,23 +623,4 @@ main(int argc, char *argv[])
h11.sample(i);
h12.sample(i);
}
-
- prepare();
-
- if (text) {
- Text out(cout);
- out.descriptions = descriptions;
- out();
- }
-
-#if USE_MYSQL
- if (!mysql_name.empty()) {
- MySql out;
- out.connect(mysql_host, mysql_db, mysql_user, mysql_passwd, "test",
- mysql_name, "test");
- out();
- }
-#endif
-
- return 0;
}