aboutsummaryrefslogtreecommitdiff
path: root/tests/test_wa_sysfs_extractor.py
blob: 25ef8c704f6fced25393d71bcb54ef6370c4734f (plain)
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
#    Copyright 2015-2017 ARM Limited
#
# 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.
#


import os
import subprocess
import unittest

import utils_tests

import trappy.wa

class TestWASysfsExtractor(utils_tests.SetupDirectory):
    """Test the WA specific interface to get parameters from a sysfs extractor"""
    def __init__(self, *args, **kwargs):
        self.wa_sysfs_fname = "WA_sysfs_extract.tar.xz"
        super(TestWASysfsExtractor, self).__init__(
            [(self.wa_sysfs_fname, self.wa_sysfs_fname)],
            *args, **kwargs)

    def setUp(self):
        super(TestWASysfsExtractor, self).setUp()
        subprocess.check_call(["tar", "xf", self.wa_sysfs_fname])

    def test_get_parameters(self):
        """Test that we can get the parameters of a sysfs extractor output"""

        os.chdir("..")
        thermal_params = trappy.wa.SysfsExtractor(self.out_dir).get_parameters()
        self.assertEquals(thermal_params["cdev0_weight"], 1024)
        self.assertEquals(thermal_params["cdev1_weight"], 768)
        self.assertEquals(thermal_params["trip_point_0_temp"], 72000)
        self.assertEquals(thermal_params["policy"], "power_allocator")

    def test_print_thermal_params(self):
        """Test that printing the thermal params doesn't bomb"""

        trappy.wa.SysfsExtractor(".").pretty_print_in_ipython()

class TestWASysfsExtractorFailMode(unittest.TestCase):
    """Test the failure modes of the Workload Automation sysfs extractor"""

    def test_get_params_invalid_directory(self):
        """An invalid directory for trappy.wa.SysfsExtractor doesn't bomb"""

        sysfs_extractor = trappy.wa.SysfsExtractor(".")
        self.assertEquals(sysfs_extractor.get_parameters(), {})

        sysfs_extractor.pretty_print_in_ipython()