Esempio n. 1
0
    def test_all(self):

        Res = True

        Message = ""
        tc = self.testcases.keys()
        tc.sort()

        t = time.time()

        prologtime = 0
        for test in tc:
            t1 = time.time()
            Ans = self.test_file(self.testcases[test], showtime=False)

            Res &= (Ans != False)

            if Res:
                timetaken = time.time() - t1
                (time1, iter1) = Ans
                prologtime += int(time1)
                #Message += "\n%20s completed in %.2f seconds (%dms, %d iterations)" % (test,timetaken,int(time1),int(iter1))
                Message += "\n%20s ok: %dms, %d iterations" % (
                    test, int(time1), int(iter1))

        if Res:
            timetaken = time.time() - t
            Message = "All BTA OK %.2f seconds (PrologTime: %dms)" % (
                timetaken, int(prologtime)) + Message
            ErrDialog.complain_loudly(master=self.app,
                                      msg=Message,
                                      title="Bta Tests")

        print Res
Esempio n. 2
0
    def test_file(self, filename, showtime=True):
        print "Running Bta test for %s" % (filename)

        #remove any existing annfile
        annfile = filename + ".ann"
        if (os.path.exists(annfile)):
            os.remove(annfile)

        #run autobta
        (time, iter) = self.run_bta(filename)

        #test if output is correct!
        diffannfile = os.path.dirname(
            annfile) + "/expected/" + os.path.basename(annfile)
        cmd = "diff %s %s" % (annfile, diffannfile)

        if os.system(cmd) == 0:
            print "OK", showtime
            if showtime:
                Message = "TestCase ok: %dms, %d iterations" % (int(time),
                                                                int(iter))
                ErrDialog.complain_loudly(master=self.app,
                                          msg=Message,
                                          title="Bta Tests")
            return (time, iter)
        else:
            print "Failed"
            ErrDialog.complain_loudly(master=self.app,
                                      msg="BTA Test failed for %s" % filename,
                                      title="Bta Tests-Error")
            return False
Esempio n. 3
0
    def test_all(self):
        
        Res = True

        Message = ""
        tc = self.testcases.keys()
        tc.sort()

        t = time.time()

        prologtime = 0
        for test in tc: 
            t1 = time.time()
            Ans = self.test_file(self.testcases[test],showtime=False)
            
            Res &= (Ans != False)
            
            if Res:
                timetaken = time.time() - t1
                (time1,iter1) = Ans
                prologtime += int(time1)
                #Message += "\n%20s completed in %.2f seconds (%dms, %d iterations)" % (test,timetaken,int(time1),int(iter1))
                Message += "\n%20s ok: %dms, %d iterations" % (test,int(time1),int(iter1))
                
                

        if Res:
            timetaken = time.time() - t
            Message = "All BTA OK %.2f seconds (PrologTime: %dms)" % (timetaken,int(prologtime)) + Message
            ErrDialog.complain_loudly(master=self.app,
                                      msg=Message,
                                      title="Bta Tests")

        
        print Res
Esempio n. 4
0
    def test_file(self, filename,showtime=True):
        print "Running Bta test for %s" % (filename)

        #remove any existing annfile
        annfile = filename + ".ann"
        if (os.path.exists(annfile)):
            os.remove(annfile)

        
        #run autobta
        (time,iter) = self.run_bta(filename)

       
        #test if output is correct!
        diffannfile = os.path.dirname(annfile) + "/expected/" + os.path.basename(annfile)
        cmd =  "diff %s %s" % (annfile, diffannfile)

        if os.system(cmd) == 0:
            print "OK",showtime
            if showtime:
                Message = "TestCase ok: %dms, %d iterations" % (int(time),int(iter))
                ErrDialog.complain_loudly(master=self.app,
                                      msg=Message,
                                      title="Bta Tests")
            return (time,iter)
        else:
            print "Failed"
            ErrDialog.complain_loudly(master=self.app,
                                      msg="BTA Test failed for %s" % filename,
                                      title="Bta Tests-Error")
            return False
Esempio n. 5
0
    def run_one(self, Ann, goal):

        ### check this is not in the cache, if it is the just use that value
        cache = self.output.check_cache(Ann)
        if cache is not None:
            (Ann, (benchtime, code, _score)) = cache
            return (benchtime, code, Ann)

        self.app.ann_frame.annotate_from_str(Ann.ann,
                                             self.filename,
                                             Ann.filter,
                                             tcl_index=True)
        self.app.save_ann()
        #
        if self.bta:
            self.app.auto_bta()
        else:
            self.app.filter_prop()
        self.app.save_ann()

        ## annotations may have changed since we requested them due to filter + bta
        ## so we sould return the correct ones, not the ones we used
        Ann = Annotation(self.app.ann_frame.ann_to_string(),
                         self.app.ann_frame.filter_to_string(), True, self.app)

        ###  Check this is not in the cache either (we may have changed as a result of BTA)
        cache = self.output.check_cache(Ann)
        if cache is not None:
            (Ann, (benchtime, code, _score)) = cache
            return (benchtime, code, Ann)

        #print "specialise with timeout"
        #print "  NEED TO ADD TIMEOUT!"
        try:
            #pr  t "RUN_ONE:SPECIALISE", goal
            t1 = time.time()
            self.app.specialise(goal=goal,
                                timeout=self.timeout,
                                catch_exception=False,
                                clean=True)  ##could give goal here....

            ### DO NOT ADD BACK IN UNTIL YOU FIX ENTRY POINT! (it makes benchmarking fail otherwise)
            #if self.pp:
            #    self.app.run_pp()
            timetaken = (time.time() - t1) * 1000
            print "Timeout value:", timetaken

        except Prolog.PrologException, e:
            print e
            ErrDialog.complain_loudly(master=None, title="Error", msg=e)
            return (None, None, Ann)
Esempio n. 6
0
 def parse_check(self):
     self.text.tag_remove("errorTag", "1.0", "end")        
     try:
         self.app.logen.parse_file(self.filename)
         
     except PrologException, (Type,Msg):
         lineno = re.compile('.*lines::([0-9]+)-([0-9]+)\n.*')
         m = lineno.search(Msg)
         if m is not None:
             line = m.group(1)
             lineend = m.group(2)
             self.text.tag_add("errorTag", "%s.0"%line,"%s.0 lineend"%lineend)
         ErrDialog.complain_loudly(master=self,title="Parse Error:::",msg=Msg+"\nPlease fix errors before entering annotation mode")
         return False
Esempio n. 7
0
    def run_one(self,Ann,goal):

        ### check this is not in the cache, if it is the just use that value
        cache = self.output.check_cache(Ann)        
        if cache is not None:
            (Ann, (benchtime,code,_score)) = cache
            return (benchtime, code,Ann)

        
        
        
        self.app.ann_frame.annotate_from_str(Ann.ann,self.filename,Ann.filter,tcl_index=True)
        self.app.save_ann()
        #
        if self.bta:
            self.app.auto_bta()
        else:
            self.app.filter_prop()
        self.app.save_ann()

        ## annotations may have changed since we requested them due to filter + bta
        ## so we sould return the correct ones, not the ones we used
        Ann = Annotation(self.app.ann_frame.ann_to_string(),self.app.ann_frame.filter_to_string(),True,self.app)

        ###  Check this is not in the cache either (we may have changed as a result of BTA)
        cache = self.output.check_cache(Ann)        
        if cache is not None:
            (Ann, (benchtime,code,_score)) = cache
            return (benchtime, code,Ann)
        
        #print "specialise with timeout"
        #print "  NEED TO ADD TIMEOUT!"
        try:
            #pr  t "RUN_ONE:SPECIALISE", goal
            t1 = time.time()
            self.app.specialise(goal=goal,timeout=self.timeout,catch_exception=False,clean=True) ##could give goal here....

            ### DO NOT ADD BACK IN UNTIL YOU FIX ENTRY POINT! (it makes benchmarking fail otherwise)
            #if self.pp:
            #    self.app.run_pp()
            timetaken = (time.time() - t1) * 1000
            print "Timeout value:",timetaken
            
            
        except Prolog.PrologException,e:
            print e
            ErrDialog.complain_loudly(master=None, title="Error", msg=e)              
            return (None,None,Ann)
Esempio n. 8
0
    def calc_score(self, Time,Size,alpha=None,beta=None):
        #try:
        if alpha is None:
            alpha = self.alpha
        if beta is None:
            alpha = self.beta           

        #print "Norm Time:", self.normalise_time
        #print "Time:", Time

        try:
            if float(Time) == 0:
                ErrDialog.complain_loudly(master=None, title="Error", msg="Benchmark time 0ms unable to calculate a fair score")              
            norm_Time = 1/(float(Time)/float(self.normalise_time))
            norm_Size = 1/(float(Size)/float(self.normalise_code))
            score = pow(norm_Time,alpha) * pow(norm_Size, beta)            
            score = max(0,score)
        except Exception,e:
            print e
            score = -1