Commit 8fed41d6 authored by phlo's avatar phlo

added simulate until exit > 0 option to main (-c)

parent 63b01a22
# Demo Example
> [Intel Litmus Test #3](../litmus/intel/3)
Loads may be reordered with an earlier store to a different location.
## Programs
| Processor 0 | Processor 1 | Checker |
| ----------- | ----------- | ------------- |
| ADDI 1 | ADDI 1 | |
| STORE 0 | STORE 1 | |
| LOAD 1 | LOAD 0 | |
| CHECK 0 | CHECK 0 | CHECK 0 |
| | | ADD 0 |
| | | ADD 1 |
| | | JZ error |
| | | EXIT 0 |
| | | error: EXIT 1 |
CHECK 0
ADD 0
ADD 1
JZ error
EXIT 0
error: EXIT 1
ADDI 1
STORE 0
LOAD 1
CHECK 0
ADDI 1
STORE 1
LOAD 0
CHECK 0
......@@ -51,6 +51,7 @@ void print_usage_simulate (const char * name)
" simulate [options] <program> ..." <<
eol << eol <<
"options:" << eol <<
" -c run until an exit code > 0 is encountered" << eol <<
" -k bound execute a specific number of steps" << eol <<
" -m mmap read initial heap contents from file" << eol <<
" -o name output file name (default: sim.{trace,mmap})" << eol <<
......@@ -163,11 +164,18 @@ int simulate (const char * name, const int argc, const char ** argv)
// output file name
std::string outfile = "sim";
// run until exit > 0
bool check = false;
// parse options
int i = 0;
do
{
if (!strcmp(argv[i], "-k"))
if (!strcmp(argv[i], "-c"))
{
check = true;
}
else if (!strcmp(argv[i], "-k"))
{
if (++i >= argc)
{
......@@ -248,7 +256,12 @@ int simulate (const char * name, const int argc, const char ** argv)
programs->push_back(create_from_file<Program>(argv[i++]));
// simulate
auto trace = Simulator().simulate(programs, mmap, bound);
Simulator simulator;
auto trace = simulator.simulate(programs, mmap, bound);
for (; check && !trace->exit; seed++)
trace = simulator.simulate(programs, mmap, bound);
write(*trace, outfile);
return trace->exit;
}
......
......@@ -25,12 +25,6 @@ inline void erase (C & container, T & val)
// Simulator
//==============================================================================
//------------------------------------------------------------------------------
// public constructors
//------------------------------------------------------------------------------
Simulator::Simulator () : random(seed) {}
//------------------------------------------------------------------------------
// public member functions
//------------------------------------------------------------------------------
......@@ -283,6 +277,7 @@ void Simulator::init (const std::shared_ptr<Program::List> & p,
{
const size_t num_threads = p->size();
random.seed(seed);
programs = p.get();
trace = std::make_unique<Trace>(p, m);
bound = b ? b : static_cast<size_t>(-1);
......
......@@ -40,12 +40,6 @@ public: //======================================================================
exited = 'E' // exit called
};
//----------------------------------------------------------------------------
// public constructors
//----------------------------------------------------------------------------
Simulator ();
//----------------------------------------------------------------------------
// public member functions
//----------------------------------------------------------------------------
......
......@@ -121,7 +121,7 @@ TEST_F(Main, simulate)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(sim_trace);
const auto trace = create_from_file<Trace>(sim_trace);
ASSERT_EQ(2, trace.size());
for (const auto & it : trace) ASSERT_EQ(0, it.pc);
......@@ -142,12 +142,40 @@ TEST_F(Main, simulate_uninitialized)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(sim_trace);
auto mmap = create_from_file<MMap>(sim_mmap);
const auto trace = create_from_file<Trace>(sim_trace);
const auto mmap = create_from_file<MMap>(sim_mmap);
ASSERT_EQ(4, trace.size());
ASSERT_EQ(mmap[0], trace.accu(0));
ASSERT_EQ(mmap[1], trace.accu(1));
ASSERT_EQ(mmap.at(0), trace.accu(0));
ASSERT_EQ(mmap.at(1), trace.accu(1));
}
TEST_F(Main, simulate_exit_greater_zero)
{
const std::filesystem::path demo = "examples/demo/";
fs::cd(fs::mktmp(demo));
const auto out =
shell::run({
bin,
simulate,
"-c",
"-s", "0",
"-m", cwd / demo / "init.mmap",
cwd / demo / "processor.0.asm",
cwd / demo / "processor.1.asm",
cwd / demo / "checker.asm"});
ASSERT_EQ(1, out.exit);
ASSERT_EQ("", out.stdout.str());
const auto trace = create_from_file<Trace>(sim_trace);
const auto mmap = create_from_file<MMap>(sim_mmap);
ASSERT_EQ(15, trace.size());
ASSERT_EQ(0, trace.accu(0));
ASSERT_EQ(0, trace.accu(1));
}
TEST_F(Main, simulate_missing_args)
......@@ -175,7 +203,7 @@ TEST_F(Main, simulate_bound)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(sim_trace);
const auto trace = create_from_file<Trace>(sim_trace);
ASSERT_EQ(5, trace.size());
for (const auto & it : trace) ASSERT_EQ(0, it.pc);
......@@ -213,16 +241,16 @@ TEST_F(Main, simulate_mmap)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stderr.str());
auto trace = create_from_file<Trace>(sim_trace);
const auto trace = create_from_file<Trace>(sim_trace);
ASSERT_EQ(sim_mmap, trace.mmap->path);
auto mmap = create_from_file<MMap>(sim_mmap);
const auto mmap = create_from_file<MMap>(sim_mmap);
ASSERT_EQ(6, trace.size());
ASSERT_EQ(mmap[1], trace.accu(0));
ASSERT_EQ(mmap[2], trace.accu(1));
ASSERT_EQ(mmap[3], trace.accu(2));
ASSERT_EQ(mmap.at(1), trace.accu(0));
ASSERT_EQ(mmap.at(2), trace.accu(1));
ASSERT_EQ(mmap.at(3), trace.accu(2));
}
TEST_F(Main, simulate_mmap_missing)
......@@ -251,11 +279,11 @@ TEST_F(Main, simulate_outfile)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(stem + ".trace");
auto mmap = create_from_file<MMap>(stem + ".mmap");
const auto trace = create_from_file<Trace>(stem + ".trace");
const auto mmap = create_from_file<MMap>(stem + ".mmap");
ASSERT_EQ(2, trace.size());
ASSERT_EQ(mmap[0], trace.accu(0));
ASSERT_EQ(mmap.at(0), trace.accu(0));
}
TEST_F(Main, simulate_outfile_missing)
......@@ -284,13 +312,13 @@ TEST_F(Main, simulate_seed)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto t1 = create_from_file<Trace>(sim_trace);
const auto t1 = create_from_file<Trace>(sim_trace);
out = shell::run(cmd);
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto t2 = create_from_file<Trace>(sim_trace);
const auto t2 = create_from_file<Trace>(sim_trace);
ASSERT_EQ(t1, t2);
}
......@@ -331,7 +359,7 @@ TEST_F(Main, solve)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(smt_trace);
const auto trace = create_from_file<Trace>(smt_trace);
ASSERT_EQ(2, trace.size());
for (const auto & it : trace) ASSERT_EQ(0, it.pc);
......@@ -355,12 +383,12 @@ TEST_F(Main, solve_uninitialized)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(smt_trace);
auto mmap = create_from_file<MMap>(smt_mmap);
const auto trace = create_from_file<Trace>(smt_trace);
const auto mmap = create_from_file<MMap>(smt_mmap);
ASSERT_EQ(4, trace.size());
ASSERT_EQ(mmap[0], trace.accu(0));
ASSERT_EQ(mmap[1], trace.accu(1));
ASSERT_EQ(mmap.at(0), trace.accu(0));
ASSERT_EQ(mmap.at(1), trace.accu(1));
}
TEST_F(Main, solve_missing_args)
......@@ -395,7 +423,7 @@ TEST_F(Main, solve_bound)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(smt_trace);
const auto trace = create_from_file<Trace>(smt_trace);
ASSERT_EQ(5, trace.size());
for (const auto & it : trace) ASSERT_EQ(0, it.pc);
......@@ -616,16 +644,16 @@ TEST_F(Main, solve_mmap)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(smt_trace);
const auto trace = create_from_file<Trace>(smt_trace);
ASSERT_EQ(smt_mmap, trace.mmap->path);
auto mmap = create_from_file<MMap>(smt_mmap);
const auto mmap = create_from_file<MMap>(smt_mmap);
ASSERT_EQ(6, trace.size());
ASSERT_EQ(mmap[1], trace.accu(0));
ASSERT_EQ(mmap[2], trace.accu(1));
ASSERT_EQ(mmap[3], trace.accu(2));
ASSERT_EQ(mmap.at(1), trace.accu(0));
ASSERT_EQ(mmap.at(2), trace.accu(1));
ASSERT_EQ(mmap.at(3), trace.accu(2));
}
TEST_F(Main, solve_mmap_missing)
......@@ -662,11 +690,11 @@ TEST_F(Main, solve_outfile)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(stem + ".trace");
auto mmap = create_from_file<MMap>(stem + ".mmap");
const auto trace = create_from_file<Trace>(stem + ".trace");
const auto mmap = create_from_file<MMap>(stem + ".mmap");
ASSERT_EQ(2, trace.size());
ASSERT_EQ(mmap[0], trace.accu(0));
ASSERT_EQ(mmap.at(0), trace.accu(0));
}
TEST_F(Main, solve_outfile_missing)
......@@ -704,12 +732,12 @@ TEST_F(Main, solve_solver_btormc)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(smt_trace);
auto mmap = create_from_file<MMap>(smt_mmap);
const auto trace = create_from_file<Trace>(smt_trace);
const auto mmap = create_from_file<MMap>(smt_mmap);
ASSERT_EQ(4, trace.size());
ASSERT_EQ(mmap[0], trace.accu(0));
ASSERT_EQ(mmap[1], trace.accu(1));
ASSERT_EQ(mmap.at(0), trace.accu(0));
ASSERT_EQ(mmap.at(1), trace.accu(1));
}
TEST_F(Main, solve_solver_boolector)
......@@ -730,12 +758,12 @@ TEST_F(Main, solve_solver_boolector)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(smt_trace);
auto mmap = create_from_file<MMap>(smt_mmap);
const auto trace = create_from_file<Trace>(smt_trace);
const auto mmap = create_from_file<MMap>(smt_mmap);
ASSERT_EQ(4, trace.size());
ASSERT_EQ(mmap[0], trace.accu(0));
ASSERT_EQ(mmap[1], trace.accu(1));
ASSERT_EQ(mmap.at(0), trace.accu(0));
ASSERT_EQ(mmap.at(1), trace.accu(1));
}
TEST_F(Main, solve_solver_cvc4)
......@@ -756,12 +784,12 @@ TEST_F(Main, solve_solver_cvc4)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(smt_trace);
auto mmap = create_from_file<MMap>(smt_mmap);
const auto trace = create_from_file<Trace>(smt_trace);
const auto mmap = create_from_file<MMap>(smt_mmap);
ASSERT_EQ(4, trace.size());
ASSERT_EQ(mmap[0], trace.accu(0));
ASSERT_EQ(mmap[1], trace.accu(1));
ASSERT_EQ(mmap.at(0), trace.accu(0));
ASSERT_EQ(mmap.at(1), trace.accu(1));
}
TEST_F(Main, solve_solver_z3)
......@@ -782,12 +810,12 @@ TEST_F(Main, solve_solver_z3)
ASSERT_EQ(0, out.exit);
ASSERT_EQ("", out.stdout.str());
auto trace = create_from_file<Trace>(smt_trace);
auto mmap = create_from_file<MMap>(smt_mmap);
const auto trace = create_from_file<Trace>(smt_trace);
const auto mmap = create_from_file<MMap>(smt_mmap);
ASSERT_EQ(4, trace.size());
ASSERT_EQ(mmap[0], trace.accu(0));
ASSERT_EQ(mmap[1], trace.accu(1));
ASSERT_EQ(mmap.at(0), trace.accu(0));
ASSERT_EQ(mmap.at(1), trace.accu(1));
}
TEST_F(Main, solve_solver_missing)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment