Line 1... |
Line 1... |
/*!
|
/*!
|
flashbench -- Flash memory benchmark for ZTEX USB Module 1.0
|
flashbench -- Flash memory benchmark for ZTEX USB Module 1.0
|
Copyright (C) 2009-2010 ZTEX e.K.
|
Copyright (C) 2009-2011 ZTEX GmbH.
|
http://www.ztex.de
|
http://www.ztex.de
|
|
|
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
it under the terms of the GNU General Public License version 3 as
|
it under the terms of the GNU General Public License version 3 as
|
published by the Free Software Foundation.
|
published by the Free Software Foundation.
|
Line 54... |
Line 54... |
}
|
}
|
|
|
// ******* testRW **************************************************************
|
// ******* testRW **************************************************************
|
// measures read + write performance
|
// measures read + write performance
|
public double testRW ( int num ) throws UsbException, InvalidFirmwareException, CapabilityException {
|
public double testRW ( int num ) throws UsbException, InvalidFirmwareException, CapabilityException {
|
byte[] buf1 = new byte[flashSectorSize()];
|
int secNum = 2048 / flashSectorSize();
|
byte[] buf2 = new byte[flashSectorSize()];
|
byte[] buf1 = new byte[flashSectorSize() * secNum];
|
|
byte[] buf2 = new byte[flashSectorSize() * secNum];
|
int errors = 0;
|
int errors = 0;
|
|
|
long t0 = new Date().getTime();
|
long t0 = new Date().getTime();
|
|
|
for ( int i=0; i<num; i++ ) {
|
for ( int i=0; i<num; i+=secNum ) {
|
|
int l = Math.min(num-i,secNum);
|
int j=(int) Math.round(65535*Math.random());
|
int j=(int) Math.round(65535*Math.random());
|
for (int k=0; k<flashSectorSize(); k++) {
|
for (int k=0; k<flashSectorSize()*l; k++) {
|
buf1[k] = (byte) (j & 255);
|
buf1[k] = (byte) (j & 255);
|
j+=57;
|
j+=57;
|
}
|
}
|
|
|
System.out.print("Sector " + (i+1) + "/" + num+ " " + Math.round(10000.0*(i+1)/num)/100.0 + "% \r");
|
System.out.print("Sector " + (i+l) + "/" + num+ " " + Math.round(10000.0*(i+1)/num)/100.0 + "% \r");
|
flashWriteSector(i,buf1);
|
flashWriteSector(i,l,buf1);
|
flashReadSector(i,buf2);
|
flashReadSector(i,l,buf2);
|
|
|
int diffs=flashSectorSize();
|
int diffs=flashSectorSize()*l;
|
for (int k=0; k<flashSectorSize(); k++)
|
for (int k=0; k<flashSectorSize()*l; k++)
|
if ( buf1[k] == buf2[k] )
|
if ( buf1[k] == buf2[k] )
|
diffs -= 1;
|
diffs -= 1;
|
if ( diffs!=0 && errors==0) {
|
if ( diffs!=0 /*&& errors==0 */) {
|
System.out.print("Error occured: Sector " + i +": " + diffs + " differences: ");
|
System.out.println("Error occured at sector " + i +": " + diffs + " differences");
|
}
|
}
|
if ( diffs!=0 )
|
if ( diffs!=0 )
|
errors+=1;
|
errors+=1;
|
}
|
}
|
System.out.println("testRW: " + errors +" errors detected");
|
System.out.println("testRW: " + errors +" errors detected");
|
Line 89... |
Line 91... |
}
|
}
|
|
|
// ******* testW **************************************************************
|
// ******* testW **************************************************************
|
// measures write performance
|
// measures write performance
|
public double testW ( int num, int seed ) throws UsbException, InvalidFirmwareException, CapabilityException {
|
public double testW ( int num, int seed ) throws UsbException, InvalidFirmwareException, CapabilityException {
|
byte[] buf = new byte[flashSectorSize()];
|
int secNum = 2048 / flashSectorSize();
|
|
byte[] buf = new byte[flashSectorSize() * secNum];
|
long t0 = new Date().getTime();
|
long t0 = new Date().getTime();
|
for ( int i=0; i<num; i++ ) {
|
for ( int i=0; i<num; i+=secNum ) {
|
System.out.print("Sector " + (i+1) + "/" + num+ " " + Math.round(10000.0*(i+1)/num)/100.0 + "% \r");
|
int j = Math.min(num-i,secNum);
|
for (int k=0; k<flashSectorSize(); k++) {
|
System.out.print("Sector " + (i+j) + "/" + num+ " " + Math.round(10000.0*(i+1)/num)/100.0 + "% \r");
|
|
for (int k=0; k<flashSectorSize()*j; k++) {
|
buf[k] = (byte) (seed & 255);
|
buf[k] = (byte) (seed & 255);
|
seed+=79;
|
seed+=79;
|
}
|
}
|
flashWriteSector(i,buf);
|
flashWriteSector(i,j,buf);
|
}
|
}
|
return num*512.0/(new Date().getTime() - t0);
|
return num*512.0/(new Date().getTime() - t0);
|
}
|
}
|
|
|
// ******* testR **************************************************************
|
// ******* testR **************************************************************
|
// measures read performance
|
// measures read performance
|
public double testR ( int num, int seed ) throws UsbException, InvalidFirmwareException, CapabilityException {
|
public double testR ( int num, int seed ) throws UsbException, InvalidFirmwareException, CapabilityException {
|
byte[] buf = new byte[flashSectorSize()];
|
int secNum = 2048 / flashSectorSize();
|
|
byte[] buf = new byte[flashSectorSize() * secNum];
|
int errors = 0;
|
int errors = 0;
|
long t0 = new Date().getTime();
|
long t0 = new Date().getTime();
|
for ( int i=0; i<num; i++ ) {
|
for ( int i=0; i<num; i+=secNum ) {
|
System.out.print("Sector " + (i+1) + "/" + num+ " " + Math.round(10000.0*(i+1)/num)/100.0 + "% \r");
|
int j = Math.min(num-i,secNum);
|
flashReadSector(i,buf);
|
System.out.print("Sector " + (i+j) + "/" + num+ " " + Math.round(10000.0*(i+1)/num)/100.0 + "% \r");
|
int diffs = flashSectorSize();
|
flashReadSector(i,j,buf);
|
for (int k=0; k<flashSectorSize(); k++) {
|
int diffs = flashSectorSize()*j;
|
|
for (int k=0; k<flashSectorSize()*j; k++) {
|
if ( buf[k] == (byte) (seed & 255) )
|
if ( buf[k] == (byte) (seed & 255) )
|
diffs-=1;
|
diffs-=1;
|
seed+=79;
|
seed+=79;
|
}
|
}
|
if ( diffs!=0 && errors==0 ) {
|
if ( diffs!=0 && errors==0 ) {
|
System.out.print("Error occured: Sector " + i +": " + diffs + " differences: ");
|
System.out.println("Error occured at sector " + i +": " + diffs + " differences");
|
}
|
}
|
if ( diffs!=0 )
|
if ( diffs!=0 )
|
errors+=1;
|
errors+=1;
|
}
|
}
|
System.out.println("testR: " + errors +" errors detected");
|
System.out.println("testR: " + errors +" errors detected");
|