Skip to content

Commit ef29365

Browse files
authored
Add JLINKARM_SetLogFile support (#90)
* Add JLINKARM_SetLogFile Support.
1 parent 2e01645 commit ef29365

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

pylink/jlink.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,25 @@ def test(self):
810810
res = self._dll.JLINKARM_Test()
811811
return (res == 0)
812812

813+
@open_required
814+
def set_log_file(self, file_path):
815+
"""Sets the log file output path.
816+
see https://wiki.segger.com/Enable_J-Link_log_file
817+
818+
Args:
819+
self (JLink): the ``JLink`` instance
820+
file_path (str): the file path where the log file will be stored
821+
822+
Returns:
823+
``None``
824+
825+
Raises:
826+
JLinkException: if the path specified is invalid.
827+
"""
828+
res = self._dll.JLINKARM_SetLogFile(file_path.encode())
829+
if res:
830+
raise errors.JLinkException(res)
831+
813832
@open_required
814833
def invalidate_firmware(self):
815834
"""Invalidates the emulator's firmware.

tests/unit/test_jlink.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6201,6 +6201,32 @@ def test_cp15_register_write_raises_exception_if_CP15_WriteEx_fails(self):
62016201
with self.assertRaises(JLinkException):
62026202
self.jlink.cp15_register_write(0, 0, 0, 0, 0)
62036203

6204+
def test_set_log_file_success(self):
6205+
"""Tests that set_log_file uses provided parameters.
6206+
6207+
Args:
6208+
self (TestJLink): the ``TestJLink`` instance
6209+
6210+
Returns:
6211+
``None``
6212+
"""
6213+
args = ['my/file/path']
6214+
self.dll.JLINKARM_SetLogFile.return_value = 0
6215+
self.jlink.set_log_file(*args)
6216+
assert self.dll.JLINKARM_SetLogFile.called_once_with(*args)
6217+
6218+
def test_set_log_file_raises_exception_if_SetLogFile_fails(self):
6219+
"""Tests that set_log_file raises a JLinkException on failure.
6220+
Args:
6221+
self (TestJLink): the ``TestJLink`` instance
6222+
6223+
Returns:
6224+
``None``
6225+
"""
6226+
self.dll.JLINKARM_SetLogFile.return_value = -1
6227+
with self.assertRaises(JLinkException):
6228+
self.jlink.set_log_file('my/file/path')
6229+
62046230

62056231
if __name__ == '__main__':
62066232
unittest.main()

0 commit comments

Comments
 (0)