treewide: restucture source tree per project
Signed-off-by: Max Regan <mgregan2@gmail.com>
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
#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,79 +0,0 @@
|
||||
#include "gbasm/assemble.h"
|
||||
#include "gbasm/emitter.h"
|
||||
#include "tests/gbasm/test.h"
|
||||
#include "tests/gbasm/inc.h"
|
||||
#include "tests/gbasm/fixed.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <string.h> /* memset */
|
||||
#include <glib.h>
|
||||
|
||||
const static struct gbasm_tests *tests[] = {
|
||||
&gbasm_fixed_tests,
|
||||
&gbasm_inc_tests,
|
||||
};
|
||||
|
||||
static int cmp_mem(const uint8_t *test_data, const uint8_t *expected_data, size_t len)
|
||||
{
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (test_data[i] != expected_data[i]) {
|
||||
g_test_message("memory contents differed at index %zu, data=%x, expected=%x",
|
||||
i, test_data[i], expected_data[i]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void run_test(const void *test_data)
|
||||
{
|
||||
static uint8_t program[4096];
|
||||
const struct gbasm_test *test = test_data;
|
||||
struct emitter emitter;
|
||||
struct buffer_emitter buffer_emitter;
|
||||
char *src;
|
||||
int rc;
|
||||
size_t len;
|
||||
|
||||
src = strdup(test->asm_source);
|
||||
|
||||
memset(program, 0, sizeof(program));
|
||||
buffer_emitter_init(&emitter, &buffer_emitter, program, sizeof(program));
|
||||
|
||||
rc = gbasm_assemble(src, &emitter);
|
||||
g_assert_cmpint(rc, ==, 0);
|
||||
|
||||
len = test->expected_output_len;
|
||||
|
||||
if (len != buffer_emitter.cursor) {
|
||||
g_warning("output lengths were not equal expected %zu, actual %zu",
|
||||
len, buffer_emitter.cursor);
|
||||
g_test_fail();
|
||||
len = MIN(len, buffer_emitter.cursor);
|
||||
}
|
||||
|
||||
rc = cmp_mem(program, test->expected_output, len);
|
||||
g_assert_cmpint(rc, ==, 0);
|
||||
|
||||
free(src);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char test_name_buff[256];
|
||||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
|
||||
for (int i = 0; i < ARRAY_SIZE(tests); i++) {
|
||||
for (int j = 0; j < tests[i]->num_tests; j++) {
|
||||
snprintf(test_name_buff, sizeof(test_name_buff),
|
||||
"/gbasm/%s/%s",
|
||||
tests[i]->name,
|
||||
tests[i]->tests[j]->name);
|
||||
g_test_add_data_func(test_name_buff, tests[i]->tests[j], run_test);
|
||||
}
|
||||
}
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
@@ -10,11 +10,11 @@
|
||||
#include <stdbool.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "common/common.h"
|
||||
#include "gb_disas.h"
|
||||
#include "cpu.h"
|
||||
#include "video.h"
|
||||
#include "tri.h"
|
||||
#include "gbemu/cpu.h"
|
||||
#include "gbemu/video.h"
|
||||
#include "common/tri.h"
|
||||
|
||||
#define INPUT_MAX_LEN 512
|
||||
#define MAX_BREAKPTS 256 /* Should be plenty for anyone */
|
||||
|
||||
@@ -1,124 +0,0 @@
|
||||
#include "tri.h"
|
||||
#include "common.h"
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define TO_PTR(x) ((void *) (uintptr_t) (x))
|
||||
#define TO_INT(x) ((int) (uintptr_t) (x))
|
||||
|
||||
static void test_tri_get_string(void)
|
||||
{
|
||||
struct tri tri;
|
||||
|
||||
tri_init(&tri);
|
||||
|
||||
g_assert_cmpint(tri_add_string(&tri, "a", TO_PTR(1)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "ab", TO_PTR(2)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "abc", TO_PTR(3)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "af", TO_PTR(4)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "abd", TO_PTR(5)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "$a!0123~&.`", TO_PTR(6)), ==, 0);
|
||||
|
||||
g_assert_cmpint(TO_INT(tri_get_string(&tri, "a")), ==, 1);
|
||||
g_assert_cmpint(TO_INT(tri_get_string(&tri, "ab")), ==, 2);
|
||||
g_assert_cmpint(TO_INT(tri_get_string(&tri, "abc")), ==, 3);
|
||||
g_assert_cmpint(TO_INT(tri_get_string(&tri, "af")), ==, 4);
|
||||
g_assert_cmpint(TO_INT(tri_get_string(&tri, "abd")), ==, 5);
|
||||
g_assert_cmpint(TO_INT(tri_get_string(&tri, "abz")), ==, 0);
|
||||
g_assert_cmpint(TO_INT(tri_get_string(&tri, "ag")), ==, 0);
|
||||
g_assert_cmpint(TO_INT(tri_get_string(&tri, "$a!0123~&.`")), ==, 6);
|
||||
|
||||
tri_free(&tri);
|
||||
}
|
||||
|
||||
static void test_tri_prefix_match(void)
|
||||
{
|
||||
struct tri tri;
|
||||
|
||||
tri_init(&tri);
|
||||
|
||||
g_assert_cmpint(tri_add_string(&tri, "pr", TO_PTR(1)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "pref", TO_PTR(2)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "Z", TO_PTR(3)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "prefix", TO_PTR(4)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "blah", TO_PTR(5)), ==, 0);
|
||||
|
||||
g_assert_cmpint(TO_INT(tri_prefix_match(&tri, "p")), ==, 0);
|
||||
g_assert_cmpint(TO_INT(tri_prefix_match(&tri, "pr")), ==, 1);
|
||||
g_assert_cmpint(TO_INT(tri_prefix_match(&tri, "pre")), ==, 1);
|
||||
g_assert_cmpint(TO_INT(tri_prefix_match(&tri, "pref")), ==, 2);
|
||||
g_assert_cmpint(TO_INT(tri_prefix_match(&tri, "prefix10")), ==, 4);
|
||||
g_assert_cmpint(TO_INT(tri_prefix_match(&tri, "asdfasdf")), ==, 0);
|
||||
|
||||
tri_free(&tri);
|
||||
}
|
||||
|
||||
static void test_tri_autocomplete(void)
|
||||
{
|
||||
struct tri tri;
|
||||
bool ambiguous;
|
||||
|
||||
tri_init(&tri);
|
||||
|
||||
g_assert_cmpint(tri_add_string(&tri, "pr", TO_PTR(1)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "pref", TO_PTR(2)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "Z", TO_PTR(3)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "prefix", TO_PTR(4)), ==, 0);
|
||||
g_assert_cmpint(tri_add_string(&tri, "blah", TO_PTR(5)), ==, 0);
|
||||
|
||||
|
||||
g_assert_null(tri_get_string_autocomplete(&tri, "p", &ambiguous));
|
||||
g_assert_true(ambiguous);
|
||||
|
||||
g_assert_null(tri_get_string_autocomplete(&tri, "pr", &ambiguous));
|
||||
g_assert_true(ambiguous);
|
||||
|
||||
g_assert_null(tri_get_string_autocomplete(&tri, "pre", &ambiguous));
|
||||
g_assert_true(ambiguous);
|
||||
|
||||
g_assert_null(tri_get_string_autocomplete(&tri, "pref", &ambiguous));
|
||||
g_assert_true(ambiguous);
|
||||
|
||||
g_assert_null(tri_get_string_autocomplete(&tri, "prefix10", &ambiguous));
|
||||
g_assert_false(ambiguous);
|
||||
|
||||
g_assert_null(tri_get_string_autocomplete(&tri, "asdfasdf", &ambiguous));
|
||||
g_assert_false(ambiguous);
|
||||
|
||||
g_assert_cmpint(TO_INT(tri_get_string_autocomplete(&tri, "bla", &ambiguous)), ==, 5);
|
||||
g_assert_false(ambiguous);
|
||||
|
||||
g_assert_cmpint(TO_INT(tri_get_string_autocomplete(&tri, "prefi", &ambiguous)), ==, 4);
|
||||
g_assert_false(ambiguous);
|
||||
|
||||
g_assert_cmpint(TO_INT(tri_get_string_autocomplete(&tri, "prefix", &ambiguous)), ==, 4);
|
||||
g_assert_false(ambiguous);
|
||||
|
||||
g_assert_cmpint(TO_INT(tri_get_string_autocomplete(&tri, "Z", &ambiguous)), ==, 3);
|
||||
g_assert_false(ambiguous);
|
||||
|
||||
tri_free(&tri);
|
||||
}
|
||||
|
||||
static void test_tri_null(void)
|
||||
{
|
||||
struct tri tri;
|
||||
|
||||
tri_init(&tri);
|
||||
|
||||
g_assert_cmpint(tri_add_string(&tri, NULL, TO_PTR(1)), ==, -1);
|
||||
g_assert_null(tri_prefix_match(&tri, NULL));
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func("/tri/get_string", test_tri_get_string);
|
||||
g_test_add_func("/tri/prefix_match", test_tri_prefix_match);
|
||||
g_test_add_func("/tri/autocomplete", test_tri_autocomplete);
|
||||
g_test_add_func("/tri/null", test_tri_null);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
Reference in New Issue
Block a user