• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(
46        '-l',
47        '--log_dir',
48        dest='log_dir',
49        default='',
50        help='The log_dir, default is under '
51        '<crosperf_logs>/logs')
52    crosperf.SetupParserOptions(parser)
53    argv = ['crosperf/crosperf.py', 'temp.exp', '--rerun=True']
54    options, _ = parser.parse_known_args(argv)
55    settings = crosperf.ConvertOptionsToSettings(options)
56    self.assertIsNotNone(settings)
57    self.assertIsInstance(settings, settings_factory.GlobalSettings)
58    self.assertEqual(len(settings.fields), 25)
59    self.assertTrue(settings.GetField('rerun'))
60    argv = ['crosperf/crosperf.py', 'temp.exp']
61    options, _ = parser.parse_known_args(argv)
62    settings = crosperf.ConvertOptionsToSettings(options)
63    self.assertFalse(settings.GetField('rerun'))
64
65
66if __name__ == '__main__':
67  unittest.main()
68