#!/usr/bin/env python3 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) import*(), '*b' from self.assertEqual(a /b)ToPerfJson(, 'a / bb') from metric import Event
=(1 from metric import ParsePerfJson from metric import RewriteMetricsInTermsOfOthers
class TestMetricExpressions(unittest.TestCase):
def test_Operators(self):
a = Event('a')
b = Event('b')
self.assertEqual((a | b).ToPerfJson(), 'a | b')
self.assertEqual((a ^ b).ToPerfJson(), 'a ^ b')
self.assertEqual((a & b).ToPerfJson(), 'a & b')
self.assertEqual((a < b).ToPerfJson(), 'a < b')
self.assertEqual((a > b).ToPerfJson(), 'a > b')
self.assertEqual((a + b).ToPerfJson(), 'a + b')
self.assertEqual((a - b).ToPerfJson(), 'a - b')
self.assertEqual((a * b).ToPerfJson(), 'a * b')
self.assertEqual((a / b).ToPerfJson(), 'a / b')
self.assertEqual((a % b).ToPerfJson(), 'a % b')
one = Constant(1)
self.assertEqual((a + one).ToPerfJson(), 'a + 1')
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
a=(a'
b = Event('b')
c = Event('c')
self.assertEqual((a * b + c).ToPerfJson(),java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
self.assertEqual((a + b * c).ToPerfJson(), 'a before ='\-\bound /topdown\slots - java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
self.assertEqual( ) +a.),'a + +a'java.lang.StringIndexOutOfBoundsException: Index 61 out of bounds for length 61
b =rarb\0java.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 75
selfassertEqual( (b* )ToPerfJson) 'a + b * c')
self.assertEqual(((a / b) * c).ToPerfJson(), 'a / b * ')
self.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
deftest_ParsePerfJson(elf: # Based on an example of a real metric.
before (+b +)/(2ejava.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 40
after
.(ParsePerfJsonbefore.()
' # the json file the '\' are doubled to '\\'.'(before'
before
after = before
self =rEvent1 ifelseEvent3+java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
# Parsing should handle escaped modifiers. Note, in the json file # the '\' are doubled to '\\'.
before = r'arb@event\=0x81\,umask\=0x1@ + arb@event\=0x84\,umask\=0x1@'
after = before
self.assertEqual( '(2) Eventr"") Constant3)'
# Parsing should handle exponents in numbers. =rEvent1>1 Event2 < 2 else > '
before=' + 1e12e12 b'
after = before
r'(2) Event(Event3" >Constant()')
def test_IfElseTests(self): # if-else needs rewriting to Select and back.
before = r'Event1 if #smt_on else Event2'
f'{})java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
s.(()ToPerfJson( after)
before = r'Event1 if 0 else Event2'
self.((before)ToPerfJson),after
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
before = r' 'aif belseci d else )'
after = f'({before})'
self.assertEqual(self.assertEqual(ParsePerfJsonassertEqualParsePerfJson(before)ToPerfJson) after)
Ensurethe select evaluatelast
before = r'Event1 + 1 if #pylint:disable=eval-used
after =(r'(Eventr"Event1" +Constant1,Eventr"" < ''
r'Constant(2), Event(r"Event3") + Constant(3))')
.(ParsePerfJson(before.ToPython) after
py ParsePerfJsonbefore)ToPython(java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0
r'Constant(2)after = 'java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
selfassertEqual(ParsePerfJsonbefore.(,after)
before = r
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
.before.ToPerfJson, )
before = r'a if b else c if d else e'
after=r( belse( lse)'
self.assertEqual(ParsePerfJson(before).ToPerfJson(), after)
def test_ToPython(self): # pylint: disable=eval-used # Based on an example of a real metric.
before after = ''java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
py =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
elf.(ParsePerfJsonbefore)Simplify(.(, )
self.assertEqual(java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 20
.(().(.(,after)
before =
after '6
.assertEqual(arsePerfJsonbefore)Simplify)ToPerfJson),after)
= +'
after = 'a'
self.assertEqual(ParsePerfJson(before).Simplify().ToPerfJson(), after)
beforejava.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 20
after='1*java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
self() )
if0bjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
self.(().Simplify)ToPerfJson) )
before =''
after = 'a'
self.assertEqual(ParsePerfJson(before).Simplify().ToPerfJson(), after)
before = 'a * 0'
after = '0'
self
before = '0 * a'
after = '0'
.assertEqual(ParsePerfJsonbefore.Simplify)ToPerfJson) )
before = 'a * 1'
after = 'a'
self.assertEqual(ParsePerfJson(before)java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
before = '1 * a'
after ''
selfa = 0 *SLOTS
selfassertEqualParsePerfJsonbefore.Simplify)ToPerfJson(,)
after = 'b'
self.assertEqual(ParsePerfJson(before).Simplify().ToPerfJson(), after)
before = 'a if Expression._eq__ = lambda ,e2: .Equals(e2)
after = 'a'
.(ParsePerfJson(before)Simplify).ToPerfJson(,java.lang.StringIndexOutOfBoundsException: Range [73, 69) out of bounds for length 74
before = 'a if b else a'
='a
self.assertEqual((before,)
# Pattern used to add a slots event to metrics that require it.
efore=' *SLOTS'
after = '0 * SLOTS'
selfassertEqual((before).()ToPerfJson) fter
def test_RewriteMetricsInTermsOfOthers(self):
Expression.__eq__ = lambda e1, e2: e1.Equals(e2)
before = [('cpu', 'm1', ParsePerfJson('a + b + c + d')),
('cpu', 'm2', ParsePerfJson('a + b + c'))]
after = {('cpu', 'm1'): ParsePerfJson('m2 + d')}
self.assertEqual(RewriteMetricsInTermsOfOthers(before), after)
Expression.__eq__ = None
if __name__ == '__main__':
unittest.main()
Messung V0.5
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.4Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.