#!/usr/bin/env python # ParseTest.py -- parse and test Cactus testsuite results # # Frank Loffler # Josh Harris import sys, os, re, itertools, glob #Usage = "usage: ParseTest.py test_dir_1 test_dir_2 tolerance" # Carpet ascii output format (one of them): # 1:it 2:tl 3:rl 4:c 5:ml 6:ix 7:iy 8:iz 9:time 10:x 11:y 12:z 13:data # Used as 'primary key' here is the combination of '1,2,3,5,6,7,8'. # Data to test would be everything from '10' on, with '10,11,12' having a # quite strict requirement on accuracy, while tolerances for everything from # '13' on would be user-set. # Comments are denoted using '#' in the file, and empty lines should be # ignored. class Datum: def __init__(self, it, tl, rl, c, ml, ix, iy, iz, time, x, y, z, data): self.it = it self.tl = tl self.rl = rl self.c = c self.ml = ml self.ix = ix self.iy = iy self.iz = iz self.time = time self.x = x self.y = y self.z = z self.data = float(data) self.key = it+'|'+tl+'|'+rl+'|'+ml+'|'+ix+'|'+iy+'|'+iz self.xyz = ix + iy + iz def getXYZ(self): return self.xyz def getKey(self): return self.key def getData(self): return self.data def makeDatum(info): it, tl, rl, c, ml, ix, iy, iz, time, x, y, z, data = info.split(' ') return Datum(it, tl, rl, c, ml, ix, iy, iz, time, x, y, z, data) def readDatum(filename): fileData = [] keySet = set() f = open (filename, 'r') for line in f: if not line.strip().startswith("#") and not re.match(r'^\s*$', line): preformattedline = re.sub(r'\$','\n',line) DataObj = makeDatum(re.sub(r'\t',' ',preformattedline)) if(DataObj.getKey() not in keySet): keySet.add(DataObj.getKey()) fileData.append(DataObj) return fileData def bothCompare(d1,d2,tol,input1,input2): numfail = 0 result = open('results','a') for counter, datum1 in enumerate(d1): for counter2, datum2 in enumerate(d2): if datum1.getKey() == datum2.getKey(): tolcheck = float(tol) diff = abs(datum1.getData() - datum2.getData()) printkey = datum1.getKey() if tolcheck < diff: result.write('\n\nFiles '+input1+' and '+input2+' failed with a difference of '+str(diff)+' on Key: '+printkey) numfail+=1 if(numfail > 0): print('Files '+input1+' and '+input2+' had '+str(numfail)+ ' lines above tolerance.') result.close() dir1=sys.argv[1] dir2=sys.argv[2] if len(sys.argv) < 4: tolerance = 0.0 else: tolerance = sys.argv[3] fl1 = glob.glob(dir1 + "/*") fl2 = glob.glob(dir2 + "/*") filelist = fl1+fl2 for file1,file2 in itertools.combinations(filelist,2): if file1.split(".")[-2] == file2.split(".")[-2]: Data1=readDatum(file1) Data2=readDatum(file2) bothCompare(Data1,Data2,tolerance,file1,file2)