summaryrefslogtreecommitdiff
path: root/benchmarks/CUDA/CP/common/python/filecompare.py
diff options
context:
space:
mode:
authorTor Aamodt <[email protected]>2010-10-01 08:55:28 -0800
committerTor Aamodt <[email protected]>2010-10-01 08:55:28 -0800
commit11b308e7363e937966b035b4891db32b4eece3bf (patch)
tree50ca4c9ad6f163ac4acb2bf505e64dfebed66947 /benchmarks/CUDA/CP/common/python/filecompare.py
parentbb820c116764d7a1b8e071137d32b74e7f34dd2f (diff)
integrating recent changes from fermi-test into fermi
(i'll use "fermi" for more disruptive changes to the pipeline model such as updating the MSHRs and getting rid of the warp tracker, ripping out DWF, etc...) [git-p4: depot-paths = "//depot/gpgpu_sim_research/fermi/distribution/": change = 7805]
Diffstat (limited to 'benchmarks/CUDA/CP/common/python/filecompare.py')
-rw-r--r--benchmarks/CUDA/CP/common/python/filecompare.py154
1 files changed, 0 insertions, 154 deletions
diff --git a/benchmarks/CUDA/CP/common/python/filecompare.py b/benchmarks/CUDA/CP/common/python/filecompare.py
deleted file mode 100644
index a9a5c57..0000000
--- a/benchmarks/CUDA/CP/common/python/filecompare.py
+++ /dev/null
@@ -1,154 +0,0 @@
-# (c) Copyright 2007 The Board of Trustees of the University of Illinois.
-
-import sys
-
-# A monad for comparing two files. Comparing proceeds until the first
-# mismatch occurs, at which point comparison stops and the error is
-# reported.
-class CompareMonad(object):
- def checkType(x):
- if not isinstance(x, CompareMonad):
- raise TypeError, "Not a CompareMonad instance"
- checkType = staticmethod(checkType)
-
- def run(self, ref_file, out_file):
- raise NotImplementedError
-
-# The >>= operator. Executes 'fst', then executes 'snd' with the result
-# of 'fst'.
-class Bind(CompareMonad):
-
- def __init__(self, fst, snd):
- CompareMonad.checkType(fst)
- self.fst = fst
- self.snd = snd
-
- def run(self, ref_file, out_file):
- (ok, value) = self.fst.run(ref_file, out_file)
- if ok:
- sndMonad = self.snd(value)
- CompareMonad.checkType(sndMonad)
- return sndMonad.run(ref_file, out_file)
- return (False, None)
-
-# The >> operator. Executes 'fst', then executes 'snd'.
-class Then(CompareMonad):
- def __init__(self, fst, snd):
- CompareMonad.checkType(fst)
- CompareMonad.checkType(snd)
- self.fst = fst
- self.snd = snd
-
- def run(self, ref_file, out_file):
- (ok, value) = self.fst.run(ref_file, out_file)
- if ok:
- return self.snd.run(ref_file, out_file)
- return (False, None)
-
-# The 'return' operator. Returns a value that is accessible
-# within the monad.
-class Return(CompareMonad):
- def __init__(self, value):
- self.value = value
-
- def run(self, ref_file, out_file):
- return (True, self.value)
-
-# Run a list of monad instances and return their results as
-# a list.
-class Sequence(CompareMonad):
- def __init__(self, ms):
- self.ms = ms
-
- def run(self, ref_file, out_file):
- values = []
- for m in self.ms:
- CompareMonad.checkType(m)
- (ok, value) = m.run(ref_file, out_file)
- if not ok: return (False, None)
- values.append(value)
-
- return (True, values)
-
-# Run a list of monad instances, ignoring their results.
-class Sequence_(CompareMonad):
- def __init__(self, ms):
- self.ms = ms
-
- def run(self, ref_file, out_file):
- for m in self.ms:
- CompareMonad.checkType(m)
- (ok, value) = m.run(ref_file, out_file)
- if not ok: return (False, None)
-
- return (True, None)
-
-# The basic CompareMonad routine. This reads a value from both input
-# files, compares the result, and, if the comparison was successful,
-# returns the value.
-class Compare(CompareMonad):
- """Read an item from both input files and compare it."""
-
- def __init__(self,
- read = file.read,
- equal = lambda x, y: x == y,
- message = "Output does not match the expected output"):
- self.read = read
- self.equal = equal
- self.message = message
-
- def run(self, ref_file, out_file):
- try:
- x = self.read(ref_file)
- except ValueError, e:
- sys.stderr.write("Malformed reference file!\n")
- return (False, None)
- except EOFError:
- sys.stderr.write("Unexpected end of reference file!\n")
- return (False, None)
- try:
- y = self.read(out_file)
- except ValueError, e:
- sys.stderr.write("Malformed output file;\n")
- sys.stderr.write(str(e))
- sys.stderr.write('\n')
- return (False, None)
- except EOFError:
- sys.stderr.write("Unexpected end of output file\n")
- return (False, None)
-
- # Compare reference data to result data
- if self.equal(x, y):
- return (True, x)
- else:
- sys.stderr.write(self.message)
- sys.stderr.write('\n')
- return (False, None)
-
-def open_or_abort(filename):
- try: f = file(filename, "r")
- except:
- sys.stderr.write("Cannot open file '" + filename + "'\n")
- sys.exit(-1)
- return f
-
-
-def default_main(comparison_routine):
- """Default main() routine. Read file names from sys.argv
- and compare the files."""
-
- if len(sys.argv) != 3:
- sys.stderr.write("Usage: compare-output <from-file> <to-file>\n")
- sys.exit(-1)
-
- ref = open_or_abort(sys.argv[1])
- out = open_or_abort(sys.argv[2])
-
- (ok, _) = comparison_routine.run(ref, out)
- if ok:
- sys.stdout.write("Pass\n")
- sys.exit(0)
- else:
- sys.stdout.write("Mismatch\n")
- sys.exit(-1)
-