stattest.cc (8229:78bf55f23338) stattest.cc (8235:6381dc8bcfcc)
1/*
2 * Copyright (c) 2003-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;

--- 18 unchanged lines hidden (view full) ---

27 *
28 * Authors: Nathan Binkert
29 */
30
31#include <iomanip>
32#include <iostream>
33#include <string>
34
1/*
2 * Copyright (c) 2003-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;

--- 18 unchanged lines hidden (view full) ---

27 *
28 * Authors: Nathan Binkert
29 */
30
31#include <iomanip>
32#include <iostream>
33#include <string>
34
35#include "base/stats/mysql.hh"
36#include "base/stats/text.hh"
37#include "base/cprintf.hh"
38#include "base/misc.hh"
39#include "base/statistics.hh"
40#include "base/types.hh"
41#include "sim/core.hh"
42#include "sim/stat_control.hh"
43
35#include "base/cprintf.hh"
36#include "base/misc.hh"
37#include "base/statistics.hh"
38#include "base/types.hh"
39#include "sim/core.hh"
40#include "sim/stat_control.hh"
41
42// override the default main() code for this unittest
43const char *m5MainCommands[] = {
44 "import m5.stattestmain",
45 "m5.stattestmain.main()",
46 0 // sentinel is required
47};
48
44using namespace std;
45using namespace Stats;
46
47double
48testfunc()
49{
50 return 9.8;
51}
52
53class TestClass {
54 public:
55 double operator()() { return 9.7; }
56};
57
49using namespace std;
50using namespace Stats;
51
52double
53testfunc()
54{
55 return 9.8;
56}
57
58class TestClass {
59 public:
60 double operator()() { return 9.7; }
61};
62
58const char *progname = "";
59
60void
61usage()
63struct StatTest
62{
64{
63 panic("incorrect usage.\n"
64 "usage:\n"
65 "\t%s [-t [-c] [-d]]\n", progname);
66}
67
68int
69main(int argc, char *argv[])
70{
71 bool descriptions = false;
72 bool text = false;
73
74#if USE_MYSQL
75 string mysql_name;
76 string mysql_db;
77 string mysql_host;
78 string mysql_user = "binkertn";
79 string mysql_passwd;
80#endif
81
82 char c;
83 progname = argv[0];
84 while ((c = getopt(argc, argv, "cD:dh:P:p:s:tu:")) != -1) {
85 switch (c) {
86 case 'd':
87 descriptions = true;
88 break;
89 case 't':
90 text = true;
91 break;
92#if USE_MYSQL
93 case 'D':
94 mysql_db = optarg;
95 break;
96 case 'h':
97 mysql_host = optarg;
98 break;
99 case 'P':
100 mysql_passwd = optarg;
101 break;
102 case 's':
103 mysql_name = optarg;
104 break;
105 case 'u':
106 mysql_user = optarg;
107 break;
108#endif
109 default:
110 usage();
111 }
112 }
113
114 if (!text && descriptions)
115 usage();
116
117 initSimStats();
118
119 Scalar s1;
120 Scalar s2;
121 Average s3;
122 Scalar s4;
123 Vector s5;
124 Distribution s6;
125 Vector s7;
126 AverageVector s8;

--- 21 unchanged lines hidden (view full) ---

148 Histogram h12;
149
150 Formula f1;
151 Formula f2;
152 Formula f3;
153 Formula f4;
154 Formula f5;
155
65 Scalar s1;
66 Scalar s2;
67 Average s3;
68 Scalar s4;
69 Vector s5;
70 Distribution s6;
71 Vector s7;
72 AverageVector s8;

--- 21 unchanged lines hidden (view full) ---

94 Histogram h12;
95
96 Formula f1;
97 Formula f2;
98 Formula f3;
99 Formula f4;
100 Formula f5;
101
102 void run();
103 void init();
104};
105
106StatTest __stattest;
107void
108stattest_init()
109{
110 __stattest.init();
111}
112
113void
114stattest_run()
115{
116 __stattest.run();
117}
118
119void
120StatTest::init()
121{
156 cprintf("sizeof(Scalar) = %d\n", sizeof(Scalar));
157 cprintf("sizeof(Vector) = %d\n", sizeof(Vector));
158 cprintf("sizeof(Distribution) = %d\n", sizeof(Distribution));
159
160 s1
161 .name("Stat01")
162 .desc("this is statistic 1")
163 ;

--- 217 unchanged lines hidden (view full) ---

381
382
383 f1 = s1 + s2;
384 f2 = (-s1) / (-s2) * (-s3 + ULL(100) + s4);
385 f3 = sum(s5) * s7;
386 f4 += constant(10.0);
387 f4 += s5[3];
388 f5 = constant(1);
122 cprintf("sizeof(Scalar) = %d\n", sizeof(Scalar));
123 cprintf("sizeof(Vector) = %d\n", sizeof(Vector));
124 cprintf("sizeof(Distribution) = %d\n", sizeof(Distribution));
125
126 s1
127 .name("Stat01")
128 .desc("this is statistic 1")
129 ;

--- 217 unchanged lines hidden (view full) ---

347
348
349 f1 = s1 + s2;
350 f2 = (-s1) / (-s2) * (-s3 + ULL(100) + s4);
351 f3 = sum(s5) * s7;
352 f4 += constant(10.0);
353 f4 += s5[3];
354 f5 = constant(1);
355}
389
356
390 enable();
391 reset();
392
357void
358StatTest::run()
359{
393 s16[1][0] = 1;
394 s16[0][1] = 3;
395 s16[0][0] = 2;
396 s16[1][1] = 9;
397 s16[1][1] += 9;
398 s16[1][8] += 8;
399 s16[1][7] += 7;
400 s16[1][6] += 6;

--- 250 unchanged lines hidden (view full) ---

651 h09.sample(i);
652 h10.sample(i);
653 }
654
655 for (int i = -1024; i <= 1023; i++) {
656 h11.sample(i);
657 h12.sample(i);
658 }
360 s16[1][0] = 1;
361 s16[0][1] = 3;
362 s16[0][0] = 2;
363 s16[1][1] = 9;
364 s16[1][1] += 9;
365 s16[1][8] += 8;
366 s16[1][7] += 7;
367 s16[1][6] += 6;

--- 250 unchanged lines hidden (view full) ---

618 h09.sample(i);
619 h10.sample(i);
620 }
621
622 for (int i = -1024; i <= 1023; i++) {
623 h11.sample(i);
624 h12.sample(i);
625 }
659
660 prepare();
661
662 if (text) {
663 Text out(cout);
664 out.descriptions = descriptions;
665 out();
666 }
667
668#if USE_MYSQL
669 if (!mysql_name.empty()) {
670 MySql out;
671 out.connect(mysql_host, mysql_db, mysql_user, mysql_passwd, "test",
672 mysql_name, "test");
673 out();
674 }
675#endif
676
677 return 0;
678}
626}