summaryrefslogtreecommitdiff
path: root/zephyr/zmake
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-05-20 14:50:54 -0600
committerCommit Bot <commit-bot@chromium.org>2021-05-26 02:53:57 +0000
commit6618432597ee657c4c878879b82caacf1dc427c9 (patch)
treeeb18b998e89a479bc47028519430fcb8bc355164 /zephyr/zmake
parent52b9dbb7d0ff0bf58bd3d2cedaeb9a21515bcff7 (diff)
downloadchrome-ec-6618432597ee657c4c878879b82caacf1dc427c9.tar.gz
zmake: Allow filter tests to be run without pytest
Put these tests in a class and add a main program so we can run the tests directly. This makes it easier to see any output produced by the test, for debugging purposes. For example a print() added to a test will not be suppressed. This makes debugging easier. BUG=b:184298184 BRANCH=none TEST=(cd zephyr/zmake/; PYTHONPATH=`pwd` python3 tests/test_zmake.py TestFunctional.test_filter ) Signed-off-by: Simon Glass <sjg@chromium.org> Change-Id: Ic5384d8926e54322a4bf828dd6ee91b1ab4507ff Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2911474 Reviewed-by: Jeremy Bettis <jbettis@chromium.org> Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
Diffstat (limited to 'zephyr/zmake')
-rw-r--r--zephyr/zmake/tests/test_zmake.py100
1 files changed, 54 insertions, 46 deletions
diff --git a/zephyr/zmake/tests/test_zmake.py b/zephyr/zmake/tests/test_zmake.py
index eef63a31cb..82c9704cb4 100644
--- a/zephyr/zmake/tests/test_zmake.py
+++ b/zephyr/zmake/tests/test_zmake.py
@@ -9,6 +9,7 @@ import os
import pathlib
import re
import tempfile
+import unittest
import unittest.mock as mock
from unittest.mock import patch
@@ -108,49 +109,56 @@ def do_test_with_log_level(log_level):
return recs, tmpname
-def test_filter_normal():
- """Test filtering of a normal build (with no errors)"""
- recs, _ = do_test_with_log_level(logging.ERROR)
- assert not recs
-
-
-def test_filter_info():
- """Test what appears on the INFO level"""
- recs, tmpname = do_test_with_log_level(logging.INFO)
- # TODO: Remove sets and figure out how to check the lines are in the
- # right order.
- expected = {
- 'Building {}:build-ro: /usr/bin/ninja -C {}/build-build-ro'.format(
- tmpname, tmpname),
- 'Building {}:build-rw: /usr/bin/ninja -C {}/build-build-rw'.format(
- tmpname, tmpname),
- }
- for suffix in ['ro', 'rw']:
- with open(get_test_filepath('%s_INFO' % suffix)) as f:
- for line in f:
- expected.add(
- "[{}:build-{}]{}".format(tmpname, suffix, line.strip()))
- # This produces an easy-to-read diff if there is a difference
- assert set(recs) == expected
-
-
-def test_filter_debug():
- """Test what appears on the DEBUG level"""
- recs, tmpname = do_test_with_log_level(logging.DEBUG)
- # TODO: Remove sets and figure out how to check the lines are in the
- # right order.
- expected = {
- 'Building {}:build-ro: /usr/bin/ninja -C {}/build-build-ro'.format(
- tmpname, tmpname),
- 'Building {}:build-rw: /usr/bin/ninja -C {}/build-build-rw'.format(
- tmpname, tmpname),
- 'Running cat {}/files/sample_ro.txt'.format(OUR_PATH),
- 'Running cat {}/files/sample_rw.txt'.format(OUR_PATH),
- }
- for suffix in ['ro', 'rw']:
- with open(get_test_filepath(suffix)) as f:
- for line in f:
- expected.add(
- "[{}:build-{}]{}".format(tmpname, suffix, line.strip()))
- # This produces an easy-to-read diff if there is a difference
- assert set(recs) == expected
+class TestFilters(unittest.TestCase):
+ """Test filtering of stdout and stderr"""
+
+ def test_filter_normal(self):
+ """Test filtering of a normal build (with no errors)"""
+ recs, _ = do_test_with_log_level(logging.ERROR)
+ self.assertFalse(recs)
+
+
+ def test_filter_info(self):
+ """Test what appears on the INFO level"""
+ recs, tmpname = do_test_with_log_level(logging.INFO)
+ # TODO: Remove sets and figure out how to check the lines are in the
+ # right order.
+ expected = {
+ 'Building {}:build-ro: /usr/bin/ninja -C {}/build-build-ro'.format(
+ tmpname, tmpname),
+ 'Building {}:build-rw: /usr/bin/ninja -C {}/build-build-rw'.format(
+ tmpname, tmpname),
+ }
+ for suffix in ['ro', 'rw']:
+ with open(get_test_filepath('%s_INFO' % suffix)) as f:
+ for line in f:
+ expected.add(
+ "[{}:build-{}]{}".format(tmpname, suffix, line.strip()))
+ # This produces an easy-to-read diff if there is a difference
+ self.assertEqual(expected, set(recs))
+
+
+ def test_filter_debug(self):
+ """Test what appears on the DEBUG level"""
+ recs, tmpname = do_test_with_log_level(logging.DEBUG)
+ # TODO: Remove sets and figure out how to check the lines are in the
+ # right order.
+ expected = {
+ 'Building {}:build-ro: /usr/bin/ninja -C {}/build-build-ro'.format(
+ tmpname, tmpname),
+ 'Building {}:build-rw: /usr/bin/ninja -C {}/build-build-rw'.format(
+ tmpname, tmpname),
+ 'Running cat {}/files/sample_ro.txt'.format(OUR_PATH),
+ 'Running cat {}/files/sample_rw.txt'.format(OUR_PATH),
+ }
+ for suffix in ['ro', 'rw']:
+ with open(get_test_filepath(suffix)) as f:
+ for line in f:
+ expected.add(
+ "[{}:build-{}]{}".format(tmpname, suffix, line.strip()))
+ # This produces an easy-to-read diff if there is a difference
+ self.assertEqual(expected, set(recs))
+
+
+if __name__ == "__main__":
+ unittest.main()