mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Add some YJIT runtime tests
This is just for helping my own understanding, but could be useful for others as well.
This commit is contained in:
parent
71cef74432
commit
a0bb731f4f
1 changed files with 57 additions and 2 deletions
|
@ -58,7 +58,7 @@ void check_bytes(codeblock_t* cb, const char* bytes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void run_tests()
|
void run_assembler_tests()
|
||||||
{
|
{
|
||||||
printf("Running assembler tests\n");
|
printf("Running assembler tests\n");
|
||||||
|
|
||||||
|
@ -353,9 +353,64 @@ void run_tests()
|
||||||
printf("Assembler tests done\n");
|
printf("Assembler tests done\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void assert_equal(expected, actual)
|
||||||
|
{
|
||||||
|
if (expected != actual) {
|
||||||
|
fprintf(stderr, "expected %d, got %d\n", expected, actual);
|
||||||
|
exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void run_runtime_tests()
|
||||||
|
{
|
||||||
|
printf("Running runtime tests\n");
|
||||||
|
|
||||||
|
codeblock_t codeblock;
|
||||||
|
codeblock_t* cb = &codeblock;
|
||||||
|
|
||||||
|
uint8_t* mem_block = alloc_exec_mem(4096);
|
||||||
|
cb_init(cb, mem_block, 4096);
|
||||||
|
|
||||||
|
int (*function)(void);
|
||||||
|
function = (int (*)(void))mem_block;
|
||||||
|
|
||||||
|
#define TEST(BODY) cb_set_pos(cb, 0); BODY ret(cb); assert_equal(7, function());
|
||||||
|
|
||||||
|
// add
|
||||||
|
TEST({ mov(cb, RAX, imm_opnd(0)); add(cb, RAX, imm_opnd(7)); })
|
||||||
|
TEST({ mov(cb, RAX, imm_opnd(0)); mov(cb, RCX, imm_opnd(7)); add(cb, RAX, RCX); })
|
||||||
|
|
||||||
|
// and
|
||||||
|
TEST({ mov(cb, RAX, imm_opnd(31)); and(cb, RAX, imm_opnd(7)); })
|
||||||
|
TEST({ mov(cb, RAX, imm_opnd(31)); mov(cb, RCX, imm_opnd(7)); and(cb, RAX, RCX); })
|
||||||
|
|
||||||
|
// or
|
||||||
|
TEST({ mov(cb, RAX, imm_opnd(3)); or(cb, RAX, imm_opnd(4)); })
|
||||||
|
TEST({ mov(cb, RAX, imm_opnd(3)); mov(cb, RCX, imm_opnd(4)); or(cb, RAX, RCX); })
|
||||||
|
|
||||||
|
// push/pop
|
||||||
|
TEST({ mov(cb, RCX, imm_opnd(7)); push(cb, RCX); pop(cb, RAX); })
|
||||||
|
|
||||||
|
// shr
|
||||||
|
TEST({ mov(cb, RAX, imm_opnd(31)); shr(cb, RAX, imm_opnd(2)); })
|
||||||
|
|
||||||
|
// sub
|
||||||
|
TEST({ mov(cb, RAX, imm_opnd(12)); sub(cb, RAX, imm_opnd(5)); })
|
||||||
|
TEST({ mov(cb, RAX, imm_opnd(12)); mov(cb, RCX, imm_opnd(5)); sub(cb, RAX, RCX); })
|
||||||
|
|
||||||
|
// xor
|
||||||
|
TEST({ mov(cb, RAX, imm_opnd(13)); xor(cb, RAX, imm_opnd(10)); })
|
||||||
|
TEST({ mov(cb, RAX, imm_opnd(13)); mov(cb, RCX, imm_opnd(10)); xor(cb, RAX, RCX); })
|
||||||
|
|
||||||
|
#undef TEST
|
||||||
|
|
||||||
|
printf("Runtime tests done\n");
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
run_tests();
|
run_assembler_tests();
|
||||||
|
run_runtime_tests();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue