ext: Remove LogWrapper/TestLogWrapper from log.py
authorGiacomo Travaglini <giacomo.travaglini@arm.com>
Thu, 11 Jun 2020 11:45:27 +0000 (12:45 +0100)
committerGiacomo Travaglini <giacomo.travaglini@arm.com>
Thu, 18 Jun 2020 14:28:14 +0000 (14:28 +0000)
This patch is removing:

* LogWrapper (wrapping Log)
* TestLogWrapper (wrapping LogWrapper)

There is now a single Log class to be used for logging

JIRA: https://gem5.atlassian.net/projects/GEM5/issues/GEM5-533

Change-Id: I038298565e2ccbe448664a538f888c96fdce8f4a
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/30234
Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Hoa Nguyen <hoanguyen@ucdavis.edu>
ext/testlib/log.py
ext/testlib/main.py
ext/testlib/runner.py

index 451ee1dc64fe80f4ac754533a16941decff8754b..1bdb373b2809a94679e71e700c326574b05f1dbf 100644 (file)
@@ -110,7 +110,19 @@ class LibraryMessage(Record):
 
 
 class Log(object):
-    def __init__(self):
+    _result_typemap = {
+        wrappers.LoadedLibrary.__name__: LibraryResult,
+        wrappers.LoadedSuite.__name__: SuiteResult,
+        wrappers.LoadedTest.__name__: TestResult,
+    }
+    _status_typemap = {
+        wrappers.LoadedLibrary.__name__: LibraryStatus,
+        wrappers.LoadedSuite.__name__: SuiteStatus,
+        wrappers.LoadedTest.__name__: TestStatus,
+    }
+
+    def __init__(self, test=None):
+        self.test = test
         self.handlers = []
         self._opened = False # TODO Guards to methods
         self._closed = False # TODO Guards to methods
@@ -133,39 +145,15 @@ class Log(object):
         for handler in self.handlers:
             handler.handle(record)
 
-    def add_handler(self, handler):
-        if self._opened:
-            raise Exception('Unable to add a handler once the log is open.')
-        self.handlers.append(handler)
-
-    def close_handler(self, handler):
-        handler.close()
-        self.handlers.remove(handler)
-
-class LogWrapper(object):
-    _result_typemap = {
-        wrappers.LoadedLibrary.__name__: LibraryResult,
-        wrappers.LoadedSuite.__name__: SuiteResult,
-        wrappers.LoadedTest.__name__: TestResult,
-    }
-    _status_typemap = {
-        wrappers.LoadedLibrary.__name__: LibraryStatus,
-        wrappers.LoadedSuite.__name__: SuiteStatus,
-        wrappers.LoadedTest.__name__: TestStatus,
-    }
-    def __init__(self, log):
-        self.log_obj = log
-
-    def log(self, *args, **kwargs):
-        self.log_obj.log(*args, **kwargs)
-
-    # Library Logging Methods
-    # TODO Replace these methods in a test/create a wrapper?
-    # That way they still can log like this it's just hidden that they
-    # capture the current test.
     def message(self, message, level=LogLevel.Info, bold=False, **metadata):
-        self.log_obj.log(LibraryMessage(message=message, level=level,
-                bold=bold, **metadata))
+        if self.test:
+            record = TestMessage(message=message, level=level,
+                test_uid=self.test.uid, suite_uid=self.test.parent_suite.uid)
+        else:
+            record = LibraryMessage(message=message, level=level,
+                bold=bold, **metadata)
+
+        self.log(record)
 
     def error(self, message):
         self.message(message, LogLevel.Error)
@@ -182,52 +170,21 @@ class LogWrapper(object):
     def trace(self, message):
         self.message(message, LogLevel.Trace)
 
-    # Ongoing Test Logging Methods
     def status_update(self, obj, status):
-        self.log_obj.log(
-                self._status_typemap[obj.__class__.__name__](obj, status))
+        self.log(
+            self._status_typemap[obj.__class__.__name__](obj, status))
 
     def result_update(self, obj, result):
-        self.log_obj.log(
-                self._result_typemap[obj.__class__.__name__](obj, result))
-
-    def test_message(self, test, message, level):
-        self.log_obj.log(TestMessage(message=message, level=level,
-                test_uid=test.uid, suite_uid=test.parent_suite.uid))
-
-    # NOTE If performance starts to drag on logging stdout/err
-    # replace metadata with just test and suite uid tags.
-    def test_stdout(self, test, suite, buf):
-        self.log_obj.log(TestStdout(buffer=buf, metadata=test.metadata))
-
-    def test_stderr(self, test, suite, buf):
-        self.log_obj.log(TestStderr(buffer=buf, metadata=test.metadata))
-
-    def close(self):
-        self.log_obj.close()
-
-class TestLogWrapper(object):
-    def __init__(self, log, test, suite):
-        self.log_obj = log
-        self.test = test
-
-    def test_message(self, message, level):
-        self.log_obj.test_message(test=self.test,
-                message=message, level=level)
-
-    def error(self, message):
-        self.test_message(message, LogLevel.Error)
-
-    def warn(self, message):
-        self.test_message(message, LogLevel.Warn)
+        self.log(
+            self._result_typemap[obj.__class__.__name__](obj, result))
 
-    def info(self, message):
-        self.test_message(message, LogLevel.Info)
-
-    def debug(self, message):
-        self.test_message(message, LogLevel.Debug)
+    def add_handler(self, handler):
+        if self._opened:
+            raise Exception('Unable to add a handler once the log is open.')
+        self.handlers.append(handler)
 
-    def trace(self, message):
-        self.test_message(message, LogLevel.Trace)
+    def close_handler(self, handler):
+        handler.close()
+        self.handlers.remove(handler)
 
-test_log = LogWrapper(Log())
+test_log = Log()
index 9c9ed03dd1ad9ea85a857e0198cdda170ef0d2ae..198b010ee0ac7a0792d8066345b302eb6b2b932f 100644 (file)
@@ -56,7 +56,7 @@ class RunLogHandler():
         self.mp_handler = handlers.MultiprocessingHandlerWrapper(
                 summary_handler, term_handler)
         self.mp_handler.async_process()
-        log.test_log.log_obj.add_handler(self.mp_handler)
+        log.test_log.add_handler(self.mp_handler)
         entry_message()
 
     def schedule_finalized(self, test_schedule):
@@ -214,7 +214,7 @@ def do_list():
         verbosity=configuration.config.verbose+log.LogLevel.Info,
         machine_only=configuration.config.quiet
     )
-    log.test_log.log_obj.add_handler(term_handler)
+    log.test_log.add_handler(term_handler)
 
     entry_message()
 
index bd50b813a5359a9926fa865c61773166d5a03259..9b096376f6d3d90849416a554dba0e3431307ca8 100644 (file)
@@ -79,7 +79,7 @@ class TestParameters(object):
     def __init__(self, test, suite):
         self.test = test
         self.suite = suite
-        self.log = log.TestLogWrapper(log.test_log, test, suite)
+        self.log = log.Log(test)
 
     @helper.cacheresult
     def _fixtures(self):