aboutsummaryrefslogtreecommitdiff
path: root/crosperf/experiment_file_unittest.py
diff options
context:
space:
mode:
Diffstat (limited to 'crosperf/experiment_file_unittest.py')
-rwxr-xr-xcrosperf/experiment_file_unittest.py127
1 files changed, 5 insertions, 122 deletions
diff --git a/crosperf/experiment_file_unittest.py b/crosperf/experiment_file_unittest.py
index 12b68223..d4a02107 100755
--- a/crosperf/experiment_file_unittest.py
+++ b/crosperf/experiment_file_unittest.py
@@ -1,16 +1,12 @@
#!/usr/bin/env python2
-# -*- coding: utf-8 -*-
# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-
"""The unittest of experiment_file."""
from __future__ import print_function
-
-import io
+import StringIO
import unittest
-
from experiment_file import ExperimentFile
EXPERIMENT_FILE_1 = """
@@ -69,75 +65,6 @@ EXPERIMENT_FILE_3 = """
}
"""
-EXPERIMENT_FILE_4 = """
- board: x86-alex
- remote: chromeos-alex3
- iterations: 3
-
- benchmark: webrtc {
- test_args: --story-filter=datachannel
- }
-
- benchmark: webrtc {
- test_args: --story-tag-filter=smoothness
- }
-
- image1 {
- chromeos_image:/usr/local/google/cros_image1.bin
- }
- """
-
-DUT_CONFIG_EXPERIMENT_FILE_GOOD = """
- board: kevin64
- remote: chromeos-kevin.cros
- turbostat: False
- intel_pstate: no_hwp
- cooldown_temp: 38
- cooldown_time: 5
- governor: powersave
- cpu_usage: exclusive_cores
- cpu_freq_pct: 50
- top_interval: 5
-
- benchmark: speedometer {
- iterations: 3
- suite: telemetry_Crosperf
- }
-
- image1 {
- chromeos_image:/usr/local/google/cros_image1.bin
- }
- """
-
-DUT_CONFIG_EXPERIMENT_FILE_BAD_GOV = """
- board: kevin64
- remote: chromeos-kevin.cros
- intel_pstate: active
- governor: misspelled_governor
-
- benchmark: speedometer2 {
- iterations: 3
- suite: telemetry_Crosperf
- }
- """
-
-DUT_CONFIG_EXPERIMENT_FILE_BAD_CPUUSE = """
- board: kevin64
- remote: chromeos-kevin.cros
- turbostat: False
- governor: ondemand
- cpu_usage: unknown
-
- benchmark: speedometer2 {
- iterations: 3
- suite: telemetry_Crosperf
- }
-
- image1 {
- chromeos_image:/usr/local/google/cros_image1.bin
- }
- """
-
OUTPUT_FILE = """board: x86-alex
remote: chromeos-alex3
perf_args: record -a -e cycles
@@ -161,7 +88,7 @@ class ExperimentFileTest(unittest.TestCase):
"""The main class for Experiment File test."""
def testLoadExperimentFile1(self):
- input_file = io.BytesIO(EXPERIMENT_FILE_1)
+ input_file = StringIO.StringIO(EXPERIMENT_FILE_1)
experiment_file = ExperimentFile(input_file)
global_settings = experiment_file.GetGlobalSettings()
self.assertEqual(global_settings.GetField('remote'), ['chromeos-alex3'])
@@ -181,7 +108,7 @@ class ExperimentFileTest(unittest.TestCase):
self.assertEqual(label_settings[0].GetField('remote'), ['chromeos-alex3'])
def testOverrideSetting(self):
- input_file = io.BytesIO(EXPERIMENT_FILE_2)
+ input_file = StringIO.StringIO(EXPERIMENT_FILE_2)
experiment_file = ExperimentFile(input_file)
global_settings = experiment_file.GetGlobalSettings()
self.assertEqual(global_settings.GetField('remote'), ['chromeos-alex3'])
@@ -194,59 +121,15 @@ class ExperimentFileTest(unittest.TestCase):
self.assertEqual(benchmark_settings[1].GetField('iterations'), 2)
def testDuplicateLabel(self):
- input_file = io.BytesIO(EXPERIMENT_FILE_3)
+ input_file = StringIO.StringIO(EXPERIMENT_FILE_3)
self.assertRaises(Exception, ExperimentFile, input_file)
- def testDuplicateBenchmark(self):
- input_file = io.BytesIO(EXPERIMENT_FILE_4)
- experiment_file = ExperimentFile(input_file)
- benchmark_settings = experiment_file.GetSettings('benchmark')
- self.assertEqual(benchmark_settings[0].name, 'webrtc')
- self.assertEqual(benchmark_settings[0].GetField('test_args'),
- '--story-filter=datachannel')
- self.assertEqual(benchmark_settings[1].name, 'webrtc')
- self.assertEqual(benchmark_settings[1].GetField('test_args'),
- '--story-tag-filter=smoothness')
-
def testCanonicalize(self):
- input_file = io.BytesIO(EXPERIMENT_FILE_1)
+ input_file = StringIO.StringIO(EXPERIMENT_FILE_1)
experiment_file = ExperimentFile(input_file)
res = experiment_file.Canonicalize()
self.assertEqual(res, OUTPUT_FILE)
- def testLoadDutConfigExperimentFile_Good(self):
- input_file = io.BytesIO(DUT_CONFIG_EXPERIMENT_FILE_GOOD)
- experiment_file = ExperimentFile(input_file)
- global_settings = experiment_file.GetGlobalSettings()
- self.assertEqual(global_settings.GetField('turbostat'), False)
- self.assertEqual(global_settings.GetField('intel_pstate'), 'no_hwp')
- self.assertEqual(global_settings.GetField('governor'), 'powersave')
- self.assertEqual(global_settings.GetField('cpu_usage'), 'exclusive_cores')
- self.assertEqual(global_settings.GetField('cpu_freq_pct'), 50)
- self.assertEqual(global_settings.GetField('cooldown_time'), 5)
- self.assertEqual(global_settings.GetField('cooldown_temp'), 38)
- self.assertEqual(global_settings.GetField('top_interval'), 5)
-
- def testLoadDutConfigExperimentFile_WrongGovernor(self):
- input_file = io.BytesIO(DUT_CONFIG_EXPERIMENT_FILE_BAD_GOV)
- with self.assertRaises(RuntimeError) as msg:
- ExperimentFile(input_file)
- self.assertRegexpMatches(
- str(msg.exception), 'governor: misspelled_governor')
- self.assertRegexpMatches(
- str(msg.exception), "Invalid enum value for field 'governor'."
- r' Must be one of \(performance, powersave, userspace, ondemand,'
- r' conservative, schedutils, sched, interactive\)')
-
- def testLoadDutConfigExperimentFile_WrongCpuUsage(self):
- input_file = io.BytesIO(DUT_CONFIG_EXPERIMENT_FILE_BAD_CPUUSE)
- with self.assertRaises(RuntimeError) as msg:
- ExperimentFile(input_file)
- self.assertRegexpMatches(str(msg.exception), 'cpu_usage: unknown')
- self.assertRegexpMatches(
- str(msg.exception), "Invalid enum value for field 'cpu_usage'."
- r' Must be one of \(all, big_only, little_only, exclusive_cores\)')
-
if __name__ == '__main__':
unittest.main()