Changeset 2156


Ignore:
Timestamp:
01/24/07 10:15:23 (13 years ago)
Author:
melissa
Message:

Reworked configuration file structure for testing framework. Instead of
"bad-files.txt", place a ".bioformats" file in any data directory (it doesn't
matter if you place one master file in the root data directory, or smaller files
in each bottom-level directory). These configuration files should have the
following structure:

<filename> <number of series> [<x> <y> <z> <c> <t> <dimension order>

<interleaved> <rgb> <thumb x> <thumb y> <pixel type string> <little endian>]
<average plane access time (in ms)> <file size (in MB)>
<flag set to true if this file should be tested>

Note that:

  • The filename is relative to the directory the config file is in.
  • The parameters between square brackets should be repeated for each series

(so if the file has 2 series, specify <x0> <y0> <z0> ... <x1> <y1> <z1> ...)

  • Most of these parameters can be copy/pasted from the output of "inf -nometa <filename>".
Location:
trunk/loci/formats/test
Files:
1 added
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/formats/test/ReaderTest.java

    r2137 r2156  
    6565  // -- Static fields -- 
    6666 
    67   private static Vector badFiles; 
     67  private static Vector configFiles = new Vector(); 
     68  private static ConfigurationFiles config = ConfigurationFiles.newInstance(); 
    6869  private static FileWriter logFile; 
    6970  private String[] used; 
     71 
     72  private static float averagePlaneAccess; 
     73  private static int maxMemory;  // maximum measured memory usage 
     74  private static int initialMemory;  // memory usage before opening the file 
     75  private static int finalMemory;  // memory usage after closing file 
    7076 
    7177  // -- Fields -- 
     
    109115  public void testBufferedImageDimensions() { 
    110116    boolean success = true; 
    111     try { 
     117    Runtime rt = Runtime.getRuntime(); 
     118    initialMemory = (int) ((rt.totalMemory() - rt.freeMemory()) >> 20); 
     119    maxMemory = initialMemory; 
     120    try { 
     121      int planesRead = 0; 
     122      long l1 = System.currentTimeMillis(); 
    112123      for (int i=0; i<reader.getSeriesCount(id); i++) { 
     124        int usedMemory = (int) (rt.totalMemory() - rt.freeMemory()) >> 20; 
     125        if (usedMemory > maxMemory) maxMemory = usedMemory; 
    113126        reader.setSeries(id, i); 
    114127        int imageCount = reader.getImageCount(id); 
     
    128141          } 
    129142        } 
    130       } 
     143        planesRead += imageCount; 
     144      } 
     145      long l2 = System.currentTimeMillis(); 
     146      averagePlaneAccess = ((float) (l2 - l1)) / planesRead; 
    131147    } 
    132148    catch (Exception e) { 
     
    137153    try { reader.close(); } 
    138154    catch (Exception e) { } 
     155    finalMemory = (int) (rt.totalMemory() - rt.freeMemory()) >> 20; 
    139156    assertTrue(success); 
    140157  } 
     
    267284  } 
    268285 
     286  /**  
     287   * Checks that the core metadata values match those given in  
     288   * the configuration file.  Note that this test will fail if there was 
     289   * no configuration file. 
     290   */ 
     291  public void testConsistent() { 
     292    boolean success = true; 
     293    int nSeries = 0; 
     294    try { 
     295      nSeries = reader.getSeries(id); 
     296      if (nSeries != config.getNumSeries(id)) { 
     297        success = false; 
     298        writeLog(id + " failed consistent series count check"); 
     299      } 
     300    } 
     301    catch (Exception e) { 
     302      if (DEBUG) e.printStackTrace(); 
     303      success = false; 
     304    } 
     305    if (success) { 
     306      try { 
     307        for (int i=0; i<nSeries; i++) { 
     308          config.setSeries(id, i); 
     309          reader.setSeries(id, i); 
     310          if (config.getWidth(id) != reader.getSizeX(id)) { 
     311            success = false; 
     312            writeLog(id + " failed consistent width check in series " + i); 
     313          } 
     314          if (config.getHeight(id) != reader.getSizeY(id)) { 
     315            success = false; 
     316            writeLog(id + " failed consistent height check in series " + i); 
     317          } 
     318          if (config.getZ(id) != reader.getSizeZ(id)) { 
     319            success = false; 
     320            writeLog(id + " failed consistent sizeZ check in series " + i); 
     321          } 
     322          if (config.getC(id) != reader.getSizeC(id)) { 
     323            success = false; 
     324            writeLog(id + " failed consistent sizeC check in series " + i); 
     325          } 
     326          if (config.getT(id) != reader.getSizeT(id)) { 
     327            success = false; 
     328            writeLog(id + " failed consistent sizeT check in series " + i); 
     329          } 
     330          if (!config.getDimOrder(id).equals(reader.getDimensionOrder(id))) { 
     331            success = false; 
     332            writeLog(id +  
     333              " failed consistent dimension order check in series " + i); 
     334          } 
     335          if (config.isInterleaved(id) != reader.isInterleaved(id)) { 
     336            success = false; 
     337            writeLog(id +  
     338              " failed consistent interleaving flag check in series " + i); 
     339          } 
     340          if (config.isRGB(id) != reader.isRGB(id)) { 
     341            success = false; 
     342            writeLog(id + " failed consistent RGB flag check in series " + i); 
     343          } 
     344          if (config.getThumbX(id) != reader.getThumbSizeX(id)) { 
     345            success = false; 
     346            writeLog(id +  
     347              " failed consistent thumbnail width check in series " + i); 
     348          } 
     349          if (config.getThumbY(id) != reader.getThumbSizeY(id)) { 
     350            success = false; 
     351            writeLog(id +  
     352              " failed consistent thumbnail height check in series " + i); 
     353          } 
     354          if (config.getPixelType(id) != reader.getPixelType(id)) { 
     355            success = false; 
     356            writeLog(id + " failed consistent pixel type check in series " + i); 
     357          } 
     358          if (config.isLittleEndian(id) != reader.isLittleEndian(id)) { 
     359            success = false; 
     360            writeLog(id +  
     361              " failed consistent endianness flag check in series " + i); 
     362          } 
     363        } 
     364      } 
     365      catch (Exception e) { 
     366        if (DEBUG) e.printStackTrace(); 
     367        success = false; 
     368      } 
     369    } 
     370    assertTrue(success); 
     371  } 
     372 
     373  /** Check that the memory usage is acceptable. */ 
     374  public void testMemoryUsage() { 
     375    boolean success = true; 
     376     
     377    // we want the maximum usage to be no more than twice the file size 
     378    if (maxMemory - initialMemory > 2*config.getFileSize(id)) { 
     379      success = false; 
     380      writeLog(id + " failed maximum memory usage test (used " +  
     381        (maxMemory - initialMemory) + "MB; expected <= " +  
     382        2*config.getFileSize(id) + "MB)"); 
     383    } 
     384   
     385    // check that the reader doesn't have any (significant) memory leaks 
     386    if (finalMemory - initialMemory > 10) { 
     387      success = false; 
     388      writeLog(id + " failed memory leak test (" +  
     389        (finalMemory - initialMemory) + "MB leaked)"); 
     390    } 
     391 
     392    assertTrue(success); 
     393  } 
     394 
     395  /** Check that the average access time per plane is reasonable. */ 
     396  public void testAccessTime() { 
     397    boolean success = true; 
     398    if (averagePlaneAccess - config.getTimePerPlane(id) > 10.0) { 
     399      success = false; 
     400      writeLog(id + " failed consistent access time test (got " + 
     401        averagePlaneAccess + " ms, expected " + config.getTimePerPlane(id) + 
     402        " ms)"); 
     403    } 
     404    assertTrue(success); 
     405  } 
     406 
    269407  // -- TestCase API methods -- 
    270408 
     
    302440    suite.addTest(new ReaderTest("testImageCount", id)); 
    303441    suite.addTest(new ReaderTest("testOMEXML", id)); 
     442    if (config.initialized(id)) { 
     443      suite.addTest(new ReaderTest("testConsistent", id)); 
     444      suite.addTest(new ReaderTest("testMemoryUsage", id)); 
     445      suite.addTest(new ReaderTest("testAccessTime", id)); 
     446    } 
    304447    return suite; 
    305448  } 
     
    310453   */ 
    311454  public static boolean isBadFile(String file) { 
    312     if (badFiles == null) { 
    313       try { 
    314         badFiles = new Vector(); 
    315         BufferedReader in = new BufferedReader(new InputStreamReader( 
    316           ReaderTest.class.getResourceAsStream("bad-files.txt"))); 
    317         while (true) { 
    318           String line = in.readLine(); 
    319           if (line == null) break; 
    320           if (line.trim().equals("")) continue; // blank line 
    321           if (line.startsWith("#")) continue; // comment 
    322           badFiles.add(line); 
    323         } 
    324         in.close(); 
    325       } 
    326       catch (IOException io) { 
    327         if (DEBUG) io.printStackTrace(); 
    328       } 
    329     } 
    330     String absFile = new Location(file).getAbsolutePath(); 
    331     for (int i=0; i<badFiles.size(); i++) { 
    332       String bad = (String) badFiles.elementAt(i); 
    333       if (absFile.endsWith(bad)) return true; 
    334     } 
    335     return false; 
     455    if (config.numFiles() == 0) { 
     456      for (int i=0; i<configFiles.size(); i++) { 
     457        try { 
     458          config.addFile((String) configFiles.get(i));   
     459        } 
     460        catch (IOException e) { 
     461          if (DEBUG) e.printStackTrace(); 
     462        } 
     463      } 
     464    } 
     465    return !config.testFile(file) && !file.endsWith(".bioformats"); 
    336466  } 
    337467 
     
    340470    Location f = new Location(root); 
    341471    String[] subs = f.list(); 
     472    Arrays.sort(subs); 
    342473    if (subs == null) { 
    343474      System.out.println("Invalid directory: " + root); 
     
    347478    for (int i=0; i<subs.length; i++) { 
    348479      if (DEBUG) debug("Checking file " + subs[i]); 
    349       subs[i] = root + File.separator + subs[i]; 
     480      subs[i] = new Location(root, subs[i]).getAbsolutePath(); 
    350481      if (isBadFile(subs[i])) { 
    351482        if (DEBUG) debug(subs[i] + " is a bad file"); 
     
    354485      Location file = new Location(subs[i]); 
    355486      if (file.isDirectory()) getFiles(subs[i], files); 
     487      else if (file.getName().equals(".bioformats")) { 
     488        // special config file for the test suite 
     489        configFiles.add(file.getAbsolutePath()); 
     490      } 
    356491      else { 
    357492        if (ir.isThisType(subs[i])) { 
     
    432567    } 
    433568  } 
    434  
    435569} 
Note: See TracChangeset for help on using the changeset viewer.