2 * Copyright (c) 2003-2005 The Regents of The University of Michigan
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.
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.
28 * Authors: Nathan Binkert
31 #include "pybind11/pybind11.h"
37 #include "base/cprintf.hh"
38 #include "base/logging.hh"
39 #include "base/statistics.hh"
40 #include "base/types.hh"
41 #include "sim/core.hh"
42 #include "sim/init.hh"
43 #include "sim/stat_control.hh"
45 namespace py
= pybind11
;
47 // override the default main() code for this unittest
48 const char *m5MainCommands
[] = {
49 "import m5.stattestmain",
50 "m5.stattestmain.main()",
51 0 // sentinel is required
55 using namespace Stats
;
59 StatTest
& __stattest();
70 double operator()() { return 9.7; }
87 VectorDistribution s13
;
88 VectorStandardDeviation s14
;
89 VectorAverageDeviation s15
;
131 EventQueue
*q
= getEventQueue(0);
134 cprintf("sizeof(Scalar) = %d\n", sizeof(Scalar
));
135 cprintf("sizeof(Vector) = %d\n", sizeof(Vector
));
136 cprintf("sizeof(Distribution) = %d\n", sizeof(Distribution
));
140 .desc("this is statistic 1")
145 .desc("this is statistic 2")
151 .desc("this is statistic 3")
157 .desc("this is statistic 4")
164 .desc("this is statistic 5")
176 .desc("this is statistic 6")
183 .desc("this is statistic 7")
192 .desc("this is statistic 8")
200 .desc("this is statistic 9")
207 .desc("this is statistic 10")
214 .desc("this is statistic 12")
220 .desc("this is statistic 13")
226 .desc("this is statistic 14")
232 .desc("this is statistic 15")
238 .desc("this is statistic 16")
249 .desc("this is stat 17")
256 .desc("this is stat 18")
262 .desc("this is histogram 1")
268 .desc("this is histogram 2")
274 .desc("this is histogram 3")
280 .desc("this is histogram 4")
286 .desc("this is histogram 5")
292 .desc("this is histogram 6")
298 .desc("this is histogram 7")
304 .desc("this is histogram 8")
310 .desc("this is histogram 9")
316 .desc("this is histogram 10")
322 .desc("this is histogram 11")
328 .desc("this is histogram 12")
333 .name("SparseHistogram1")
334 .desc("this is sparse histogram 1")
339 .desc("this is formula 1")
345 .desc("this is formula 2")
352 .desc("this is formula 3")
363 .desc("this is formula 4")
369 .desc("this is statistic 19 for vector op testing")
370 .flags(total
| nozero
| nonan
)
375 .desc("this is statistic 20 for vector op testing")
376 .flags(total
| nozero
| nonan
)
380 .name("vector_op_test_formula")
381 .desc("The total stat should equal 1")
382 .flags(total
|nozero
|nonan
)
386 f2
= (-s1
) / (-s2
) * (-s3
+ ULL(100) + s4
);
388 f4
+= constant(10.0);
422 s10
.sample(1000000000);
423 curEventQueue()->setCurTick(curTick() + ULL(1000000));
498 curEventQueue()->setCurTick(curTick() + ULL(1000000));
500 curEventQueue()->setCurTick(curTick() + ULL(1000000));
502 curEventQueue()->setCurTick(curTick() + ULL(1000000));
504 curEventQueue()->setCurTick(curTick() + ULL(1000000));
506 curEventQueue()->setCurTick(curTick() + ULL(1000000));
513 curEventQueue()->setCurTick(curTick() + ULL(1000000));
515 curEventQueue()->setCurTick(curTick() + ULL(1000000));
517 curEventQueue()->setCurTick(curTick() + ULL(1000000));
519 curEventQueue()->setCurTick(curTick() + ULL(1000000));
522 curEventQueue()->setCurTick(curTick() + ULL(1000000));
524 curEventQueue()->setCurTick(curTick() + ULL(1000000));
526 curEventQueue()->setCurTick(curTick() + ULL(1000000));
528 curEventQueue()->setCurTick(curTick() + ULL(1000000));
534 curEventQueue()->setCurTick(curTick() + ULL(1000000));
541 curEventQueue()->setCurTick(curTick() + ULL(1000000));
550 curEventQueue()->setCurTick(curTick() + 9);
625 curEventQueue()->setCurTick(curTick() + 9);
634 for (int i
= 0; i
< 100; i
++) {
639 for (int i
= -100; i
< 100; i
++) {
644 for (int i
= -100; i
< 1000; i
++) {
649 for (int i
= 100; i
>= -1000; i
--) {
654 for (int i
= 0; i
<= 1023; i
++) {
659 for (int i
= -1024; i
<= 1023; i
++) {
664 for (int i
= 0; i
< 1000; i
++) {
665 sh1
.sample(random() % 10000);
676 stattest_init_pybind(py::module
&m_internal
)
678 py::module m
= m_internal
.def_submodule("stattest");
681 .def("stattest_init", []() { __stattest().init(); })
682 .def("stattest_run", []() { __stattest().run(); })
686 static EmbeddedPyBind
embed_("stattest", stattest_init_pybind
);