summaryrefslogtreecommitdiff
path: root/build-aux/measurestack/test_app_plugins.py
diff options
context:
space:
mode:
Diffstat (limited to 'build-aux/measurestack/test_app_plugins.py')
-rw-r--r--build-aux/measurestack/test_app_plugins.py137
1 files changed, 129 insertions, 8 deletions
diff --git a/build-aux/measurestack/test_app_plugins.py b/build-aux/measurestack/test_app_plugins.py
index abdccca..8aa0a6c 100644
--- a/build-aux/measurestack/test_app_plugins.py
+++ b/build-aux/measurestack/test_app_plugins.py
@@ -104,15 +104,21 @@ def test_assert_msg_fail() -> None:
assert BaseName("__assert_msg_fail") in models
orig_model = models[BaseName("__assert_msg_fail")]
- def wrapped_model_fn(chain: typing.Sequence[QName], call: QName) -> bool:
- assert len(chain) > 1
- assert chain[-1] == QName("__assert_msg_fail")
- assert (
- "=>".join(str(c) for c in chain)
- == "__assert_msg_fail=>__lm_light_printf=>fmt_vfctprintf=>stdio_putchar=>__assert_msg_fail"
+ def wrapped_model_fn(
+ chain: typing.Sequence[QName], node: Node, call: QName
+ ) -> bool:
+ dbgstr = (
+ ("=>".join(str(c) for c in [*chain, node.funcname]))
+ + "=?=>"
+ + str(call)
)
- assert call in [QName("__lm_light_printf"), QName("__lm_abort")]
- return orig_model.fn(chain, call)
+ assert dbgstr in [
+ "__assert_msg_fail=?=>__lm_light_printf",
+ "__assert_msg_fail=?=>__lm_abort",
+ "__assert_msg_fail=>__lm_light_printf=>fmt_vfctprintf=>stdio_putchar=>__assert_msg_fail=?=>__lm_light_printf",
+ "__assert_msg_fail=>__lm_light_printf=>fmt_vfctprintf=>stdio_putchar=>__assert_msg_fail=?=>__lm_abort",
+ ]
+ return orig_model.fn(chain, node, call)
models[BaseName("__assert_msg_fail")] = SkipModel(
orig_model.nchain, wrapped_model_fn
@@ -136,3 +142,118 @@ def test_assert_msg_fail() -> None:
aprime_assert(
s, result.groups["Main"].rows[QName("main")].nstatic, [0, 1, 3, 6, 5, 1, 2]
)
+
+
+def test_fct() -> None:
+ num_funcs = 13
+ max_call_depth = 12
+ s = aprime_gen(num_funcs, max_call_depth)
+
+ class TestPlugin:
+ def is_intrhandler(self, name: QName) -> bool:
+ return False
+
+ def init_array(self) -> typing.Collection[QName]:
+ return []
+
+ def extra_includes(self) -> typing.Collection[BaseName]:
+ return []
+
+ def indirect_callees(
+ self, loc: str, line: str
+ ) -> tuple[typing.Collection[QName], bool] | None:
+ return None
+
+ def skipmodels(self) -> dict[BaseName, analyze.SkipModel]:
+ return {}
+
+ def extra_nodes(self) -> typing.Collection[Node]:
+ # 1. | a +s[0] | b +s[ 1] | c +s[ 2] |*
+ # 2. | fmt_vsnprintf +s[3] | vprintf +s[ 4] | __lm_light_printf +s[ 5] |*
+ # 3. | fmt_vfctprintf +s[6] | fmt_vfctprintf +s[ 6] | fmt_vfctprintf +s[ 6] |
+ # 4. | fmt_state_putchar +s[7] | fmt_state_putchar +s[ 7] | fmt_state_putchar +s[ 7] |
+ # 5. | _out_buffer +s[8] | stdio_buffered_printer +s[ 9] | libfmt_light_fct +s[10] |*
+ # 6. | | __assert_msg_fail +s[11] | __assert_msg_fail +s[11] |
+ # 7. | | a. __lm_light_printf +s[ 5] | a. __lm_light_printf +s[ 5] |
+ # 8. | | a. fmt_vfctprintf +s[ 6] | a. fmt_vfctprintf +s[ 6] |
+ # 9. | | a. fmt_state_putchar +s[ 7] | a. fmt_state_putchar +s[ 7] |
+ # 10. | | a. libfmt_light_fct +s[10] | a. libfmt_light_fct +s[10] |
+ # 11. | | a. __assert_msg_fail +s[11] | a. __assert_msg_fail +s[11] |
+ # 12. | | a. __lm_abort +s[12] | a. __lm_abort +s[12] |
+ # 7. | | b. __lm_abort | b. __lm_abort |
+ return [
+ # main.c
+ util.synthetic_node("a", s[0], {"fmt_vsnprintf"}), # _out_buffer
+ util.synthetic_node("b", s[1], {"vprintf"}), # stdio_buffered_printer
+ util.synthetic_node(
+ "c", s[2], {"__lm_light_printf"}
+ ), # libfmt_light_printf
+ # wrappers
+ util.synthetic_node("fmt_vsnprintf", s[3], {"fmt_vfctprintf"}),
+ util.synthetic_node("__wrap_vprintf", s[4], {"fmt_vfctprintf"}),
+ util.synthetic_node("__lm_light_printf", s[5], {"fmt_vfctprintf"}),
+ # printf.c
+ util.synthetic_node("fmt_vfctprintf", s[6], {"fmt_state_putchar"}),
+ util.synthetic_node(
+ "fmt_state_putchar",
+ s[7],
+ {"_out_buffer", "stdio_buffered_printer", "libfmt_light_fct"},
+ ),
+ # fcts
+ util.synthetic_node("_out_buffer", s[8]),
+ util.synthetic_node(
+ "stdio_buffered_printer", s[9], {"__assert_msg_fail"}
+ ),
+ util.synthetic_node("libfmt_light_fct", s[10], {"__assert_msg_fail"}),
+ # assert.c
+ util.synthetic_node(
+ "__assert_msg_fail",
+ s[11],
+ {"__lm_light_printf", "__lm_abort"},
+ ),
+ # intercept.c / libfmt/libmisc.c
+ util.synthetic_node("__lm_abort", s[12]),
+ ]
+
+ plugins: list[util.Plugin] = [
+ TestPlugin(),
+ app_plugins.LibMiscPlugin(arg_c_fnames=[]),
+ # fmt_vsnprintf => fct=_out_buffer
+ # if rp2040:
+ # __wrap_vprintf => fct=stdio_buffered_printer
+ # stdio_vprintf => fct=stdio_buffered_printer
+ # __lm_light_printf => fct=libfmt_light_fct
+ # if host:
+ # __lm_printf => fct=libfmt_libc_fct
+ # __lm_light_printf => fct=libfmt_libc_fct
+ app_plugins.PicoFmtPlugin("rp2040"),
+ ]
+
+ def test_filter(name: QName) -> tuple[int, bool]:
+ if str(name.base()) in ["a", "b", "c"]:
+ return 1, True
+ return 0, False
+
+ def _str_location_xform(loc: str) -> str:
+ return loc
+
+ result = analyze.analyze(
+ ci_fnames=[],
+ app_func_filters={
+ "Main": test_filter,
+ },
+ app=util.PluginApplication(_str_location_xform, plugins),
+ cfg_max_call_depth=max_call_depth,
+ )
+
+ aprime_assert(s, result.groups["Main"].rows[QName("a")].nstatic, [0, 3, 6, 7, 8])
+ aprime_assert(
+ s,
+ result.groups["Main"].rows[QName("b")].nstatic,
+ [1, 4, 6, 7, 9, 11, 5, 6, 7, 10, 11, 12],
+ )
+ aprime_assert(
+ s,
+ result.groups["Main"].rows[QName("c")].nstatic,
+ [2, 5, 6, 7, 10, 11, 5, 6, 7, 10, 11, 12],
+ )