blob: 5c1a2370ced89d54a4c7970ec56c03e629e15779 [file] [log] [blame]
Chris Lattner30fdc8d2010-06-08 16:52:24 +00001#!/usr/bin/env python
2# -*- coding: utf8 -*-
3
Zachary Turner35d017f2015-10-23 17:04:29 +00004from __future__ import print_function
5
Chris Lattner30fdc8d2010-06-08 16:52:24 +00006import math, os.path, re, sys, time, unittest
7
8def setupSysPath():
9 testPath = sys.path[0]
Johnny Chena02199f2010-06-22 00:11:26 +000010 rem = re.match("(^.*/)test$", testPath)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000011 if not rem:
Zachary Turner35d017f2015-10-23 17:04:29 +000012 print("This script expects to reside in .../test.")
Chris Lattner30fdc8d2010-06-08 16:52:24 +000013 sys.exit(-1)
14 lldbBasePath = rem.group(1)
15 lldbDebugPythonPath = "build/Debug/LLDB.framework/Resources/Python"
16 lldbReleasePythonPath = "build/Release/LLDB.framework/Resources/Python"
17 lldbPythonPath = None
18 if os.path.isfile(lldbDebugPythonPath + "/lldb.py"):
19 lldbPythonPath = lldbDebugPythonPath
20 if os.path.isfile(lldbReleasePythonPath + "/lldb.py"):
21 lldbPythonPath = lldbReleasePythonPath
22 if not lldbPythonPath:
Zachary Turner35d017f2015-10-23 17:04:29 +000023 print("This script requires lldb.py to be in either " + lldbDebugPythonPath, end='')
24 print("or" + lldbReleasePythonPath)
Chris Lattner30fdc8d2010-06-08 16:52:24 +000025 sys.exit(-1)
26 sys.path.append(lldbPythonPath)
27
28def prettyTime(t):
29 if t == 0.0:
30 return "0s"
31 if t < 0.000001:
32 return ("%.3f" % (t * 1000000000.0)) + "ns"
33 if t < 0.001:
34 return ("%.3f" % (t * 1000000.0)) + "µs"
35 if t < 1:
36 return ("%.3f" % (t * 1000.0)) + "ms"
37 return str(t) + "s"
38
39class ExecutionTimes:
40 @classmethod
41 def executionTimes(cls):
42 if cls.m_executionTimes == None:
43 cls.m_executionTimes = ExecutionTimes()
44 for i in range(100):
45 cls.m_executionTimes.start()
46 cls.m_executionTimes.end("null")
47 return cls.m_executionTimes
48 def __init__(self):
49 self.m_times = dict()
50 def start(self):
51 self.m_start = time.time()
52 def end(self, component):
53 e = time.time()
54 if component not in self.m_times:
55 self.m_times[component] = list()
56 self.m_times[component].append(e - self.m_start)
57 def dumpStats(self):
Zachary Turner606e1e32015-10-23 17:53:51 +000058 for key in list(self.m_times.keys()):
Chris Lattner30fdc8d2010-06-08 16:52:24 +000059 if len(self.m_times[key]):
60 sampleMin = float('inf')
61 sampleMax = float('-inf')
62 sampleSum = 0.0
63 sampleCount = 0.0
64 for time in self.m_times[key]:
65 if time > sampleMax:
66 sampleMax = time
67 if time < sampleMin:
68 sampleMin = time
69 sampleSum += time
70 sampleCount += 1.0
71 sampleMean = sampleSum / sampleCount
72 sampleVariance = 0
73 for time in self.m_times[key]:
74 sampleVariance += (time - sampleMean) ** 2
75 sampleVariance /= sampleCount
76 sampleStandardDeviation = math.sqrt(sampleVariance)
Zachary Turner35d017f2015-10-23 17:04:29 +000077 print(key + ": [" + prettyTime(sampleMin) + ", " + prettyTime(sampleMax) + "] ", end='')
78 print("µ " + prettyTime(sampleMean) + ", σ " + prettyTime(sampleStandardDeviation))
Chris Lattner30fdc8d2010-06-08 16:52:24 +000079 m_executionTimes = None
80
81setupSysPath()
82
83import lldb
84
85class LLDBTestCase(unittest.TestCase):
86 def setUp(self):
Johnny Chenf94c8c22010-06-25 23:22:48 +000087 debugger = lldb.SBDebugger.Create()
88 debugger.SetAsync(True)
89 self.m_commandInterpreter = debugger.GetCommandInterpreter()
Chris Lattner30fdc8d2010-06-08 16:52:24 +000090 if not self.m_commandInterpreter:
Zachary Turner35d017f2015-10-23 17:04:29 +000091 print("Couldn't get the command interpreter")
Chris Lattner30fdc8d2010-06-08 16:52:24 +000092 sys.exit(-1)
93 def runCommand(self, command, component):
94 res = lldb.SBCommandReturnObject()
95 ExecutionTimes.executionTimes().start()
96 self.m_commandInterpreter.HandleCommand(command, res, False)
97 ExecutionTimes.executionTimes().end(component)
98 if res.Succeeded():
99 return res.GetOutput()
100 else:
101 self.fail("Command " + command + " returned an error")
102 return None
Enrico Granata165f8af2012-09-21 19:10:53 +0000103 def getCategories(self):
104 return []
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000105
106class SanityCheckTestCase(LLDBTestCase):
107 def runTest(self):
108 ret = self.runCommand("show arch", "show-arch")
Zachary Turner35d017f2015-10-23 17:04:29 +0000109 #print(ret)
Enrico Granata165f8af2012-09-21 19:10:53 +0000110 def getCategories(self):
111 return []
Chris Lattner30fdc8d2010-06-08 16:52:24 +0000112
113suite = unittest.TestLoader().loadTestsFromTestCase(SanityCheckTestCase)
114unittest.TextTestRunner(verbosity=2).run(suite)
115ExecutionTimes.executionTimes().dumpStats()