blob: 25ef8c704f6fced25393d71bcb54ef6370c4734f [file] [log] [blame]
Brendan Jackmane81fdcb2017-01-04 17:10:29 +00001# Copyright 2015-2017 ARM Limited
Javi Merino348fe162015-06-15 14:59:00 +01002#
Javi Merinoaace7c02015-08-10 14:10:47 +01003# 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
Javi Merino348fe162015-06-15 14:59:00 +010016
17import os
18import subprocess
Javi Merino96f2b842015-06-15 16:45:38 +010019import unittest
Javi Merino348fe162015-06-15 14:59:00 +010020
21import utils_tests
22
Javi Merino435457c2015-08-10 15:59:10 +010023import trappy.wa
Javi Merinob97695d2015-06-15 16:09:45 +010024
Javi Merino348fe162015-06-15 14:59:00 +010025class TestWASysfsExtractor(utils_tests.SetupDirectory):
26 """Test the WA specific interface to get parameters from a sysfs extractor"""
27 def __init__(self, *args, **kwargs):
28 self.wa_sysfs_fname = "WA_sysfs_extract.tar.xz"
29 super(TestWASysfsExtractor, self).__init__(
30 [(self.wa_sysfs_fname, self.wa_sysfs_fname)],
31 *args, **kwargs)
32
33 def setUp(self):
34 super(TestWASysfsExtractor, self).setUp()
Javi Merino541c8872016-03-08 11:35:46 +000035 subprocess.check_call(["tar", "xf", self.wa_sysfs_fname])
Javi Merino348fe162015-06-15 14:59:00 +010036
37 def test_get_parameters(self):
38 """Test that we can get the parameters of a sysfs extractor output"""
39
Javi Merino348fe162015-06-15 14:59:00 +010040 os.chdir("..")
Javi Merino435457c2015-08-10 15:59:10 +010041 thermal_params = trappy.wa.SysfsExtractor(self.out_dir).get_parameters()
Javi Merino348fe162015-06-15 14:59:00 +010042 self.assertEquals(thermal_params["cdev0_weight"], 1024)
43 self.assertEquals(thermal_params["cdev1_weight"], 768)
44 self.assertEquals(thermal_params["trip_point_0_temp"], 72000)
45 self.assertEquals(thermal_params["policy"], "power_allocator")
Javi Merinob97695d2015-06-15 16:09:45 +010046
47 def test_print_thermal_params(self):
48 """Test that printing the thermal params doesn't bomb"""
49
Javi Merino435457c2015-08-10 15:59:10 +010050 trappy.wa.SysfsExtractor(".").pretty_print_in_ipython()
Javi Merino96f2b842015-06-15 16:45:38 +010051
52class TestWASysfsExtractorFailMode(unittest.TestCase):
53 """Test the failure modes of the Workload Automation sysfs extractor"""
54
55 def test_get_params_invalid_directory(self):
Javi Merino435457c2015-08-10 15:59:10 +010056 """An invalid directory for trappy.wa.SysfsExtractor doesn't bomb"""
Javi Merino96f2b842015-06-15 16:45:38 +010057
Javi Merino435457c2015-08-10 15:59:10 +010058 sysfs_extractor = trappy.wa.SysfsExtractor(".")
Javi Merino96f2b842015-06-15 16:45:38 +010059 self.assertEquals(sysfs_extractor.get_parameters(), {})
60
61 sysfs_extractor.pretty_print_in_ipython()