aboutsummaryrefslogtreecommitdiff
path: root/crosperf/experiment_file_unittest.py
blob: d08c7eb54b1b61b05089b696baf219bef797ea34 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/python

# 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.

import StringIO
import unittest
from experiment_file import ExperimentFile

EXPERIMENT_FILE_1 = """
  board: x86-alex
  remote: chromeos-alex3
  perf_args: record -a -e cycles
  benchmark: PageCycler {
    iterations: 3
  }

  image1 {
    chromeos_image: /usr/local/google/cros_image1.bin
  }

  image2 {
    board: lumpy
    remote: chromeos-lumpy1
    chromeos_image: /usr/local/google/cros_image2.bin
  }
  """

EXPERIMENT_FILE_2 = """
  board: x86-alex
  remote: chromeos-alex3
  iterations: 3

  benchmark: PageCycler {
  }

  benchmark: AndroidBench {
    iterations: 2
  }

  image1 {
    chromeos_image:/usr/local/google/cros_image1.bin
  }

  image2 {
    chromeos_image: /usr/local/google/cros_image2.bin
  }
  """

EXPERIMENT_FILE_3 = """
  board: x86-alex
  remote: chromeos-alex3
  iterations: 3

  benchmark: PageCycler {
  }

  image1 {
    chromeos_image:/usr/local/google/cros_image1.bin
  }

  image1 {
    chromeos_image: /usr/local/google/cros_image2.bin
  }
  """


class ExperimentFileTest(unittest.TestCase):
  def testLoadExperimentFile1(self):
    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"])
    self.assertEqual(global_settings.GetField("perf_args"),
                     "record -a -e cycles")
    benchmark_settings = experiment_file.GetSettings("benchmark")
    self.assertEqual(len(benchmark_settings), 1)
    self.assertEqual(benchmark_settings[0].name, "PageCycler")
    self.assertEqual(benchmark_settings[0].GetField("iterations"), 3)

    label_settings = experiment_file.GetSettings("label")
    self.assertEqual(len(label_settings), 2)
    self.assertEqual(label_settings[0].name, "image1")
    self.assertEqual(label_settings[0].GetField("board"), "x86-alex")
    self.assertEqual(label_settings[0].GetField("chromeos_image"),
                     "/usr/local/google/cros_image1.bin")
    self.assertEqual(label_settings[1].GetField("remote"), ["chromeos-lumpy1"])
    self.assertEqual(label_settings[0].GetField("remote"), ["chromeos-alex3"])

  def testOverrideSetting(self):
    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"])

    benchmark_settings = experiment_file.GetSettings("benchmark")
    self.assertEqual(len(benchmark_settings), 2)
    self.assertEqual(benchmark_settings[0].name, "PageCycler")
    self.assertEqual(benchmark_settings[0].GetField("iterations"), 3)
    self.assertEqual(benchmark_settings[1].name, "AndroidBench")
    self.assertEqual(benchmark_settings[1].GetField("iterations"), 2)

  def testDuplicateLabel(self):
    input_file = StringIO.StringIO(EXPERIMENT_FILE_3)
    self.assertRaises(Exception, ExperimentFile, input_file)


if __name__ == "__main__":
  unittest.main()