fixed up testing code for filemapper

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-SparseFileStorage@6078 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-01-19 18:08:31 +00:00
parent 0c0dc3ff0e
commit 570913565c
3 changed files with 18 additions and 7 deletions

View File

@ -2,11 +2,12 @@
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <iostream>
#include "ftfilemapper.h"
#include "ftchunkmap.h"
//#define DEBUG_FILEMAPPER
#define DEBUG_FILEMAPPER
ftFileMapper::ftFileMapper(uint64_t file_size,uint32_t chunk_size)
: _file_size(file_size),_chunk_size(chunk_size)
@ -192,6 +193,7 @@ uint32_t ftFileMapper::allocateNewEmptyChunk(FILE *fd_out)
#endif
uint32_t first_free_chunk = _data_chunk_ids.size() ;
_data_chunk_ids.push_back(first_free_chunk) ;
if(_mapped_chunks[first_free_chunk] >= 0 && _mapped_chunks[first_free_chunk] < (int)first_free_chunk)
{
@ -203,7 +205,6 @@ uint32_t ftFileMapper::allocateNewEmptyChunk(FILE *fd_out)
moveChunk(_mapped_chunks[first_free_chunk],first_free_chunk,fd_out) ;
_mapped_chunks[first_free_chunk] = first_free_chunk ;
_data_chunk_ids.push_back(first_free_chunk) ;
#ifdef DEBUG_FILEMAPPER
std::cerr << "(DD) Returning " << old_chunk << std::endl;
@ -231,6 +232,7 @@ bool ftFileMapper::wipeChunk(uint32_t cid,FILE *fd) const
uint32_t size = (cid == _mapped_chunks.size()-1)?(_file_size - cid*_chunk_size) : _chunk_size ;
void *buf = malloc(size) ;
memset(buf,0,size) ; // Avoids uninitialized memory read below.
if(buf == NULL)
{

View File

@ -12,8 +12,7 @@ include $(RS_TOP_DIR)/tests/scripts/config.mk
TESTOBJ = pqitestor.o ftfilemappertest.o ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o fttransfermoduletest.o ftcrc32test.o ftcrossprovidercreatortest.o ftcontrollertest.o ftserver1test.o ftserver2test.o ftserver3test.o ftdata_dummy.o ftsearch_dummy.o
TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest fttransfermoduletest ftcrc32test ftcrossprovidercreatortest ftcontrollertest ftserver1test ftserver2test fttransfermoduletest ftserver3test
#ftfilemappertest
TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest fttransfermoduletest ftcrc32test ftcrossprovidercreatortest ftcontrollertest ftserver1test ftserver2test fttransfermoduletest ftserver3test ftfilemappertest
all: tests

View File

@ -4,21 +4,31 @@
#include <util/utest.h>
#include <util/rsdir.h>
#include <common/argstream.h>
#include <stdlib.h>
#include <iostream>
#include <stdint.h>
INITTEST();
int main()
int main(int argc,char *argv[])
{
/* Use ftfilemapper to create a file with chunks downloaded on a random direction. */
argstream as(argc,argv) ;
int random_seed = 0 ;
uint64_t size = 1024*1024*12+234;//4357283 ; // some size. Not an integer number of chunks
as >> parameter('r',"random-seed",random_seed,"Random seed for the test. Use the same seed to get the same behavior.",false)
>> parameter('s',"size",size,"file size to test.",false)
>> help() ;
as.defaultErrorHandling() ;
static const std::string tmpdir = "." ;
static const std::string input_file = tmpdir+"/"+"input.bin" ;
static const std::string output_file = tmpdir+"/"+"output.bin" ;
static const uint64_t size = 1024*1024*12+234;//4357283 ; // some size. Not an integer number of chunks
static const uint32_t chunk_size = 1024*1024 ; // 1MB
static const uint32_t chunk_size = 1024*1024 ; // 1MB
pid_t pid = getpid() ;
srand48(pid) ;