def assembler(jar, testes, in_dir, out_dir, bits, processos): start_time = time.time() rotina_mkdir = ["mkdir"] if platform.system() == "Windows": jar = jar.replace('/', '\\') testes = testes.replace('/', '\\') in_dir = in_dir.replace('/', '\\') out_dir = out_dir.replace('/', '\\') else: rotina_mkdir.append( "-p") # para criar os subdiretórios no mkdir no UNIX rotina_mkdir.append(out_dir) subprocess.call(rotina_mkdir, shell=True) # cria subdiretório para resultados nomes_testes = loadTestes.testes(testes) error_code = 0 n_done = 0 n_error = 0 n_skiped = 0 for i in nomes_testes: nome = i.split() # Testa se arquivos existem, senão pula if os.path.exists(in_dir + "{0}.nasm".format(nome[0])): rotina = [ 'java', '-jar', jar, in_dir + "{0}.nasm".format(nome[0]), "-s", "-o", out_dir + "{0}.hack".format(nome[0]), "-f", out_dir + "{0}.mif".format(nome[0]) ] if bits == 32: rotina.append("-b") rotina.append("32") error = subprocess.call(rotina) if (error != 0): error_code += error n_error += 1 else: n_done += 1 else: n_skiped += 1 elapsed_time = time.time() - start_time print('\033[92m' + "Assembled {0} file(s) in {1:.2f} seconds".format( n_done, elapsed_time) + '\033[0m') if (n_skiped != 0): print('\033[93m' + "Skipped {0} file(s)".format(n_skiped) + '\033[0m') if (error_code != 0): print('\033[91m' + "Failed {0} file(s)".format(n_error) + '\033[0m') exit(error_code)
def vmtranslator(jar, testes, in_dir, out_dir, processos): start_time = time.time() subprocess.call(["mkdir", "-p", out_dir]) nomes_testes = loadTestes.testes(testes) error_code = 0 done = 0 for i in nomes_testes: nome = i.split() no_bootstrap = False directory = False for f in range(3, len(nome)): if (nome[f] == "/"): directory = True if (nome[f] == "n"): no_bootstrap = True if directory: entrada = in_dir + "{0}".format(nome[0]) else: entrada = in_dir + "{0}.vm".format(nome[0]) saida = out_dir + "{0}.nasm".format(nome[0]) #rotina = ['java', '-jar', 'Codigos/VMTranslator/target/VMTranslator-1.0.jar', rotina = ['java', '-jar', jar, entrada, "-o", saida] # remove rotina de bootstrap do vmtranslator if no_bootstrap: rotina.append("-n") error = subprocess.call(rotina) if (error != 0): error_code += error else: done += 1 elapsed_time = time.time() - start_time print('\033[92m' + "VM Translated {0} file(s) in {1:.2f} seconds".format( done, elapsed_time) + '\033[0m') if (error_code != 0): print('\033[91m' + "Failed {0} file(s)".format(len(nomes_testes) - done) + '\033[0m') exit(error_code)
def compiler(testes, in_dir, out_dir, processos): start_time = time.time() if os.sep == "\\": in_dir.replace("\\", "/") out_dir.replace("\\", "/") subprocess.call(["mkdir", "-p", out_dir]) nomes_testes = loadTestes.testes(testes) error_code = 0 done = 0 for i in nomes_testes: nome = i.split() error = subprocess.call([ 'java', '-classpath', '${CLASSPATH}:TestesSW/Compiler:TestesSW/Compiler/Hack.jar:TestesSW/Compiler/Compilers.jar', 'Hack.Compiler.JackCompiler', in_dir + "{0}".format(nome[0]) ]) if (error != 0): error_code += error else: done += 1 subprocess.call(["mkdir", "-p", out_dir + nome[0]]) subprocess.call([ "mv {0} {1}".format(in_dir + nome[0] + "/*.vm", out_dir + nome[0]) ], shell=True) subprocess.call( ["cp {0} {1}".format("TestesSW/OS/*.vm", out_dir + nome[0])], shell=True) elapsed_time = time.time() - start_time print( '\033[92m' + "Compiled {0} file(s) in {1:.2f} seconds".format(done, elapsed_time) + '\033[0m') if (error_code != 0): print('\033[91m' + "Failed {0} file(s)".format(len(nomes_testes) - done) + '\033[0m') exit(error_code)
def assembler(testes, in_dir, out_dir, bits, processos): start_time = time.time() subprocess.call(["mkdir", "-p", out_dir]) nomes_testes = loadTestes.testes(testes) error_code = 0 n_done = 0 n_error = 0 n_skiped = 0 for i in nomes_testes: nome = i.split() # Testa se arquivos existem, senão pula if os.path.exists(in_dir + "{0}.nasm".format(nome[0])): rotina = [ 'java', '-jar', 'TestesSW/Assembler/AssemblerZ0.jar', in_dir + "{0}.nasm".format(nome[0]), "-s", "-o", out_dir + "{0}.hack".format(nome[0]), "-f", out_dir + "{0}.mif".format(nome[0]) ] if bits == 32: rotina.append("-b") rotina.append("32") error = subprocess.call(rotina) if (error != 0): error_code += error n_error += 1 else: n_done += 1 else: n_skiped += 1 elapsed_time = time.time() - start_time print('\033[92m' + "Assembled {0} file(s) in {1:.2f} seconds".format( n_done, elapsed_time) + '\033[0m') if (n_skiped != 0): print('\033[93m' + "Skipped {0} file(s)".format(n_skiped) + '\033[0m') if (error_code != 0): print('\033[91m' + "Failed {0} file(s)".format(n_error) + '\033[0m') exit(error_code)
# Testador de emulação # Arquivo: testComp.nasm # Criado por: Luciano Soares <*****@*****.**> # Data: 16/03/2017 import sys, getopt import unittest import pytest import loadTestes import detectImage nomes_testes = loadTestes.testes("TestesSW/testesAssembly.txt") @pytest.mark.parametrize(('nomes_testes'), nomes_testes) def test_Assembly(nomes_testes): nomes_testes = nomes_testes.split() if int(nomes_testes[1]) > 0: for i in range(int(nomes_testes[1])): resultado = "TestesSW/machine_code/{0}{1}_out.mif".format( nomes_testes[0], i) teste = "TestesSW/testesAssembly/{0}{1}_tst.mif".format( nomes_testes[0], i) debug = False ram = {} validacao = {}
def compiler(jar, testes, in_dir, out_dir, processos): start_time = time.time() rotina_mkdir = ["mkdir"] shell = False if platform.system() == "Windows": testes = testes.replace('/', '\\') in_dir = in_dir.replace('/', '\\') out_dir = out_dir.replace('/', '\\') shell = True else: rotina_mkdir.append( "-p") # para criar os subdiretórios no mkdir no UNIX rotina_mkdir.append(out_dir) subprocess.call(rotina_mkdir, shell=shell) # cria subdiretório para resultados nomes_testes = loadTestes.testes(testes) error_code = 0 done = 0 for i in nomes_testes: nome = i.split() directory = False for f in range(3, len(nome)): if (nome[f] == "/"): directory = True if directory: entrada = in_dir + "{0}".format(nome[0]) else: entrada = in_dir + "{0}.jack".format(nome[0]) saida = out_dir + "{0}".format(nome[0]) rotina = ['java', '-jar', jar, entrada, "-o", saida] if platform.system() == "Windows": subprocess.call(["mkdir", out_dir + nome[0]], shell=True) subprocess.call( ["copy", "/Y", "TestesSW\\OS\\*.vm", out_dir + nome[0]], shell=True) else: subprocess.call(["mkdir", "-p", out_dir + nome[0]]) subprocess.call( ["cp {0} {1}".format("TestesSW/OS/*.vm", out_dir + nome[0])], shell=True) error = subprocess.call(rotina, shell=shell) if (error != 0): error_code += error else: done += 1 elapsed_time = time.time() - start_time print( '\033[92m' + "Compiled {0} file(s) in {1:.2f} seconds".format(done, elapsed_time) + '\033[0m') if (error_code != 0): print('\033[91m' + "Failed {0} file(s)".format(len(nomes_testes) - done) + '\033[0m') exit(error_code)
#!/usr/bin/env python # -*- coding: utf-8 -*- # Testador de emulação # Arquivo: testCompiler.py # Criado por: Luciano Soares <*****@*****.**> # Data: 24/05/2017 import sys, getopt import unittest import pytest import loadTestes import diffImage import checkUnitTests nomes_testes = loadTestes.testes("TestesSW/testesCompiler.txt") @pytest.mark.skipif(checkUnitTests.checkUnitTests("Codigos/Compiler/target/"), reason="Testes unitários anteriores não passaram por completo, não executando teste de sistema.") @pytest.mark.parametrize(('nomes_testes'),nomes_testes) def test_Compiler(nomes_testes): nomes_testes = nomes_testes.split() debug = False if int(nomes_testes[1]) == 0: resultado = "TestesSW/compiled_code/{0}_out.mif".format(nomes_testes[0]) teste = "TestesSW/testesCompiler/{0}_tst.mif".format(nomes_testes[0])
# Testador da tradução de máquina virtual a pilha # Arquivo: testVMTranslator.py # Criado por: Luciano Soares <*****@*****.**> # Data: 4/05/2017 import sys, getopt import unittest import pytest import loadTestes import checkUnitTests nomes_testes = loadTestes.testes("TestesSW/testesVMTranslator.txt") # Testes a serem realizados @pytest.mark.skipif(checkUnitTests.checkUnitTests("Codigos/VMTranslator/target/"), reason="Testes unitários anteriores não passaram por completo, não executando teste de sistema.") @pytest.mark.parametrize(('nomes_testes'),nomes_testes) def test_Assembly(nomes_testes): nomes_testes = nomes_testes.split() resultado = "TestesSW/vm_code/{0}_out.mif".format(nomes_testes[0]) teste = "TestesSW/testesVMTranslator/{0}_tst.mif".format(nomes_testes[0]) debug = False ram = {} validacao = {} # rotina de leitura do resultado da emulação with open(resultado, 'r') as arquivo: linhas = arquivo.read().splitlines()
def emulate(testes,in_dir,out_dir,bits,processos,resolution): processes = set() max_processes = processos start_time = time.time() nomes_testes = loadTestes.testes(testes) n_error = 0 n_done = 0 n_skiped = 0 count = 0 for j in nomes_testes: nome = j.split() if int(nome[1]) > 0: for i in range(int(nome[1])): # Testa se arquivos existem, senão pula if os.path.exists(out_dir+"{0}.hack".format(nome[0])): rotina = ['java', '-jar', 'TestesSW/Elemulator/Elemulator.jar', out_dir+"{0}.hack".format(nome[0]), "-i",in_dir+"{0}{1}_in.mif".format(nome[0],i), "-o",out_dir+"{0}{1}_out.mif".format(nome[0],i),"-c",nome[2]] if bits==32: rotina.append("-b") rotina.append("32") print("\nEmulating: "+nome[0]+" >> Exec: "+" ".join(rotina)) processes.add(subprocess.Popen(rotina)) count += 1 while count >= max_processes: count = 0 time.sleep(0.1) for p in processes: if p.poll() is None: count += 1 else: n_skiped += 1 elif int(nome[1]) == 0: # caso só um teste # Testa se arquivos existem, senão pula if os.path.exists(out_dir+"{0}.hack".format(nome[0])): rotina = ['java', '-jar', 'TestesSW/Elemulator/Elemulator.jar', out_dir+"{0}.hack".format(nome[0]), "-i",in_dir+"{0}_in.mif".format(nome[0]), "-o",out_dir+"{0}_out.mif".format(nome[0]),"-c",nome[2]] if bits==32: rotina.append("-b") rotina.append("32") print("\nEmulating: "+nome[0]+" >> Exec: "+" ".join(rotina)) processes.add(subprocess.Popen(rotina)) count += 1 while count >= max_processes: count = 0 time.sleep(0.1) for p in processes: if p.poll() is None: count += 1 else: n_skiped += 1 else: # caso saida gráfica # Testa se arquivos existem, senão pula if os.path.exists(out_dir+"{0}.hack".format(nome[0])): rotina = ['java', '-jar', 'TestesSW/Elemulator/Elemulator.jar', out_dir+"{0}.hack".format(nome[0]), "-p",out_dir+"{0}.pbm".format(nome[0]), "-o",out_dir+"{0}_out.mif".format(nome[0]), "-c",nome[2],"-r",resolution[0],resolution[1]] if in_dir: rotina.append("-i") rotina.append(in_dir+"{0}_in.mif".format(nome[0])) if bits==32: rotina.append("-b") rotina.append("32") print("\nEmulating: "+nome[0]+" >> Exec: "+" ".join(rotina)) processes.add(subprocess.Popen(rotina)) count += 1 while count >= max_processes: count = 0 time.sleep(0.1) for p in processes: if p.poll() is None: count += 1 else: n_skiped += 1 #Check if all the child processes were closed for p in processes: p.wait() if(p.returncode==0): n_done+=1 else: n_error+=1 # exibe as imagens no terminal for i in nomes_testes: nome = i.split() if int(nome[1]) < 0: subprocess.call(['echo',"\n{0}.pbm".format(nome[0],i)]) subprocess.call(['img2txt',out_dir+"{0}.pbm".format(nome[0],i)]) elapsed_time = time.time() - start_time print('\033[92m'+"Emulated {0} process(es) in {1:.2f} seconds".format(n_done,elapsed_time)+'\033[0m') if(n_skiped!=0): print('\033[93m'+"Skipped {0} file(s)".format(n_skiped)+'\033[0m') if(n_error!=0): print('\033[91m'+"Failed {0} process(es)".format(n_error)+'\033[0m') exit(n_error)
############################## # # # Baseado no testAssembly # # tentar unificar no futuro # # # ############################## import sys, getopt import unittest import pytest import loadTestes import detectImage import checkUnitTests nomes_testes = loadTestes.testes("TestesSW/testesJack.txt") @pytest.mark.parametrize(('nomes_testes'), nomes_testes) def test_Assembly(nomes_testes): dir_dados = "TestesSW/jack_code/" nomes_testes = nomes_testes.split() #resultado = dir_dados+"{0}_out.mif".format(nomes_testes[0]) teste = "TestesSW/testesJack/{0}_tst.txt".format(nomes_testes[0]) imagem = dir_dados + "{0}.pbm".format(nomes_testes[0]) #debug = False linha = []
def compiler(testes, in_dir, out_dir, processos): start_time = time.time() rotina_mkdir = ["mkdir"] if platform.system() == "Windows": jar = '"%CLASSPATH%;TestesSW\Compiler;TestesSW\Compiler\Hack.jar;TestesSW\Compiler\Compilers.jar"' testes = testes.replace('/', '\\') in_dir = in_dir.replace('/', '\\') out_dir = out_dir.replace('/', '\\') else: rotina_mkdir.append( "-p") # para criar os subdiretórios no mkdir no UNIX jar = '${CLASSPATH}:TestesSW/Compiler:TestesSW/Compiler/Hack.jar:TestesSW/Compiler/Compilers.jar' rotina_mkdir.append(out_dir) subprocess.call(rotina_mkdir, shell=True) # cria subdiretório para resultados nomes_testes = loadTestes.testes(testes) error_code = 0 done = 0 for i in nomes_testes: nome = i.split() rotina = [ 'java', '-classpath', jar, 'Hack.Compiler.JackCompiler', in_dir + "{0}".format(nome[0]) ] error = subprocess.call(rotina, shell=True) if (error != 0): error_code += error else: done += 1 if platform.system() == "Windows": subprocess.call(["mkdir", out_dir + nome[0]], shell=True) subprocess.call( ["move", "/Y", in_dir + nome[0] + "\\*.vm", out_dir + nome[0]], shell=True) subprocess.call( ["copy", "/Y", "TestesSW\\OS\\*.vm", out_dir + nome[0]], shell=True) else: subprocess.call(["mkdir", "-p", out_dir + nome[0]]) subprocess.call([ "mv {0} {1}".format(in_dir + nome[0] + "/*.vm", out_dir + nome[0]) ], shell=True) subprocess.call( ["cp {0} {1}".format("TestesSW/OS/*.vm", out_dir + nome[0])], shell=True) elapsed_time = time.time() - start_time print( '\033[92m' + "Compiled {0} file(s) in {1:.2f} seconds".format(done, elapsed_time) + '\033[0m') if (error_code != 0): print('\033[91m' + "Failed {0} file(s)".format(len(nomes_testes) - done) + '\033[0m') exit(error_code)
############################## # # # Baseado no testAssembly # # tentar unificar no futuro # # # ############################## import sys, getopt import unittest import pytest import loadTestes import detectImage import checkUnitTests nomes_testes = loadTestes.testes( "C:\\Users\\1513 IRON\\Desktop\\Insper\\3_semestre\\Elementos de Sistema\\Z0\\TestesSW\\testesJack.txt" ) @pytest.mark.parametrize(('nomes_testes'), nomes_testes) def test_Assembly(nomes_testes): dir_dados = "TestesSW/jack_code/" nomes_testes = nomes_testes.split() #resultado = dir_dados+"{0}_out.mif".format(nomes_testes[0]) teste = "C:\\Users\\1513 IRON\\Desktop\\Insper\\3_semestre\\Elementos de Sistema\\Z0\\TestesSW\\testesJack\\{0}_tst.txt".format( nomes_testes[0]) imagem = dir_dados + "{0}.pbm".format(nomes_testes[0]) #debug = False
def vmtranslator(jar, testes, in_dir, out_dir, processos): start_time = time.time() rotina_mkdir = ["mkdir"] if platform.system() == "Windows": jar = jar.replace('/', '\\') testes = testes.replace('/', '\\') in_dir = in_dir.replace('/', '\\') out_dir = out_dir.replace('/', '\\') else: rotina_mkdir.append( "-p") # para criar os subdiretórios no mkdir no UNIX rotina_mkdir.append(out_dir) subprocess.call(rotina_mkdir, shell=True) # cria subdiretório para resultados nomes_testes = loadTestes.testes(testes) error_code = 0 done = 0 for i in nomes_testes: nome = i.split() no_bootstrap = False directory = False for f in range(3, len(nome)): if (nome[f] == "/"): directory = True if (nome[f] == "n"): no_bootstrap = True if directory: entrada = in_dir + "{0}".format(nome[0]) else: entrada = in_dir + "{0}.vm".format(nome[0]) saida = out_dir + "{0}.nasm".format(nome[0]) #rotina = ['java', '-jar', 'Codigos/VMTranslator/target/VMTranslator-1.0.jar', rotina = ['java', '-jar', jar, entrada, "-o", saida] # remove rotina de bootstrap do vmtranslator if no_bootstrap: rotina.append("-n") error = subprocess.call(rotina) if (error != 0): error_code += error else: done += 1 elapsed_time = time.time() - start_time print('\033[92m' + "VM Translated {0} file(s) in {1:.2f} seconds".format( done, elapsed_time) + '\033[0m') if (error_code != 0): print('\033[91m' + "Failed {0} file(s)".format(len(nomes_testes) - done) + '\033[0m') exit(error_code)