Skip to content

Commit

Permalink
expect : add counter
Browse files Browse the repository at this point in the history
  • Loading branch information
lathuili committed Jul 3, 2023
1 parent 079565e commit 0259a5f
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 31 deletions.
113 changes: 85 additions & 28 deletions vr_expect_clr.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ HChar vr_postApplyKeyStr[]= "post-apply: ";
SizeT vr_postApplyKeyStrSize=sizeof(vr_postApplyKeyStr)-1;


HChar vr_verboseKeyStr[]= "verbose: ";
SizeT vr_verboseKeyStrSize=sizeof(vr_verboseKeyStr)-1;


#define DEFAULT_MAX 10
#define DEFAULT_SIZE_MAX 30
Expand Down Expand Up @@ -104,18 +107,22 @@ HChar defaultStr[]="default";
HChar stopStr[]="stop";
HChar startStr[]="start";
HChar displayCounterStr[]="display_counter";
HChar dumpCoverStr[]="dumpCoverStr";
HChar nbInstrStr[]="nb_instr";
HChar resetCounterStr[]="reset_counter";
HChar dumpCoverStr[]="dump_cover";
HChar panicStr[]="panic";
HChar exitStr[]="exit";



typedef enum {nopKey=0, emptyKey, defaultKey,stopKey, startKey, displayCounterKey, dumpCoverKey, panicKey,exitKey} Vr_applyKey;
static const SizeT actionNumber=9;
HChar* actionStrTab[]={nopStr, emptyStr, defaultStr, stopStr, startStr, displayCounterStr,dumpCoverStr, panicStr, exitStr};
SizeT actionSizeTab[]={sizeof(nopStr), sizeof(emptyStr),sizeof(defaultStr),sizeof(stopStr), sizeof(startStr), sizeof(displayCounterStr),sizeof(dumpCoverStr),sizeof(panicStr),sizeof(exitStr)};
typedef enum {nopKey=0, emptyKey, defaultKey, stopKey, startKey, displayCounterKey, nbInstrKey, resetCounterKey, dumpCoverKey, panicKey, exitKey} Vr_applyKey;
static const SizeT actionNumber=11;
HChar* actionStrTab[]={nopStr, emptyStr, defaultStr, stopStr, startStr, displayCounterStr, nbInstrStr, resetCounterStr, dumpCoverStr, panicStr, exitStr};
SizeT actionSizeTab[]={sizeof(nopStr), sizeof(emptyStr),sizeof(defaultStr),sizeof(stopStr), sizeof(startStr), sizeof(displayCounterStr), sizeof(nbInstrStr), sizeof(resetCounterStr), sizeof(dumpCoverStr),sizeof(panicStr),sizeof(exitStr)};

Bool actionRequireCacheCleanTab[]={False, False, False, True, True, False, False, False, False, False, False };

Bool actionRequireCacheCleanTab[]={False, False, False, True, True, False, False, False, False };
UInt expect_verbose=1;

static Vr_applyKey vr_CmdToEnum(const HChar* cmd){

Expand Down Expand Up @@ -158,8 +165,8 @@ Bool vr_valid_apply_cmd(const HChar* cmd){



/*Remarks : get_char and VG_(get_line) are reimplemented because of a side-effect
of VG_(get_line) which implies to fully read a file before to read an other. Moreover VG_(get_line)
/*Remarks : get_char and VG_(get_line) are reimplemented because of a side-effect
of VG_(get_line) which implies to fully read a file before to read an other. Moreover VG_(get_line)
has specificities for suppression file
*/
Expand Down Expand Up @@ -337,11 +344,16 @@ void vr_expect_clr_init (const HChar * fileName) {
SizeT lineNo = 0;

while (! get_fullnc_line(vr.expectCLRFileInput, &vr_expectTmpLine, &lineNo)) {
if(expect_verbose>3){
VG_(umsg)("debug line : %s\n", vr_expectTmpLine);
}

//Treat default key
if( VG_(strncmp)(vr_expectTmpLine, vr_defaultKeyStr, vr_defaultKeyStrSize)==0 ){
const HChar* defaultAction=vr_expectTmpLine+vr_defaultKeyStrSize;
VG_(umsg)("default action str : %s\n", defaultAction);
if(expect_verbose>1){
VG_(umsg)("default action str : %s\n", defaultAction);
}
if (vr_valid_apply_cmd(defaultAction)){
VG_(fprintf)(vr.expectCLRFileOutput, "default action [%lu] : %s\n",vr_nbDefault ,defaultAction);
VG_(strncpy)(vr_applyDefault[vr_nbDefault],defaultAction, DEFAULT_SIZE_MAX);
Expand All @@ -367,8 +379,11 @@ void vr_expect_clr_init (const HChar * fileName) {

if( VG_(strncmp)(vr_expectTmpLine, vr_applyKeyStr, vr_applyKeyStrSize)==0 ){
const HChar* applyCmd=vr_expectTmpLine+vr_applyKeyStrSize;
if(expect_verbose>1){
VG_(umsg)("apply : %s\n", applyCmd);
}
if(vr_nbApplyMatch<0){
VG_(tool_panic)("vr_expect_clr : match expected before apply ");
VG_(tool_panic)("vr_expect_clr : match expected befor apply ");
}
vr_nbApplyMatch[vr_nbMatch-1]++;
if(vr_nbApplyMatch[vr_nbMatch-1]>=APPLY_PER_MATCH_MAX ){
Expand All @@ -380,8 +395,11 @@ void vr_expect_clr_init (const HChar * fileName) {

if( VG_(strncmp)(vr_expectTmpLine, vr_postApplyKeyStr, vr_postApplyKeyStrSize)==0 ){
const HChar* applyCmd=vr_expectTmpLine+vr_postApplyKeyStrSize;
if(expect_verbose>1){
VG_(umsg)("post_apply : %s\n", applyCmd);
}
if(vr_nbApplyMatch<0){
VG_(tool_panic)("vr_expect_clr : match expected before post-apply ");
VG_(tool_panic)("vr_expect_clr : match expected befor post-apply ");
}
vr_nbPostApplyMatch[vr_nbMatch-1]++;
if(vr_nbPostApplyMatch[vr_nbMatch-1]>=POST_APPLY_PER_MATCH_MAX ){
Expand All @@ -394,19 +412,30 @@ void vr_expect_clr_init (const HChar * fileName) {

//Treat begin key
if( VG_(strncmp)(vr_expectTmpLine, vr_beginKeyStr, vr_beginKeyStrSize)==0 ){
break;
vr_expectTmpLine[0]='\0';
break;
}
if( VG_(strncmp)(vr_expectTmpLine, vr_verboseKeyStr, vr_verboseKeyStrSize)==0 ){
const HChar* verboseStr=vr_expectTmpLine+vr_verboseKeyStrSize;
expect_verbose=VG_(strtoull10)(verboseStr, NULL);
continue;
}

//Treat filter line exec key
if( VG_(strncmp)(vr_expectTmpLine, vr_filterLineExecKeyStr, vr_filterLineExecKeyStrSize)==0 ){
const HChar* filterExecCmd=vr_expectTmpLine+vr_filterLineExecKeyStrSize;
VG_(umsg)("filter line exec str : %s\n", filterExecCmd);
if(expect_verbose>1){
VG_(umsg)("filter line exec str : %s\n", filterExecCmd);
}

if(vr_filter==True){
VG_(tool_panic)("vr_expect_clr : only one filter_line_exec cmd is accepted");
}
vr_filter=True;
VG_(strncpy)(vr_filter_cmd,filterExecCmd,FILTER_SIZEMAX);
VG_(umsg)("vr_filter_cmd : %s\n", vr_filter_cmd);
if(expect_verbose>1){
VG_(umsg)("vr_filter_cmd : %s\n", vr_filter_cmd);
}
vr_filtered_buff=VG_(malloc)("vr_filtered_buff.1", LINE_SIZEMAX*sizeof(HChar));
Int id=VG_(mkstemp) ("vrFilterCmd", tmpFileNameFilter );
VG_(close)(id);
Expand All @@ -418,12 +447,14 @@ void vr_expect_clr_init (const HChar * fileName) {
vr_last_expect_lineNo=lineNo;
return;
}
VG_(umsg)("unused line : %s\n", vr_expectTmpLine);
if(expect_verbose>0){
VG_(umsg)("Unused line : %s\n", vr_expectTmpLine);
}
}

while (! get_fullnc_line(vr.expectCLRFileInput, &vr_expectTmpLine, &lineNo)) {
//Treat expect key
if( VG_(strncmp)(vr_expectTmpLine, vr_expectKeyStr, vr_expectKeyStrSize)==0 ){
if( VG_(strncmp)(vr_expectTmpLine, vr_expectKeyStr, vr_expectKeyStrSize)==0 ){
vr_currentExpectStr=vr_expectTmpLine+vr_expectKeyStrSize;
vr_last_expect_lineNo=lineNo;
break;
Expand All @@ -436,7 +467,9 @@ void vr_expect_clr_init (const HChar * fileName) {


static void vr_applyCmd(Vr_applyKey key, const HChar* cmd){

if(expect_verbose>1){
VG_(umsg)("vr_applyCmd : %s\n", cmd);
}
switch(key){
case nopKey:
return;
Expand All @@ -457,6 +490,17 @@ static void vr_applyCmd(Vr_applyKey key, const HChar* cmd){
vr_ppOpCount();
VG_(fprintf)(vr.expectCLRFileOutput,"apply: display_counter\n");
return;
case nbInstrKey:
{
UInt nbInstr=vr_count_fp_instrumented();
VG_(fprintf)(vr.expectCLRFileOutput,"fp_instr: %u\n", nbInstr );
return;
}
case resetCounterKey:
{
vr_resetCount();
return;
}
case dumpCoverKey:
{
SizeT ret;
Expand All @@ -482,7 +526,10 @@ static void vr_applyCmd(Vr_applyKey key, const HChar* cmd){

static
void vr_expect_apply_clr(const HChar* cmd, Bool noIntrusiveOnly){
VG_(umsg)("vr_expect_apply_clr: %s\n",cmd);
if(expect_verbose>2){
VG_(umsg)("vr_expect_apply_clr: %s\n",cmd);
}

Vr_applyKey key=vr_CmdToEnum(cmd);
if(key==defaultKey){
for(SizeT i=0; i< vr_nbDefault;i++){
Expand Down Expand Up @@ -525,7 +572,9 @@ void vr_expect_apply_clrs(void){

// what to do with this line
VG_(fprintf)(vr.expectCLRFileOutput,"Line %lu ignored : %s\n", lineNo, vr_expectTmpLine);
VG_(umsg)("expect_clr : Line %lu ignored : %s\n", lineNo, vr_expectTmpLine);
if( expect_verbose >0){
VG_(umsg)("expect_clr : Line %lu ignored : %s\n", lineNo, vr_expectTmpLine);
}
}
if(countApply==0){
vr_expect_apply_clr("default", False);
Expand Down Expand Up @@ -557,10 +606,10 @@ void vr_expect_clr_checkmatch(const HChar* writeLine,SizeT size){
if(previousMatchIndex!=-1){
for(SizeT postApplyIndex=0 ; postApplyIndex< vr_nbPostApplyMatch[previousMatchIndex]; postApplyIndex++){
vr_expect_apply_clr(vr_postApplyMatch[previousMatchIndex][postApplyIndex], False);
}
}
previousMatchIndex=-1;
}

if(vr_filter){
// apply filter

Expand All @@ -577,10 +626,14 @@ void vr_expect_clr_checkmatch(const HChar* writeLine,SizeT size){

if( vr_currentExpectStr!=NULL && VG_(string_match)(vr_currentExpectStr,filteredBuf)){
//The line match the expect pattern
VG_(umsg)("expect: %s\n", vr_writeLineBuffCurrent);
if(expect_verbose >0){
VG_(umsg)("expect: %s\n", vr_writeLineBuffCurrent);
}
VG_(fprintf)(vr.expectCLRFileOutput,"expect: %s\n", vr_writeLineBuffCurrent);
if(vr_filter){
VG_(umsg)("expect(filtered): %s\n", filteredBuf);
if(vr_filter){
if(expect_verbose >0){
VG_(umsg)("expect(filtered): %s\n", filteredBuf);
}
VG_(fprintf)(vr.expectCLRFileOutput,"expect(filtered): %s\n", filteredBuf);
}

Expand All @@ -591,10 +644,14 @@ void vr_expect_clr_checkmatch(const HChar* writeLine,SizeT size){
for(SizeT matchIndex=0; matchIndex< vr_nbMatch; matchIndex++){
if( VG_(string_match)(vr_matchPattern[matchIndex],filteredBuf)){
//The line match the expect pattern
VG_(umsg)("match: %s\n", vr_matchPattern[matchIndex]);
VG_(fprintf)(vr.expectCLRFileOutput,"match: %s\n", vr_writeLineBuffCurrent);
if(expect_verbose>0){
VG_(umsg)("match [%lu]: %s\n",matchIndex ,vr_writeLineBuffCurrent);
}
VG_(fprintf)(vr.expectCLRFileOutput,"match [%lu]: %s\n",matchIndex ,vr_writeLineBuffCurrent);
if(vr_filter){
VG_(umsg)("match(filtered): %s\n", filteredBuf);
if(expect_verbose>0){
VG_(umsg)("match(filtered): %s\n", filteredBuf);
}
VG_(fprintf)(vr.expectCLRFileOutput,"match(filtered): %s\n", filteredBuf);
}
//Loop apply to DO
Expand All @@ -608,7 +665,7 @@ void vr_expect_clr_checkmatch(const HChar* writeLine,SizeT size){
//post_apply only on the first match : the test can be simple if match only once is activated (cf. continue behind)
previousMatchIndex=matchIndex;
}
continue; //match only once
break; //match only once
}
}
}
Expand Down
25 changes: 22 additions & 3 deletions vr_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ static const HChar* vr_ppVec (Vr_Vec vec) {


static ULong vr_opCount[VR_OP][VR_PREC][VR_VEC][VR_INSTR];

void vr_resetCount(void){
Vr_Op op;
Vr_Prec prec;
Vr_Vec vec;
for (op = 0 ; op<VR_OP ; ++op) {
for (prec = 0 ; prec < VR_PREC ; ++prec) {
for (vec = 0 ; vec < VR_VEC ; ++vec) {
vr_opCount[op][prec][vec][VR_INSTR_ON]=0;
vr_opCount[op][prec][vec][VR_INSTR_OFF]=0;
}
}
}
};

static VG_REGPARM(2) void vr_incOpCount (ULong* counter, SizeT increment) {
counter[vr.instrument] += increment;
}
Expand All @@ -163,9 +178,6 @@ static VG_REGPARM(2) void vr_incUnstrumentedOpCount (ULong* counter, SizeT incre
}


static VG_REGPARM(0) void vr_updatep_prandom (void) {
verrou_updatep_prandom();
}


static void vr_countOp (IRSB* sb, Vr_Op op, Vr_Prec prec, Vr_Vec vec, Bool instr) {
Expand Down Expand Up @@ -326,6 +338,11 @@ void vr_ppOpCount (void) {
}
}

static VG_REGPARM(0) void vr_updatep_prandom (void) {
verrou_updatep_prandom();
}


#include "vr_traceBB_impl.h"


Expand Down Expand Up @@ -1637,6 +1654,8 @@ static void vr_post_clo_init(void)
// vr.genAbove = VG_(strdup)("vr.post_clo_init.gen-above", "main");
// }

vr_resetCount();

if(vr.sourceExcludeActivated){
if(!vr_includeSourceMutuallyExclusive(vr.includeSource, vr.excludeSourceRead)){
VG_(tool_panic)("--source and --warn-unknown-source are incompatible");
Expand Down
1 change: 1 addition & 0 deletions vr_main.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ extern Vr_State vr;
UInt vr_count_fp_instrumented (void);
UInt vr_count_fp_not_instrumented (void);
void vr_ppOpCount (void);
void vr_resetCount(void);
void vr_cancellation_handler(int cancelled );
void vr_denorm_handler(void);
void vr_float_max_handler(void);
Expand Down

0 comments on commit 0259a5f

Please sign in to comment.