fix(hftest): recover from UTF-8 errors in logs
Strings logged by `dlog` may contain arbitrary bytes, which may not be
valid UTF-8. This can cause `hftest` to crash when reading the log
files.
Change `read_file` to open files with the `backslashreplace` error
handler, so that bytes that are invalid UTF-8 will be replaced with
backslash escape sequences.
Example:
```c
HFTEST_LOG("Hello, world \x80");
```
Before:
```
File "/Users/karmea01/git/work/spm/./test/hftest/hftest.py", line 73, in read_file
return f.read()
^^^^^^^^
File "<frozen codecs>", line 322, in decode
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 2350: invalid start byte
```
After:
```
[1 0] [hftest] hello world \x80
```
Change-Id: I8d729846d27c94d5f227bbcebb764a2d0a8659de
Signed-off-by: Karl Meakin <karl.meakin@arm.com>
diff --git a/test/hftest/hftest.py b/test/hftest/hftest.py
index 85ed905..45e844f 100755
--- a/test/hftest/hftest.py
+++ b/test/hftest/hftest.py
@@ -69,7 +69,7 @@
QEMU_CPU_MAX = "max,pauth-impdef=true"
def read_file(path):
- with open(path, "r") as f:
+ with open(path, "r", encoding="utf-8", errors="backslashreplace") as f:
return f.read()
def write_file(path, to_write, append=False):