src/mess/tools/messtest/testmess.c
| r2566 | r2567 | |
| 23 | 23 | #include "debug/debugcpu.h" |
| 24 | 24 | #endif /* ENABLE_DEBUGGER */ |
| 25 | 25 | |
| 26 | |
| 27 | /*************************************************************************** |
| 28 | CONSTANTS |
| 29 | ***************************************************************************/ |
| 30 | |
| 31 | #define MESSTEST_ALWAYS_DUMP_SCREENSHOT 1 |
| 32 | |
| 33 | |
| 34 | |
| 35 | /*************************************************************************** |
| 36 | TYPE DEFINITIONS |
| 37 | ***************************************************************************/ |
| 38 | |
| 26 | 39 | typedef enum |
| 27 | 40 | { |
| 28 | 41 | STATE_READY, |
| r2566 | r2567 | |
| 31 | 44 | STATE_DONE |
| 32 | 45 | } messtest_running_state_t; |
| 33 | 46 | |
| 47 | |
| 48 | |
| 34 | 49 | typedef enum |
| 35 | 50 | { |
| 36 | 51 | MESSTEST_COMMAND_END, |
| r2566 | r2567 | |
| 51 | 66 | MESSTEST_COMMAND_HARD_RESET |
| 52 | 67 | } messtest_command_type_t; |
| 53 | 68 | |
| 54 | | struct messtest_command |
| 69 | |
| 70 | |
| 71 | typedef struct _messtest_device_identity messtest_device_identity; |
| 72 | struct _messtest_device_identity |
| 55 | 73 | { |
| 74 | const char *tag; |
| 75 | iodevice_t type; |
| 76 | int slot; |
| 77 | }; |
| 78 | |
| 79 | |
| 80 | |
| 81 | typedef struct _messtest_command messtest_command; |
| 82 | struct _messtest_command |
| 83 | { |
| 56 | 84 | messtest_command_type_t command_type; |
| 57 | 85 | union |
| 58 | 86 | { |
| r2566 | r2567 | |
| 69 | 97 | offs_t end; |
| 70 | 98 | const void *verify_data; |
| 71 | 99 | size_t verify_data_size; |
| 72 | | iodevice_t device_type; |
| 73 | | int device_slot; |
| 100 | messtest_device_identity device_ident; |
| 74 | 101 | } verify_args; |
| 75 | 102 | struct |
| 76 | 103 | { |
| 77 | 104 | const char *filename; |
| 78 | 105 | const char *format; |
| 79 | | iodevice_t device_type; |
| 80 | | int device_slot; |
| 81 | | const char *device_tag; |
| 106 | messtest_device_identity device_ident; |
| 82 | 107 | } image_args; |
| 83 | 108 | struct |
| 84 | 109 | { |
| r2566 | r2567 | |
| 88 | 113 | } u; |
| 89 | 114 | }; |
| 90 | 115 | |
| 91 | | struct messtest_testcase |
| 116 | |
| 117 | |
| 118 | typedef struct _messtest_testcase messtest_testcase; |
| 119 | struct _messtest_testcase |
| 92 | 120 | { |
| 93 | 121 | const char *name; |
| 94 | 122 | const char *bios; |
| 95 | 123 | const char *driver; |
| 96 | 124 | attotime time_limit; /* 0.0 = default */ |
| 97 | | struct messtest_command *commands; |
| 125 | messtest_command *commands; |
| 98 | 126 | |
| 99 | 127 | /* options */ |
| 100 | 128 | UINT32 ram; |
| r2566 | r2567 | |
| 102 | 130 | unsigned int enabled : 1; |
| 103 | 131 | }; |
| 104 | 132 | |
| 133 | |
| 134 | |
| 135 | typedef struct _messtest_specific_state messtest_specific_state; |
| 105 | 136 | struct messtest_specific_state |
| 106 | 137 | { |
| 107 | | struct messtest_testcase testcase; |
| 138 | messtest_testcase testcase; |
| 108 | 139 | int command_count; |
| 109 | | struct messtest_command current_command; |
| 140 | messtest_command current_command; |
| 110 | 141 | }; |
| 111 | 142 | |
| 143 | |
| 144 | |
| 112 | 145 | typedef enum |
| 113 | 146 | { |
| 114 | 147 | MESSTEST_RESULT_SUCCESS, |
| r2566 | r2567 | |
| 116 | 149 | MESSTEST_RESULT_RUNTIMEFAILURE |
| 117 | 150 | } messtest_result_t; |
| 118 | 151 | |
| 119 | | struct messtest_results |
| 152 | |
| 153 | |
| 154 | typedef struct _messtest_results messtest_results; |
| 155 | struct _messtest_results |
| 120 | 156 | { |
| 121 | 157 | messtest_result_t rc; |
| 122 | 158 | UINT64 runtime_hash; /* A value that is a hash taken from certain runtime parameters; used to detect different execution paths */ |
| r2566 | r2567 | |
| 124 | 160 | |
| 125 | 161 | |
| 126 | 162 | |
| 127 | | #define MESSTEST_ALWAYS_DUMP_SCREENSHOT 1 |
| 163 | /*************************************************************************** |
| 164 | LOCAL VARIABLES |
| 165 | ***************************************************************************/ |
| 128 | 166 | |
| 129 | | |
| 130 | 167 | static messtest_running_state_t state; |
| 131 | 168 | static int had_failure; |
| 132 | 169 | static attotime wait_target; |
| 133 | 170 | static attotime final_time; |
| 134 | | static const struct messtest_command *current_command; |
| 171 | static const messtest_command *current_command; |
| 135 | 172 | static int test_flags; |
| 136 | 173 | static int screenshot_num; |
| 137 | 174 | static int format_index; |
| r2566 | r2567 | |
| 143 | 180 | static mess_pile command_pile; |
| 144 | 181 | static object_pool *command_pool; |
| 145 | 182 | static int command_count; |
| 146 | | static struct messtest_command new_command; |
| 183 | static messtest_command new_command; |
| 147 | 184 | |
| 148 | | static struct messtest_testcase current_testcase; |
| 185 | static messtest_testcase current_testcase; |
| 149 | 186 | |
| 150 | 187 | static const options_entry win_mess_opts[] = |
| 151 | 188 | { |
| r2566 | r2567 | |
| 157 | 194 | |
| 158 | 195 | |
| 159 | 196 | |
| 197 | /*************************************************************************** |
| 198 | IMPLEMENTATION |
| 199 | ***************************************************************************/ |
| 200 | |
| 160 | 201 | static astring *assemble_software_path(astring *str, const game_driver *gamedrv, const char *filename) |
| 161 | 202 | { |
| 162 | 203 | if (osd_is_absolute_path(filename)) |
| r2566 | r2567 | |
| 264 | 305 | |
| 265 | 306 | |
| 266 | 307 | |
| 267 | | static messtest_result_t run_test(int flags, struct messtest_results *results) |
| 308 | static messtest_result_t run_test(int flags, messtest_results *results) |
| 268 | 309 | { |
| 269 | 310 | const game_driver *driver; |
| 270 | 311 | messtest_result_t rc; |
| r2566 | r2567 | |
| 320 | 361 | fullpath = assemble_software_path(astring_alloc(), driver, current_command->u.image_args.filename); |
| 321 | 362 | |
| 322 | 363 | /* get the option name */ |
| 323 | | device_opt = device_typename(current_command->u.image_args.device_type); |
| 364 | device_opt = device_typename(current_command->u.image_args.device_ident.type); |
| 324 | 365 | |
| 325 | 366 | /* set the option */ |
| 326 | 367 | options_set_string(opts, device_opt, astring_c(fullpath), OPTION_PRIORITY_CMDLINE); |
| r2566 | r2567 | |
| 656 | 697 | } |
| 657 | 698 | |
| 658 | 699 | |
| 700 | |
| 701 | static const device_config *find_device_by_identity(running_machine *machine, const messtest_device_identity *ident) |
| 702 | { |
| 703 | const device_config *device; |
| 704 | |
| 705 | /* look up the image slot */ |
| 706 | if (ident->type == IO_UNKNOWN) |
| 707 | { |
| 708 | /* no device_type was specified; use the new preferred mechanism */ |
| 709 | device = device_list_find_by_tag(machine->config->devicelist, DEVICE_TYPE_WILDCARD, ident->tag); |
| 710 | } |
| 711 | else if (ident->tag != NULL) |
| 712 | { |
| 713 | /* perform a legacy lookup by tag */ |
| 714 | device = image_from_devtag_and_index(machine, ident->tag, ident->slot); |
| 715 | } |
| 716 | else |
| 717 | { |
| 718 | /* perform a legacy lookup by device type */ |
| 719 | device = image_from_devtype_and_index(ident->type, ident->slot); |
| 720 | } |
| 721 | |
| 722 | /* did the image slot lookup fail? */ |
| 723 | if (device == NULL) |
| 724 | { |
| 725 | state = STATE_ABORTED; |
| 726 | report_message(MSG_FAILURE, "Device '%s %i' does not exist", |
| 727 | device_typename(ident->type), ident->slot); |
| 728 | } |
| 729 | |
| 730 | return device; |
| 731 | } |
| 732 | |
| 733 | |
| 734 | |
| 659 | 735 | static void command_image_loadcreate(running_machine *machine) |
| 660 | 736 | { |
| 661 | 737 | const device_config *image; |
| 662 | | int device_type; |
| 663 | | int device_slot; |
| 664 | | const char *device_tag; |
| 665 | 738 | int i, format_index = 0; |
| 666 | 739 | const char *filename; |
| 667 | 740 | const char *format; |
| r2566 | r2567 | |
| 672 | 745 | int success; |
| 673 | 746 | const game_driver *gamedrv; |
| 674 | 747 | |
| 675 | | device_slot = current_command->u.image_args.device_slot; |
| 676 | | device_type = current_command->u.image_args.device_type; |
| 677 | | device_tag = current_command->u.image_args.device_tag; |
| 678 | | |
| 679 | 748 | /* look up the image slot */ |
| 680 | | if (device_tag) |
| 681 | | image = image_from_devtag_and_index(machine, device_tag, device_slot); |
| 682 | | else |
| 683 | | image = image_from_devtype_and_index(device_type, device_slot); |
| 684 | | if (!image) |
| 685 | | { |
| 686 | | state = STATE_ABORTED; |
| 687 | | report_message(MSG_FAILURE, "Image slot '%s %i' does not exist", |
| 688 | | device_typename(device_type), device_slot); |
| 749 | image = find_device_by_identity(machine, ¤t_command->u.image_args.device_ident); |
| 750 | if (image == NULL) |
| 689 | 751 | return; |
| 690 | | } |
| 752 | |
| 691 | 753 | info = image_device_getinfo(machine->config, image); |
| 692 | 754 | file_extensions = info.file_extensions; |
| 693 | 755 | |
| r2566 | r2567 | |
| 852 | 914 | verify_data = (const UINT8 *) current_command->u.verify_args.verify_data; |
| 853 | 915 | verify_data_size = current_command->u.verify_args.verify_data_size; |
| 854 | 916 | |
| 855 | | image = image_from_devtype_and_index(current_command->u.verify_args.device_type, current_command->u.verify_args.device_slot); |
| 917 | /* look up the device */ |
| 918 | image = find_device_by_identity(machine, ¤t_command->u.verify_args.device_ident); |
| 919 | if (image == NULL) |
| 920 | return; |
| 921 | |
| 856 | 922 | filename = image_filename(image); |
| 857 | | if (!filename) |
| 923 | if (filename == NULL) |
| 858 | 924 | { |
| 859 | 925 | state = STATE_ABORTED; |
| 860 | 926 | report_message(MSG_FAILURE, "Failed verification: Device Not Loaded"); |
| r2566 | r2567 | |
| 1059 | 1125 | { |
| 1060 | 1126 | if (pile_write(&command_pile, &new_command, sizeof(new_command))) |
| 1061 | 1127 | return FALSE; |
| 1062 | | current_testcase.commands = (struct messtest_command *) pile_getptr(&command_pile); |
| 1128 | current_testcase.commands = (messtest_command *) pile_getptr(&command_pile); |
| 1063 | 1129 | command_count++; |
| 1064 | 1130 | return TRUE; |
| 1065 | 1131 | } |
| r2566 | r2567 | |
| 1208 | 1274 | |
| 1209 | 1275 | |
| 1210 | 1276 | |
| 1211 | | static void node_image(xml_data_node *node, messtest_command_type_t command) |
| 1277 | static int get_device_identity_tags(xml_data_node *node, messtest_device_identity *ident) |
| 1212 | 1278 | { |
| 1213 | 1279 | xml_attribute_node *attr_node; |
| 1214 | 1280 | const char *s2; |
| 1215 | | int preload, device_type; |
| 1216 | 1281 | |
| 1282 | /* clear out the result */ |
| 1283 | memset(ident, 0, sizeof(*ident)); |
| 1284 | |
| 1285 | /* 'type' attribute */ |
| 1286 | attr_node = xml_get_attribute(node, "type"); |
| 1287 | if (attr_node != NULL) |
| 1288 | { |
| 1289 | s2 = attr_node->value; |
| 1290 | |
| 1291 | ident->type = device_typeid(s2); |
| 1292 | if (ident->type <= IO_UNKNOWN) |
| 1293 | { |
| 1294 | error_baddevicetype(s2); |
| 1295 | return FALSE; |
| 1296 | } |
| 1297 | } |
| 1298 | else |
| 1299 | { |
| 1300 | /* the device type was unspecified */ |
| 1301 | ident->type = IO_UNKNOWN; |
| 1302 | } |
| 1303 | |
| 1304 | /* 'slot' attribute */ |
| 1305 | attr_node = xml_get_attribute(node, "slot"); |
| 1306 | ident->slot = (attr_node != NULL) ? atoi(attr_node->value) : 0; |
| 1307 | |
| 1308 | /* 'tag' attribute */ |
| 1309 | attr_node = xml_get_attribute(node, "tag"); |
| 1310 | ident->tag = (attr_node != NULL) ? attr_node->value : NULL; |
| 1311 | |
| 1312 | return TRUE; |
| 1313 | } |
| 1314 | |
| 1315 | |
| 1316 | |
| 1317 | static void node_image(xml_data_node *node, messtest_command_type_t command) |
| 1318 | { |
| 1319 | xml_attribute_node *attr_node; |
| 1320 | int preload; |
| 1321 | |
| 1217 | 1322 | memset(&new_command, 0, sizeof(new_command)); |
| 1218 | 1323 | new_command.command_type = command; |
| 1219 | 1324 | |
| r2566 | r2567 | |
| 1227 | 1332 | attr_node = xml_get_attribute(node, "filename"); |
| 1228 | 1333 | new_command.u.image_args.filename = attr_node ? attr_node->value : NULL; |
| 1229 | 1334 | |
| 1230 | | /* 'type' attribute */ |
| 1231 | | attr_node = xml_get_attribute(node, "type"); |
| 1232 | | if (!attr_node) |
| 1233 | | { |
| 1234 | | error_missingattribute("type"); |
| 1335 | /* 'tag', 'type', 'slot' attributes */ |
| 1336 | if (!get_device_identity_tags(node, &new_command.u.image_args.device_ident)) |
| 1235 | 1337 | return; |
| 1236 | | } |
| 1237 | | s2 = attr_node->value; |
| 1238 | 1338 | |
| 1239 | | device_type = device_typeid(s2); |
| 1240 | | if (device_type < 0) |
| 1241 | | { |
| 1242 | | error_baddevicetype(s2); |
| 1243 | | return; |
| 1244 | | } |
| 1245 | | new_command.u.image_args.device_type = device_type; |
| 1246 | | |
| 1247 | | /* 'slot' attribute */ |
| 1248 | | attr_node = xml_get_attribute(node, "slot"); |
| 1249 | | new_command.u.image_args.device_slot = attr_node ? atoi(attr_node->value) : 0; |
| 1250 | | |
| 1251 | 1339 | /* 'format' attribute */ |
| 1252 | 1340 | format_index = 0; |
| 1253 | 1341 | attr_node = xml_get_attribute(node, "format"); |
| 1254 | 1342 | new_command.u.image_args.format = attr_node ? attr_node->value : NULL; |
| 1255 | 1343 | |
| 1256 | | /* 'tag' attribute */ |
| 1257 | | attr_node = xml_get_attribute(node, "tag"); |
| 1258 | | new_command.u.image_args.device_tag = attr_node ? attr_node->value : NULL; |
| 1259 | | |
| 1260 | 1344 | if (!append_command()) |
| 1261 | 1345 | { |
| 1262 | 1346 | error_outofmemory(); |
| r2566 | r2567 | |
| 1341 | 1425 | |
| 1342 | 1426 | static void node_imageverify(xml_data_node *node) |
| 1343 | 1427 | { |
| 1344 | | xml_attribute_node *attr_node; |
| 1345 | | const char *s; |
| 1346 | | iodevice_t device_type; |
| 1347 | 1428 | void *new_buffer; |
| 1348 | 1429 | mess_pile pile; |
| 1349 | 1430 | |
| r2566 | r2567 | |
| 1351 | 1432 | memset(&new_command, 0, sizeof(new_command)); |
| 1352 | 1433 | new_command.command_type = MESSTEST_COMMAND_VERIFY_IMAGE; |
| 1353 | 1434 | |
| 1354 | | /* 'type' attribute */ |
| 1355 | | attr_node = xml_get_attribute(node, "type"); |
| 1356 | | s = attr_node ? attr_node->value : NULL; |
| 1357 | | if (!s) |
| 1358 | | { |
| 1359 | | error_missingattribute("type"); |
| 1435 | /* 'tag', 'type', 'slot' attributes */ |
| 1436 | if (!get_device_identity_tags(node, &new_command.u.verify_args.device_ident)) |
| 1360 | 1437 | return; |
| 1361 | | } |
| 1362 | 1438 | |
| 1363 | | device_type = device_typeid(s); |
| 1364 | | if (device_type < 0) |
| 1365 | | { |
| 1366 | | error_baddevicetype(s); |
| 1367 | | return; |
| 1368 | | } |
| 1369 | | |
| 1370 | | new_command.u.verify_args.device_type = device_type; |
| 1371 | | |
| 1372 | 1439 | pile_init(&pile); |
| 1373 | 1440 | messtest_get_data(node, &pile); |
| 1374 | 1441 | new_buffer = pool_malloc(command_pool, pile_size(&pile)); |