Skip to content
Snippets Groups Projects
Commit 46bb7a33 authored by Julien Michel's avatar Julien Michel
Browse files

TEST: Adding a test to demonstrate the jpeg file descriptor ressource leak

parent c3ba9c23
Branches
Tags
No related merge requests found
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
#include "base/ossimFilename.h" #include "base/ossimFilename.h"
#include "itkTimeProbe.h"
namespace otb namespace otb
{ {
...@@ -160,8 +162,14 @@ void TileMapImageIO::Read(void* buffer) ...@@ -160,8 +162,14 @@ void TileMapImageIO::Read(void* buffer)
int nTilesY = (int) ceil(totLines/256.)+1; int nTilesY = (int) ceil(totLines/256.)+1;
unsigned char * bufferTile = new unsigned char[256*256*nComponents]; unsigned char * bufferTile = new unsigned char[256*256*nComponents];
std::cout<<"TileMapIO: reading region "<<this->GetIORegion()<<std::endl;
std::cout<<"TileMapIO: number of tiles: "<<nTilesX<<" x "<<nTilesY<<std::endl;
//Read all the required tiles //Read all the required tiles
//FIXME assume RGB image //FIXME assume RGB image
itk::TimeProbe probeOverall;
probeOverall.Start();
for (int numTileY=0; numTileY<nTilesY; numTileY++) for (int numTileY=0; numTileY<nTilesY; numTileY++)
{ {
for (int numTileX=0; numTileX<nTilesX; numTileX++) for (int numTileX=0; numTileX<nTilesX; numTileX++)
...@@ -169,9 +177,17 @@ void TileMapImageIO::Read(void* buffer) ...@@ -169,9 +177,17 @@ void TileMapImageIO::Read(void* buffer)
double xTile = (firstSample+256*numTileX)/((1 << m_Depth)*256.); double xTile = (firstSample+256*numTileX)/((1 << m_Depth)*256.);
double yTile = (firstLine+256*numTileY)/((1 << m_Depth)*256.); double yTile = (firstLine+256*numTileY)/((1 << m_Depth)*256.);
//Retrieve the tile //Retrieve the tile
itk::TimeProbe probeFetch;
probeFetch.Start();
InternalRead(xTile, yTile, bufferTile); InternalRead(xTile, yTile, bufferTile);
probeFetch.Stop();
std::cout<<"Tile "<<xTile<<", "<<yTile<<" fetched in "<< probeFetch.GetMeanTime()<<" seconds"<<std::endl;
//Copy the tile in the output buffer //Copy the tile in the output buffer
itk::TimeProbe probeCopy;
probeCopy.Start();
for (int tileJ=0; tileJ<256; tileJ++) for (int tileJ=0; tileJ<256; tileJ++)
{ {
long int yImageOffset=(long int) (256*floor(firstLine/256.)+256*numTileY-firstLine+tileJ); long int yImageOffset=(long int) (256*floor(firstLine/256.)+256*numTileY-firstLine+tileJ);
...@@ -199,11 +215,17 @@ void TileMapImageIO::Read(void* buffer) ...@@ -199,11 +215,17 @@ void TileMapImageIO::Read(void* buffer)
} }
}//end of tile copy
}//end of tile copy
probeCopy.Stop();
std::cout<<"Tile "<<xTile<<", "<<yTile<<" copied to output in "<< probeCopy.GetMeanTime()<<" seconds"<<std::endl;
} }
}//end of full image copy }//end of full image copy
probeOverall.Stop();
std::cout<<"Overall region processing took "<<probeOverall.GetMeanTime()<<" seconds."<<std::endl;
delete[] bufferTile; delete[] bufferTile;
......
...@@ -2233,6 +2233,12 @@ ADD_TEST(ioTvImageKeywordlistErs ${IO_TESTS18} ...@@ -2233,6 +2233,12 @@ ADD_TEST(ioTvImageKeywordlistErs ${IO_TESTS18}
ENDIF(OTB_DATA_USE_LARGEINPUT) ENDIF(OTB_DATA_USE_LARGEINPUT)
ADD_TEST(ioTvOssimJpegFileRessourceLeak ${IO_TESTS18}
otbOssimJpegFileRessourceLeakTest
${INPUTDATA}/poupees.jpg
1200
)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbIOTESTS19 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbIOTESTS19 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...@@ -2475,6 +2481,7 @@ otbIkonosImageMetadataInterfaceNew.cxx ...@@ -2475,6 +2481,7 @@ otbIkonosImageMetadataInterfaceNew.cxx
otbTerraSarImageMetadataInterfaceNew.cxx otbTerraSarImageMetadataInterfaceNew.cxx
otbImageMetadataInterfaceTest.cxx otbImageMetadataInterfaceTest.cxx
otbImageMetadataInterfaceTest2.cxx otbImageMetadataInterfaceTest2.cxx
otbOssimJpegFileRessourceLeakTest.cxx
) )
IF(OTB_USE_CURL) IF(OTB_USE_CURL)
......
...@@ -35,4 +35,5 @@ REGISTER_TEST(otbQuickBirdImageMetadataInterfaceNew); ...@@ -35,4 +35,5 @@ REGISTER_TEST(otbQuickBirdImageMetadataInterfaceNew);
REGISTER_TEST(otbTerraSarImageMetadataInterfaceNew); REGISTER_TEST(otbTerraSarImageMetadataInterfaceNew);
REGISTER_TEST(otbImageMetadataInterfaceTest); REGISTER_TEST(otbImageMetadataInterfaceTest);
REGISTER_TEST(otbImageMetadataInterfaceTest2); REGISTER_TEST(otbImageMetadataInterfaceTest2);
REGISTER_TEST(otbOssimJpegFileRessourceLeakTest);
} }
/*
* JpegFileDescriptorRessourceLeak.cxx
*
* Created on: 12 mars 2010
* Author: jmichel
*/
#include <imaging/ossimImageHandler.h>
#include <imaging/ossimImageHandlerRegistry.h>
#include <base/ossimFilename.h>
#include <stdlib.h>
#include <iostream>
// This test demonstrate that handler->close() does not release the file descriptor for jpeg files.
int otbOssimJpegFileRessourceLeakTest(int argc, char * argv[])
{
if(argc != 3)
{
std::cerr<<"Usage:"<<std::endl;
std::cerr<<argv[0]<<" infname nbReading"<<std::endl;
return 1;
}
const char * infname = argv[1];
const unsigned int nbReading = atoi(argv[2]);
for(unsigned int i = 0; i < nbReading; ++i)
{
// Create the handler
ossimImageHandler * handler = ossimImageHandlerRegistry::instance()->open(ossimFilename(infname));
if(!handler)
{
std::cerr<<"Failed to open image "<<i<<" times."<<std::endl;
return 1;
}
handler->close();
}
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment