<commit_before>#!/usr/bin/python
import os, sys
import subprocess

outFiles = ["hitsmisses.out", "busshouts.out"]

def report(test, sol):
  if test == sol:
    print "TEST PASSED!"
  else:
    print "TEST FAILED..."


def checkHitsMisses(parsed, traceFile):
  sol = []
  if traceFile == "traces/easy1.trace":
    sol = ['M','M','M','H','H','H','M','H','H','H']
  elif traceFile == "traces/evict1.trace":
    sol = ['M','M','H','H','E','E']
  elif traceFile == "traces/coherent1.trace":
    sol = ['M','M','M','H','H','H']

  report(parsed[0], sol)


def checkBusShouts(parsed, traceFile):
  sol = []
  if traceFile == "traces/easy1.trace":
    sol = ['R','R','R','U','R']
  elif traceFile == "traces/evict1.trace":
    sol = ['R','R','R','R']
  elif traceFile == "traces/coherent1.trace":
    sol = ['R','R','R','U','X']

  report(parsed[1], sol)


def parse():
  parsedFiles = []
  for outFile in outFiles:
    with open(outFile) as f:
      content = f.readlines()
      bare = map (lambda r: r.strip(), content)
      parsedFiles.append(bare)
  return parsedFiles


def run(traceFile):
  subprocess.call(["./cache", "-t", traceFile])


def clean():
  for outFile in outFiles:
    subprocess.call(["rm", outFile])


def main():
  if len(sys.argv) < 2:
    print "Usage: python " + sys.argv[0] + " <trace file>"
    sys.exit(1)

  traceFile = sys.argv[1]
  run(traceFile)

  print
  print "~ Verifying output"

  parsed = parse()

  print "~ Checking Hits/Misses/Evictions"
  checkHitsMisses(parsed, traceFile)

  print "~ Checking Bus Shouts"
  checkBusShouts(parsed, traceFile)

  clean()


if __name__ == '__main__':
  main()
<commit_msg>Make verif.py take in protocol arg, also use argparse<commit_after>#!/usr/bin/python
import os, sys
import subprocess
import argparse

outFiles = ["hitsmisses.out", "busshouts.out"]

def report(test, sol):
  if test == sol:
    print "TEST PASSED!"
  else:
    print "TEST FAILED..."


def checkHitsMisses(parsed, traceFile):
  sol = []
  if traceFile == "traces/easy1.trace":
    sol = ['M','M','M','H','H','H','M','H','H','H']
  elif traceFile == "traces/evict1.trace":
    sol = ['M','M','H','H','E','E']
  elif traceFile == "traces/coherent1.trace":
    sol = ['M','M','M','H','H','H']

  report(parsed[0], sol)


def checkBusShouts(parsed, traceFile):
  sol = []
  if traceFile == "traces/easy1.trace":
    sol = ['R','R','R','U','R']
  elif traceFile == "traces/evict1.trace":
    sol = ['R','R','R','R']
  elif traceFile == "traces/coherent1.trace":
    sol = ['R','R','R','U','X']

  report(parsed[1], sol)


def parse():
  parsedFiles = []
  for outFile in outFiles:
    with open(outFile) as f:
      content = f.readlines()
      bare = map (lambda r: r.strip(), content)
      parsedFiles.append(bare)
  return parsedFiles


def run(traceFile, protocol):
  subprocess.call(["./cache", "-t", traceFile, "-p", protocol])


def clean():
  for outFile in outFiles:
    subprocess.call(["rm", outFile])


def main():
  ap = argparse.ArgumentParser()
  ap.add_argument('-t', help="Tracefile path")
  ap.add_argument('-p', help="Coherence protocol")
  opts = ap.parse_args()

  traceFile = opts.t
  protocol = opts.p
  run(traceFile, protocol)

  print
  print "~ Verifying output"

  parsed = parse()

  print "~ Checking Hits/Misses/Evictions"
  checkHitsMisses(parsed, traceFile)

  print "~ Checking Bus Shouts"
  checkBusShouts(parsed, traceFile)

  clean()


if __name__ == '__main__':
  main()

{'fraction_non_alphanumeric': 0.1980858468677494, 'fraction_numerical': 0.00580046403712297, 'mean_word_length': 3.7704011065006915, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '172411', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1275, 'n_words': 288}