Example #1
0
def gene(caso,nume,accion,loops,filename): 
    	cadena = ap1.read_config_case("../config.ini","case_"+caso)['actions']
	predicado=''
	if (not cadena==''):
	   dic={}
	   cade=cadena.split(':') 
	   for e in cade:
		    elem=e.split(',')
		    dic[elem[0]]=elem[1] 	
                    if not dic.get(accion)==None:
         		 predicado= ap1.load_pred_aux("../examples/"+caso+"/models/aux_pred_2.als")
			 print predicado
			    #predicado=predicado.split("\n")[0]
			    #os.system(" sed -i 's/\/\*INI_PRE.*FIN_PRE\*\//\/\*INI_PRE\*\/"+predicado+"\/\*FIN_PRE\*\//g ' "+filename)
   			    #sys.exit(0)
        return 0
Example #2
0
def gen_input_fact_i32_jt(caso,i,lista,accion,loops,pin,result): #lee el elemento i de la lista i lo reemplaza en resultado.als 
	out=[]
        
	#aca
	if (i<len(lista)):
		cade=lista[i]
		
		data=cade.split('?')
		pares={}
		for e in data:
		   s=e.split(':')
		   pares[s[0]]=s[1]			
		param=''
		t=int(pares['size'])+loops+1
		n=int(pares['cantidad_enteros'])+loops+1				
		#scope_int=minBitwidthToRepresent(t)
		#check='check programa_wap for '+str(t)+" but "+str(n)+" JavaPrimitiveIntegerValue, "+str(scope_int)+" int" 
                check='check programa_wap for 0 but '+str(n)+" JavaPrimitiveIntegerValue " 
		parametros_de_accion_rota=pin
		res=[]
		cade=''
		p=0
		f=0
		for e in pin:
		     if (e[1]=='JavaPrimitiveIntegerValue' and p==0):	
				res.append( "QF."+e[0]+"_0="+pares['pi32_a'])
				#cade=cade+" "+e[0]+"="+ap1.bin_to_int(pares['pi32_a'])
				p=1
		     else:	
			     if(e[1]=='JavaPrimitiveIntegerValue' and p==1):	
					res.append( "QF."+e[0]+"_0="+pares['pi32_b'])
				#	cade=cade+" "+e[0]+"="+ap1.bin_to_int(pares['pi32_b'])

		     if (e[1]=='Int'and f==0):	
				res.append("eq[QF."+e[0]+"_0,"+pares['indice_a']+"]")
				cade=cade+" "+e[0]+"="+pares['indice_a']
				f=1
		     else:
	  	     	     if (e[1]=='Int'and f==1):	
				res.append("QF."+e[0]+"_0="+pares['indice_b'])
				cade=cade+" "+e[0]+"="+pares['indice_b']



		out.append(pares[' lista'])
		print pares[' lista']
		print 'action to fix: '+accion+"("+cade+")"		 
		out.append('action to fix: '+accion+"("+cade+")")

		parametros_de_acciones="fact { "+(" and ").join(res)+"} "


    	        cadena = ap1.read_config_case("../config.ini","case_"+caso)['actions']
		predicado=''

		if (not cadena==''):
			dic={}
		        cade=cadena.split(':') 
			for e in cade:
			    
			    elem=e.split(',')
			    dic[elem[0]]=elem[1] 	

		
			    # obtiene el scope de la accion almacenada para saber que archivo de aux_pred invocar. tenganse en cuenta que 
			    # por ejemplo para el predicado que indica el size depende de la entrada y de la accion



			if not dic.get(accion)==None:
				predicado= ap1.load_pred_aux("../examples/"+caso+"/models/aux_pred_"+str(int(dic.get(accion))+ int(pares['size']))+".als")

		
				predicado=predicado.split("\n")[0]



		pegar=pares['estado']+" "+parametros_de_acciones+" "+check+" "+predicado

		os.system(" sed -i 's/\/\*INI_PRE.*FIN_PRE\*\//\/\*INI_PRE\*\/"+pegar+"\/\*FIN_PRE\*\//g ' resultado.als")

		result[i]=out
	return [pares['size'],result]
Example #3
0
import os, sys, glob, new2_generate_alt1, generate_alt2, ap1
from sets import Set

if len(sys.argv) == 3:
    print 'Error: missing parameters.'
    print 'Use: python generate.py <case_study> <action_fix> <method>. Method is 1 or 2.'
else:

    casos_de_studio = os.listdir('../examples')
    tiempo_to = ap1.read_config_case("../config.ini", "options")['timeout']
    input_file = ap1.read_config_case("../config.ini", "options")['input_file']

    if sys.argv[3] == '1':

        if not (sys.argv[1] in casos_de_studio):
            print "Error: '" + sys.argv[1] + "' isn't a valid case study. "
        else:
            lista_ac = glob.glob('../examples/' + sys.argv[1] +
                                 '/actions/*_act')
            cade = "cat ../examples/" + sys.argv[
                1] + "/actions/preludio " + " ".join(
                    lista_ac) + " > temporalnew.dals"
            os.system(cade)
            print 'salio'
            sys.exit(0)

            if not "../examples/" + sys.argv[1] + "/actions/" + sys.argv[
                    2] + "_act" in lista_ac:
                print 'Error : not found action ' + sys.argv[2]
            else:
Example #4
0
def fix_a2(caso, accion, sc, pin, accion_name, cadeQF, tiempo_to, input_file):
    cant_estados = 0
    cant_wa = 0
    ttotal = 0
    ttotal_sin_to = 0
    tpromedio = 0
    suma_tam_lista = 0
    to = 0
    i = 0

    entradas = traer_pres_desde_archivo('../examples/' + caso + '/' +
                                        input_file)
    modelo_alloy_accion = accion
    emin = 10000
    emax = -1
    temin = 0
    temax = 0
    for entrada in entradas:
        print 'control<' + str(i) + '>'
        nd = input(entrada)
        suma_tam_lista = suma_tam_lista + int(nd['size'])
        sn = str(int(nd['size']) + int(sc))
        p = 0
        f = 0
        res = []
        cade = ''
        parametros_de_acciones = ''

        if len(pin) > 0:
            for e in pin:
                if (e == 'JavaPrimitiveIntegerValue' and p == 0
                        and cadeQF.find('intJ_1_0') > 0):
                    res.append("QF.intJ_1_0=" + nd['pi32_a'])
                    p = 1
                else:
                    if (e == 'JavaPrimitiveIntegerValue' and p == 1
                            and cadeQF.find('intJ_2_0') > 0):
                        res.append("QF.intJ_2_0=" + nd['pi32_a'])

                if (e[1] == 'Int' and f == 0 and cadeQF.find('intA_1_0') > 0):
                    res.append("equ[QF.intA_1_0," + nd['indice_a'] + "]")
                    cade = cade + " " + e + "=" + nd['indice_a']
                    f = 1
                else:
                    if (e == 'Int' and f == 1 and cadeQF.find('intA_2_0') > 0):
                        res.append("equ[QF.intA_2_0," + nd['indice_b'] + "]")
                        cade = cade + " " + e + "=" + nd['indice_b']
            parametros_de_acciones = " fact { " + (" and ").join(res) + "} "

            fact_in = nd['estado'] + parametros_de_acciones

        else:
            fact_in = nd['estado']

        linea = 'Control<' + str(i) + '>'
        rr = "echo '" + linea + "' >> ../examples/" + caso + "/results/alt2/alt2_output"
        os.system(rr)

        print 'size: ' + nd['size']
        linea = 'size: ' + nd['size']
        rr = "echo '" + linea + "' >> ../examples/" + caso + "/results/alt2/alt2_output"
        os.system(rr)

        print 'input : ' + nd['lista']
        linea = nd['lista']
        rr = "echo '" + linea + "' >> ../examples/" + caso + "/results/alt2/alt2_output"
        os.system(rr)

        print 'action to fix: ' + accion_name + "(" + cade + ")"
        linea = 'action to fix: ' + accion_name + "(" + cade + ")"
        rr = "echo '" + linea + "' >> ../examples/" + caso + "/results/alt2/alt2_output"
        os.system(rr)

        # lee el prefijo del archivo de configuracion config.ini
        cadena = ap1.read_config_case("../config.ini",
                                      "case_" + caso)['prefix']

        #ajusta la cantidad de enteros java a exactamente lo que necesita
        # para ello reemplaza la clausula exactly del modelo als por la que viene del estado inicial de randoop

        #aca si size con cantidad_enteros es diferente habria que agregar los v10 , v11
        #print '-----------------------'
        #print nd['size']
        #print nd['cantidad_enteros']
        #print '-----------------------'

        os.system(
            "sed -i 's/exactly[[:space:]][0-9]*[[:space:]]*JavaPrimitiveIntegerValue/exactly "
            + str(nd['cantidad_enteros']) + "  JavaPrimitiveIntegerValue/g' " +
            " ../examples/" + caso + "/models/" + cadena + str(sn) + ".als")

        gen_resultado_als('../examples/' + caso + '/models/' + cadena, caso,
                          sn, modelo_alloy_accion, fact_in, cadeQF)

        tiempo_inicio_wa = time.time()
        ######################### call alloy analyzer   ###############################

        ap1.run_modelo_alloy_pewa('resultado.als', i, 0, accion_name, caso, 2,
                                  tiempo_to)

        ###############################################################################
        t2 = time.time() - tiempo_inicio_wa

        ttotal = ttotal + t2

        tiempo_o = ap1.read_config_case("../config.ini", "options")['timeout']

        cant_estados = cant_estados + 1

        #

        if ap1.UNSAT('temp') == 2 and (ap1.time_time(tiempo_o) <= t2):
            to = to + 1
            print 'timeout.'
            rr = "echo 'timeout'  >> ../examples/" + caso + "/results/alt2/alt2_output"
            os.system(rr)
            linea = "-------------------------------------------------------"
            rr = "echo '" + linea + "' >> ../examples/" + caso + "/results/alt1/alt1_output"
            os.system(rr)

        if ap1.UNSAT('temp') == 1:
            print 'Workaround not found.'
            linea = 'Workaround not found. '
            rr = "echo '" + linea + "' >> ../examples/" + caso + "/results/alt2/alt2_output"
            os.system(rr)

        if ap1.UNSAT('temp') == 0:
            ap1.expor(
                '../examples/' + caso + '/results/alt2/wa_' + caso + '_' +
                accion_name + '_', i)
            os.system('cp resultado.als ../examples/' + caso +
                      '/results/alt2/wa_' + caso + '_' + accion_name + '_' +
                      str(i) + '.als')
            if emin >= int(nd['size']):
                if (emin == int(nd['size'])
                        and temin < t2) or (emin > int(nd['size'])):
                    temin = t2
                emin = int(nd['size'])
            if emax <= int(nd['size']):
                if (emax == int(nd['size'])
                        and temax < t2) or (emax < int(nd['size'])):
                    temax = t2
                emax = int(nd['size'])

            print 'first wac found in: ' + nume(
                str(t2)
            ) + ' seconds.\n-----------------------------------------------\n'
            linea = 'first wac found in: ' + nume(
                str(t2)
            ) + ' seconds.\n-----------------------------------------------\n'
            rr = "echo '" + linea + "' >> ../examples/" + caso + "/results/alt2/alt2_output"
            os.system(rr)
            ttotal_sin_to = ttotal_sin_to + t2
            cant_wa = cant_wa + 1

        os.system('rm temp')
        i = i + 1

    print '---------------------------------------------------'
    resultado = 'Action ' + accion_name
    resultado = resultado + ' | Number of inputs processed: ' + str(
        cant_estados)
    print resultado
    resultadof = resultado + '|'

    if (cant_estados > 0):
        resultadof = resultadof + "Avg. input size: " + nume(
            str(float(suma_tam_lista) / float(cant_estados)))
        print "Avg. input size: " + nume(
            str(float(suma_tam_lista) / float(cant_estados)))
        resultadof = resultadof + '|'

    resultadof = resultadof + 'Number of workarrounds found: ' + str(cant_wa)
    print 'Number of workarrounds found: ' + str(cant_wa)
    resultadof = resultadof + '|'
    resultadof = resultadof + 'Number of failures (exceeding a ' + tiempo_to + ' timeout): ' + str(
        to)
    print 'Number of failures (exceeding a ' + tiempo_to + ' timeout): ' + str(
        to)
    resultadof = resultadof + '|'
    if (cant_wa > 0):
        prome = ttotal_sin_to / float(cant_wa)
        resultadof = resultadof + 'Avg. time to find a workaround (not including failures): ' + nume(
            str(prome)) + ' seconds.'
        print 'Avg. time to find a workaround (not including failures): ' + nume(
            str(prome)) + ' seconds.'
        resultadof = resultadof + '|'
    if (cant_wa > 0):
        prome = ttotal / float(cant_wa)
        resultadof = resultadof + 'Avg. time to find a workaround: ' + nume(
            str(prome)) + ' seconds.'
        print 'Avg. time to find a workaround: ' + nume(
            str(prome)) + ' seconds.'
        resultadof = resultadof + '|'
    resultadof = resultadof + 'Total running time: ' + nume(str(
        float(ttotal))) + ' seconds.'
    print 'Total running time: ' + nume(str(float(ttotal))) + ' seconds.'
    resultadof = resultadof + '|'

    if not emin == 10000:
        resultadof = resultadof + 'Smallest input size: ' + str(
            emin) + ' elements.'
        print 'Smallest input size: ' + str(emin) + ' elements.'
        resultadof = resultadof + '|'
        resultadof = resultadof + 'Maximum time to find a workaround for the smallest input: ' + nume(
            str(temin))
        print 'Maximum time to find a workaround for the smallest input: ' + nume(
            str(temin))

        resultadof = resultadof + '|'
        resultadof = resultadof + 'Largest input size: ' + str(
            emax) + ' elements.'

    if not emax == -1:
        print 'Largest input size: ' + str(emax) + ' elements.'
        resultadof = resultadof + '|'
        resultadof = resultadof + 'Maximum time to find a workaround for the largest input: ' + nume(
            str(temax))
        print 'Maximum time to find a workaround for the largest input: ' + nume(
            str(temax))
        resultadof = resultadof + '|'
    print '---------------------------------------------------'
    rr = 'echo "' + resultadof + '" >> ../examples/' + sys.argv[
        1] + '/results/alt2/alt2_output'
    os.system(rr)
    return