From dc07c8d87eee198443038e7cb017bb4856483f9c Mon Sep 17 00:00:00 2001
From: Sergei Trofimov <sergei.trofimov@arm.com>
Date: Wed, 27 Jan 2016 16:37:46 +0000
Subject: [PATCH 1/3] BaseLinuxDevice: added lsmod() method

Execute lsmod on the target device and parses the output into named
tuples.
---
 wlauto/common/linux/device.py | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/wlauto/common/linux/device.py b/wlauto/common/linux/device.py
index 32924af4..8c63d8b7 100644
--- a/wlauto/common/linux/device.py
+++ b/wlauto/common/linux/device.py
@@ -37,6 +37,7 @@ FSTAB_ENTRY_REGEX = re.compile(r'(\S+) on (\S+) type (\S+) \((\S+)\)')
 
 FstabEntry = namedtuple('FstabEntry', ['device', 'mount_point', 'fs_type', 'options', 'dump_freq', 'pass_num'])
 PsEntry = namedtuple('PsEntry', 'user pid ppid vsize rss wchan pc state name')
+LsmodEntry = namedtuple('LsmodEntry', ['name', 'size', 'use_count', 'used_by'])
 
 
 class BaseLinuxDevice(Device):  # pylint: disable=abstract-method
@@ -821,6 +822,24 @@ class LinuxDevice(BaseLinuxDevice):
 
     # misc
 
+    def lsmod(self):
+        """List loaded kernel modules."""
+        lines = self.execute('lsmod').splitlines()
+        entries = []
+        for line in lines[1:]:  # first line is the header
+            if not line.strip():
+                continue
+            parts = line.split()
+            name = parts[0]
+            size = int(parts[1])
+            use_count = int(parts[2])
+            if len(parts) > 3:
+                used_by = ''.join(parts[3:]).split(',')
+            else:
+                used_by = []
+            entries.append(LsmodEntry(name, size, use_count, used_by))
+        return entries
+
     def ping(self):
         try:
             # May be triggered inside initialize()

From eaabe01fa5a90ffdde76a15f116c90e3f4d6cb68 Mon Sep 17 00:00:00 2001
From: Sergei Trofimov <sergei.trofimov@arm.com>
Date: Wed, 27 Jan 2016 17:03:52 +0000
Subject: [PATCH 2/3] BaseLinuxDevice: added insmod() method.

Allows insting a kernel module on the target from a .ko located on the
host.
---
 wlauto/common/linux/device.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/wlauto/common/linux/device.py b/wlauto/common/linux/device.py
index 8c63d8b7..12191f95 100644
--- a/wlauto/common/linux/device.py
+++ b/wlauto/common/linux/device.py
@@ -840,6 +840,12 @@ class LinuxDevice(BaseLinuxDevice):
             entries.append(LsmodEntry(name, size, use_count, used_by))
         return entries
 
+    def insmod(self, path):
+        """Install a kernel module located on the host on the target device."""
+        target_path = self.path.join(self.working_directory, os.path.basename(path))
+        self.push_file(path, target_path)
+        self.execute('insmod {}'.format(target_path), as_root=True)
+
     def ping(self):
         try:
             # May be triggered inside initialize()

From da720c8613b7c7ece44f7582870a5c3521d5c29b Mon Sep 17 00:00:00 2001
From: Sergei Trofimov <sergei.trofimov@arm.com>
Date: Wed, 27 Jan 2016 16:40:41 +0000
Subject: [PATCH 3/3] pep8

---
 wlauto/commands/record.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/wlauto/commands/record.py b/wlauto/commands/record.py
index 2fc640aa..ae6e2ab1 100644
--- a/wlauto/commands/record.py
+++ b/wlauto/commands/record.py
@@ -158,6 +158,7 @@ class ReplayCommand(RecordCommand):
         self.device.execute(command)
         self.logger.info("Finished replay")
 
+
 # Used to satisfy the API
 class LightContext(object):
     def __init__(self, config):