1#    Copyright 2015-2017 ARM Limited
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14#
15
16
17import unittest
18import matplotlib
19import pandas as pd
20import utils_tests
21import trappy
22import shutil
23
24from test_thermal import BaseTestThermal
25
26
27class TestPlotterDupVals(BaseTestThermal):
28
29    """Test Duplicate Entries in plotter"""
30
31    def __init__(self, *args, **kwargs):
32        super(TestPlotterDupVals, self).__init__(*args, **kwargs)
33
34    def test_plotter_duplicates(self):
35        """Test that plotter handles duplicates fine"""
36        with open("trace.txt", "w") as fout:
37            fout.write("""version = 6
38cpus=6
39       rcuos/2-22 [001] 0000.018510: sched_load_avg_sg: cpus=00000001 load=0 utilization=0
40       rcuos/2-22 [001] 6550.018611: sched_load_avg_sg: cpus=00000002 load=1 utilization=1
41       rcuos/2-22 [001] 6550.018611: sched_load_avg_sg: cpus=00000004 load=2 utilization=2
42       rcuos/2-22 [001] 6550.018612: sched_load_avg_sg: cpus=00000001 load=2 utilization=3
43       rcuos/2-22 [001] 6550.018624: sched_load_avg_sg: cpus=00000002 load=1 utilization=4
44       rcuos/2-22 [001] 6550.018625: sched_load_avg_sg: cpus=00000002 load=2 utilization=5
45       rcuos/2-22 [001] 6550.018626: sched_load_avg_sg: cpus=00000002 load=3 utilization=6
46       rcuos/2-22 [001] 6550.018627: sched_load_avg_sg: cpus=00000002 load=1 utilization=7
47       rcuos/2-22 [001] 6550.018628: sched_load_avg_sg: cpus=00000004 load=2 utilization=8\n""")
48            fout.close()
49        trace1 = trappy.FTrace(name="first")
50        l = trappy.LinePlot(
51            trace1,
52            trappy.sched.SchedLoadAvgSchedGroup,
53            column=['utilization'],
54            filters={
55                "load": [
56                    1,
57                    2]},
58            pivot="cpus",
59            marker='o',
60            linestyle='none',
61            per_line=3)
62        l.view(test=True)
63
64    def test_plotter_triplicates(self):
65
66        """Test that plotter handles triplicates fine"""
67
68        with open("trace.txt", "w") as fout:
69            fout.write("""version = 6
70cpus=6
71       rcuos/2-22 [001] 0000.018510: sched_load_avg_sg: cpus=00000001 load=0 utilization=0
72       rcuos/2-22 [001] 6550.018611: sched_load_avg_sg: cpus=00000002 load=1 utilization=1
73       rcuos/2-22 [001] 6550.018611: sched_load_avg_sg: cpus=00000004 load=2 utilization=2
74       rcuos/2-22 [001] 6550.018611: sched_load_avg_sg: cpus=00000004 load=2 utilization=2
75       rcuos/2-22 [001] 6550.018612: sched_load_avg_sg: cpus=00000001 load=2 utilization=3
76       rcuos/2-22 [001] 6550.018624: sched_load_avg_sg: cpus=00000002 load=1 utilization=4
77       rcuos/2-22 [001] 6550.018625: sched_load_avg_sg: cpus=00000002 load=2 utilization=5
78       rcuos/2-22 [001] 6550.018626: sched_load_avg_sg: cpus=00000002 load=3 utilization=6
79       rcuos/2-22 [001] 6550.018627: sched_load_avg_sg: cpus=00000002 load=1 utilization=7
80       rcuos/2-22 [001] 6550.018628: sched_load_avg_sg: cpus=00000004 load=2 utilization=8\n""")
81            fout.close()
82
83        trace1 = trappy.FTrace(name="first")
84        l = trappy.LinePlot(
85            trace1,
86            trappy.sched.SchedLoadAvgSchedGroup,
87            column=['utilization'],
88            filters={
89                "load": [
90                    1,
91                    2]},
92            pivot="cpus",
93            marker='o',
94            linestyle='none',
95            per_line=3)
96        l.view(test=True)
97