Skip to content

Commit

Permalink
[ISSUE-188] Add jlink script file support via set_script_file() (#210)
Browse files Browse the repository at this point in the history
Adds support to specify a script file via `set_script_file()` as detailed
in ISSUE-188.
  • Loading branch information
gtowers-dukosi authored Sep 3, 2024
1 parent 1cb1253 commit d29e6b0
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pylink/jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,27 @@ def set_log_file(self, file_path):
if res:
raise errors.JLinkException(res)

@open_required
def set_script_file(self, file_path):
"""Sets the custom `Script File`_ to use.
Args:
self (JLink): the ``JLink`` instance
file_path (str): file path to the JLink script file to be used
Returns:
``None``
Raises:
JLinkException: if the path specified is invalid.
.. _Script File:
https://wiki.segger.com/J-Link_script_files
"""
res = self.exec_command('scriptfile = %s' % file_path)
if res:
raise errors.JLinkException('Failed to set JLink Script File: %r' % file_path)

@open_required
def invalidate_firmware(self):
"""Invalidates the emulator's firmware.
Expand Down
30 changes: 30 additions & 0 deletions tests/unit/test_jlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -6260,6 +6260,36 @@ def test_set_log_file_raises_exception_if_SetLogFile_fails(self):
with self.assertRaises(JLinkException):
self.jlink.set_log_file('my/file/path')

def test_set_script_file_success(self):
"""Tests that set_script_file uses provided parameters.
Args:
self (TestJLink): the ``TestJLink`` instance
Returns:
``None``
"""
args = ['my/file/path']
expected = ['scriptfile = my/file/path']
self.jlink.exec_command = mock.Mock()
self.jlink.exec_command.return_value = 0

self.jlink.set_script_file(*args)
self.jlink.exec_command.assert_called_once_with(*expected)

def test_set_script_file_raises_exception_if_exec_command_fails(self):
"""Tests that set_script_file raises a JLinkException on failure.
Args:
self (TestJLink): the ``TestJLink`` instance
Returns:
``None``
"""
self.jlink.exec_command = mock.Mock()
self.jlink.exec_command.return_value = -1
with self.assertRaises(JLinkException):
self.jlink.set_script_file('my/file/path')


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

0 comments on commit d29e6b0

Please sign in to comment.