FAFT: Support recording cr50 console on FAFT

Similar to CPU and EC, record the Cr50 (if available) console on
every FAFT test,

BUG=chrome-os-partner:56835
TEST=Ran a FAFT test and saw the cr50 console recorded.

Change-Id: I1081238d00212017a31259859e999d4b95390d82
Reviewed-on: https://chromium-review.googlesource.com/435516
Commit-Ready: Wai-Hong Tam <waihong@google.com>
Tested-by: Wai-Hong Tam <waihong@google.com>
Reviewed-by: Mary Ruthven <mruthven@chromium.org>
diff --git a/server/cros/faft/firmware_test.py b/server/cros/faft/firmware_test.py
index e86e352..e2707f4 100644
--- a/server/cros/faft/firmware_test.py
+++ b/server/cros/faft/firmware_test.py
@@ -666,8 +666,16 @@
         """Setup the CPU/EC/PD UART capture."""
         self.cpu_uart_file = os.path.join(self.resultsdir, 'cpu_uart.txt')
         self.servo.set('cpu_uart_capture', 'on')
+        self.cr50_console_file = None
         self.ec_uart_file = None
         self.usbpd_uart_file = None
+        try:
+            self.servo.set('cr50_console_capture', 'on')
+            self.cr50_console_file = os.path.join(self.resultsdir,
+                                                  'cr50_console.txt')
+        except error.TestFail as e:
+            if 'No control named' in str(e):
+                logging.warn('cr50 console capture not supported.')
         if self.faft_config.chrome_ec:
             try:
                 self.servo.set('ec_uart_capture', 'on')
@@ -694,6 +702,9 @@
         if self.cpu_uart_file:
             with open(self.cpu_uart_file, 'a') as f:
                 f.write(ast.literal_eval(self.servo.get('cpu_uart_stream')))
+        if self.cr50_console_file:
+            with open(self.cr50_console_file, 'a') as f:
+                f.write(ast.literal_eval(self.servo.get('cr50_console_stream')))
         if self.ec_uart_file and self.faft_config.chrome_ec:
             with open(self.ec_uart_file, 'a') as f:
                 f.write(ast.literal_eval(self.servo.get('ec_uart_stream')))
@@ -707,6 +718,8 @@
         # Flush the remaining UART output.
         self._record_uart_capture()
         self.servo.set('cpu_uart_capture', 'off')
+        if self.cr50_console_file:
+            self.servo.set('cr50_console_capture', 'off')
         if self.ec_uart_file and self.faft_config.chrome_ec:
             self.servo.set('ec_uart_capture', 'off')
         if (self.usbpd_uart_file and self.faft_config.chrome_ec and