Gabe Black has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/27565 )
Change subject: util: Make m5 commands return a bool instead of calling
usage.
......................................................................
util: Make m5 commands return a bool instead of calling usage.
By delegating actually calling usage() elsewhere, we can remove a dependency
from the commands themselves, and also make testing easier since we won't
exit() every time we call a command with bad arguments.
Change-Id: I6b8e2cb77ce0456b16673f10349362cc53218bba
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/27565
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
Tested-by: kokoro <[email protected]>
---
M util/m5/src/command.cc
M util/m5/src/command.hh
M util/m5/src/command.test.cc
M util/m5/src/command/addsymbol.cc
M util/m5/src/command/checkpoint.cc
M util/m5/src/command/dumpresetstats.cc
M util/m5/src/command/dumpstats.cc
M util/m5/src/command/exit.cc
M util/m5/src/command/fail.cc
M util/m5/src/command/initparam.cc
M util/m5/src/command/loadsymbol.cc
M util/m5/src/command/readfile.cc
M util/m5/src/command/resetstats.cc
M util/m5/src/command/sum.cc
M util/m5/src/command/writefile.cc
15 files changed, 51 insertions(+), 39 deletions(-)
Approvals:
Gabe Black: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/util/m5/src/command.cc b/util/m5/src/command.cc
index d7dc030..2527dc6 100644
--- a/util/m5/src/command.cc
+++ b/util/m5/src/command.cc
@@ -52,6 +52,5 @@
if (num_args < cmd.minArgs || num_args > cmd.maxArgs)
return false;
- cmd.func(dt, args);
- return true;
+ return cmd.func(dt, args);
}
diff --git a/util/m5/src/command.hh b/util/m5/src/command.hh
index 8348d11..7321d39 100644
--- a/util/m5/src/command.hh
+++ b/util/m5/src/command.hh
@@ -46,7 +46,7 @@
// The maximum number of arguments the command can handle.
const int maxArgs;
- using FuncType = void (*)(const DispatchTable &dt, Args &args);
+ using FuncType = bool (*)(const DispatchTable &dt, Args &args);
// A function which processes command line arguments and passes them to
// the underlying function through the dispatch table.
FuncType func;
diff --git a/util/m5/src/command.test.cc b/util/m5/src/command.test.cc
index 342a42c..b29d648 100644
--- a/util/m5/src/command.test.cc
+++ b/util/m5/src/command.test.cc
@@ -40,18 +40,20 @@
DispatchTable dt;
-void
+bool
do_test1(const DispatchTable &dt, Args &args)
{
ran_test1 = true;
+ return true;
}
bool ran_test2 = false;
-void
+bool
do_test2(const DispatchTable &dt, Args &args)
{
ran_test2 = true;
+ return true;
}
TEST(CommandTest, OneCommandNoArgs)
diff --git a/util/m5/src/command/addsymbol.cc
b/util/m5/src/command/addsymbol.cc
index dfd20d7..0ebd6b2 100644
--- a/util/m5/src/command/addsymbol.cc
+++ b/util/m5/src/command/addsymbol.cc
@@ -29,20 +29,21 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
-void
+bool
do_add_symbol(const DispatchTable &dt, Args &args)
{
uint64_t addr;
if (!args.pop(addr))
- usage();
+ return false;
const std::string &symbol = args.pop();
(*dt.m5_add_symbol)(addr, symbol.c_str());
+
+ return true;
}
Command add_symbol = {
diff --git a/util/m5/src/command/checkpoint.cc
b/util/m5/src/command/checkpoint.cc
index bd234a7..b16307c 100644
--- a/util/m5/src/command/checkpoint.cc
+++ b/util/m5/src/command/checkpoint.cc
@@ -29,19 +29,19 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
-void
+bool
do_checkpoint(const DispatchTable &dt, Args &args)
{
uint64_t ns_delay, ns_period;
if (!args.pop(ns_delay, 0) || !args.pop(ns_period, 0))
- usage();
+ return false;
(*dt.m5_checkpoint)(ns_delay, ns_period);
+ return true;
}
Command checkpoint = {
diff --git a/util/m5/src/command/dumpresetstats.cc
b/util/m5/src/command/dumpresetstats.cc
index e3a7cc6..b5337af 100644
--- a/util/m5/src/command/dumpresetstats.cc
+++ b/util/m5/src/command/dumpresetstats.cc
@@ -29,19 +29,20 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
-void
+bool
do_dump_reset_stats(const DispatchTable &dt, Args &args)
{
uint64_t ns_delay, ns_period;
if (!args.pop(ns_delay, 0) || !args.pop(ns_period, 0))
- usage();
+ return false;
(*dt.m5_dump_reset_stats)(ns_delay, ns_period);
+
+ return true;
}
Command dump_reset_stats = {
diff --git a/util/m5/src/command/dumpstats.cc
b/util/m5/src/command/dumpstats.cc
index eef3b38..106f822 100644
--- a/util/m5/src/command/dumpstats.cc
+++ b/util/m5/src/command/dumpstats.cc
@@ -29,19 +29,20 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
-void
+bool
do_dump_stats(const DispatchTable &dt, Args &args)
{
uint64_t ns_delay, ns_period;
if (!args.pop(ns_delay, 0) || !args.pop(ns_period, 0))
- usage();
+ return false;
(*dt.m5_dump_stats)(ns_delay, ns_period);
+
+ return true;
}
Command dump_stats = {
diff --git a/util/m5/src/command/exit.cc b/util/m5/src/command/exit.cc
index ea322ca..4f8815c 100644
--- a/util/m5/src/command/exit.cc
+++ b/util/m5/src/command/exit.cc
@@ -29,19 +29,20 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
-void
+bool
do_exit(const DispatchTable &dt, Args &args)
{
uint64_t ns_delay;
if (!args.pop(ns_delay, 0))
- usage();
+ return false;
(*dt.m5_exit)(ns_delay);
+
+ return true;
}
Command exit_cmd = {
diff --git a/util/m5/src/command/fail.cc b/util/m5/src/command/fail.cc
index db21979..c34571c 100644
--- a/util/m5/src/command/fail.cc
+++ b/util/m5/src/command/fail.cc
@@ -29,19 +29,20 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
-void
+bool
do_fail(const DispatchTable &dt, Args &args)
{
uint64_t ns_delay, code;
if (!args.pop(code) || !args.pop(ns_delay, 0))
- usage();
+ return false;
(*dt.m5_fail)(ns_delay, code);
+
+ return true;
}
Command fail_cmd = {
diff --git a/util/m5/src/command/initparam.cc
b/util/m5/src/command/initparam.cc
index 3fe000c..eb1fdff 100644
--- a/util/m5/src/command/initparam.cc
+++ b/util/m5/src/command/initparam.cc
@@ -31,19 +31,21 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
-void
+bool
do_initparam(const DispatchTable &dt, Args &args)
{
uint64_t key_str[2];
if (!args.pop(key_str, 2))
- usage();
+ return false;
+
uint64_t val = (*dt.m5_init_param)(key_str[0], key_str[1]);
std::cout << val;
+
+ return true;
}
Command init_param = {
diff --git a/util/m5/src/command/loadsymbol.cc
b/util/m5/src/command/loadsymbol.cc
index c55ae99..794e53b 100644
--- a/util/m5/src/command/loadsymbol.cc
+++ b/util/m5/src/command/loadsymbol.cc
@@ -29,15 +29,15 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
-void
+bool
do_loadsymbol(const DispatchTable &dt, Args &args)
{
(*dt.m5_load_symbol)();
+ return true;
}
Command load_symbol = {
diff --git a/util/m5/src/command/readfile.cc
b/util/m5/src/command/readfile.cc
index 9295dfd..92c39e2 100644
--- a/util/m5/src/command/readfile.cc
+++ b/util/m5/src/command/readfile.cc
@@ -32,7 +32,6 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
@@ -62,13 +61,15 @@
return offset;
}
-void
+bool
do_read_file(const DispatchTable &dt, Args &args)
{
if (args.size() > 0)
- usage();
+ return false;
read_file(dt, std::cout);
+
+ return true;
}
Command read_file_cmd = {
diff --git a/util/m5/src/command/resetstats.cc
b/util/m5/src/command/resetstats.cc
index 2408fb3..cf51bfb 100644
--- a/util/m5/src/command/resetstats.cc
+++ b/util/m5/src/command/resetstats.cc
@@ -29,19 +29,20 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
-void
+bool
do_reset_stats(const DispatchTable &dt, Args &args)
{
uint64_t ns_delay, ns_period;
if (!args.pop(ns_delay, 0) || !args.pop(ns_period, 0))
- usage();
+ return false;
(*dt.m5_reset_stats)(ns_delay, ns_period);
+
+ return true;
}
Command reset_stats = {
diff --git a/util/m5/src/command/sum.cc b/util/m5/src/command/sum.cc
index c7d44b3..8b1b3d2 100644
--- a/util/m5/src/command/sum.cc
+++ b/util/m5/src/command/sum.cc
@@ -31,22 +31,23 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
// For testing purposes.
-void
+bool
do_sum(const DispatchTable &dt, Args &args)
{
uint64_t a, b, c, d, e, f;
if (!args.pop(a) || !args.pop(b) || !args.pop(c, 0) ||
!args.pop(d, 0) || !args.pop(e, 0) || !args.pop(f, 0))
- usage();
+ return false;
unsigned sum = (*dt.m5_sum)(a, b, c, d, e, f);
std::cout << "Sum is " << sum << "." << std::endl;
+
+ return true;
}
Command sum = {
diff --git a/util/m5/src/command/writefile.cc
b/util/m5/src/command/writefile.cc
index 801b7af..bef1932 100644
--- a/util/m5/src/command/writefile.cc
+++ b/util/m5/src/command/writefile.cc
@@ -33,7 +33,6 @@
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
@@ -75,13 +74,15 @@
std::cerr << "Wrote " << offset << " bytes." << std::endl;
}
-void
+bool
do_write_file(const DispatchTable &dt, Args &args)
{
const std::string &filename = args.pop();
const std::string &host_filename = args.pop(filename);
write_file(dt, filename, host_filename);
+
+ return true;
}
Command write_file_cmd = {
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/27565
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: I6b8e2cb77ce0456b16673f10349362cc53218bba
Gerrit-Change-Number: 27565
Gerrit-PatchSet: 26
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: Pouya Fotouhi <[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