summaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/api/conftest.py22
-rw-r--r--tests/unit/api/metric_controller_test.py37
-rw-r--r--tests/unit/api/plan_controller_test.py49
-rw-r--r--tests/unit/api/qpi_controller_test.py43
-rw-r--r--tests/unit/cli/cmd_report_test.py32
-rw-r--r--tests/unit/reporter/console_test.py32
6 files changed, 191 insertions, 24 deletions
diff --git a/tests/unit/api/conftest.py b/tests/unit/api/conftest.py
new file mode 100644
index 00000000..23a3be82
--- /dev/null
+++ b/tests/unit/api/conftest.py
@@ -0,0 +1,22 @@
+##############################################################################
+# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import pytest
+
+from qtip.api import __main__
+
+
+@pytest.fixture(scope="session")
+def app():
+ return __main__.get_app().app
+
+
+@pytest.fixture(scope="session")
+def app_client(app):
+ return app.test_client()
diff --git a/tests/unit/api/metric_controller_test.py b/tests/unit/api/metric_controller_test.py
new file mode 100644
index 00000000..caba7972
--- /dev/null
+++ b/tests/unit/api/metric_controller_test.py
@@ -0,0 +1,37 @@
+##############################################################################
+# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import httplib
+import json
+
+from qtip.base.constant import BaseProp
+
+
+def test_get_list_metrics(app_client):
+ response_success = app_client.get("/v1.0/metrics")
+ assert response_success.status_code == httplib.OK
+ metric_list = json.loads(response_success.data)['metrics']
+ assert len(metric_list) > 0
+ assert metric_list[0].endswith('.yaml')
+
+
+def test_get_metric(app_client):
+ response_success = app_client.get("/v1.0/metrics/dpi.yaml")
+ assert response_success.status_code == httplib.OK
+ metric_data = json.loads(response_success.data)
+ assert BaseProp.NAME in metric_data
+ assert BaseProp.WORKLOADS in metric_data
+ assert isinstance(metric_data[BaseProp.WORKLOADS], list)
+
+
+def test_get_metric_not_found(app_client):
+ response_not_found = app_client.get("/v1.0/metrics/fake.yaml")
+ response_data = json.loads(response_not_found.data)
+ assert response_not_found.status_code == httplib.NOT_FOUND
+ assert response_data['title'] == "Metric not found"
diff --git a/tests/unit/api/plan_controller_test.py b/tests/unit/api/plan_controller_test.py
new file mode 100644
index 00000000..136bd3c6
--- /dev/null
+++ b/tests/unit/api/plan_controller_test.py
@@ -0,0 +1,49 @@
+##############################################################################
+# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import httplib
+import json
+
+
+from qtip.loader.plan import PlanProp
+
+
+def test_invalid_url(app_client):
+ response_url_not_found = app_client.get("/v1.0/fakeresource")
+ assert response_url_not_found.status_code == httplib.NOT_FOUND
+
+
+def test_get_list_plans(app_client):
+ response_success = app_client.get("/v1.0/plans")
+ assert response_success.status_code == httplib.OK
+ plan_list = json.loads(response_success.data)['plans']
+ assert len(plan_list) > 0
+ assert plan_list[0].endswith('.yaml')
+
+
+def test_get_plan(app_client):
+ response_success = app_client.get("/v1.0/plans/sample.yaml")
+ assert response_success.status_code == httplib.OK
+ plan_data = json.loads(response_success.data)
+ assert PlanProp.NAME in plan_data
+ assert PlanProp.DESCRIPTION in plan_data
+ assert PlanProp.CONFIG in plan_data
+ assert PlanProp.QPIS in plan_data
+
+
+def test_get_plan_not_found(app_client):
+ response_not_found = app_client.get("/v1.0/plans/fake.yaml")
+ response_data = json.loads(response_not_found.data)
+ assert response_not_found.status_code == httplib.NOT_FOUND
+ assert response_data['title'] == "Plan not found"
+
+
+def test_runner_not_implemented(app_client):
+ response_error = app_client.post("/v1.0/plans/fake.yaml?action=run", follow_redirects=False)
+ assert response_error.status_code == httplib.NOT_IMPLEMENTED
diff --git a/tests/unit/api/qpi_controller_test.py b/tests/unit/api/qpi_controller_test.py
new file mode 100644
index 00000000..6291dd9b
--- /dev/null
+++ b/tests/unit/api/qpi_controller_test.py
@@ -0,0 +1,43 @@
+##############################################################################
+# Copyright (c) 2017 akhil.batra@research.iiit.ac.in and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+
+import httplib
+import json
+
+from qtip.base.constant import FormulaName
+from qtip.base.constant import SpecProp
+
+
+def test_get_list_qpis(app_client):
+ response_success = app_client.get("/v1.0/qpis")
+ assert response_success.status_code == httplib.OK
+ qpi_spec_list = json.loads(response_success.data)['qpis']
+ assert len(qpi_spec_list) > 0
+ assert qpi_spec_list[0].endswith('.yaml')
+
+
+def test_get_qpi(app_client):
+ response_success = app_client.get("/v1.0/qpis/compute.yaml")
+ assert response_success.status_code == httplib.OK
+ qpi_data = json.loads(response_success.data)
+ assert SpecProp.DESCRIPTION in qpi_data
+ assert SpecProp.FORMULA in qpi_data
+ assert SpecProp.SECTIONS in qpi_data
+ assert qpi_data[SpecProp.FORMULA] in FormulaName.__dict__.values()
+ sections = qpi_data[SpecProp.SECTIONS]
+ assert isinstance(sections, list)
+ for section in sections:
+ assert SpecProp.NAME in section
+
+
+def test_get_qpi_not_found(app_client):
+ response_not_found = app_client.get("/v1.0/qpis/fake.yaml")
+ response_data = json.loads(response_not_found.data)
+ assert response_not_found.status_code == httplib.NOT_FOUND
+ assert response_data['title'] == "QPI not found"
diff --git a/tests/unit/cli/cmd_report_test.py b/tests/unit/cli/cmd_report_test.py
index 963ce987..9263707f 100644
--- a/tests/unit/cli/cmd_report_test.py
+++ b/tests/unit/cli/cmd_report_test.py
@@ -8,6 +8,7 @@
##############################################################################
import pytest
+from os import path
from click.testing import CliRunner
from qtip.cli.entry import cli
@@ -18,10 +19,17 @@ def runner():
return CliRunner()
-def test_dhrystone(runner):
+@pytest.fixture(scope="module")
+def result_path():
+ result = path.join(path.dirname(__file__), path.pardir, path.pardir,
+ 'data/reporter')
+ return result
+
+
+def test_dhrystone(runner, result_path):
"""Test dhrystone report"""
- result = runner.invoke(cli, ['report', 'show', 'dhrystone'])
+ result = runner.invoke(cli, ['report', 'show', 'dhrystone', '-p', result_path])
assert "Benchmark: dhrystone" in result.output
assert "CPU Usage: 3%" in result.output
assert "Number: 40" in result.output
@@ -30,10 +38,10 @@ def test_dhrystone(runner):
assert "Total CPUs: 40" in result.output
-def test_whetstone(runner):
+def test_whetstone(runner, result_path):
""" Test whetstone output"""
- result = runner.invoke(cli, ['report', 'show', 'whetstone'])
+ result = runner.invoke(cli, ['report', 'show', 'whetstone', '-p', result_path])
assert "Benchmark: whetstone" in result.output
assert "CPU Usage: 3%" in result.output
assert "Results:" in result.output
@@ -43,9 +51,9 @@ def test_whetstone(runner):
assert "Single CPU:" in result.output
-def test_dpi(runner):
+def test_dpi(runner, result_path):
""" Test dpi report"""
- result = runner.invoke(cli, ['report', 'show', 'dpi'])
+ result = runner.invoke(cli, ['report', 'show', 'dpi', '-p', result_path])
assert "Benchmark: dpi" in result.output
assert "CPU Usage: 3%" in result.output
assert "Bits per Second: 3.638" in result.output
@@ -54,9 +62,9 @@ def test_dpi(runner):
assert "Packets per Second: 1.458" in result.output
-def test_ramspeed(runner):
+def test_ramspeed(runner, result_path):
""" Test ramspeed report """
- result = runner.invoke(cli, ['report', 'show', 'ramspeed'])
+ result = runner.invoke(cli, ['report', 'show', 'ramspeed', '-p', result_path])
assert "Benchmark: ramspeed" in result.output
assert "CPU Usage: 3%" in result.output
assert "Float Addition: 10217.62" in result.output
@@ -68,10 +76,10 @@ def test_ramspeed(runner):
assert "Integer Average: 11396.35" in result.output
-def test_ssl(runner):
+def test_ssl(runner, result_path):
""" Test ssl report"""
- result = runner.invoke(cli, ['report', 'show', 'ssl'])
+ result = runner.invoke(cli, ['report', 'show', 'ssl', '-p', result_path])
assert "Benchmark: ssl" in result.output
assert "CPU Usage: 3%" in result.output
assert "AES 128 CBC (bytes):" in result.output
@@ -82,10 +90,10 @@ def test_ssl(runner):
assert "4096: 7688.5" in result.output
-def test_sys(runner):
+def test_sys(runner, result_path):
""" Test sys_info """
- result = runner.invoke(cli, ['report', 'show', 'ssl'])
+ result = runner.invoke(cli, ['report', 'show', 'ssl', '-p', result_path])
assert "System Information:" in result.output
assert "Host Name: node-38.zte.com.cn" in result.output
assert "Memory: 4403.7/128524.1MB" in result.output
diff --git a/tests/unit/reporter/console_test.py b/tests/unit/reporter/console_test.py
index aa7f848b..037ef2fb 100644
--- a/tests/unit/reporter/console_test.py
+++ b/tests/unit/reporter/console_test.py
@@ -8,6 +8,7 @@
##############################################################################
import pytest
+from os import path
from qtip.reporter.console import ConsoleReporter
@@ -17,14 +18,21 @@ def console_reporter():
return ConsoleReporter({})
+@pytest.fixture
+def result_path():
+ result = path.join(path.dirname(__file__), path.pardir, path.pardir,
+ 'data/reporter')
+ return result
+
+
def test_constructor(console_reporter):
assert isinstance(console_reporter, ConsoleReporter)
-def test_dhrystone(console_reporter):
+def test_dhrystone(console_reporter, result_path):
""" Test dhrystone report"""
- result = console_reporter.render('dhrystone')
+ result = console_reporter.render('dhrystone', result_path)
assert "Benchmark: dhrystone" in result
assert "Number: 40" in result
assert "Score: 63529.6" in result
@@ -32,10 +40,10 @@ def test_dhrystone(console_reporter):
assert "Total CPUs: 40" in result
-def test_whetstone(console_reporter):
+def test_whetstone(console_reporter, result_path):
""" Test whetstone output"""
- result = console_reporter.render('whetstone')
+ result = console_reporter.render('whetstone', result_path)
assert "Benchmark: whetstone" in result
assert "Results:" in result
assert "Multi CPU:" in result
@@ -44,10 +52,10 @@ def test_whetstone(console_reporter):
assert "Single CPU:" in result
-def test_dpi(console_reporter):
+def test_dpi(console_reporter, result_path):
""" Test dpi report"""
- result = console_reporter.render('dpi')
+ result = console_reporter.render('dpi', result_path)
assert "Benchmark: dpi" in result
assert "Bits per Second: 3.638" in result
assert "Packets per Second: 1.45" in result
@@ -55,10 +63,10 @@ def test_dpi(console_reporter):
assert "Packets per Second: 1.458" in result
-def test_ramspeed(console_reporter):
+def test_ramspeed(console_reporter, result_path):
""" Test ramspeed report """
- result = console_reporter.render('ramspeed')
+ result = console_reporter.render('ramspeed', result_path)
assert "Float Addition: 10217.62" in result
assert "Float Average: 9176.88" in result
assert "Float Copy: 8127.13" in result
@@ -68,10 +76,10 @@ def test_ramspeed(console_reporter):
assert "Integer Average: 11396.35" in result
-def test_ssl(console_reporter):
+def test_ssl(console_reporter, result_path):
""" Test ssl report"""
- result = console_reporter.render('ssl')
+ result = console_reporter.render('ssl', result_path)
assert "AES 128 CBC (bytes):" in result
assert "256: 584951.30k" in result
assert "RSA SIGN:" in result
@@ -80,10 +88,10 @@ def test_ssl(console_reporter):
assert "4096: 7688.5" in result
-def test_sys(console_reporter):
+def test_sys(console_reporter, result_path):
""" Test sys_info """
- result = console_reporter.render('ssl')
+ result = console_reporter.render('ssl', result_path)
assert "System Information:" in result
assert "Host Name: node-38.zte.com.cn" in result
assert "Memory: 4403.7/128524.1MB" in result