forked from GoogleCloudPlatform/PerfKitBenchmarker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultichase_benchmark_test.py
90 lines (65 loc) · 2.75 KB
/
multichase_benchmark_test.py
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
# Copyright 2016 PerfKitBenchmarker Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for perfkitbenchmarker.linux_benchmarks.multichase_benchmark."""
import functools
import unittest
from perfkitbenchmarker import units
from perfkitbenchmarker.linux_benchmarks import multichase_benchmark
class MemorySizeParserTestCase(unittest.TestCase):
def setUp(self):
self._parser = multichase_benchmark._MEMORY_SIZE_PARSER
def testParseNoUnits(self):
with self.assertRaises(ValueError):
self._parser.parse('10')
def testParseInvalidUnits(self):
with self.assertRaises(ValueError):
self._parser.parse('20 seconds')
def testParseExplicitMemory(self):
q = self._parser.parse('30 GiB')
self.assertEqual(q.magnitude, 30)
self.assertEqual(q.units, units.Unit('gibibyte'))
def testParsePercent(self):
q = self._parser.parse('40%')
self.assertEqual(q.magnitude, 40)
self.assertEqual(q.units, units.percent)
class TranslateMemorySizeTestCase(unittest.TestCase):
def setUp(self):
self._func = multichase_benchmark._TranslateMemorySize
def testExplicitSize(self):
result = self._func(lambda: 1024, units.Quantity('1 GiB'))
self.assertEqual(result, 1073741824)
def testPercent(self):
result = self._func(lambda: 1024, units.Quantity('25%'))
self.assertEqual(result, 256)
class IterMemorySizesTestCase(unittest.TestCase):
def setUp(self):
self._func = functools.partial(multichase_benchmark._IterMemorySizes,
lambda: 1024)
def testHitsUpperBound(self):
result = list(self._func(1 * units.byte, 32 * units.byte))
self.assertEqual(result, [1, 2, 4, 8, 16, 32])
def testSurpassesUpperBound(self):
result = list(self._func(1 * units.byte, 20 * units.byte))
self.assertEqual(result, [1, 2, 4, 8, 16])
def testPercent(self):
result = list(self._func(1 * units.percent, 10 * units.percent))
self.assertEqual(result, [10, 20, 40, 80])
def testEqual(self):
result = list(self._func(32 * units.byte, 32 * units.byte))
self.assertEqual(result, [32])
def testMaxLessThanMin(self):
result = list(self._func(64 * units.byte, 32 * units.byte))
self.assertEqual(result, [])
if __name__ == '__main__':
unittest.main()