Ejemplo n.º 1
0
void k_debugger(regs *r,uint32 eip, uint32 cs, uint32 eflags)
{
    char *line;
    uint32 n;
	
    kprintf("OpenBLT Kernel Debugger");

    for(;;){
        krefresh();
        line = kgetline(linebuf,80);

		if(!strncmp(line,"pgroup ",7)) { dumppgroup(readnum(line+7)); continue; }
        if(!strncmp(line,"resource ", 9)) { dumponersrc(line+9); continue; }
        if(!strcmp(line,"resources")) { dumprsrc(&resource_list); continue; }
		if(!strncmp(line,"queue ",6)) { dumpqueue(readnum(line+6)); continue; }
        if(!strcmp(line,"tasks")) { dumptasks(); continue; }
        if(!strcmp(line,"ports")) { dumpports(); continue; }
        if(!strcmp(line,"memory")) { memory_status(); continue; }
        if(!strcmp(line,"trace")) { trace(r->ebp,eip); continue; }
        if(!strcmp(line,"regs")) { print_regs(r,eip,cs,eflags); continue; }
        if(!strncmp(line,"dump ",5)) { dump(readnum(line+5),16); continue; }
        if(!strncmp(line,"aspace ",7)) { dumpaddr(readnum(line+7)); continue; }
        if(!strcmp(line,"reboot")) { reboot(); }
        if(!strncmp(line,"checksum ",9)) { checksum(line+9); continue; }
		if(!strncmp(line,"team ",5)) { dumpteam(readnum(line+5)); continue; }
		if(!strncmp(line,"find ",5)) { findpage(readnum(line+5)); continue; }
		if(!strcmp(line,"teams")) { dumpteams(); continue; }
		
        if(!strcmp(line,"exit")) break;
        if(!strcmp(line,"x")) break;
        if(!strcmp(line,"c")) break;
    }
}
Ejemplo n.º 2
0
static void parse_simple(const char *fname, kstring_t *id, kstring_t *secret)
{
    kstring_t text = { 0, 0, NULL };
    char *s;
    size_t len;

    FILE *fp = expand_tilde_open(fname, "r");
    if (fp == NULL) return;

    while (kgetline(&text, (kgets_func *) fgets, fp) >= 0)
        kputc(' ', &text);
    fclose(fp);

    s = text.s;
    while (isspace_c(*s)) s++;
    kputsn(s, len = strcspn(s, " \t"), id);

    s += len;
    while (isspace_c(*s)) s++;
    kputsn(s, strcspn(s, " \t"), secret);

    free(text.s);
}
Ejemplo n.º 3
0
static void parse_ini(const char *fname, const char *section, ...)
{
    kstring_t line = { 0, 0, NULL };
    int active = 1;  // Start active, so global properties are accepted
    char *s;

    FILE *fp = expand_tilde_open(fname, "r");
    if (fp == NULL) return;

    while (line.l = 0, kgetline(&line, (kgets_func *) fgets, fp) >= 0)
        if (line.s[0] == '[' && (s = strchr(line.s, ']')) != NULL) {
            *s = '\0';
            active = (strcmp(&line.s[1], section) == 0);
        }
        else if (active && (s = strpbrk(line.s, ":=")) != NULL) {
            const char *key = line.s, *value = &s[1], *akey;
            va_list args;

            while (isspace_c(*key)) key++;
            while (s > key && isspace_c(s[-1])) s--;
            *s = '\0';

            while (isspace_c(*value)) value++;
            while (line.l > 0 && isspace_c(line.s[line.l-1]))
                line.s[--line.l] = '\0';

            va_start(args, section);
            while ((akey = va_arg(args, const char *)) != NULL) {
                kstring_t *avar = va_arg(args, kstring_t *);
                if (strcmp(key, akey) == 0) { kputs(value, avar); break; }
            }
            va_end(args);
        }

    fclose(fp);
    free(line.s);
}
int main(int argc, char**argv)
{
    // test state
    const int NUM_TESTS = 1;
    int verbose = 0;
    int success = 0;
    int failure = 0;

    int getopt_char;
    while ((getopt_char = getopt(argc, argv, "v")) != -1) {
        switch (getopt_char) {
            case 'v':
                ++verbose;
                break;
            default:
                printf(
                       "usage: test_expand_format_string [-v]\n\n"
                       " -v verbose output\n"
                       );
                break;
        }
    }


    // Setup pysamerr redirect
    kstring_t res = { 0, 0, NULL };
    FILE* orig_pysamerr = fdopen(dup(STDERR_FILENO), "a"); // Save pysamerr
    char* tempfname = (optind < argc)? argv[optind] : "test_expand_format_string.tmp";
    FILE* check = NULL;

    // setup
    if (verbose) printf("BEGIN test 1\n");  // default format string test
    const char* format_string_1 = "%*_%#.bam";
    const char* basename_1 = "basename";
    const char* rg_id_1 = "1#2.3";
    const int rg_idx_1 = 4;
    if (verbose > 1) {
        printf("format_string:%s\n"
               "basename:%s\n"
               "rg_id:%s\n"
               "rg_idx:%d\n", format_string_1, basename_1, rg_id_1, rg_idx_1);
    }
    if (verbose) printf("RUN test 1\n");

    // test
    xfreopen(tempfname, "w", pysamerr); // Redirect pysamerr to pipe
    char* output_1 = expand_format_string(format_string_1, basename_1, rg_id_1, rg_idx_1, NULL);
    fclose(pysamerr);

    if (verbose) printf("END RUN test 1\n");
    if (verbose > 1) {
        printf("format_string:%s\n"
               "basename:%s\n"
               "rg_id:%s\n"
               "rg_idx:%d\n", format_string_1, basename_1, rg_id_1, rg_idx_1);
    }

    // check result
    res.l = 0;
    check = fopen(tempfname, "r");
    if (output_1 != NULL && !strcmp(output_1, "basename_4.bam")
        && kgetline(&res, (kgets_func *)fgets, check) < 0
        && (feof(check) || res.l == 0)) {
        ++success;
    } else {
        ++failure;
        if (verbose) printf("FAIL test 1\n");
    }
    fclose(check);

    // teardown
    free(output_1);
    if (verbose) printf("END test 1\n");

    // Cleanup test harness
    free(res.s);
    remove(tempfname);
    if (failure > 0)
        fprintf(orig_pysamerr, "%d failures %d successes\n", failure, success);
    fclose(orig_pysamerr);

    return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE;
}
Ejemplo n.º 5
0
int main(int argc, char**argv)
{
    // test state
    const int NUM_TESTS = 6;
    int verbose = 0;
    int success = 0;
    int failure = 0;

    int getopt_char;
    while ((getopt_char = getopt(argc, argv, "v")) != -1) {
        switch (getopt_char) {
            case 'v':
                ++verbose;
                break;
            default:
                break;
        }
    }

    bam1_t* b;

    // Setup stderr redirect
    kstring_t res = { 0, 0, NULL };
    FILE* orig_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save stderr
    char* tempfname = (optind < argc)? argv[optind] : "test_bam_translate.tmp";
    FILE* check = NULL;

    // setup
    if (verbose) printf("BEGIN test 1\n");  // TID test
    trans_tbl_t tbl1;
    setup_test_1(&b,&tbl1);
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
    }
    if (verbose) printf("RUN test 1\n");

    // test
    xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe
    bam_translate(b, &tbl1);
    fclose(stderr);

    if (verbose) printf("END RUN test 1\n");
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
    }

    // check result
    check = fopen(tempfname, "r");
    res.l = 0;
    if (kgetline(&res, (kgets_func *)fgets, check) < 0 &&
        (feof(check) || res.l == 0) ) {
        ++success;
    } else {
        ++failure;
        if (verbose) printf("FAIL test 1\n");
    }
    fclose(check);

    // teardown
    bam_destroy1(b);
    trans_tbl_destroy(&tbl1);
    if (verbose) printf("END test 1\n");

    // setup
    if (verbose) printf("BEGIN test 2\n");  // RG exists and translate test
    trans_tbl_t tbl2;
    setup_test_2(&b,&tbl2);
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
    }
    if (verbose) printf("RUN test 2\n");

    // test
    xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe
    bam_translate(b, &tbl2);
    fclose(stderr);

    if (verbose) printf("END RUN test 2\n");
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
    }

    // check result
    check = fopen(tempfname, "r");
    res.l = 0;
    if (kgetline(&res, (kgets_func *)fgets, check) < 0 &&
        (feof(check) || res.l == 0) ) {
        ++success;
    } else {
        ++failure;
        if (verbose) printf("FAIL test 2\n");
    }
    fclose(check);

    // teardown
    bam_destroy1(b);
    trans_tbl_destroy(&tbl2);
    if (verbose) printf("END test 2\n");

    if (verbose) printf("BEGIN test 3\n");  // PG exists and translate  test
    // setup
    trans_tbl_t tbl3;
    setup_test_3(&b,&tbl3);
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
    }
    if (verbose) printf("RUN test 3\n");

    // test
    xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe
    bam_translate(b, &tbl3);
    fclose(stderr);

    if (verbose) printf("END RUN test 3\n");
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
    }

    // check result
    check = fopen(tempfname, "r");
    res.l = 0;
    if (kgetline(&res, (kgets_func *)fgets, check) < 0 &&
        (feof(check) || res.l == 0)) {
        ++success;
    } else {
        ++failure;
        if (verbose) printf("FAIL test 3\n");
    }
    fclose(check);

    // teardown
    bam_destroy1(b);
    trans_tbl_destroy(&tbl3);
    if (verbose) printf("END test 3\n");

    if (verbose) printf("BEGIN test 4\n");  // RG test non-existent
    // setup
    trans_tbl_t tbl4;
    setup_test_4(&b,&tbl4);
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
    }
    if (verbose) printf("RUN test 4\n");

    // test
    xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe
    bam_translate(b, &tbl4);
    fclose(stderr);

    if (verbose) printf("END RUN test 4\n");
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
    }
    // check result
    check = fopen(tempfname, "r");
    res.l = 0;
    if (kgetline(&res, (kgets_func *)fgets, check) >= 0 &&
        strcmp("[bam_translate] RG tag \"rg4hello\" on read \"123456789\" encountered with no corresponding entry in header, tag lost. Unknown tags are only reported once per input file for each tag ID.",res.s) == 0) {
        ++success;
    } else {
        ++failure;
        if (verbose) printf("FAIL test 4\n");
    }
    fclose(check);

    // teardown
    bam_destroy1(b);
    trans_tbl_destroy(&tbl4);
    if (verbose) printf("END test 4\n");

    if (verbose) printf("BEGIN test 5\n");  // PG test non-existent
    // setup
    trans_tbl_t tbl5;
    setup_test_5(&b,&tbl5);
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
        printf("RUN test 5\n");
    }
    // test
    xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe
    bam_translate(b, &tbl5);
    fclose(stderr);

    if (verbose) printf("END RUN test 5\n");
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
    }

    // check result
    check = fopen(tempfname, "r");
    res.l = 0;
    if (kgetline(&res, (kgets_func *)fgets, check) >= 0 &&
        strcmp("[bam_translate] PG tag \"pg5hello\" on read \"123456789\" encountered with no corresponding entry in header, tag lost. Unknown tags are only reported once per input file for each tag ID.",res.s) == 0) {
        ++success;
    } else {
        ++failure;
        if (verbose) printf("FAIL test 5\n");
    }
    fclose(check);

    // teardown
    bam_destroy1(b);
    trans_tbl_destroy(&tbl5);
    if (verbose) printf("END test 5\n");

    if (verbose) printf("BEGIN test 6\n");  // RG and PG exists and translate test
    // setup
    trans_tbl_t tbl6;
    setup_test_6(&b,&tbl6);
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
    }
    if (verbose) printf("RUN test 6\n");

    // test
    xfreopen(tempfname, "w", stderr); // Redirect stderr to pipe
    bam_translate(b, &tbl6);
    fclose(stderr);

    if (verbose) printf("END RUN test 6\n");
    if (verbose > 1) {
        printf("b\n");
        dump_read(b);
    }

    // check result
    check = fopen(tempfname, "r");
    res.l = 0;
    if (kgetline(&res, (kgets_func *)fgets, check) < 0 &&
        (feof(check) || res.l == 0) ) {
        ++success;
    } else {
        ++failure;
        if (verbose) printf("FAIL test 6\n");
    }
    fclose(check);

    // teardown
    bam_destroy1(b);
    trans_tbl_destroy(&tbl6);
    if (verbose) printf("END test 6\n");

    // Cleanup
    free(res.s);
    remove(tempfname);
    if (failure > 0)
        fprintf(orig_stderr, "%d failures %d successes\n", failure, success);
    fclose(orig_stderr);

    return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE;
}
Ejemplo n.º 6
0
int samtools_test_count_rg_main(int argc, char**argv)
{
    // test state
    const int NUM_TESTS = 1;
    int verbose = 0;
    int success = 0;
    int failure = 0;

    int getopt_char;
    while ((getopt_char = getopt(argc, argv, "v")) != -1) {
        switch (getopt_char) {
            case 'v':
                ++verbose;
                break;
            default:
                fprintf(pysam_stdout, 
                       "usage: test_count_rg [-v]\n\n"
                       " -v verbose output\n"
                       );
                break;
        }
    }


    // Setup pysam_stderr redirect
    kstring_t res = { 0, 0, NULL };
    FILE* orig_pysam_stderr = fdopen(dup(STDERR_FILENO), "a"); // Save pysam_stderr
    char* tempfname = (optind < argc)? argv[optind] : "test_count_rg.tmp";
    FILE* check = NULL;

    // setup
    if (verbose) fprintf(pysam_stdout, "BEGIN test 1\n");  // TID test
    bam_hdr_t* hdr1;
    size_t count;
    char** output;
    setup_test_1(&hdr1);
    if (verbose > 1) {
        fprintf(pysam_stdout, "hdr1\n");
        dump_hdr(hdr1);
    }
    if (verbose) fprintf(pysam_stdout, "RUN test 1\n");

    // test
    xfreopen(tempfname, "w", pysam_stderr); // Redirect pysam_stderr to pipe
    bool result_1 = count_RG(hdr1, &count, &output);
    fclose(pysam_stderr);

    if (verbose) fprintf(pysam_stdout, "END RUN test 1\n");
    if (verbose > 1) {
        fprintf(pysam_stdout, "b\n");
        dump_hdr(hdr1);
    }

    // check result
    check = fopen(tempfname, "r");
    if (result_1 && count == 1 && !strcmp(output[0], "fish")
        && kgetline(&res, (kgets_func *)fgets, check) < 0
        && (feof(check) || res.l == 0)) {
        ++success;
    } else {
        ++failure;
        if (verbose) fprintf(pysam_stdout, "FAIL test 1\n");
    }
    fclose(check);

    // teardown
    int i;
    for (i = 0; i < count; i++){
        free(output[i]);
    }
    free(output);
    bam_hdr_destroy(hdr1);
    if (verbose) fprintf(pysam_stdout, "END test 1\n");

    // Cleanup
    free(res.s);
    remove(tempfname);
    if (failure > 0)
        fprintf(orig_pysam_stderr, "%d failures %d successes\n", failure, success);
    fclose(orig_pysam_stderr);

    return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE;
}
Ejemplo n.º 7
0
int main(int argc, char**argv)
{
    // test state
    const int NUM_TESTS = 2;
    int verbose = 0;
    int success = 0;
    int failure = 0;

    int getopt_char;
    while ((getopt_char = getopt(argc, argv, "v")) != -1) {
        switch (getopt_char) {
            case 'v':
                ++verbose;
                break;
            default:
                printf(
                       "usage: test_filter_header_rg [-v]\n\n"
                       " -v verbose output\n"
                       );
                break;
        }
    }


    // Setup pysamerr redirect
    kstring_t res = { 0, 0, NULL };
    FILE* orig_pysamerr = fdopen(dup(STDERR_FILENO), "a"); // Save pysamerr
    char* tempfname = (optind < argc)? argv[optind] : "test_count_rg.tmp";
    FILE* check = NULL;

    // setup
    if (verbose) printf("BEGIN test 1\n");  // test eliminating a tag that isn't there
    bam_hdr_t* hdr1;
    const char* id_to_keep_1 = "1#2.3";
    setup_test_1(&hdr1);
    if (verbose > 1) {
        printf("hdr1\n");
        dump_hdr(hdr1);
    }
    if (verbose) printf("RUN test 1\n");

    // test
    xfreopen(tempfname, "w", pysamerr); // Redirect pysamerr to pipe
    bool result_1 = filter_header_rg(hdr1, id_to_keep_1);
    fclose(pysamerr);

    if (verbose) printf("END RUN test 1\n");
    if (verbose > 1) {
        printf("hdr1\n");
        dump_hdr(hdr1);
    }

    // check result
    res.l = 0;
    check = fopen(tempfname, "r");
    if ( result_1
        && check_test_1(hdr1)
        && kgetline(&res, (kgets_func *)fgets, check) < 0
        && (feof(check) || res.l == 0)) {
        ++success;
    } else {
        ++failure;
        if (verbose) printf("FAIL test 1\n");
    }
    fclose(check);

    // teardown
    bam_hdr_destroy(hdr1);
    if (verbose) printf("END test 1\n");

    if (verbose) printf("BEGIN test 2\n");  // test eliminating a tag that is there
    bam_hdr_t* hdr2;
    const char* id_to_keep_2 = "fish";
    setup_test_2(&hdr2);
    if (verbose > 1) {
        printf("hdr2\n");
        dump_hdr(hdr2);
    }
    if (verbose) printf("RUN test 2\n");

    // test
    xfreopen(tempfname, "w", pysamerr); // Redirect pysamerr to pipe
    bool result_2 = filter_header_rg(hdr2, id_to_keep_2);
    fclose(pysamerr);

    if (verbose) printf("END RUN test 2\n");
    if (verbose > 1) {
        printf("hdr2\n");
        dump_hdr(hdr2);
    }

    // check result
    res.l = 0;
    check = fopen(tempfname, "r");
    if ( result_2
        && check_test_2(hdr2)
        && kgetline(&res, (kgets_func *)fgets, check) < 0
        && (feof(check) || res.l == 0)) {
        ++success;
    } else {
        ++failure;
        if (verbose) printf("FAIL test 2\n");
    }
    fclose(check);

    // teardown
    bam_hdr_destroy(hdr2);
    if (verbose) printf("END test 2\n");


    // Cleanup
    free(res.s);
    remove(tempfname);
    if (failure > 0)
        fprintf(orig_pysamerr, "%d failures %d successes\n", failure, success);
    fclose(orig_pysamerr);

    return (success == NUM_TESTS)? EXIT_SUCCESS : EXIT_FAILURE;
}