static void node_setattr(struct imgtooltest_state *state, xml_data_node *node) { imgtoolerr_t err; xml_attribute_node *attr_node; UINT32 attribute; imgtool_attribute value; attr_node = xml_get_attribute(node, "path"); if (!attr_node) { state->m_failed = 1; error_missingattribute("path"); return; } attribute = identify_attribute(state, node, &value); if (!attribute) return; err = imgtool_partition_put_file_attribute(state->m_partition, attr_node->value, attribute, value); if (err) { state->m_failed = 1; report_imgtoolerr(err); return; } }
static void node_deletedirectory(struct imgtooltest_state *state, xml_data_node *node) { imgtoolerr_t err; xml_attribute_node *attr_node; if (!state->m_partition) { state->m_failed = 1; report_message(MSG_FAILURE, "Partition not loaded"); return; } attr_node = xml_get_attribute(node, "path"); if (!attr_node) { state->m_failed = 1; error_missingattribute("path"); return; } err = imgtool_partition_delete_directory(state->m_partition, attr_node->value); if (err) { state->m_failed = 1; report_imgtoolerr(err); return; } }
static void get_file_params(xml_data_node *node, const char **filename, const char **fork, filter_getinfoproc *filter) { xml_attribute_node *attr_node; *filename = NULL; *fork = NULL; *filter = NULL; attr_node = xml_get_attribute(node, "name"); if (!attr_node) { error_missingattribute("name"); return; } *filename = attr_node->value; attr_node = xml_get_attribute(node, "fork"); if (attr_node) *fork = attr_node->value; attr_node = xml_get_attribute(node, "filter"); if (attr_node) { *filter = filter_lookup(attr_node->value); if (!*filter) report_message(MSG_FAILURE, "Cannot find filter '%s'", attr_node->value); } }
static UINT32 identify_attribute(struct imgtooltest_state *state, xml_data_node *node, imgtool_attribute *value) { xml_attribute_node *attr_node; UINT32 attribute; attr_node = xml_get_attribute(node, "name"); if (!attr_node) { state->m_failed = 1; error_missingattribute("name"); return 0; } if (!strcmp(attr_node->value, "mac_file_type")) attribute = IMGTOOLATTR_INT_MAC_TYPE; else if (!strcmp(attr_node->value, "mac_file_creator")) attribute = IMGTOOLATTR_INT_MAC_CREATOR; else { error_missingattribute("name"); return 0; } attr_node = xml_get_attribute(node, "value"); if (!attr_node) { state->m_failed = 1; error_missingattribute("value"); return 0; } switch(attribute) { case IMGTOOLATTR_INT_MAC_TYPE: case IMGTOOLATTR_INT_MAC_CREATOR: if (strlen(attr_node->value) != 4) { state->m_failed = 1; error_missingattribute("value"); return 0; } value->i = pick_integer_be(attr_node->value, 0, 4); break; } return attribute; }
static void node_image(xml_data_node *node, messtest_command_type_t command) { xml_attribute_node *attr_node; const char *s2; int preload, device_type; memset(&new_command, 0, sizeof(new_command)); new_command.command_type = command; /* 'preload' attribute */ attr_node = xml_get_attribute(node, "preload"); preload = attr_node ? atoi(attr_node->value) : 0; if (preload) new_command.command_type += 2; /* 'filename' attribute */ attr_node = xml_get_attribute(node, "filename"); new_command.u.image_args.filename = attr_node ? attr_node->value : NULL; /* 'type' attribute */ attr_node = xml_get_attribute(node, "type"); if (!attr_node) { error_missingattribute("type"); return; } s2 = attr_node->value; device_type = device_typeid(s2); if (device_type < 0) { error_baddevicetype(s2); return; } new_command.u.image_args.device_type = device_type; /* 'slot' attribute */ attr_node = xml_get_attribute(node, "slot"); new_command.u.image_args.device_slot = attr_node ? atoi(attr_node->value) : 0; /* 'format' attribute */ format_index = 0; attr_node = xml_get_attribute(node, "format"); new_command.u.image_args.format = attr_node ? attr_node->value : NULL; /* 'tag' attribute */ attr_node = xml_get_attribute(node, "tag"); new_command.u.image_args.device_tag = attr_node ? attr_node->value : NULL; if (!append_command()) { error_outofmemory(); return; } }
static void node_memverify(xml_data_node *node) { xml_attribute_node *attr_node; const char *s1; const char *s2; const char *s3; int region; void *new_buffer; mess_pile pile; /* <memverify> - verifies that a range of memory contains specific data */ attr_node = xml_get_attribute(node, "start"); s1 = attr_node ? attr_node->value : NULL; if (!s1) { error_missingattribute("start"); return; } attr_node = xml_get_attribute(node, "end"); s2 = attr_node ? attr_node->value : NULL; if (!s2) s2 = "0"; attr_node = xml_get_attribute(node, "region"); s3 = attr_node ? attr_node->value : NULL; memset(&new_command, 0, sizeof(new_command)); new_command.command_type = MESSTEST_COMMAND_VERIFY_MEMORY; new_command.u.verify_args.start = parse_offset(s1); new_command.u.verify_args.end = parse_offset(s2); if (s3) { region = memory_region_from_string(s3); if (region == REGION_INVALID) error_invalidmemregion(s3); new_command.u.verify_args.mem_region = region; } pile_init(&pile); messtest_get_data(node, &pile); new_buffer = pool_malloc(&command_pool, pile_size(&pile)); memcpy(new_buffer, pile_getptr(&pile), pile_size(&pile)); new_command.u.verify_args.verify_data = new_buffer; new_command.u.verify_args.verify_data_size = pile_size(&pile); pile_delete(&pile); if (!append_command()) { error_outofmemory(); return; } }
static void node_switch(xml_data_node *node) { xml_attribute_node *attr_node; const char *s1; const char *s2; /* <switch> - switches a DIP switch/config setting */ memset(&new_command, 0, sizeof(new_command)); new_command.command_type = MESSTEST_COMMAND_SWITCH; /* 'name' attribute */ attr_node = xml_get_attribute(node, "name"); if (!attr_node) { error_missingattribute("name"); return; } s1 = attr_node->value; /* 'value' attribute */ attr_node = xml_get_attribute(node, "value"); if (!attr_node) { error_missingattribute("value"); return; } s2 = attr_node->value; new_command.u.switch_args.name = s1; new_command.u.switch_args.value = s2; if (!append_command()) { error_outofmemory(); return; } }
static void node_imageverify(xml_data_node *node) { xml_attribute_node *attr_node; const char *s; iodevice_t device_type; void *new_buffer; mess_pile pile; /* <imageverify> - verifies that an image contains specific data */ memset(&new_command, 0, sizeof(new_command)); new_command.command_type = MESSTEST_COMMAND_VERIFY_IMAGE; /* 'type' attribute */ attr_node = xml_get_attribute(node, "type"); s = attr_node ? attr_node->value : NULL; if (!s) { error_missingattribute("type"); return; } device_type = device_typeid(s); if (device_type < 0) { error_baddevicetype(s); return; } new_command.u.verify_args.device_type = device_type; pile_init(&pile); messtest_get_data(node, &pile); new_buffer = pool_malloc(&command_pool, pile_size(&pile)); memcpy(new_buffer, pile_getptr(&pile), pile_size(&pile)); new_command.u.verify_args.verify_data = new_buffer; new_command.u.verify_args.verify_data_size = pile_size(&pile); pile_delete(&pile); if (!append_command()) { error_outofmemory(); return; } }
static void node_wait(xml_data_node *node) { xml_attribute_node *attr_node; attr_node = xml_get_attribute(node, "time"); if (!attr_node) { error_missingattribute("time"); return; } memset(&new_command, 0, sizeof(new_command)); new_command.command_type = MESSTEST_COMMAND_WAIT; new_command.u.wait_time = mame_time_to_double(parse_time(attr_node->value)); if (!append_command()) { error_outofmemory(); return; } }
static void node_checkattr(struct imgtooltest_state *state, xml_data_node *node) { imgtoolerr_t err; xml_attribute_node *attr_node; UINT32 attribute; imgtool_attribute value; imgtool_attribute expected_value; memset(&value, 0, sizeof(value)); memset(&expected_value, 0, sizeof(expected_value)); attr_node = xml_get_attribute(node, "path"); if (!attr_node) { state->m_failed = 1; error_missingattribute("path"); return; } attribute = identify_attribute(state, node, &expected_value); if (!attribute) return; err = imgtool_partition_get_file_attribute(state->m_partition, attr_node->value, attribute, &value); if (err) { state->m_failed = 1; report_imgtoolerr(err); return; } if (memcmp(&value, &expected_value, sizeof(value))) { state->m_failed = 1; report_message(MSG_FAILURE, "Comparison failed"); return; } }
void node_testmess(xml_data_node *node) { xml_data_node *child_node; xml_attribute_node *attr_node; int result; pile_init(&command_pile); pool_init(&command_pool); memset(&new_command, 0, sizeof(new_command)); command_count = 0; /* 'driver' attribute */ attr_node = xml_get_attribute(node, "driver"); if (!attr_node) { error_missingattribute("driver"); return; } current_testcase.driver = attr_node->value; /* 'name' attribute */ attr_node = xml_get_attribute(node, "name"); current_testcase.name = attr_node ? attr_node->value : current_testcase.driver; /* 'ramsize' attribute */ attr_node = xml_get_attribute(node, "ramsize"); current_testcase.ram = attr_node ? ram_parse_string(attr_node->value) : 0; /* 'wavwrite' attribute */ attr_node = xml_get_attribute(node, "wavwrite"); current_testcase.wavwrite = attr_node && (atoi(attr_node->value) != 0); /* report the beginning of the test case */ report_testcase_begin(current_testcase.name); current_testcase.commands = NULL; for (child_node = node->child; child_node; child_node = child_node->next) { if (!strcmp(child_node->name, "wait")) node_wait(child_node); else if (!strcmp(child_node->name, "input")) node_input(child_node); else if (!strcmp(child_node->name, "rawinput")) node_rawinput(child_node); else if (!strcmp(child_node->name, "switch")) node_switch(child_node); else if (!strcmp(child_node->name, "screenshot")) node_screenshot(child_node); else if (!strcmp(child_node->name, "checkblank")) node_checkblank(child_node); else if (!strcmp(child_node->name, "imagecreate")) node_imagecreate(child_node); else if (!strcmp(child_node->name, "imageload")) node_imageload(child_node); else if (!strcmp(child_node->name, "memverify")) node_memverify(child_node); else if (!strcmp(child_node->name, "imageverify")) node_imageverify(child_node); else if (!strcmp(child_node->name, "trace")) node_trace(child_node); } memset(&new_command, 0, sizeof(new_command)); new_command.command_type = MESSTEST_COMMAND_END; if (!append_command()) { error_outofmemory(); return; } result = run_test(0, NULL); report_testcase_ran(result); pile_delete(&command_pile); pool_exit(&command_pool); }
static void node_createimage(struct imgtooltest_state *state, xml_data_node *node) { imgtoolerr_t err; xml_data_node *child_node; xml_attribute_node *attr_node; option_resolution *opts = NULL; const imgtool_module *module; const char *driver; const char *param_name; const char *param_value; attr_node = xml_get_attribute(node, "driver"); if (!attr_node) { error_missingattribute("driver"); return; } driver = attr_node->value; /* does image creation support options? */ module = imgtool_find_module(attr_node->value); if (module && module->createimage_optguide && module->createimage_optspec) opts = option_resolution_create(module->createimage_optguide, module->createimage_optspec); report_message(MSG_INFO, "Creating image (module '%s')", driver); for (child_node = xml_get_sibling(node->child, "param"); child_node; child_node = xml_get_sibling(child_node->next, "param")) { if (!opts) { report_message(MSG_FAILURE, "Cannot specify creation options with this module"); return; } attr_node = xml_get_attribute(child_node, "name"); if (!attr_node) { error_missingattribute("name"); return; } param_name = attr_node->value; attr_node = xml_get_attribute(child_node, "value"); if (!attr_node) { error_missingattribute("value"); return; } param_value = attr_node->value; option_resolution_add_param(opts, param_name, param_value); } err = imgtool_image_create_byname(driver, tempfile_name(), opts, &state->m_image); if (opts) { option_resolution_close(opts); opts = NULL; } if (err) { state->m_failed = 1; report_imgtoolerr(err); return; } err = imgtool_partition_open(state->m_image, 0, &state->m_partition); if (err) { state->m_failed = 1; report_imgtoolerr(err); return; } }