aboutsummaryrefslogtreecommitdiff
path: root/tests/test_wa_sysfs_extractor.py
blob: 2d7a54e3b673ebdd9c6f78e497ab3a8305bbd425 (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
# $Copyright:
# ----------------------------------------------------------------
# This confidential and proprietary software may be used only as
# authorised by a licensing agreement from ARM Limited
#  (C) COPYRIGHT 2015 ARM Limited
#       ALL RIGHTS RESERVED
# The entire notice above must be reproduced on all authorised
# copies and copies may only be made to the extent permitted
# by a licensing agreement from ARM Limited.
# ----------------------------------------------------------------
# File:        test_wa_sysfs_extractor.py
# ----------------------------------------------------------------
# $
#

import os
import subprocess
import unittest

import utils_tests

import cr2.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.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 = cr2.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"""

        cr2.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 cr2.wa.SysfsExtractor doesn't bomb"""

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

        sysfs_extractor.pretty_print_in_ipython()