Skip to content

Instantly share code, notes, and snippets.

@tuzhucheng
Last active December 24, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tuzhucheng/6845468 to your computer and use it in GitHub Desktop.
Save tuzhucheng/6845468 to your computer and use it in GitHub Desktop.
This gist compares the MIPS language program created by your own Asm.java with the one created by binasm and see if they are the same. Used for testing purposes.
import os
import fnmatch
import subprocess
import sys
import getopt
print("CS241 A3 A4 Automated Python Test Framework")
print("Compiling Asm...")
subprocess.call(["javac", "Asm.java"])
asm_files = os.listdir('.')
asm_files = fnmatch.filter(asm_files, '*.asm')
print("The following test cases will be run against cs241.binasm")
print(asm_files)
print('\n')
for asm_file in asm_files:
try:
os.remove('test.mips')
os.remove('test2.mips')
os.remove('asm_xxd_out.hex')
os.remove('binasm_xxd_out.hex')
except OSError:
pass
mips_out = open('test.mips', 'wb+')
binasm_mips_out = open('test2.mips', 'wb+')
asm_xxd_out = open('asm_xxd_out.hex', 'wb+')
binasm_xxd_out = open('binasm_xxd_out.hex', 'wb+')
print("Testing with " + str(asm_file))
with open(asm_file, 'r') as test_case:
subprocess.call(["java", "cs241.binasm"], stdin=test_case, stdout=binasm_mips_out)
subprocess.call(["xxd", "test2.mips"], stdout=binasm_xxd_out)
with open(asm_file, 'r') as test_case:
subprocess.call(["java", "Asm"], stdin=test_case, stdout=mips_out)
subprocess.call(["xxd", "test.mips"], stdout=asm_xxd_out)
subprocess.call(["diff", "-s", "asm_xxd_out.hex", "binasm_xxd_out.hex"])
print('\n')
try:
os.remove('test.mips')
os.remove('test2.mips')
os.remove('asm_xxd_out.hex')
os.remove('binasm_xxd_out.hex')
except OSError:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment