Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 3 | # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 6 | |
| 7 | import StringIO |
| 8 | import unittest |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 9 | |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 10 | from utils.file_utils import FileUtils |
| 11 | |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 12 | from experiment_factory import ExperimentFactory |
| 13 | from experiment_file import ExperimentFile |
| 14 | import test_flag |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 15 | |
| 16 | EXPERIMENT_FILE_1 = """ |
| 17 | board: x86-alex |
| 18 | remote: chromeos-alex3 |
| 19 | |
| 20 | benchmark: PageCycler { |
| 21 | iterations: 3 |
| 22 | } |
| 23 | |
| 24 | image1 { |
| 25 | chromeos_image: /usr/local/google/cros_image1.bin |
| 26 | } |
| 27 | |
| 28 | image2 { |
| 29 | chromeos_image: /usr/local/google/cros_image2.bin |
| 30 | } |
| 31 | """ |
| 32 | |
| 33 | |
| 34 | class ExperimentFactoryTest(unittest.TestCase): |
| 35 | def testLoadExperimentFile1(self): |
| 36 | experiment_file = ExperimentFile(StringIO.StringIO(EXPERIMENT_FILE_1)) |
Luis Lozano | f81680c | 2013-03-15 14:44:13 -0700 | [diff] [blame] | 37 | experiment = ExperimentFactory().GetExperiment(experiment_file, |
| 38 | working_directory="", |
| 39 | log_dir="") |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 40 | self.assertEqual(experiment.remote, ["chromeos-alex3"]) |
| 41 | |
| 42 | self.assertEqual(len(experiment.benchmarks), 1) |
| 43 | self.assertEqual(experiment.benchmarks[0].name, "PageCycler") |
Yunlian Jiang | 04dc5dc | 2013-04-23 15:05:05 -0700 | [diff] [blame] | 44 | self.assertEqual(experiment.benchmarks[0].test_name, "PageCycler") |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 45 | self.assertEqual(experiment.benchmarks[0].iterations, 3) |
| 46 | |
| 47 | self.assertEqual(len(experiment.labels), 2) |
| 48 | self.assertEqual(experiment.labels[0].chromeos_image, |
| 49 | "/usr/local/google/cros_image1.bin") |
| 50 | self.assertEqual(experiment.labels[0].board, |
| 51 | "x86-alex") |
| 52 | |
| 53 | |
| 54 | if __name__ == "__main__": |
| 55 | FileUtils.Configure(True) |
Ahmad Sharif | 4467f00 | 2012-12-20 12:09:49 -0800 | [diff] [blame] | 56 | test_flag.SetTestMode(True) |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 57 | unittest.main() |