if (num_args < cmd.minArgs || num_args > cmd.maxArgs)
return false;
- cmd.func(dt, args);
- return true;
+ return cmd.func(dt, args);
}
// 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;
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)
#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 = {
#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 = {
#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 = {
#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 = {
#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 = {
#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 = {
#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 = {
#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 = {
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
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 = {
#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 = {
#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 = {
#include "args.hh"
#include "command.hh"
#include "dispatch_table.hh"
-#include "usage.hh"
namespace
{
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 = {