| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
from pyocd.gdbserver.gdbserver import ( |
| 18 |
escape, |
| 19 |
unescape, |
| 20 |
) |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
class TestGdbServerEscaping: |
| 31 |
def test_escape_transparent(self): |
| 32 |
assert escape(b"hello") == b"hello" |
| 33 |
|
| 34 |
def test_escape_individual(self): |
| 35 |
assert escape(b"hello#foo") == b"hello}\x03foo" |
| 36 |
assert escape(b"hello$foo") == b"hello}\x04foo" |
| 37 |
assert escape(b"hello}foo") == b"hello}]foo" |
| 38 |
assert escape(b"hello*foo") == b"hello}\x0afoo" |
| 39 |
|
| 40 |
def test_escape_single(self): |
| 41 |
assert escape(b"#") == b"}\x03" |
| 42 |
assert escape(b"$") == b"}\x04" |
| 43 |
assert escape(b"}") == b"}]" |
| 44 |
assert escape(b"*") == b"}\x0a" |
| 45 |
|
| 46 |
def test_escape_combined(self): |
| 47 |
assert escape(b"#$}*") == b"}\x03}\x04}]}\x0a" |
| 48 |
assert escape(b'}}}') == b"}]}]}]" |
| 49 |
|
| 50 |
def test_unescape_transparent(self): |
| 51 |
assert unescape(b"bytes") == list(b"bytes") |
| 52 |
|
| 53 |
def test_unescape_individual(self): |
| 54 |
assert unescape(b"hello}\x03foo") == list(b"hello#foo") |
| 55 |
assert unescape(b"hello}\x04foo") == list(b"hello$foo") |
| 56 |
assert unescape(b"hello}]foo") == list(b"hello}foo") |
| 57 |
assert unescape(b"hello}\x0afoo") == list(b"hello*foo") |
| 58 |
|
| 59 |
def test_unescape_single(self): |
| 60 |
assert unescape(b"}\x03") == [b'#'[0]] |
| 61 |
assert unescape(b"}\x04") == [b'$'[0]] |
| 62 |
assert unescape(b"}]") == [b'}'[0]] |
| 63 |
assert unescape(b"}\x0a") == [b'*'[0]] |
| 64 |
|
| 65 |
def test_unescape_combined(self): |
| 66 |
assert unescape(b"}\x03}\x04}]}\x0a") == list(b"#$}*") |
| 67 |
assert unescape(b"}]}]}]") == list(b"}}}") |