Skip to content

Commit

Permalink
Add IPL unit test & fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
BlockoS committed Oct 20, 2024
1 parent 8820455 commit 34286d7
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 6 deletions.
21 changes: 15 additions & 6 deletions ipl.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

static bool ipl_read_header(IPL *out, FILE *in, const char *filename) {
bool ret = false;

if(fread(out->load_start_record, 1, 3, in) != 3) {
ERROR_MSG("Failed to read IPLBLK from %s: %s", filename, strerror(errno));
} else if(fread(&out->load_sector_count, 1, 1, in) != 1) {
Expand Down Expand Up @@ -107,21 +108,29 @@ void ipl_print(IPL *in) {
} else {
fprintf(stream, "IPLBLK: .db $%02x, $%02x, $%02x\n", in->load_start_record[0], in->load_start_record[1], in->load_start_record[2]);
fprintf(stream, "IPLBKN: .db $%02x\n", in->load_sector_count);
fprintf(stream, "IPLSTA: .dw $%02x%02x\n", in->load_store_address[0], in->load_store_address[1]);
fprintf(stream, "IPLJMP: .dw $%02x%02x\n", in->load_exec_address[0], in->load_exec_address[1]);
fprintf(stream, "IPLSTA: .dw $%02x%02x\n", in->load_store_address[1], in->load_store_address[0]);
fprintf(stream, "IPLJMP: .dw $%02x%02x\n", in->load_exec_address[1], in->load_exec_address[0]);
fprintf(stream, "IPLMPR: .db $%02x, $%02x, $%02x, $%02x, $%02x\n", in->mpr[0], in->mpr[1], in->mpr[2], in->mpr[3], in->mpr[4]);
fprintf(stream, "OPENMODE: .db $%02x\n", in->opening_mode);
fprintf(stream, "GRPBLK: .db $%02x, $%02x, $%02x\n", in->opening_gfx_record[0], in->opening_gfx_record[1], in->opening_gfx_record[2]);
fprintf(stream, "GRPBLN: .db $%02x\n", in->opening_gfx_sector_count);
fprintf(stream, "GRPADR: .dw $%02x%02x\n", in->opening_gfx_read_address[0], in->opening_gfx_read_address[1]);
fprintf(stream, "GRPADR: .dw $%02x%02x\n", in->opening_gfx_read_address[1], in->opening_gfx_read_address[0]);
fprintf(stream, "ADPBLK: .db $%02x, $%02x, $%02x\n", in->opening_adpcm_record[0], in->opening_adpcm_record[1], in->opening_adpcm_record[2]);
fprintf(stream, "ADPBLN: .db %02x\n", in->opening_adpcm_sector_count);
fprintf(stream, "ADPRATE: .db $%02x\b", in->opening_adpcm_sampling_rate);
fprintf(stream, "ADPRATE: .db $%02x\n", in->opening_adpcm_sampling_rate);
fprintf(stream, "RESERVED: .db $%02x, $%02x, $%02x, $%02x, $%02x, $%02x, $%02x\n",
in->reserved[0], in->reserved[1], in->reserved[2], in->reserved[3],
in->reserved[4], in->reserved[5], in->reserved[6]);
fprintf(stream, "ID STR: .db \"%.24s\"\n", in->id);
fprintf(stream, "LEGAL: .db \"%.50s\"\n", in->legal);
fprintf(stream, "ID STR: .db \"%.24s\"", in->id);
for(int i=23; (i>=0) && (in->id[i] == '\0'); i--) {
fprintf(stream, ",0");
}
fputc('\n', stream);
fprintf(stream, "LEGAL: .db \"%.50s\"", in->legal);
for(int i=49; (i>=0) && (in->legal[i] == '\0'); i--) {
fprintf(stream, ",0");
}
fputc('\n', stream);
fprintf(stream,"PROGRAM NAME: .db \"%.16s\"\n", in->program_name);
fprintf(stream,"EXTRA: .db \"%.6s\"\n", in->extra);
fclose(stream);
Expand Down
10 changes: 10 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,13 @@ add_unit_test(
LIBRARIES cwalk jansson
INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}
)

add_unit_test(
NAME ipl
SOURCES
ipl.c
${PROJECT_SOURCE_DIR}/message.c
${PROJECT_SOURCE_DIR}/message/console.c
LIBRARIES cwalk
INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}
)
137 changes: 137 additions & 0 deletions test/ipl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
¬°¤*,¸¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸
¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯
__/¯\____ ___/\__ _/\__ _/\_ _/\__ _/\___ ___/\__ __/\_ _/\__
\_ ____/_> ____ \_/ _ \_ \ < /_ \_/ _>> ____ \_ > \_/ _ \_
_> ___/ ¯>__> <<__// __ _/ |> ></ _/> </ ¯ \\__> <<__// /\ // __ _/
_> \7 <__/:. \__/:. \> \_/ L/ _____/. 7> .\_/:. \__/ <_/ </:. \> \_
|:::::::::::::::::::::::/:::::::::::::>::::::::/::::::::::::::::::::::::/:::::|
|¯¯\::::/\:/¯\::::/¯¯¯¯<::::/\::/¯¯\:/¯¯¯¯¯¯\::\::/¯¯\::::/¯¯\::::/¯¯¯¯<::::/¯|
|__ |¯¯| T _ |¯¯¯| ___ |¯¯| |¯| _ T ______ |¯¯¯¯| _ |¯¯¯| _ |¯¯¯| ___ |¯¯| _|
\|__|/\|/ \|___|/ \|__|/\|_|/ \|/ \| |/ \|___|/ \|___|/dNo\|__|/
¬°¤*,¸¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸
¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯
This file is part of Etripator,
copyright (c) 2009--2024 Vincent Cruz.
Etripator is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Etripator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Etripator. If not, see <http://www.gnu.org/licenses/>.
¬°¤*,¸¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸
¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯¬°¤*,¸_¸,*¤°¬°¤*,¸,*¤°¬¯
*/
#include <munit.h>

#include "../ipl.c"

#include "message.h"
#include "message/console.h"

static uint8_t g_hcd8004_ipl[] = {
0x00, 0x00, 0x02, 0x04, 0x00, 0x40, 0x00, 0x40, 0x00, 0x01, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x50, 0x43, 0x20, 0x45, 0x6E, 0x67, 0x69, 0x6E, 0x65, 0x20, 0x43, 0x44, 0x2D, 0x52, 0x4F, 0x4D,
0x20, 0x53, 0x59, 0x53, 0x54, 0x45, 0x4D, 0x00, 0x43, 0x6F, 0x70, 0x79, 0x72, 0x69, 0x67, 0x68,
0x74, 0x20, 0x48, 0x55, 0x44, 0x53, 0x4F, 0x4E, 0x20, 0x53, 0x4F, 0x46, 0x54, 0x20, 0x2F, 0x20,
0x4E, 0x45, 0x43, 0x20, 0x48, 0x6F, 0x6D, 0x65, 0x20, 0x45, 0x6C, 0x65, 0x63, 0x74, 0x72, 0x6F,
0x6E, 0x69, 0x63, 0x73, 0x2C, 0x4C, 0x74, 0x64, 0x2E, 0x00, 0x53, 0x70, 0x61, 0x63, 0x65, 0x20,
0x41, 0x64, 0x76, 0x65, 0x6E, 0x74, 0x75, 0x72, 0x65, 0x20, 0x43, 0x4F, 0x42, 0x52, 0x41, 0x20,
};

void* setup(const MunitParameter params[] __attribute__((unused)), void* user_data __attribute__((unused))) {
message_printer_init();
console_message_printer_init();
return NULL;
}

void tear_down(void* fixture __attribute__((unused))) {
message_printer_destroy();
}

MunitResult ipl_read_test(const MunitParameter params[] __attribute__((unused)), void* fixture __attribute__((unused))) {
IPL ipl = {0};
const char *filename = "data/HCD8004.ipl";

FILE *in = fmemopen(g_hcd8004_ipl, sizeof(g_hcd8004_ipl), "r");

munit_assert_not_null(in);
munit_assert_true(ipl_read_header(&ipl, in, filename));
munit_assert_int(fclose(in), ==, 0);

munit_assert_uint8(ipl.load_start_record[0], ==, 0x00U);
munit_assert_uint8(ipl.load_start_record[1], ==, 0x00U);
munit_assert_uint8(ipl.load_start_record[2], ==, 0x02U);

munit_assert_uint8(ipl.load_sector_count, ==, 0x04U);

munit_assert_uint8(ipl.load_store_address[0], ==, 0x00U);
munit_assert_uint8(ipl.load_store_address[1], ==, 0x40U);

munit_assert_uint8(ipl.load_exec_address[0], ==, 0x00U);
munit_assert_uint8(ipl.load_exec_address[1], ==, 0x40U);

munit_assert_uint8(ipl.mpr[0], ==, 0x00U);
munit_assert_uint8(ipl.mpr[1], ==, 0x01U);
munit_assert_uint8(ipl.mpr[2], ==, 0x02U);
munit_assert_uint8(ipl.mpr[3], ==, 0x03U);
munit_assert_uint8(ipl.mpr[4], ==, 0x04U);

munit_assert_uint8(ipl.opening_mode, ==, 0x00U);

munit_assert_uint8(ipl.opening_gfx_record[0], ==, 0x00U);
munit_assert_uint8(ipl.opening_gfx_record[1], ==, 0x00U);
munit_assert_uint8(ipl.opening_gfx_record[2], ==, 0x00U);

munit_assert_uint8(ipl.opening_gfx_sector_count, ==, 0x00U);

munit_assert_uint8(ipl.opening_gfx_read_address[0], ==, 0x00U);
munit_assert_uint8(ipl.opening_gfx_read_address[1], ==, 0x00U);

munit_assert_uint8(ipl.opening_adpcm_record[0], ==, 0x00U);
munit_assert_uint8(ipl.opening_adpcm_record[1], ==, 0x00U);
munit_assert_uint8(ipl.opening_adpcm_record[2], ==, 0x00U);

munit_assert_uint8(ipl.opening_adpcm_sector_count, ==, 0x00U);

munit_assert_uint8(ipl.opening_adpcm_sampling_rate, ==, 0x00U);

for(unsigned int i=0; i<7; i++) {
munit_assert_uint8(ipl.reserved[i], ==, 0x00U);
}

munit_assert_memory_equal(24U, ipl.id, "PC Engine CD-ROM SYSTEM");

munit_assert_memory_equal(50U, ipl.legal, "Copyright HUDSON SOFT / NEC Home Electronics,Ltd.");

munit_assert_memory_equal(16U, ipl.program_name, "Space Adventure ");

munit_assert_memory_equal(6U, ipl.extra, "COBRA ");

return MUNIT_OK;
}

static MunitTest g_ipl_tests[] = {
{ "/read", ipl_read_test, setup, tear_down, MUNIT_TEST_OPTION_NONE, NULL },
{ NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL }
};

static const MunitSuite g_ipl_test_suite = {
"Label test suite", g_ipl_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE
};

int main (int argc, char* const* argv) {
return munit_suite_main(&g_ipl_test_suite, NULL, argc, argv);
}

0 comments on commit 34286d7

Please sign in to comment.