File: test_loadobjs.py

package info (click to toggle)
m1n1 1.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,468 kB
  • sloc: python: 42,002; ansic: 33,376; asm: 1,101; makefile: 271; xml: 177; sh: 116
file content (49 lines) | stat: -rw-r--r-- 1,740 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# SPDX-License-Identifier: MIT
"""Tests for proxyclient/m1n1/loadobjs.py"""

import pytest

from proxyclient.m1n1.loadobjs import run_tool
from proxyclient.m1n1.loadobjs import tool_output_lines


# pylint: disable=redefined-outer-name
def test_tool_output_lines(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)
    )
    if fx_toolchain.use_clang:
        assert output == fx_loadobjs_nm_output["clang"]
    else:
        assert output == fx_loadobjs_nm_output["gcc"]


def test_tool_output_lines_exception(capfd: pytest.CaptureFixture[str], fx_toolchain, fx_loadobjs_nm_error):
    """Test nm tool"""
    with pytest.raises(Exception, match=r".*nm \(args: \(\)\) exited with status 1$"):
        list(line for line in tool_output_lines(fx_toolchain.NM))
    _, err = capfd.readouterr()
    error_message = err.split(":", 1)[1]
    if fx_toolchain.use_clang:
        assert error_message == fx_loadobjs_nm_error["clang"]
    else:
        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):
    """Test nm tool"""
    run_tool(fx_toolchain.NM, "-g", fx_asm_object.elffile)
    output, _ = capfd.readouterr()
    if fx_toolchain.use_clang:
        assert output == fx_loadobjs_nm_output["clang"]
    else:
        assert output == fx_loadobjs_nm_output["gcc"]

def test_run_tool_silent(
    capfd: pytest.CaptureFixture[str], fx_toolchain, fx_asm_object
):
    """Test nm tool"""
    run_tool(fx_toolchain.NM, "-g", fx_asm_object.elffile, silent=True)
    output, _ = capfd.readouterr()
    assert output == ""