/* * mode_create_pattern_file -- 'create' mode function */ static int mode_create_pattern_file(const char *path_license, const char *path_pattern) { char pattern[LICENSE_MAX_LEN]; if (create_pattern(path_license, pattern) == -1) return -1; return write_pattern(path_pattern, pattern); }
int main(int argc, char *argv[]) { read_options(argc, argv); allocate(); write_pattern(); start_threads(); return 0; }
// ============================================================== int main(int argc, char** argv) // ============================================================== { read_parameters(argc,argv); if (argc-1>num_of_opts) AR = alignment_reader(argv[num_of_opts+1]); else AR = alignment_reader(stdin); alignment_reader::iterator a_it = AR.begin(); alignment_reader::iterator a_fragrep = AR.end(); alignment_reader::iterator a_end = AR.end(); for (; a_it!=a_end; ++a_it) { if (a_it->first=="FRAGREP" || a_it->first=="#=FRAGREP") { block_line = a_it->second; a_fragrep = a_it; } } if (a_fragrep==a_end) { std::cout<<"No block defining sequence found.\n"; return 0; } block_line = a_fragrep->second; AR.erase(a_fragrep); clean_sequences(); GC_ratio = get_GC_ratio(); scan_block_line(); if (!make_matrices) write_pattern(); else { write_matrix_pattern(); //write_eps_output(); } }
static int __init tort_init(void) { int err = 0, i, infinite = !cycles_count; int bad_ebs[ebcnt]; ; ; // printk(PRINT_PREF "Warning: this program is trying to wear out your " ; ; // printk(PRINT_PREF "torture %d eraseblocks (%d-%d) of mtd%d\n", ; if (pgcnt) // printk(PRINT_PREF "torturing just %d pages per eraseblock\n", ; ; mtd = get_mtd_device(NULL, dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); ; return err; } if (mtd->writesize == 1) { // printk(PRINT_PREF "not NAND flash, assume page size is 512 " ; pgsize = 512; } else pgsize = mtd->writesize; if (pgcnt && (pgcnt > mtd->erasesize / pgsize || pgcnt < 0)) { ; goto out_mtd; } err = -ENOMEM; patt_5A5 = kmalloc(mtd->erasesize, GFP_KERNEL); if (!patt_5A5) { ; goto out_mtd; } patt_A5A = kmalloc(mtd->erasesize, GFP_KERNEL); if (!patt_A5A) { ; goto out_patt_5A5; } patt_FF = kmalloc(mtd->erasesize, GFP_KERNEL); if (!patt_FF) { ; goto out_patt_A5A; } check_buf = kmalloc(mtd->erasesize, GFP_KERNEL); if (!check_buf) { ; goto out_patt_FF; } err = 0; /* Initialize patterns */ memset(patt_FF, 0xFF, mtd->erasesize); for (i = 0; i < mtd->erasesize / pgsize; i++) { if (!(i & 1)) { memset(patt_5A5 + i * pgsize, 0x55, pgsize); memset(patt_A5A + i * pgsize, 0xAA, pgsize); } else { memset(patt_5A5 + i * pgsize, 0xAA, pgsize); memset(patt_A5A + i * pgsize, 0x55, pgsize); } } /* * Check if there is a bad eraseblock among those we are going to test. */ memset(&bad_ebs[0], 0, sizeof(int) * ebcnt); if (mtd->block_isbad) { for (i = eb; i < eb + ebcnt; i++) { err = mtd->block_isbad(mtd, (loff_t)i * mtd->erasesize); if (err < 0) { // printk(PRINT_PREF "block_isbad() returned %d " ; goto out; } if (err) { ; bad_ebs[i - eb] = 1; } } } start_timing(); while (1) { int i; void *patt; /* Erase all eraseblocks */ for (i = eb; i < eb + ebcnt; i++) { if (bad_ebs[i - eb]) continue; err = erase_eraseblock(i); if (err) goto out; cond_resched(); } /* Check if the eraseblocks contain only 0xFF bytes */ if (check) { for (i = eb; i < eb + ebcnt; i++) { if (bad_ebs[i - eb]) continue; err = check_eraseblock(i, patt_FF); if (err) { // printk(PRINT_PREF "verify failed" ; goto out; } cond_resched(); } } /* Write the pattern */ for (i = eb; i < eb + ebcnt; i++) { if (bad_ebs[i - eb]) continue; if ((eb + erase_cycles) & 1) patt = patt_5A5; else patt = patt_A5A; err = write_pattern(i, patt); if (err) goto out; cond_resched(); } /* Verify what we wrote */ if (check) { for (i = eb; i < eb + ebcnt; i++) { if (bad_ebs[i - eb]) continue; if ((eb + erase_cycles) & 1) patt = patt_5A5; else patt = patt_A5A; err = check_eraseblock(i, patt); if (err) { // printk(PRINT_PREF "verify failed for %s" // " pattern\n", // ((eb + erase_cycles) & 1) ? ; goto out; } cond_resched(); } } erase_cycles += 1; if (erase_cycles % gran == 0) { long ms; stop_timing(); ms = (finish.tv_sec - start.tv_sec) * 1000 + (finish.tv_usec - start.tv_usec) / 1000; // printk(PRINT_PREF "%08u erase cycles done, took %lu " // "milliseconds (%lu seconds)\n", ; start_timing(); } if (!infinite && --cycles_count == 0) break; } out: // printk(PRINT_PREF "finished after %u erase cycles\n", ; kfree(check_buf); out_patt_FF: kfree(patt_FF); out_patt_A5A: kfree(patt_A5A); out_patt_5A5: kfree(patt_5A5); out_mtd: put_mtd_device(mtd); if (err) ; ; return err; }
int main(int argc, char *argv[]) { const char *filename; FILE *input_FILE; const char *const *output_strings; int mode; int move_pos; char line[BUFSIZE]; char name[BUFSIZE]; char stones[BUFSIZE]; int value; char board[MAX_BOARD + 2][MAX_BOARD + 2]; Intersection board1d[BOARDSIZE]; int boardsize; int i, j, k; int pos; char color; /* Check number of arguments. */ if (argc != 4) { fprintf(stderr, USAGE); return EXIT_FAILURE; } boardsize = atoi(argv[1]); filename = argv[2]; if (strncmp(argv[3], "c", 2) == 0) { mode = C_OUTPUT; output_strings = c_output_strings; set_random_seed(HASH_RANDOM_SEED); hash_init(); } else if (strncmp(argv[3], "db", 3) == 0) { mode = DB_OUTPUT; output_strings = db_output_strings; } else { fprintf(stderr, USAGE); return EXIT_FAILURE; } assert(boardsize > 0); if (boardsize > MAX_BOARD) { printf(output_strings[PREAMBLE]); printf(output_strings[HEADER], boardsize); printf(output_strings[FOOTER]); return EXIT_SUCCESS; } input_FILE = fopen(filename, "r"); if (!input_FILE) { fprintf(stderr, "uncompress_fuseki: Cannot open file %s\n", filename); return EXIT_FAILURE; } /* Initialize the corners of the internal board description. */ board[0][0] = '+'; board[0][boardsize + 1] = '+'; board[boardsize + 1][0] = '+'; board[boardsize + 1][boardsize + 1] = '+'; /* Initialize the sides of the internal board description. */ for (k = 1; k <= boardsize; k++) { board[0][k] = '-'; board[boardsize + 1][k] = '-'; board[k][0] = '|'; board[k][boardsize + 1] = '|'; } printf(output_strings[PREAMBLE]); printf(output_strings[HEADER], boardsize); /* Loop over the lines of the compressed database. * Each line is one pattern. */ while (fgets(line, BUFSIZE, input_FILE)) { int num_stones = 0; /* Clear the internal board. */ for (i = 1; i <= boardsize; i++) for (j = 1; j <= boardsize; j++) board[i][j] = '.'; /* Initialize private 1D-board. */ for (pos = 0; pos < BOARDSIZE; pos++) if (I(pos) >= 0 && I(pos) < boardsize && J(pos) >= 0 && J(pos) < boardsize) board1d[pos] = EMPTY; else board1d[pos] = GRAY; /* Assume a line from copyright notice if misformed and * silently ignore it. */ if (sscanf(line, "%s %d %s", name, &value, stones) != 3) continue; /* The first point in the stones list is the move to be played. */ move_pos = set_boards(board, board1d, stones, '*', boardsize); /* Then follows alternating X and O stones. */ color = 'X'; for (k = 2; k < (int) strlen(stones); k += 2) { pos = set_boards(board, board1d, stones + k, color, boardsize); if (I(pos) >= 0 && I(pos) < boardsize && J(pos) >= 0 && J(pos) < boardsize) num_stones++; if (color == 'X') color = 'O'; else color = 'X'; } if (mode == DB_OUTPUT) write_pattern(name, board, value, boardsize); else write_pattern_c_code(name, board1d, move_pos, value, boardsize, num_stones); } /* Add a dummy pattern to mark the end of the array. This can't be * done statically in the footer since NUM_HASHVALUES may vary. */ if (mode == C_OUTPUT) write_pattern_c_code(NULL, board1d, NO_MOVE, 0, boardsize, -1); printf(output_strings[FOOTER]); return EXIT_SUCCESS; }
static int __init tort_init(void) { int err = 0, i, infinite = !cycles_count; int bad_ebs[ebcnt]; printk(KERN_INFO "\n"); printk(KERN_INFO "=================================================\n"); printk(PRINT_PREF "Warning: this program is trying to wear out your " "flash, stop it if this is not wanted.\n"); printk(PRINT_PREF "MTD device: %d\n", dev); printk(PRINT_PREF "torture %d eraseblocks (%d-%d) of mtd%d\n", ebcnt, eb, eb + ebcnt - 1, dev); if (pgcnt) printk(PRINT_PREF "torturing just %d pages per eraseblock\n", pgcnt); printk(PRINT_PREF "write verify %s\n", check ? "enabled" : "disabled"); mtd = get_mtd_device(NULL, dev); if (IS_ERR(mtd)) { err = PTR_ERR(mtd); printk(PRINT_PREF "error: cannot get MTD device\n"); return err; } if (mtd->writesize == 1) { printk(PRINT_PREF "not NAND flash, assume page size is 512 " "bytes.\n"); pgsize = 512; } else pgsize = mtd->writesize; if (pgcnt && (pgcnt > mtd->erasesize / pgsize || pgcnt < 0)) { printk(PRINT_PREF "error: invalid pgcnt value %d\n", pgcnt); goto out_mtd; } err = -ENOMEM; patt_5A5 = kmalloc(mtd->erasesize, GFP_KERNEL); if (!patt_5A5) { printk(PRINT_PREF "error: cannot allocate memory\n"); goto out_mtd; } patt_A5A = kmalloc(mtd->erasesize, GFP_KERNEL); if (!patt_A5A) { printk(PRINT_PREF "error: cannot allocate memory\n"); goto out_patt_5A5; } patt_FF = kmalloc(mtd->erasesize, GFP_KERNEL); if (!patt_FF) { printk(PRINT_PREF "error: cannot allocate memory\n"); goto out_patt_A5A; } check_buf = kmalloc(mtd->erasesize, GFP_KERNEL); if (!check_buf) { printk(PRINT_PREF "error: cannot allocate memory\n"); goto out_patt_FF; } err = 0; /* Initialize patterns */ memset(patt_FF, 0xFF, mtd->erasesize); for (i = 0; i < mtd->erasesize / pgsize; i++) { if (!(i & 1)) { memset(patt_5A5 + i * pgsize, 0x55, pgsize); memset(patt_A5A + i * pgsize, 0xAA, pgsize); } else { memset(patt_5A5 + i * pgsize, 0xAA, pgsize); memset(patt_A5A + i * pgsize, 0x55, pgsize); } } /* * Check if there is a bad eraseblock among those we are going to test. */ memset(&bad_ebs[0], 0, sizeof(int) * ebcnt); if (mtd->block_isbad) { for (i = eb; i < eb + ebcnt; i++) { err = mtd->block_isbad(mtd, (loff_t)i * mtd->erasesize); if (err < 0) { printk(PRINT_PREF "block_isbad() returned %d " "for EB %d\n", err, i); goto out; } if (err) { printk("EB %d is bad. Skip it.\n", i); bad_ebs[i - eb] = 1; } } } start_timing(); while (1) { int i; void *patt; /* Erase all eraseblocks */ for (i = eb; i < eb + ebcnt; i++) { if (bad_ebs[i - eb]) continue; err = erase_eraseblock(i); if (err) goto out; cond_resched(); } /* Check if the eraseblocks contain only 0xFF bytes */ if (check) { for (i = eb; i < eb + ebcnt; i++) { if (bad_ebs[i - eb]) continue; err = check_eraseblock(i, patt_FF); if (err) { printk(PRINT_PREF "verify failed" " for 0xFF... pattern\n"); goto out; } cond_resched(); } } /* Write the pattern */ for (i = eb; i < eb + ebcnt; i++) { if (bad_ebs[i - eb]) continue; if ((eb + erase_cycles) & 1) patt = patt_5A5; else patt = patt_A5A; err = write_pattern(i, patt); if (err) goto out; cond_resched(); } /* Verify what we wrote */ if (check) { for (i = eb; i < eb + ebcnt; i++) { if (bad_ebs[i - eb]) continue; if ((eb + erase_cycles) & 1) patt = patt_5A5; else patt = patt_A5A; err = check_eraseblock(i, patt); if (err) { printk(PRINT_PREF "verify failed for %s" " pattern\n", ((eb + erase_cycles) & 1) ? "0x55AA55..." : "0xAA55AA..."); goto out; } cond_resched(); } } erase_cycles += 1; if (erase_cycles % gran == 0) { long ms; stop_timing(); ms = (finish.tv_sec - start.tv_sec) * 1000 + (finish.tv_usec - start.tv_usec) / 1000; printk(PRINT_PREF "%08u erase cycles done, took %lu " "milliseconds (%lu seconds)\n", erase_cycles, ms, ms / 1000); start_timing(); } if (!infinite && --cycles_count == 0) break; } out: printk(PRINT_PREF "finished after %u erase cycles\n", erase_cycles); kfree(check_buf); out_patt_FF: kfree(patt_FF); out_patt_A5A: kfree(patt_A5A); out_patt_5A5: kfree(patt_5A5); out_mtd: put_mtd_device(mtd); if (err) printk(PRINT_PREF "error %d occurred during torturing\n", err); printk(KERN_INFO "=================================================\n"); return err; }
/* * Kernel ion user import test */ int test_kuimport(const char *ion_dev, const char *msm_ion_dev, struct ion_test_plan *ion_tp, int test_type) { int ion_kernel_fd, rc, ion_fd, map_fd; struct ion_allocation_data alloc_data; struct ion_fd_data fd_data; unsigned long addr; struct ion_test_data *test_data = (struct ion_test_data *)ion_tp->test_plan_data; ion_kernel_fd = open(msm_ion_dev, O_RDWR); if (ion_kernel_fd < 0) { debug(ERR, "Failed to open msm ion test device\n"); perror("msm ion"); return -EIO; } rc = ioctl(ion_kernel_fd, IOC_ION_KCLIENT_CREATE, NULL); if (rc < 0) { debug(ERR, "kernel client create failed\n"); close(ion_kernel_fd); return -EIO; } ion_fd = open(ion_dev, O_RDONLY); if (ion_fd < 0) { debug(ERR, "Failed to open ion device\n"); perror("msm ion"); rc = -EIO; goto kuimp_id_err; } if (test_type == ADV_TEST) { rc = ioctl(ion_kernel_fd, IOC_ION_UIMPORT, &ion_fd); if (rc < 0) rc = 0; else rc = -EIO; goto kuimp_adv_test_close; } if (test_type == NOMINAL_TEST) { alloc_data.len = test_data->size; alloc_data.align = test_data->align; alloc_data.heap_mask = test_data->heap_mask; alloc_data.flags = test_data->flags; rc = ioctl(ion_fd, ION_IOC_ALLOC, &alloc_data); if (rc) { debug(ERR, "Failed to allocate uspace ion buffer\n"); goto kuimp_adv_test_close; } fd_data.handle = alloc_data.handle; rc = ioctl(ion_fd, ION_IOC_MAP, &fd_data); if (rc) { debug(ERR, "Failed to map uspace ion buffer\n"); goto kuimp_map_err; } map_fd = fd_data.fd; addr = (unsigned long)mmap(NULL, alloc_data.len, PROT_READ | PROT_WRITE, MAP_SHARED , map_fd, 0); write_pattern(addr, alloc_data.len); rc = ioctl(ion_fd, ION_IOC_SHARE, &fd_data); if (rc) { debug(ERR, "Failed to share uspace ion buffer fd\n"); goto kuimp_share_err; } test_data->shared_fd = fd_data.fd; rc = ioctl(ion_kernel_fd, IOC_ION_UIMPORT, test_data); if (!rc) { rc = ioctl(ion_kernel_fd, IOC_ION_KMAP, NULL); if (!rc) rc = ioctl(ion_kernel_fd, IOC_ION_VERIFY, NULL); else debug(ERR, "failed to map uimp buffer\n"); ioctl(ion_kernel_fd, IOC_ION_KUMAP, NULL); ioctl(ion_kernel_fd, IOC_ION_KFREE, NULL); } if (rc) debug(ERR, "Failed to import uspace buffer\n"); kuimp_share_err: munmap((void *)addr, alloc_data.len); close(map_fd); kuimp_map_err: ioctl(ion_fd, ION_IOC_FREE, &alloc_data.handle); } kuimp_adv_test_close: close(ion_fd); kuimp_id_err: ioctl(ion_kernel_fd, IOC_ION_KCLIENT_DESTROY, NULL); close(ion_kernel_fd); return rc; }
static long ion_test_ioctl(struct file *file, unsigned cmd, unsigned long arg) { int ret; ion_phys_addr_t phys_addr; void *addr; size_t len; unsigned long flags, size; struct msm_ion_test *ion_test = file->private_data; struct ion_test_data *test_data = &ion_test->test_data; switch (cmd) { case IOC_ION_KCLIENT_CREATE: { ret = create_ion_client(ion_test); break; } case IOC_ION_KCLIENT_DESTROY: { free_ion_client(ion_test); ret = 0; break; } case IOC_ION_KALLOC: { if (copy_from_user(test_data, (void __user *)arg, sizeof(struct ion_test_data))) return -EFAULT; ret = alloc_ion_buf(ion_test, test_data); if (ret) pr_info("allocating ion buffer failed\n"); break; } case IOC_ION_KFREE: { free_ion_buf(ion_test); ret = 0; break; } case IOC_ION_KPHYS: { ret = ion_phys(ion_test->ion_client, ion_test->ion_handle, &phys_addr, &len); if (!ret) pr_info("size is 0x%x\n phys addr 0x%x", len, (unsigned int)phys_addr); break; } case IOC_ION_KMAP: { addr = ion_map_kernel(ion_test->ion_client, ion_test->ion_handle); if (IS_ERR_OR_NULL(addr)) { ret = -EIO; pr_info("mapping kernel buffer failed\n"); } else { ret = 0; test_data->vaddr = (unsigned long)addr; } break; } case IOC_ION_KUMAP: { ion_unmap_kernel(ion_test->ion_client, ion_test->ion_handle); ret = 0; break; } case IOC_ION_UIMPORT: { if (copy_from_user(test_data, (void __user *)arg, sizeof(struct ion_test_data))) return -EFAULT; ion_test->ion_handle = ion_import_dma_buf(ion_test->ion_client, test_data->shared_fd); if (IS_ERR_OR_NULL(ion_test->ion_handle)) { ret = -EIO; pr_info("import of user buf failed\n"); } else ret = 0; break; } case IOC_ION_UBUF_FLAGS: { ret = ion_handle_get_flags(ion_test->ion_client, ion_test->ion_handle, &flags); if (ret) pr_info("user flags cannot be retrieved\n"); else if (copy_to_user((void __user *)arg, &flags, sizeof(unsigned long))) ret = -EFAULT; break; } case IOC_ION_UBUF_SIZE: { ret = ion_handle_get_size(ion_test->ion_client, ion_test->ion_handle, &size); if (ret) pr_info("buffer size cannot be retrieved\n"); else if (copy_to_user((void __user *)arg, &size, sizeof(unsigned long))) ret = -EFAULT; break; } case IOC_ION_WRITE_VERIFY: { write_pattern(test_data->vaddr, test_data->size); if (verify_pattern(test_data->vaddr, test_data->size)) { pr_info("verify of mapped buf failed\n"); ret = -EIO; } else ret = 0; break; } case IOC_ION_VERIFY: { if (verify_pattern(test_data->vaddr, test_data->size)) { pr_info("fail in verifying imported buffer\n"); ret = -EIO; } else ret = 0; break; } case IOC_ION_SEC: { ret = msm_ion_secure_heap(ION_CP_MM_HEAP_ID); if (ret) pr_info("unable to secure heap\n"); else pr_info("able to secure heap\n"); break; } case IOC_ION_UNSEC: { ret = msm_ion_unsecure_heap(ION_CP_MM_HEAP_ID); if (ret) pr_info("unable to unsecure heap\n"); else pr_info("able to unsecure heap\n"); break; } default: { pr_info("command not supproted\n"); ret = -EINVAL; } }; return ret; }
int write_dpin_0000( uchar * buf, uint test_start_sector, uint test_sector_length ) { return write_pattern(buf); }
int write_dpin_0007(uchar * buf, uint test_area_start, uint test_area_length) { return write_pattern(buf); }