tests: rename to remove underscores
It makes them more amenable to using their names as the names of the lcov output reports, which complains about the dashes. Signed-Off-By: Max Regan <mgregan2@gmail.com>
This commit is contained in:
94
src/apps/cpu_integ_test.c
Normal file
94
src/apps/cpu_integ_test.c
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "gbasm/assemble.h"
|
||||
#include "gbasm/emitter.h"
|
||||
#include "cpu.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <string.h> /* memset */
|
||||
#include <glib.h>
|
||||
|
||||
static uint8_t mem[4096] = { 0 };
|
||||
|
||||
static uint8_t mem_read(struct lr35902_state *cpu, uint16_t addr)
|
||||
{
|
||||
return mem[addr];
|
||||
}
|
||||
|
||||
static void mem_write(struct lr35902_state *cpu, uint16_t addr, uint8_t val)
|
||||
{
|
||||
mem[addr] = val;
|
||||
}
|
||||
|
||||
static void test_inc(const void *test_data)
|
||||
{
|
||||
struct emitter emitter;
|
||||
struct buffer_emitter buffer_emitter;
|
||||
struct lr35902_state cpu;
|
||||
char *src;
|
||||
int rc;
|
||||
|
||||
src = strdup("inc a\n inc b\n halt\n");
|
||||
memset(mem, 0, sizeof(mem));
|
||||
buffer_emitter_init(&emitter, &buffer_emitter, mem, sizeof(mem));
|
||||
|
||||
rc = gbasm_assemble(src, &emitter);
|
||||
g_assert_cmpint(rc, ==, 0);
|
||||
|
||||
lr35902_init(&cpu, mem_read, mem_write);
|
||||
while (!cpu.halted) {
|
||||
lr35902_cycle(&cpu);
|
||||
}
|
||||
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_A), ==, 1);
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_B), ==, 1);
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_C), ==, 0);
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_D), ==, 0);
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_E), ==, 0);
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_H), ==, 0);
|
||||
|
||||
free(src);
|
||||
}
|
||||
|
||||
|
||||
static void test_dec(const void *test_data)
|
||||
{
|
||||
struct emitter emitter;
|
||||
struct buffer_emitter buffer_emitter;
|
||||
struct lr35902_state cpu;
|
||||
char *src;
|
||||
int rc;
|
||||
|
||||
src = strdup("dec a\n inc c\n dec c\n dec de\n halt\n");
|
||||
memset(mem, 0, sizeof(mem));
|
||||
buffer_emitter_init(&emitter, &buffer_emitter, mem, sizeof(mem));
|
||||
|
||||
rc = gbasm_assemble(src, &emitter);
|
||||
g_assert_cmpint(rc, ==, 0);
|
||||
|
||||
lr35902_init(&cpu, mem_read, mem_write);
|
||||
while (!cpu.halted) {
|
||||
lr35902_cycle(&cpu);
|
||||
}
|
||||
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_A), ==, 0xff);
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_B), ==, 0);
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_C), ==, 0);
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_D), ==, 0xff);
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_E), ==, 0xff);
|
||||
g_assert_cmpint(lr35902_get_reg_8(&cpu, LR35902_REG_H), ==, 0);
|
||||
|
||||
g_assert_cmpint(lr35902_get_reg_16(&cpu, LR35902_REG_DE), ==, 0xffff);
|
||||
|
||||
|
||||
free(src);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
|
||||
g_test_add_data_func("/gbemu/cpu/inc", NULL, test_inc);
|
||||
g_test_add_data_func("/gbemu/cpu/dec", NULL, test_dec);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
#include <glib.h>
|
||||
|
||||
void test_fail(const void *data)
|
||||
{
|
||||
g_test_fail();
|
||||
}
|
||||
|
||||
void test_pass(const void *data)
|
||||
{
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
|
||||
g_test_add_data_func("/pass", NULL, test_pass);
|
||||
g_test_add_data_func("/fail", NULL, test_fail);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
Reference in New Issue
Block a user