diff options
author | Zhizhou Yang <zhizhouy@google.com> | 2018-12-28 15:04:33 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-12-29 18:18:11 -0800 |
commit | 2639395908b32e4560b3b9a5290db08ae819f8e9 (patch) | |
tree | 7d980e9cc92dc3c8ac49499c7da9625f978b9730 | |
parent | ad8b237f62b9464dbff9a163647ebe6b721d6b35 (diff) | |
download | toolchain-utils-2639395908b32e4560b3b9a5290db08ae819f8e9.tar.gz |
crosperf: unit test for CPU cycles table generator
This patch added unit test for CPU table generation in tabulator.py
TEST=passed all unit tests in cros_utils and crosperf
BUG=chromium:917484
CQ-DEPEND=CL:1389035
Change-Id: Ib10bea1470fca1c5dbab8ad39b9684dd473a6183
Reviewed-on: https://chromium-review.googlesource.com/1392428
Commit-Ready: Zhizhou Yang <zhizhouy@google.com>
Tested-by: Zhizhou Yang <zhizhouy@google.com>
Reviewed-by: Luis Lozano <llozano@chromium.org>
-rw-r--r-- | cros_utils/tabulator_test.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/cros_utils/tabulator_test.py b/cros_utils/tabulator_test.py index 21cd1e73..6d3ff55c 100644 --- a/cros_utils/tabulator_test.py +++ b/cros_utils/tabulator_test.py @@ -103,6 +103,47 @@ class TabulatorTest(unittest.TestCase): table = tf.GetCellTable() self.assertTrue(table) + def testCPUCyclesTableGenerator(self): + keyvals = {'bench1': [[{'cpu_cycles': 1}, {'cpu_cycles': 2}], + [{'cpu_cycles': 3}, {'cpu_cycles': 4}]], + 'bench2': [[{'cpu_cycles': 5}, {}], + [{'cpu_cycles': 6}, {'cpu_cycles': 7}]]} + weights = {'bench1': 0.2, 'bench2': 0.7} + iter_counts = {'bench1': 2, 'bench2': 2} + labels = ['vanilla', 'modified'] + tg = tabulator.CPUCyclesTableGenerator(keyvals, labels, iter_counts, + weights) + (table, new_keyvals, new_iter_counts) = tg.GetTable() + + columns = [ + tabulator.Column(tabulator.IterationResult(), tabulator.Format()), + tabulator.Column(tabulator.AmeanResult(), tabulator.Format()), + tabulator.Column(tabulator.AmeanRatioResult(), + tabulator.PercentFormat()), + ] + # This is the function to load column info. + tf = tabulator.TableFormatter(table, columns, cpu_table=True) + # This is the function where to do all weighting calculation. + cell_table = tf.GetCellTable('summary') + self.assertTrue(cell_table) + + header = table.pop(0) + self.assertTrue(header == ['Benchmarks', 'Weights', 'vanilla', 'modified']) + row = table.pop(0) + self.assertTrue(row == ['bench1', 0.2, ((2, 0), [1*0.2, 2*0.2]), + ((2, 0), [3*0.2, 4*0.2])]) + row = table.pop(0) + self.assertTrue(row == ['bench2', 0.7, ((1, 1), [5*0.7, None]), + ((2, 0), [6*0.7, 7*0.7])]) + row = table.pop(0) + self.assertTrue(row == ['Composite Benchmark (cycles)', 'N/A', + ((1, 1), [1*0.2+5*0.7, None]), + ((2, 0), [3*0.2+6*0.7, 4*0.2+7*0.7])]) + + self.assertTrue('Composite Benchmark' in new_keyvals.keys()) + self.assertTrue('Composite Benchmark' in new_iter_counts.keys()) + + def testColspan(self): simple_table = [ ['binary', 'b1', 'b2', 'b3'], |