コード例 #1
0
ファイル: vm_dump.cpp プロジェクト: hreinecke/s390-tools
VMDump::VMDump(const char *fileName) : Dump(fileName, "rb")
{
	char fmbk_id[8] = {0xc8, 0xc3, 0xd7, 0xc4, 0xc6, 0xd4, 0xc2, 0xd2};
	
	ebcdicAsciiConv = iconv_open("ISO-8859-1", "EBCDIC-US");

	/* Record 1: adsrRecord */

	dump_seek(fh,0,SEEK_SET);
	dump_read(&adsrRecord,sizeof(adsrRecord),1,fh);

	if(debug) {
		char buf[1024];
		int i;
	
		dump_seek(fh,adsrRecord.sec3_offset,SEEK_SET);
		dump_read(buf, adsrRecord.sec3_len,1,fh);
		ebcAsc(buf,adsrRecord.sec3_len);
		for(i=0; i < adsrRecord.sec3_len; i++) {
			if((buf[i]==0) || iscntrl(buf[i]))
				buf[i]=' ';
		}
		buf[adsrRecord.sec3_len]=0;
		printf("symptom string1: %s\n",buf);
	}

	/* Record 2: fmbk */

	dump_seek(fh,0x1000,SEEK_SET);
	dump_read(&fmbkRecord,sizeof(fmbkRecord),1,fh);

	/* Check if this is a vmdump */
	if(memcmp(fmbkRecord.id, fmbk_id, 8) != 0) {
		throw DumpException("Input file is not a vmdump");
	}
	
	/* Record 3-7: fir records read by subclasses */

	/* Record 8: albk */

	dump_seek(fh,(fmbkRecord.rec_nr_access-1)*0x1000 ,SEEK_SET);
	dump_read(&albkRecord,sizeof(albkRecord),1,fh);
}
コード例 #2
0
ファイル: vm_dump.cpp プロジェクト: hreinecke/s390-tools
VMDump64::VMDump64(const char* filename) : VMDumpClassic(filename)
{
	int i;
	
	if(!fh) {
		return;
	}

	dump_seek(fh,(fmbkRecord.rec_nr_fir-1)* 0x1000 ,SEEK_SET);
	dump_read(&fir64Record,sizeof(fir64Record),1,fh);

	fir64OtherRecords = new _fir_other_64[fir64Record.online_cpus];
	for(i=0; i < fir64Record.online_cpus; i++) {
		/* fir other */
		dump_read(&fir64OtherRecords[i],sizeof(fir64OtherRecords[i]),1,
			  fh);
	}
	if(debug)
		printDebug();
}
コード例 #3
0
ファイル: vm_dump.cpp プロジェクト: hreinecke/s390-tools
VMDumpClassic::VMDumpClassic(const char *fileName) : VMDump(fileName)
{
	int storageKeyPages,bitMapPages;
		
	pageOffset = 0;

	/* Record 9: asibk */

	dump_seek(fh,fmbkRecord.rec_nr_access * 0x1000,SEEK_SET);
	dump_read(&asibkRecord,sizeof(asibkRecord),1,fh);

	/* Record 10: bitmaps */

	dump_seek(fh,(fmbkRecord.rec_nr_access + 1)* 0x1000 ,SEEK_SET);
        bitmap = new char[asibkRecord.storage_size_2GB / (0x1000 * 8)];
	dump_read(bitmap,asibkRecord.storage_size_2GB / (0x1000*8),1,fh);

        bitMapPages=asibkRecord.storage_size_2GB / (0x1000 * 8);
        if(bitMapPages % 0x1000 != 0)
                bitMapPages = bitMapPages/0x1000 + 1;
        else
                bitMapPages = bitMapPages/0x1000;

        storageKeyPages=asibkRecord.storage_size_2GB / 0x1000;
        if(storageKeyPages % 0x1000 != 0) {
                storageKeyPages = storageKeyPages/0x1000 + 1;
	} else {
                storageKeyPages = storageKeyPages/0x1000;
	}

        /* skip storage keys */

	memoryStartRecord = (fmbkRecord.rec_nr_access + 1) *0x1000 /* 0x9000 */
				+ (bitMapPages + storageKeyPages)*0x1000;
	if(debug) {
		printf("Mem Offset: %llx\n",(long long)memoryStartRecord);
	}
}
コード例 #4
0
ファイル: vm_dump.cpp プロジェクト: hreinecke/s390-tools
void
VMDump::readMem(char* buf, int size)
{
	int i;

	if(pageOffset == 0)
		dump_seek(fh, memoryStartRecord, SEEK_SET);

	if(size % 0x1000 != 0) {
		throw(DumpException("internal error: VMDump::readMem() "\
		"can only handle sizes which are multiples of page size"));
	}

	for(i = 0; i < size; i += 0x1000) {
		if(testPage(pageOffset)) {
			dump_read(buf + i, 0x1000,1,fh);
		} else {
			memset(buf + i, 0, 0x1000);
		}
		pageOffset += 1;
	}
}
コード例 #5
0
ファイル: test_bam_translate.c プロジェクト: B-UMMI/INNUca
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;
}
コード例 #6
0
ファイル: vm_dump.cpp プロジェクト: hreinecke/s390-tools
VMDump64Big::VMDump64Big(const char* filename) : VMDump(filename)
{
	int i,j;
	uint64_t pageNum, nrDumpedPages;
	
	if(!fh) {
		return;
	}
		
	/* Record 9: asibk */

	dump_seek(fh,fmbkRecord.rec_nr_access * 0x1000,SEEK_SET);
	dump_read(&asibkRecordNew,sizeof(asibkRecordNew),1,fh);

	/* Record 10: bitmaps: */
	/* Read all bitmap pages and setup bitmap array */

	pageNum = 0;
	nrDumpedPages = asibkRecordNew.storage_size_def_store / 0x1000;
	memoryStartRecord = (fmbkRecord.rec_nr_access +  1) * 0x1000;
	bitmap = new char[asibkRecordNew.storage_size_def_store/(0x1000 * 8)];
	if(!bitmap) {
		throw(DumpErrnoException("out of memory"));
	}
	memset(bitmap,0,asibkRecordNew.storage_size_def_store/(0x1000 * 8));

	dump_seek(fh,(fmbkRecord.rec_nr_access + 1)* 0x1000 ,SEEK_SET);

	do {
		char bmIndexPage[0x1000];
		dump_read(bmIndexPage,sizeof(bmIndexPage),1,fh);
		memoryStartRecord += 0x1000;
		for(i=0; i < 0x1000; i++) {
			if(testBitmapPage(bmIndexPage,i)) {
				char bmPage[0x1000];
				dump_read(bmPage,sizeof(bmPage),1,fh);
				memoryStartRecord += 0x1000;
				for(j = 0; j < 0x1000; j++) {
					if(testBitmapKeyPage(bmPage, j)) {
						setPageBit(pageNum);
					}
					pageNum++;
					if(pageNum == nrDumpedPages) {
						goto all_bitmaps_read;
					}
				}
			} else {
				pageNum += 0x1000; // empty pages
			}
		}
	} while (pageNum < nrDumpedPages);

all_bitmaps_read:

	if(debug)
		printf("Mem Offset: %llx\n",(long long)memoryStartRecord);

	dump_seek(fh,(fmbkRecord.rec_nr_fir-1)* 0x1000 ,SEEK_SET);
	dump_read(&fir64Record,sizeof(fir64Record),1,fh);

	fir64OtherRecords = new _fir_other_64[fir64Record.online_cpus];
	for(i=0; i < fir64Record.online_cpus; i++) {
		/* fir other */
		dump_read(&fir64OtherRecords[i],sizeof(fir64OtherRecords[i]),1,
			  fh);
	}
	if(debug)
		printDebug();
}