Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions proxyclient/m1n1/loadobjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@

_toolchain = Toolchain()

def _tool_env():
# Use the C locale so that tool output does not change with the host
# locale (nm symbol order, translated messages, non-ASCII characters).
return dict(os.environ, LC_ALL="C")

def tool_output_lines(progname, *args):
with subprocess.Popen([progname] + list(args),
stdout=subprocess.PIPE) as proc:
stdout=subprocess.PIPE, env=_tool_env()) as proc:
for line in proc.stdout:
yield line.decode("ascii")
proc.wait()
if proc.returncode:
raise Exception(f"{progname} (args: {args}) exited with status {proc.returncode}")

def run_tool(progname, *args, silent=False):
subprocess.check_call([progname] + list(args),
subprocess.check_call([progname] + list(args), env=_tool_env(),
stdout=subprocess.DEVNULL if silent else None)


Expand Down
25 changes: 25 additions & 0 deletions tests/python/test_proxyclient/test_m1n1/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# SPDX-License-Identifier: GPL-2.0-or-later
"""m1n1 tests common fixtures"""

import locale

import pytest

from proxyclient.m1n1.asm import ARMAsm
from proxyclient.m1n1.toolchain import Toolchain

CODE_LOCATION = 0x1238

# UTF-8 locales that do not sort like the C locale
UTF8_LOCALES = ("en_US.UTF-8", "en_GB.UTF-8", "en_AU.UTF-8", "de_DE.UTF-8")

INPUT_CODE = """
ldr x0, =0xDEADBEEF
b test
Expand Down Expand Up @@ -113,3 +118,23 @@ def fx_loadobjs_nm_error():
def fx_toolchain():
"""Return toolchain"""
return Toolchain()


@pytest.fixture(params=["C", "UTF-8"])
def fx_host_locale(request, monkeypatch):
"""Set LC_ALL to the C locale, or to an installed UTF-8 locale"""
if request.param == "C":
monkeypatch.setenv("LC_ALL", "C")
return "C"
saved = locale.setlocale(locale.LC_COLLATE)
try:
for name in UTF8_LOCALES:
try:
locale.setlocale(locale.LC_COLLATE, name)
except locale.Error:
continue
monkeypatch.setenv("LC_ALL", name)
return name
finally:
locale.setlocale(locale.LC_COLLATE, saved)
pytest.skip("no UTF-8 locale installed")
4 changes: 2 additions & 2 deletions tests/python/test_proxyclient/test_m1n1/test_loadobjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


# pylint: disable=redefined-outer-name
def test_tool_output_lines(fx_toolchain, fx_asm_object, fx_loadobjs_nm_output):
def test_tool_output_lines(fx_host_locale, fx_toolchain, fx_asm_object, fx_loadobjs_nm_output):
"""Test nm tool"""
output = "".join(
tool_output_lines(fx_toolchain.NM, "-g", fx_asm_object.elffile)
Expand All @@ -31,7 +31,7 @@ def test_tool_output_lines_exception(capfd: pytest.CaptureFixture[str], fx_toolc
assert error_message == fx_loadobjs_nm_error["gcc"]


def test_run_tool(capfd: pytest.CaptureFixture[str], fx_toolchain, fx_asm_object, fx_loadobjs_nm_output):
def test_run_tool(capfd: pytest.CaptureFixture[str], fx_host_locale, fx_toolchain, fx_asm_object, fx_loadobjs_nm_output):
"""Test nm tool"""
run_tool(fx_toolchain.NM, "-g", fx_asm_object.elffile)
output, _ = capfd.readouterr()
Expand Down