test.py 5.68 KB
Newer Older
German Leon's avatar
German Leon committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#! /usr/bin/python

import sys, os, subprocess, random, time, datetime
import pexpect, re
import os.path
from os import path
import fnmatch
import serial
import config
from config import *

def configurate_serie():
	#os.system("sudo stop ttyS0")
	Puerto=0
	try:
	   serie = serial.Serial(Puerto, 115200)
	   serie.timeout=1;
   
	except serial.SerialException:
	   #-- Error al abrir el puerto serie
	   sys.stderr.write("Error al abrir puerto (%s)\n" % str(Puerto))
	return serie

#mantener vivos los watdog softwre y hardware
def KeepWatchdog():
   os.system("/home/ubuntu/bin/refresh_watchdog > watchsoft.test")
   os.system("touch watchsoft.test")

def writeOutput(serie, output, elapsedTime, outputFileName, fileName):
#      if verbose:
#        print("\n***Elapsed time: %s ms. ***\n" % (elapsedTime))
      serie.write("\n***Elapsed time: %s ms. ***\n" % (elapsedTime))

      if verbose:
        print("%s " % (output) )
      serie.write("%s " % (output) )

      output += "\n\n***Elapsed time: " + `elapsedTime` + " ms. ***\n\n"
      outputFile = open(outputFileName, "w")
      outputFile.write(output)
      outputFile.flush()
      outputFile.close()
#      os.system("tar -rvf results/" + fileName + ".tar " + outputFileName)
#      os.system("rm " + outputFileName)

def runBenchmark(fiIni, fileName, tIni):
  
  serie=configurate_serie()
  
  numTimeouts = 0

  if (totalFiNumber == -1): # bucle infinito
      forever = True
  else:
      forever = False

  stdLogFile = open("results/"+fileName+"_"+tIni+".log", "w")

  fiNumber = fiIni - 1
  while forever or ( (fiNumber+1) < totalFiNumber+1):

    fiNumber = fiNumber + 1

    KeepWatchdog()

    try:

      x = datetime.datetime.now()
      outputFileName =  "results/"+fileName + x.strftime("_%H%M%S.err")
      ti = x.strftime("%m/%d/%Y %H:%M:%S")

      # Measure execution time
      startTime = time.time()

#      os.system("sudo /home/ubuntu/bin/gpufreq-info")
#      os.system("cpufreq-info | grep 'current CPU' | cut -d's' -f2 | cut -d'(' -f1")

#      os.system("/home/ubuntu/bin/gpufreq-info >> /home/ubuntu/rodinia/lud/rad/results/res.out")
      p = pexpect.spawn("./"+exeFile+" "+inputParameters, timeout=timeout)

      p.expect(pexpect.EOF)

      # Process elspased time
      elapsedTime = 1000*(time.time() - startTime)

      p.close()

      if (p.exitstatus == 0):
        if verbose:
          print("(%d) %s; PASS in %.2f ms. " % (fiNumber, ti, elapsedTime) )
          print(p.before)
        sys.stdout.flush()
        stdLogFile.write("(%d) %s; PASS in %.2f ms.\n" % (fiNumber, ti, elapsedTime) )
        stdLogFile.write("%s" % (p.before) )
        stdLogFile.flush()
        serie.write("(%d) %s; PASS in %.2f ms.\n\r" % (fiNumber, ti, elapsedTime) )
        serie.write("%s" % (p.before) )
      elif (p.exitstatus == 1): 
        if verbose:
          print("(%d) %s; FAIL in %.2f ms." % (fiNumber, ti, elapsedTime) )
        sys.stdout.flush()
        stdLogFile.write("(%d) %s; FAIL in %.2f ms.; %s\n" % (fiNumber, ti, elapsedTime, outputFileName) )
        stdLogFile.write("%s" % (p.before) )
        stdLogFile.flush()
        serie.write("(%d) %s; FAIL in %.2f ms.; %s\n\r" % (fiNumber, ti, elapsedTime, outputFileName) )
        writeOutput(serie, p.before, elapsedTime, outputFileName, fileName+"_"+tIni)
      else:
        if verbose:
          print("(%d) %s; Exit status: %d in %.2f ms." % (fiNumber, ti, p.exitstatus, elapsedTime) )
        sys.stdout.flush()
        stdLogFile.write("(%d) %s; Exit status: %d in %.2f ms.\n" % (fiNumber, ti, p.exitstatus, elapsedTime) )
        stdLogFile.write("%s" % (p.before) )
        stdLogFile.flush()
        serie.write("(%d) %s; Exit status: %d in %.2f ms.\n\r" % (fiNumber, ti, p.exitstatus, elapsedTime) )
        writeOutput(serie, p.before, elapsedTime, outputFileName, fileName+"_"+tIni)

      stdLogFile.flush() 

      numTimeouts = 0

    except KeyboardInterrupt:
      print("KeyboardInterrupt")
      sys.stdout.flush()
      lastFile = open("lastFiNumber", "w")
      lastFile.write("%d" % fiNumber)
      lastFile.flush()
      lastFile.close()
      stdLogFile.close()
      stdLogFile.flush()
      sys.exit(2)

    except pexpect.EOF, e:
      print("Fin de archivo")

    except pexpect.TIMEOUT, e:

      terminated = p.terminate(force=True)
      elapsedTime = time.time() - startTime

      if verbose:
        print("(%d) %s; Timeout after %.2f s." % (fiNumber, ti, elapsedTime) )
      sys.stdout.flush()
      stdLogFile.write("(%d) %s; Timeout after %.2f s.\n" % (fiNumber, ti, elapsedTime) )
      stdLogFile.write("%s" % (p.before) )
      stdLogFile.flush() 
      serie.write("(%d) %s; Timeout after %.2f s.\n\r" % (fiNumber, ti, elapsedTime) )

      sys.stdout.flush()
#      stdLogFile.close()

      numTimeouts += 1
      # Si se dan 3 timeouts seguidos, suponemoe que no se recuperara y rearrancamos la Jetson

      lastFile = open("lastFiNumber", "w")

      if (numTimeouts == 3): 
        fiNumber = fiNumber - 2 # contamos los tres ultimos timeouts consecutivos como un solo error no recuperable
        lastFile.write("%d" % fiNumber)
        lastFile.flush() 
        lastFile.close()
        time.sleep(2)
        sys.exit(3)
      else:
        lastFile.write("%d" % fiNumber)
        lastFile.flush() 
        lastFile.close()

    finally:

      lastFile = open("lastFiNumber", "w")
      lastFile.write("%d" % fiNumber)
      lastFile.flush() 
      lastFile.close()

      time.sleep(1)

  # end while
  stdLogFile.close()

#end runBenchmark

def main(argv):
  fileName = sys.argv[1]
  fiIni = int( sys.argv[2] )
  tIni = sys.argv[3]

  runBenchmark(fiIni, fileName, tIni)


##############################################################################
#main()
if __name__ == "__main__":
  main(sys.argv)