From aeb6d3b598528649e70bfa224a24136f677abf00 Mon Sep 17 00:00:00 2001 From: Mac Mollison Date: Sun, 4 Apr 2010 00:26:22 -0400 Subject: Remove runtests.py and naive_trace_reader These are outdated and I don't feel like maintaining them. --- runtests.py | 47 ----------- unit_trace/naive_trace_reader.py | 165 --------------------------------------- 2 files changed, 212 deletions(-) delete mode 100755 runtests.py delete mode 100644 unit_trace/naive_trace_reader.py diff --git a/runtests.py b/runtests.py deleted file mode 100755 index 88dddf4..0000000 --- a/runtests.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/python - -############################################################################### -# Description -############################################################################### - -# Unit Tests - - -############################################################################### -# Imports -############################################################################### - -import trace_reader -import naive_trace_reader -import os - -############################################################################### -# Trace files -############################################################################### - -files = [ -'./sample_traces/st-g6-0.bin', -'./sample_traces/st-g6-1.bin', -'./sample_traces/st-g6-2.bin', -'./sample_traces/st-g6-3.bin', -] - -############################################################################### -# Tests -############################################################################### - -# Does our fancy trace reader get the same number of files as our naive one? -# (See naive_trace_reader.py for further explanation) -def test1(): - stream = trace_reader.trace_reader(files) - num_records = len(list(stream)) - stream = naive_trace_reader.trace_reader(files) - naive_num_records = len(list(stream)) - - # We need a +1 here because the fancy reader produces a 'meta' record - # indicating the number of CPUs - if num_records != naive_num_records + 1: - return "[FAIL]" - return "[SUCCESS]" - -print "Test 1: %s" % (test1()) diff --git a/unit_trace/naive_trace_reader.py b/unit_trace/naive_trace_reader.py deleted file mode 100644 index 0f45895..0000000 --- a/unit_trace/naive_trace_reader.py +++ /dev/null @@ -1,165 +0,0 @@ -############################################################################### -# Description -############################################################################### - -# trace_reader(files) returns an iterator which produces records -# OUT OF ORDER from the files given. (the param is a list of files.) -# -# The non-naive trace_reader has a lot of complex logic which attempts to -# produce records in order (even though they are being pulled from multiple -# files which themselves are only approximately ordered). This trace_reader -# attempts to be as simple as possible and is used in the unit tests to -# make sure the total number of records read by the normal trace_reader is -# the same as the number of records read by this one. - -############################################################################### -# Imports -############################################################################### - -import struct - - -############################################################################### -# Public functions -############################################################################### - -# Generator function returning an iterable over records in a trace file. -def trace_reader(files): - for file in files: - f = open(file,'rb') - while True: - data = f.read(RECORD_HEAD_SIZE) - try: - type_num = struct.unpack_from('b',data)[0] - except struct.error: - break #We read to the end of the file - type = _get_type(type_num) - try: - values = struct.unpack_from(StHeader.format + - type.format,data) - record_dict = dict(zip(type.keys,values)) - except struct.error: - f.close() - print "Invalid record detected, stopping." - exit() - - # Convert the record_dict into an object - record = _dict2obj(record_dict) - - # Give it a type name (easier to work with than type number) - record.type_name = _get_type_name(type_num) - - # All records should have a 'record type' field. - # e.g. these are 'event's as opposed to 'error's - record.record_type = "event" - - # If there is no timestamp, set the time to 0 - if 'when' not in record.__dict__.keys(): - record.when = 0 - - yield record - -############################################################################### -# Private functions -############################################################################### - -# Convert a dict into an object -def _dict2obj(d): - class Obj: pass - o = Obj() - for key in d.keys(): - o.__dict__[key] = d[key] - return o - -############################################################################### -# Trace record data types and accessor functions -############################################################################### - -# Each class below represents a type of event record. The format attribute -# specifies how to decode the binary record and the keys attribute -# specifies how to name the pieces of information decoded. Note that all -# event records have a common initial 24 bytes, represented by the StHeader -# class. - -RECORD_HEAD_SIZE = 24 - -class StHeader(object): - format = '