Gabe Black has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/27607 )
Change subject: util: Add unit tests for most remaining m5 utility commands.
......................................................................
util: Add unit tests for most remaining m5 utility commands.
The only two which still need unit tests are the more complex commands,
readfile and writefile.
Change-Id: Ib9984c71fb4449cbbbd1e2a43f3140975328d31f
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27607
Reviewed-by: Jason Lowe-Power <[email protected]>
Maintainer: Jason Lowe-Power <[email protected]>
Tested-by: kokoro <[email protected]>
---
M util/m5/src/command/SConscript.native
A util/m5/src/command/addsymbol.test.cc
A util/m5/src/command/checkpoint.test.cc
A util/m5/src/command/dumpresetstats.test.cc
A util/m5/src/command/dumpstats.test.cc
A util/m5/src/command/exit.test.cc
A util/m5/src/command/fail.test.cc
A util/m5/src/command/initparam.test.cc
A util/m5/src/command/loadsymbol.test.cc
A util/m5/src/command/resetstats.test.cc
10 files changed, 719 insertions(+), 0 deletions(-)
Approvals:
Jason Lowe-Power: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/util/m5/src/command/SConscript.native
b/util/m5/src/command/SConscript.native
index d27cd26..10e45d2 100644
--- a/util/m5/src/command/SConscript.native
+++ b/util/m5/src/command/SConscript.native
@@ -26,6 +26,15 @@
Import('*')
command_tests = (
+ 'addsymbol',
+ 'checkpoint',
+ 'dumpresetstats',
+ 'dumpstats',
+ 'exit',
+ 'fail',
+ 'initparam',
+ 'loadsymbol',
+ 'resetstats',
'sum',
)
diff --git a/util/m5/src/command/addsymbol.test.cc
b/util/m5/src/command/addsymbol.test.cc
new file mode 100644
index 0000000..bd2fd65
--- /dev/null
+++ b/util/m5/src/command/addsymbol.test.cc
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+
+uint64_t test_addr;
+std::string test_symbol;
+
+void
+test_m5_add_symbol(uint64_t addr, const char *symbol)
+{
+ test_addr = addr;
+ // Make a copy of what is in symbol so it's still available when we go
to
+ // check it later.
+ test_symbol = symbol;
+}
+
+DispatchTable dt = { .m5_add_symbol = &test_m5_add_symbol };
+
+bool
+run(std::initializer_list<std::string> arg_args)
+{
+ Args args(arg_args);
+ return Command::run(dt, args);
+}
+
+TEST(Exit, Arguments)
+{
+ // Called with no arguments.
+ EXPECT_FALSE(run({"addsymbol"}));
+
+ // Called with one argument.
+ EXPECT_FALSE(run({"addsymbol", "1"}));
+
+ // Called with two arguments.
+ EXPECT_TRUE(run({"addsymbol", "1234", "test_symbol_name"}));
+ EXPECT_EQ(test_addr, 1234);
+ EXPECT_EQ(test_symbol, "test_symbol_name");
+
+ // Called with three arguments.
+ EXPECT_FALSE(run({"addsymbol", "1", "2", "3"}));
+}
diff --git a/util/m5/src/command/checkpoint.test.cc
b/util/m5/src/command/checkpoint.test.cc
new file mode 100644
index 0000000..fe15050
--- /dev/null
+++ b/util/m5/src/command/checkpoint.test.cc
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+
+uint64_t test_ns_delay;
+uint64_t test_ns_period;
+
+void
+test_m5_checkpoint(uint64_t ns_delay, uint64_t ns_period)
+{
+ test_ns_delay = ns_delay;
+ test_ns_period = ns_period;
+}
+
+DispatchTable dt = { .m5_checkpoint = &test_m5_checkpoint };
+
+bool
+run(std::initializer_list<std::string> arg_args)
+{
+ Args args(arg_args);
+ return Command::run(dt, args);
+}
+
+TEST(Checkpoint, Arguments)
+{
+ // Called with no arguments.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"checkpoint"}));
+ EXPECT_EQ(test_ns_delay, 0);
+ EXPECT_EQ(test_ns_period, 0);
+
+ // Called with one argument.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"checkpoint", "10"}));
+ EXPECT_EQ(test_ns_delay, 10);
+ EXPECT_EQ(test_ns_period, 0);
+
+ // Called with two arguments.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"checkpoint", "10", "20"}));
+ EXPECT_EQ(test_ns_delay, 10);
+ EXPECT_EQ(test_ns_period, 20);
+
+ // Called with three arguments.
+ EXPECT_FALSE(run({"checkpoint", "10", "20", "30"}));
+}
diff --git a/util/m5/src/command/dumpresetstats.test.cc
b/util/m5/src/command/dumpresetstats.test.cc
new file mode 100644
index 0000000..904937f
--- /dev/null
+++ b/util/m5/src/command/dumpresetstats.test.cc
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+
+uint64_t test_ns_delay;
+uint64_t test_ns_period;
+
+void
+test_m5_dump_reset_stats(uint64_t ns_delay, uint64_t ns_period)
+{
+ test_ns_delay = ns_delay;
+ test_ns_period = ns_period;
+}
+
+DispatchTable dt = { .m5_dump_reset_stats = &test_m5_dump_reset_stats };
+
+bool
+run(std::initializer_list<std::string> arg_args)
+{
+ Args args(arg_args);
+ return Command::run(dt, args);
+}
+
+TEST(Dumpresetstats, Arguments)
+{
+ // Called with no arguments.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"dumpresetstats"}));
+ EXPECT_EQ(test_ns_delay, 0);
+ EXPECT_EQ(test_ns_period, 0);
+
+ // Called with one argument.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"dumpresetstats", "10"}));
+ EXPECT_EQ(test_ns_delay, 10);
+ EXPECT_EQ(test_ns_period, 0);
+
+ // Called with two arguments.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"dumpresetstats", "10", "20"}));
+ EXPECT_EQ(test_ns_delay, 10);
+ EXPECT_EQ(test_ns_period, 20);
+
+ // Called with three arguments.
+ EXPECT_FALSE(run({"dumpresetstats", "10", "20", "30"}));
+}
diff --git a/util/m5/src/command/dumpstats.test.cc
b/util/m5/src/command/dumpstats.test.cc
new file mode 100644
index 0000000..b309bbb
--- /dev/null
+++ b/util/m5/src/command/dumpstats.test.cc
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+
+uint64_t test_ns_delay;
+uint64_t test_ns_period;
+
+void
+test_m5_dump_stats(uint64_t ns_delay, uint64_t ns_period)
+{
+ test_ns_delay = ns_delay;
+ test_ns_period = ns_period;
+}
+
+DispatchTable dt = { .m5_dump_stats = &test_m5_dump_stats };
+
+bool
+run(std::initializer_list<std::string> arg_args)
+{
+ Args args(arg_args);
+ return Command::run(dt, args);
+}
+
+TEST(Dumpstats, Arguments)
+{
+ // Called with no arguments.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"dumpstats"}));
+ EXPECT_EQ(test_ns_delay, 0);
+ EXPECT_EQ(test_ns_period, 0);
+
+ // Called with one argument.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"dumpstats", "10"}));
+ EXPECT_EQ(test_ns_delay, 10);
+ EXPECT_EQ(test_ns_period, 0);
+
+ // Called with two arguments.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"dumpstats", "10", "20"}));
+ EXPECT_EQ(test_ns_delay, 10);
+ EXPECT_EQ(test_ns_period, 20);
+
+ // Called with three arguments.
+ EXPECT_FALSE(run({"dumpstats", "10", "20", "30"}));
+}
diff --git a/util/m5/src/command/exit.test.cc
b/util/m5/src/command/exit.test.cc
new file mode 100644
index 0000000..646d23c
--- /dev/null
+++ b/util/m5/src/command/exit.test.cc
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+
+uint64_t test_ns_delay;
+
+void
+test_m5_exit(uint64_t ns_delay)
+{
+ test_ns_delay = ns_delay;
+}
+
+DispatchTable dt = { .m5_exit = &test_m5_exit };
+
+bool
+run(std::initializer_list<std::string> arg_args)
+{
+ Args args(arg_args);
+ return Command::run(dt, args);
+}
+
+TEST(Exit, Arguments)
+{
+ // Called with no arguments.
+ test_ns_delay = 50;
+ EXPECT_TRUE(run({"exit"}));
+ EXPECT_EQ(test_ns_delay, 0);
+
+ // Called with one argument.
+ test_ns_delay = 50;
+ EXPECT_TRUE(run({"exit", "1"}));
+ EXPECT_EQ(test_ns_delay, 1);
+
+ // Called with two arguments.
+ EXPECT_FALSE(run({"exit", "1", "2"}));
+}
diff --git a/util/m5/src/command/fail.test.cc
b/util/m5/src/command/fail.test.cc
new file mode 100644
index 0000000..ae65316
--- /dev/null
+++ b/util/m5/src/command/fail.test.cc
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+
+uint64_t test_ns_delay;
+uint64_t test_code;
+
+void
+test_m5_fail(uint64_t ns_delay, uint64_t code)
+{
+ test_ns_delay = ns_delay;
+ test_code = code;
+}
+
+DispatchTable dt = { .m5_fail = &test_m5_fail };
+
+bool
+run(std::initializer_list<std::string> arg_args)
+{
+ Args args(arg_args);
+ return Command::run(dt, args);
+}
+
+TEST(Fail, Arguments)
+{
+ // Called with no arguments.
+ test_ns_delay = 50;
+ test_code = 40;
+ EXPECT_FALSE(run({"fail"}));
+
+ // Called with one argument.
+ test_ns_delay = 50;
+ test_code = 40;
+ EXPECT_TRUE(run({"fail", "1"}));
+ EXPECT_EQ(test_ns_delay, 0);
+ EXPECT_EQ(test_code, 1);
+
+ // Called with two arguments.
+ test_ns_delay = 50;
+ test_code = 40;
+ EXPECT_TRUE(run({"fail", "1", "2"}));
+ EXPECT_EQ(test_ns_delay, 2);
+ EXPECT_EQ(test_code, 1);
+
+ // Called with three arguments.
+ EXPECT_FALSE(run({"fail", "1", "2", "3"}));
+}
diff --git a/util/m5/src/command/initparam.test.cc
b/util/m5/src/command/initparam.test.cc
new file mode 100644
index 0000000..6592bf3
--- /dev/null
+++ b/util/m5/src/command/initparam.test.cc
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+
+uint64_t test_key_str1;
+uint64_t test_key_str2;
+uint64_t test_result;
+
+uint64_t
+test_m5_init_param(uint64_t key_str1, uint64_t key_str2)
+{
+ test_key_str1 = key_str1;
+ test_key_str2 = key_str2;
+
+ return test_result;
+}
+
+DispatchTable dt = { .m5_init_param = &test_m5_init_param };
+
+std::string cout_output;
+
+bool
+run(std::initializer_list<std::string> arg_args)
+{
+ Args args(arg_args);
+
+ // Redirect cout into a stringstream.
+ std::stringstream buffer;
+ std::streambuf *orig = std::cout.rdbuf(buffer.rdbuf());
+
+ bool res = Command::run(dt, args);
+
+ // Capture the contents of the stringstream and restore cout.
+ cout_output = buffer.str();
+ std::cout.rdbuf(orig);
+
+ return res;
+}
+
+TEST(Fail, Arguments)
+{
+ // Called with no arguments.
+ test_key_str1 = 0;
+ test_key_str2 = 0;
+ EXPECT_FALSE(run({"initparam"}));
+ EXPECT_EQ(cout_output, "");
+
+ // Called with an empty argument.
+ test_key_str1 = 1;
+ test_key_str2 = 1;
+ test_result = 5;
+ EXPECT_TRUE(run({"initparam", ""}));
+ EXPECT_EQ(test_key_str1, 0);
+ EXPECT_EQ(test_key_str2, 0);
+ EXPECT_EQ(cout_output, "5");
+
+ // Called with a short argument.
+ test_key_str1 = 1;
+ test_key_str2 = 1;
+ test_result = 4;
+ EXPECT_TRUE(run({"initparam", "shrt"}));
+ EXPECT_EQ(test_key_str1, ((uint64_t)'s' << 0) | ((uint64_t)'h' << 8) |
+ ((uint64_t)'r' << 16) | ((uint64_t)'t' <<
24));
+ EXPECT_EQ(test_key_str2, 0);
+ EXPECT_EQ(cout_output, "4");
+
+ // Call with a longer argument.
+ test_key_str1 = 1;
+ test_key_str2 = 1;
+ test_result = 3;
+ EXPECT_TRUE(run({"initparam", "longer arg"}));
+ EXPECT_EQ(test_key_str1, ((uint64_t)'l' << 0) | ((uint64_t)'o' << 8) |
+ ((uint64_t)'n' << 16) | ((uint64_t)'g' << 24)
|
+ ((uint64_t)'e' << 32) | ((uint64_t)'r' << 40)
|
+ ((uint64_t)' ' << 48) | ((uint64_t)'a' <<
56));
+ EXPECT_EQ(test_key_str2, ((uint64_t)'r' << 0) | ((uint64_t)'g' << 8));
+ EXPECT_EQ(cout_output, "3");
+
+ // Call with an almost too long argument.
+ test_key_str1 = 1;
+ test_key_str2 = 1;
+ test_result = 2;
+ EXPECT_TRUE(run({"initparam", "1234567887654321"}));
+ EXPECT_EQ(test_key_str1, ((uint64_t)'1' << 0) | ((uint64_t)'2' << 8) |
+ ((uint64_t)'3' << 16) | ((uint64_t)'4' << 24)
|
+ ((uint64_t)'5' << 32) | ((uint64_t)'6' << 40)
|
+ ((uint64_t)'7' << 48) | ((uint64_t)'8' <<
56));
+ EXPECT_EQ(test_key_str2, ((uint64_t)'8' << 0) | ((uint64_t)'7' << 8) |
+ ((uint64_t)'6' << 16) | ((uint64_t)'5' << 24)
|
+ ((uint64_t)'4' << 32) | ((uint64_t)'3' << 40)
|
+ ((uint64_t)'2' << 48) | ((uint64_t)'1' <<
56));
+ EXPECT_EQ(cout_output, "2");
+
+ // Call with an argument that is too long.
+ EXPECT_FALSE(run({"initparam", "12345678876543210"}));
+ EXPECT_EQ(cout_output, "");
+
+ // Call with a valid argument and then one extra.
+ EXPECT_FALSE(run({"valid", "extra"}));
+ EXPECT_EQ(cout_output, "");
+}
diff --git a/util/m5/src/command/loadsymbol.test.cc
b/util/m5/src/command/loadsymbol.test.cc
new file mode 100644
index 0000000..a123a51
--- /dev/null
+++ b/util/m5/src/command/loadsymbol.test.cc
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+
+bool test_load_symbol_called;
+void test_m5_load_symbol() { test_load_symbol_called = true;}
+
+DispatchTable dt = { .m5_load_symbol = &test_m5_load_symbol };
+
+bool
+run(std::initializer_list<std::string> arg_args)
+{
+ Args args(arg_args);
+ return Command::run(dt, args);
+}
+
+TEST(Fail, Arguments)
+{
+ // Called with no arguments.
+ test_load_symbol_called = false;
+ EXPECT_TRUE(run({"loadsymbol"}));
+ EXPECT_TRUE(test_load_symbol_called);
+
+ // Call with one argument.
+ test_load_symbol_called = false;
+ EXPECT_FALSE(run({"loadsymbol", "1"}));
+ EXPECT_FALSE(test_load_symbol_called);
+}
diff --git a/util/m5/src/command/resetstats.test.cc
b/util/m5/src/command/resetstats.test.cc
new file mode 100644
index 0000000..1c1aed5
--- /dev/null
+++ b/util/m5/src/command/resetstats.test.cc
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2020 Google Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <gtest/gtest.h>
+
+#include "args.hh"
+#include "command.hh"
+#include "dispatch_table.hh"
+
+uint64_t test_ns_delay;
+uint64_t test_ns_period;
+
+void
+test_m5_reset_stats(uint64_t ns_delay, uint64_t ns_period)
+{
+ test_ns_delay = ns_delay;
+ test_ns_period = ns_period;
+}
+
+DispatchTable dt = { .m5_reset_stats = &test_m5_reset_stats };
+
+bool
+run(std::initializer_list<std::string> arg_args)
+{
+ Args args(arg_args);
+ return Command::run(dt, args);
+}
+
+TEST(Resetstats, Arguments)
+{
+ // Called with no arguments.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"resetstats"}));
+ EXPECT_EQ(test_ns_delay, 0);
+ EXPECT_EQ(test_ns_period, 0);
+
+ // Called with one argument.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"resetstats", "10"}));
+ EXPECT_EQ(test_ns_delay, 10);
+ EXPECT_EQ(test_ns_period, 0);
+
+ // Called with two arguments.
+ test_ns_delay = 50;
+ test_ns_period = 40;
+ EXPECT_TRUE(run({"resetstats", "10", "20"}));
+ EXPECT_EQ(test_ns_delay, 10);
+ EXPECT_EQ(test_ns_period, 20);
+
+ // Called with three arguments.
+ EXPECT_FALSE(run({"resetstats", "10", "20", "30"}));
+}
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/27607
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ib9984c71fb4449cbbbd1e2a43f3140975328d31f
Gerrit-Change-Number: 27607
Gerrit-PatchSet: 24
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Earl Ou <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Yu-hsin Wang <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s