Last active
December 24, 2015 18:49
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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