From a4a17c6b584c1b4b1435c92ae24796ae76f67cbc Mon Sep 17 00:00:00 2001 From: Veronique Legrand <vlegrand@pasteur.fr> Date: Tue, 8 Mar 2016 16:51:38 +0100 Subject: [PATCH] unit test didn't pass under linux. I don't know why but ftell() called after read() always returns 0. Had to change for lseek. --- src/FqAuxBackend.cpp | 3 ++- src/FqMainBackend.cpp | 14 +++++++++++--- src/unit_test_fqreader.cpp | 4 +++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/FqAuxBackend.cpp b/src/FqAuxBackend.cpp index 0e785b0..a17c28e 100644 --- a/src/FqAuxBackend.cpp +++ b/src/FqAuxBackend.cpp @@ -127,7 +127,8 @@ int FqAuxBackend::processBuffer(rinfo * p_nr) { void FqAuxBackend::readBuffer() { if ((nread=read(f_desc,buf,bufsize))!=0) { - cur_offset=ftell(f_stream); + cur_offset=lseek(f_desc,0,SEEK_CUR); +//ftell(f_stream); pos_in_buf=0; } } diff --git a/src/FqMainBackend.cpp b/src/FqMainBackend.cpp index b259f66..72d1b15 100644 --- a/src/FqMainBackend.cpp +++ b/src/FqMainBackend.cpp @@ -18,6 +18,7 @@ //#define DEBUG #ifdef DEBUG +#include <string.h> #include <iostream> using namespace std; #endif @@ -53,7 +54,8 @@ void FqMainBackend::processFile(char * filename,unsigned char f_id) { if (fp==NULL) { err(errno,"cannot open file: %s.",filename); } - cur_offset=ftell(fp); + //cur_offset=ftell(fp); + //cout<<"cur_offset="<<cur_offset<<endl; char* buf=(char *) malloc(FqBaseBackend::bufsize*sizeof(char)); if (buf==NULL) { err(errno,"cannot allocate memory: %lu bytes.",bufsize); @@ -63,7 +65,9 @@ void FqMainBackend::processFile(char * filename,unsigned char f_id) { nb_read_oper++; //cout<<"BE1: read operation nbr: "<<nb_read_oper<<endl; //printf("going to call ftell on : %p \n",fp); - cur_offset=ftell(fp); + //cur_offset=ftell(fp); // don't know why but it seems that this doesn't work under linux; always returns 0... + cur_offset = lseek(f_single, 0, SEEK_CUR); + //cout<<"cur_offset="<<cur_offset<<endl; processBuf((char *)buf,nread,f_id,cur_offset); } close(f_single); @@ -97,12 +101,16 @@ void FqMainBackend::processBuf(char * buf,int nread,unsigned char f_id,unsigned case k_read_id_start: if (qual_score) goto inc_score; else { + rstart_offset=cur_offset-nread+cnt; #ifdef DEBUG + cout<<"nread="<<nread<<endl; + cout<<"cnt="<<cnt<<endl; + cout<<"rstart_offset="<<rstart_offset<<endl; is_id=1; idx_id=0; nb_start++; #endif - rstart_offset=cur_offset-nread+cnt; + // rstart_offset=cur_offset-nread+cnt; num_l_in_rec=1; } break; case k_read_qual_start: diff --git a/src/unit_test_fqreader.cpp b/src/unit_test_fqreader.cpp index d40e7c2..28e8d88 100644 --- a/src/unit_test_fqreader.cpp +++ b/src/unit_test_fqreader.cpp @@ -7,6 +7,7 @@ * Keep using assert for the moment, don't want to add a dependency on boost (or any other test framework) just for the tests. */ #include <stdio.h> +#include <string.h> #include <iostream> #include <limits.h> #include <assert.h> @@ -38,7 +39,8 @@ void test_processSingleFile() { assert(score==5); for (it_offs=rit->second.begin();it_offs!=rit->second.end();it_offs++) { unsigned long offset_quotient=it_offs->first; - assert(offset_quotient==0); + cout<<"offset_quotient="<<offset_quotient<<endl; + assert(offset_quotient==0); for (it_struct=it_offs->second.begin();it_struct!=it_offs->second.end();it_struct++) { unsigned char fid_stored=it_struct->fileid; assert(fid_stored >>4==f_id); -- GitLab