1#!/usr/bin/env python2 2# 3# Copyright 2014 Google Inc. All Rights Reserved. 4"""Unittest for crosperf.""" 5 6from __future__ import print_function 7 8import argparse 9import StringIO 10 11import unittest 12 13import crosperf 14import settings_factory 15import experiment_file 16 17EXPERIMENT_FILE_1 = """ 18 board: x86-alex 19 remote: chromeos-alex3 20 perf_args: record -a -e cycles 21 benchmark: PageCycler { 22 iterations: 3 23 } 24 25 image1 { 26 chromeos_image: /usr/local/google/cros_image1.bin 27 } 28 29 image2 { 30 remote: chromeos-lumpy1 31 chromeos_image: /usr/local/google/cros_image2.bin 32 } 33 """ 34 35 36class CrosperfTest(unittest.TestCase): 37 """Crosperf test class.""" 38 39 def setUp(self): 40 input_file = StringIO.StringIO(EXPERIMENT_FILE_1) 41 self.exp_file = experiment_file.ExperimentFile(input_file) 42 43 def test_convert_options_to_settings(self): 44 parser = argparse.ArgumentParser() 45 parser.add_argument('-l', 46 '--log_dir', 47 dest='log_dir', 48 default='', 49 help='The log_dir, default is under ' 50 '<crosperf_logs>/logs') 51 crosperf.SetupParserOptions(parser) 52 argv = ['crosperf/crosperf.py', 'temp.exp', '--rerun=True'] 53 options, _ = parser.parse_known_args(argv) 54 settings = crosperf.ConvertOptionsToSettings(options) 55 self.assertIsNotNone(settings) 56 self.assertIsInstance(settings, settings_factory.GlobalSettings) 57 self.assertEqual(len(settings.fields), 25) 58 self.assertTrue(settings.GetField('rerun')) 59 argv = ['crosperf/crosperf.py', 'temp.exp'] 60 options, _ = parser.parse_known_args(argv) 61 settings = crosperf.ConvertOptionsToSettings(options) 62 self.assertFalse(settings.GetField('rerun')) 63 64 65if __name__ == '__main__': 66 unittest.main() 67