From 8464c328083eed2f64d156861a80044bf8418d39 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Thu, 19 Jul 2018 08:24:22 +0100 Subject: [PATCH] tests: add unit test for includes --- tests/data/includes/agenda.yaml | 7 ++++ tests/data/includes/configs/test.yaml | 1 + tests/data/includes/section-include.yaml | 2 + tests/data/includes/sections/section1.yaml | 1 + tests/data/includes/sections/section2.yaml | 2 + tests/data/includes/user/config.yaml | 2 + tests/data/includes/workloads.yaml | 5 +++ tests/test_agenda_parser.py | 45 +++++++++++++++++++++- 8 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tests/data/includes/agenda.yaml create mode 100644 tests/data/includes/configs/test.yaml create mode 100644 tests/data/includes/section-include.yaml create mode 100644 tests/data/includes/sections/section1.yaml create mode 100644 tests/data/includes/sections/section2.yaml create mode 100644 tests/data/includes/user/config.yaml create mode 100644 tests/data/includes/workloads.yaml diff --git a/tests/data/includes/agenda.yaml b/tests/data/includes/agenda.yaml new file mode 100644 index 00000000..22ce932d --- /dev/null +++ b/tests/data/includes/agenda.yaml @@ -0,0 +1,7 @@ +config: + augmentations: [~execution_time] + include#: configs/test.yaml +sections: + - include#: sections/section1.yaml + - include#: sections/section2.yaml +include#: workloads.yaml diff --git a/tests/data/includes/configs/test.yaml b/tests/data/includes/configs/test.yaml new file mode 100644 index 00000000..de6ddee5 --- /dev/null +++ b/tests/data/includes/configs/test.yaml @@ -0,0 +1 @@ +augmentations: [cpufreq, trace-cmd] diff --git a/tests/data/includes/section-include.yaml b/tests/data/includes/section-include.yaml new file mode 100644 index 00000000..834ae52f --- /dev/null +++ b/tests/data/includes/section-include.yaml @@ -0,0 +1,2 @@ +classifiers: + included: true diff --git a/tests/data/includes/sections/section1.yaml b/tests/data/includes/sections/section1.yaml new file mode 100644 index 00000000..87be7470 --- /dev/null +++ b/tests/data/includes/sections/section1.yaml @@ -0,0 +1 @@ +classifiers: {'section': 'one'} diff --git a/tests/data/includes/sections/section2.yaml b/tests/data/includes/sections/section2.yaml new file mode 100644 index 00000000..f97fb9a4 --- /dev/null +++ b/tests/data/includes/sections/section2.yaml @@ -0,0 +1,2 @@ +classifiers: {'section': 'two'} +include#: ../section-include.yaml diff --git a/tests/data/includes/user/config.yaml b/tests/data/includes/user/config.yaml new file mode 100644 index 00000000..95144a38 --- /dev/null +++ b/tests/data/includes/user/config.yaml @@ -0,0 +1,2 @@ +augmentations: [execution_time] + diff --git a/tests/data/includes/workloads.yaml b/tests/data/includes/workloads.yaml new file mode 100644 index 00000000..2619d370 --- /dev/null +++ b/tests/data/includes/workloads.yaml @@ -0,0 +1,5 @@ +workloads: + - dhrystone + - name: memcpy + classifiers: + memcpy: True diff --git a/tests/test_agenda_parser.py b/tests/test_agenda_parser.py index c14d212f..75239fcc 100644 --- a/tests/test_agenda_parser.py +++ b/tests/test_agenda_parser.py @@ -17,19 +17,26 @@ # pylint: disable=E0611 # pylint: disable=R0201 import os +import sys import yaml from collections import defaultdict from unittest import TestCase from nose.tools import assert_equal, assert_in, raises, assert_true + +DATA_DIR = os.path.join(os.path.dirname(__file__), 'data') +os.environ['WA_USER_DIRECTORY'] = os.path.join(DATA_DIR, 'includes') + from wa.framework.configuration.execution import ConfigManager from wa.framework.configuration.parsers import AgendaParser from wa.framework.exception import ConfigError from wa.utils.types import reset_all_counters -YAML_TEST_FILE = os.path.join(os.path.dirname(__file__), 'data', 'test-agenda.yaml') -YAML_BAD_SYNTAX_FILE = os.path.join(os.path.dirname(__file__), 'data', 'bad-syntax-agenda.yaml') + +YAML_TEST_FILE = os.path.join(DATA_DIR, 'test-agenda.yaml') +YAML_BAD_SYNTAX_FILE = os.path.join(DATA_DIR, 'bad-syntax-agenda.yaml') +INCLUDES_TEST_FILE = os.path.join(DATA_DIR, 'includes', 'agenda.yaml') invalid_agenda_text = """ workloads: @@ -171,3 +178,37 @@ class AgendaTest(TestCase): @raises(ConfigError) def test_bad_syntax(self): self.parser.load_from_path(self.config, YAML_BAD_SYNTAX_FILE) + + +class FakeTargetManager: + + def merge_runtime_parameters(self, params): + return params + + def validate_runtime_parameters(self, params): + pass + + +class IncludesTest(TestCase): + + def test_includes(self): + from pprint import pprint + parser = AgendaParser() + cm = ConfigManager() + tm = FakeTargetManager() + + includes = parser.load_from_path(cm, INCLUDES_TEST_FILE) + include_set = set([os.path.basename(i) for i in includes]) + assert_equal(include_set, + set(['test.yaml', 'section1.yaml', 'section2.yaml', + 'section-include.yaml', 'workloads.yaml'])) + + job_classifiers = {j.id: j.classifiers + for j in cm.jobs_config.generate_job_specs(tm)} + assert_equal(job_classifiers, + { + 's1-wk1': {'section': 'one'}, + 's2-wk1': {'section': 'two', 'included': True}, + 's1-wk2': {'section': 'one', 'memcpy': True}, + 's2-wk2': {'section': 'two', 'included': True, 'memcpy': True}, + })