Skip to content

Commit

Permalink
Merge branch 'issue-764' into develop
Browse files Browse the repository at this point in the history
Work on #764
  • Loading branch information
bchurchill committed Nov 3, 2015
2 parents dfdc7b8 + f552896 commit f4c7e82
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
47 changes: 47 additions & 0 deletions tests/sandbox/sandbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -944,4 +944,51 @@ TEST(SandboxTest, CannotReadInvalidAddress) {

}

TEST(SandboxTest, DivideBySpl1) {

std::stringstream st;
st << ".foo:" << std::endl;
st << "movl $0x0, %edx" << std::endl;
st << "divb %dl" << std::endl;
st << "retq" << std::endl;

x64asm::Code d;
st >> d;
auto cfg_2 = Cfg(TUnit(d));


std::stringstream ss;
ss << ".foo:" << std::endl;
ss << "movl $0x0, %esp" << std::endl;
ss << "divb %spl" << std::endl;
ss << "retq" << std::endl;

x64asm::Code c;
ss >> c;
auto cfg = Cfg(TUnit(c));

CpuState tc;

Sandbox sb;
sb.set_abi_check(false);

uint64_t base = 0x10;
tc.gp[x64asm::rax].get_fixed_quad(0) = base;
tc.gp[x64asm::rdx].get_fixed_quad(0) = base;

sb.insert_input(tc);
sb.run(cfg);

auto code_1 = sb.result_begin()->code;

sb.run(cfg_2);

auto code_2 = sb.result_begin()->code;

EXPECT_NE(ErrorCode::NORMAL, code_1);
EXPECT_NE(ErrorCode::NORMAL, code_2);
EXPECT_EQ(code_1, code_2);

}

} //namespace
32 changes: 32 additions & 0 deletions tests/validator/simple.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,36 @@ TEST_F(ValidatorBaseTest, Issue550) {
check_circuit(cs);
}

TEST_F(ValidatorBaseTest, Issue764) {

target_ << ".foo:" << std::endl;
target_ << "idivb %spl" << std::endl;
target_ << "retq" << std::endl;

Sandbox sb;
sb.set_abi_check(false);
StateGen sg(&sb);
CpuState cs;
sg.get(cs);
cs.gp[x64asm::rsp].get_fixed_quad(0) = 0x700000000;

check_circuit(cs);
}

TEST_F(ValidatorBaseTest, Issue764_2) {

target_ << ".foo:" << std::endl;
target_ << "divb %spl" << std::endl;
target_ << "retq" << std::endl;

Sandbox sb;
sb.set_abi_check(false);
StateGen sg(&sb);
CpuState cs;
sg.get(cs);
cs.gp[x64asm::rsp].get_fixed_quad(0) = 0x700000000;

check_circuit(cs);
}

} //namespace stoke
12 changes: 11 additions & 1 deletion tests/x64asm/read_write_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void spreadsheet_read_write_set_fuzz_callback(const Cfg& pre_cfg, void* callback

Sandbox sb;
sb.set_abi_check(false)
.set_max_jumps(1);
.set_max_jumps(10);

StateGen sg(&sb);
sg.set_max_memory(1024)
Expand Down Expand Up @@ -157,6 +157,16 @@ void spreadsheet_read_write_set_fuzz_callback(const Cfg& pre_cfg, void* callback
// test that the two states match on live_out
bool failed = false;
std::stringstream os;
if (final1.code != final2.code) {
os << "Error codes differ.";
failed = true;
report(failed, ins, cs1, cs2, final1, final2, os.str());
return;
}
if (final1.code != stoke::ErrorCode::NORMAL) {
fuzz_print() << "Error code not normal; cannot check" << std::endl;
return;
}
for (auto it = liveouts.gp_begin(); it != liveouts.gp_end(); ++it) {
x64asm::R r = *it;
std::stringstream ss;
Expand Down

0 comments on commit f4c7e82

Please sign in to comment.