int main(int argc, char **argv) { int j; for (j = 1; j < argc; j++) { if (!strcmp(argv[j], "-fullscreen")) { fullscreen = true; } else if (!strcmp(argv[j], "-waitformsc")) { use_swapbuffers = false; } else if (!strcmp(argv[j], "-divisor")) { j++; divisor = parse_num_arg(argc, argv, j); } else if (!strcmp(argv[j], "-msc-delta")) { j++; target_msc_delta = parse_num_arg(argc, argv, j); } else { fprintf(stderr, "unsupported option %s\n", argv[j]); piglit_report_result(PIGLIT_FAIL); } } if (divisor && target_msc_delta) { fprintf(stderr, "this test doesn't support using both " "-divisor and -msc-delta\n"); piglit_report_result(PIGLIT_FAIL); } if (!use_swapbuffers && !divisor && !target_msc_delta) { fprintf(stderr, "when using -waitformsc, this test requires " "either -divisor or -msc-delta\n"); piglit_report_result(PIGLIT_FAIL); } if(!divisor) { divisor=1; } piglit_automatic = true; piglit_oml_sync_control_test_run(fullscreen, draw); return 0; }
int main(int argc, char *argv[]) { struct core *core; int option; bool enable_memory_dump = false; uint32_t mem_dump_base = 0; uint32_t mem_dump_length = 0; char *mem_dump_filename = NULL; size_t mem_dump_filename_len = 0; bool verbose = false; uint32_t fb_width = 640; uint32_t fb_height = 480; bool block_device_open = false; bool enable_fb_window = false; uint32_t total_threads = 4; char *separator; uint32_t memory_size = 0x1000000; const char *shared_memory_file = NULL; struct stat st; enum { MODE_NORMAL, MODE_COSIMULATION, MODE_GDB_REMOTE_DEBUG } mode = MODE_NORMAL; while ((option = getopt(argc, argv, "f:d:vm:b:t:c:r:s:i:o:")) != -1) { switch (option) { case 'v': verbose = true; break; case 'r': screen_refresh_rate = parse_num_arg(optarg); break; case 'f': enable_fb_window = true; separator = strchr(optarg, 'x'); if (!separator) { fprintf(stderr, "Invalid frame buffer size %s\n", optarg); return 1; } fb_width = parse_num_arg(optarg); fb_height = parse_num_arg(separator + 1); break; case 'm': if (strcmp(optarg, "normal") == 0) mode = MODE_NORMAL; else if (strcmp(optarg, "cosim") == 0) mode = MODE_COSIMULATION; else if (strcmp(optarg, "gdb") == 0) mode = MODE_GDB_REMOTE_DEBUG; else { fprintf(stderr, "Unkown execution mode %s\n", optarg); return 1; } break; case 'd': // Memory dump, of the form: filename,start,length separator = strchr(optarg, ','); if (separator == NULL) { fprintf(stderr, "bad format for memory dump\n"); usage(); return 1; } mem_dump_filename_len = (size_t)(separator - optarg); mem_dump_filename = (char*) malloc(mem_dump_filename_len + 1); strncpy(mem_dump_filename, optarg, mem_dump_filename_len); mem_dump_filename[mem_dump_filename_len] = '\0'; mem_dump_base = parse_num_arg(separator + 1); separator = strchr(separator + 1, ','); if (separator == NULL) { fprintf(stderr, "bad format for memory dump\n"); usage(); return 1; } mem_dump_length = parse_num_arg(separator + 1); enable_memory_dump = true; break; case 'b': if (open_block_device(optarg) < 0) return 1; block_device_open = true; break; case 'c': memory_size = parse_num_arg(optarg); break; case 't': total_threads = parse_num_arg(optarg); if (total_threads < 1 || total_threads > 32) { fprintf(stderr, "Total threads must be between 1 and 32\n"); return 1; } break; case 's': shared_memory_file = optarg; break; case 'i': recv_interrupt_fd = open(optarg, O_RDWR); if (recv_interrupt_fd < 0) { perror("main: failed to open receive interrupt pipe"); return 1; } if (fstat(recv_interrupt_fd, &st) < 0) { perror("main: stat failed on receive interrupt pipe"); return 1; } if ((st.st_mode & S_IFMT) != S_IFIFO) { fprintf(stderr, "%s is not a pipe\n", optarg); return 1; } break; case 'o': send_interrupt_fd = open(optarg, O_RDWR); if (send_interrupt_fd < 0) { perror("main: failed to open send interrupt pipe"); return 1; } if (fstat(send_interrupt_fd, &st) < 0) { perror("main: stat failed on send interrupt pipe"); return 1; } if ((st.st_mode & S_IFMT) != S_IFIFO) { fprintf(stderr, "%s is not a pipe\n", optarg); return 1; } break; case '?': usage(); return 1; } } if (optind == argc) { fprintf(stderr, "No image filename specified\n"); usage(); return 1; } // Don't randomize memory for cosimulation mode, because // memory is checked against the hardware model to ensure a match core = init_core(memory_size, total_threads, mode != MODE_COSIMULATION, shared_memory_file); if (core == NULL) return 1; if (load_hex_file(core, argv[optind]) < 0) { fprintf(stderr, "Error reading image %s\n", argv[optind]); return 1; } if (enable_fb_window) { if (init_frame_buffer(fb_width, fb_height) < 0) return 1; } switch (mode) { case MODE_NORMAL: if (verbose) enable_tracing(core); set_stop_on_fault(core, false); if (enable_fb_window) { while (execute_instructions(core, ALL_THREADS, screen_refresh_rate)) { update_frame_buffer(core); poll_fb_window_event(); check_interrupt_pipe(core); } } else { while (execute_instructions(core, ALL_THREADS, 1000000)) check_interrupt_pipe(core); } break; case MODE_COSIMULATION: set_stop_on_fault(core, false); if (run_cosimulation(core, verbose) < 0) return 1; // Failed break; case MODE_GDB_REMOTE_DEBUG: set_stop_on_fault(core, true); remote_gdb_main_loop(core, enable_fb_window); break; } if (enable_memory_dump) write_memory_to_file(core, mem_dump_filename, mem_dump_base, mem_dump_length); dump_instruction_stats(core); if (block_device_open) close_block_device(); if (stopped_on_fault(core)) return 1; return 0; }
/*********************************************************************** ************************************************************************ #cat: procargs - Process command line arguments, setting various #cat: static variables with file scope as appropriate. Input: argc - standard argument count argv - standard argument array Return Code: none - return on success no return - exit if invalid arguments are detected ************************************************************************/ static void procargs(int argc, char **argv) { int opt, output_images_flag = 0; const char *const option_spec = "vbc:rRf:i:n:q:"; const char *rest; REC_SEL *fgp_sel = NULL, *imp_sel = NULL, *idc_sel = NULL, *lrt_sel = NULL, *nqm_sel = NULL; if ((argc == 2) && (strcmp(argv[1], "-version") == 0)) { getVersion(); exit(0); } program = strrchr(argv[0], '/'); if (NULL == program) program = argv[0]; else ++program; if (argc < 2) usage(); /* The following section handles the deprecated old-style arguments. --jck */ old_style_args_flag = ((7 == argc) && ('-' != argv[1][0])); if (old_style_args_flag) { fgp = parse_num_arg(argv[1], "FGP"); bthr_adj = parse_num_arg(argv[2], "BTHR_ADJ"); rot_search = parse_num_arg(argv[3], "ROT_SEARCH"); comp = parse_num_arg(argv[4], "COMP_SEG"); rot_seg = parse_num_arg(argv[5], "ROT_SEG"); ifile = argv[6]; optind = 7; /* End of old-style deprecated argument handling. --jck */ } else { /* Processing exclusive to new-style argument handling... -- jck */ while (-1 != (opt = getopt(argc, argv, option_spec))) { switch(opt) { case 'v': verbose = 1; break; case 'b': bthr_adj = 1; break; case 'c': output_images_flag = 1; comp = parse_num_arg(optarg, "-c <COMP_SEG>"); break; case 'r': rot_search = 1; break; case 'R': rot_seg = 1; break; case 'f': if (parse_rec_sel_option(rs_fgp, optarg, &rest, &fgp_sel, verbose)) usage(); if (parse_rec_sel_option(rs_imp, rest, NULL, &imp_sel, verbose)) usage(); break; case 'i': if (parse_rec_sel_option(rs_imp, optarg, NULL, &imp_sel, verbose)) usage(); break; case 'n': if (parse_rec_sel_option(rs_idc, optarg, NULL, &idc_sel, verbose)) usage(); break; case 't': if (parse_rec_sel_option(rs_lrt, optarg, NULL, &lrt_sel, verbose)) usage(); break; case 'q': if (parse_rec_sel_option(rs_nqm, optarg, NULL, &nqm_sel, verbose)) usage(); break; case '?': usage(); break; default: fprintf(stderr, "Programming error: " "incompletely implemented option: '%c'\n", opt); exit(EXIT_FAILURE); } } /* ANSI/NIST input file, required */ if (optind < argc) ifile = argv[optind++]; else usage(); ansi_nist_flag = is_ANSI_NIST_file(ifile); if (ansi_nist_flag < 0) exit(EXIT_FAILURE); else if ( 0 == ansi_nist_flag ) { fprintf(stderr, "Input is not an ANSI/NIST file: '%s'.\n", ifile); usage(); } /* ANSI/NIST output file, optional */ if (optind < argc) ofile = argv[optind++]; if (new_rec_sel(&opt_rec_sel, rs_and, 5, fgp_sel, imp_sel, idc_sel, lrt_sel, nqm_sel) < 0) exit(EXIT_FAILURE); } /* This processing applies to both old- and new-style arguments. */ if (optind < argc) { fprintf(stderr, "WARNING : procargs : extra arguments ignored: %s", argv[optind++]); for (/* empty */; optind < argc; optind++) fprintf(stderr, ", %s", argv[optind]); fprintf(stderr, "\n"); } output_images = (ofile == NULL || output_images_flag); if (comp != UNSET && (comp < 0 || comp > 3)) { fprintf(stderr, "Invalid COMP (%d)\n", comp); fprintf(stderr, "0=JPEGL | 1=WSQ5:1 | 2=WSQ15:1 | 3=NONE\n"); exit(EXIT_FAILURE); } check_tristate_value(bthr_adj, "BTHR_ADJ"); check_tristate_value(rot_search, "ROT_SEARCH"); check_tristate_value(rot_seg, "ROT_SEG"); return; }