diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-14 15:43:31 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2025-05-14 15:43:31 -0600 |
commit | be7a0efac25f186cd0b5ad49e9d001e99d025b74 (patch) | |
tree | b501040e75caeadeb30f8aa89e2da08d2fdf6146 /build-aux/measurestack | |
parent | 811d9700e1414dae3357361b3ca565f673f63b08 (diff) |
measurestack: Woah, stdio won't assert(0)????
Diffstat (limited to 'build-aux/measurestack')
-rw-r--r-- | build-aux/measurestack/app_plugins.py | 15 | ||||
-rw-r--r-- | build-aux/measurestack/test_app_plugins.py | 300 |
2 files changed, 55 insertions, 260 deletions
diff --git a/build-aux/measurestack/app_plugins.py b/build-aux/measurestack/app_plugins.py index e365f82..1b10b67 100644 --- a/build-aux/measurestack/app_plugins.py +++ b/build-aux/measurestack/app_plugins.py @@ -129,20 +129,7 @@ class LibMiscPlugin: return None def skipmodels(self) -> dict[BaseName, analyze.SkipModel]: - return { - BaseName("__assert_msg_fail"): analyze.SkipModel( - {BaseName("__assert_msg_fail")}, self._skipmodel___assert_msg_fail - ), - } - - def _skipmodel___assert_msg_fail( - self, chain: typing.Sequence[QName], node: Node, call: QName - ) -> bool: - if call.base() in [BaseName("__lm_printf"), BaseName("__lm_light_printf")]: - return any( - c.base() == BaseName("__assert_msg_fail") for c in reversed(chain) - ) - return False + return {} class LibHWPlugin: diff --git a/build-aux/measurestack/test_app_plugins.py b/build-aux/measurestack/test_app_plugins.py index da8be65..8a29a12 100644 --- a/build-aux/measurestack/test_app_plugins.py +++ b/build-aux/measurestack/test_app_plugins.py @@ -8,106 +8,16 @@ import typing from . import analyze, app_plugins, testutil, util -from .analyze import BaseName, Node, QName, SkipModel - - -def test_assert_msg_fail() -> None: - # 1 2 3 4 5 6 7 <= call_depth - # - main() - # - __assert_msg_fail() * - # - __lm_light_printf() - # - fmt_vfctprintf() - # - stdio_putchar() - # - __assert_msg_fail() ** - # - __lm_abort() - # - stdio_flush() (inconsequential) - # - __lm_abort() (inconsequential) - max_call_depth = 7 - exp = [ - "main", - "__assert_msg_fail", - "__lm_light_printf", - "fmt_vfctprintf", - "stdio_putchar", - "__assert_msg_fail", - "__lm_abort", - ] - graph: typing.Sequence[tuple[str, typing.Collection[str]]] = [ - # main.c - ("main", {"__assert_msg_fail"}), - # assert.c - ("__assert_msg_fail", {"__lm_light_printf", "__lm_abort"}), - # intercept.c / libfmt/libmisc.c - ("__lm_abort", {}), - ("__lm_light_printf", {"fmt_vfctprintf", "stdio_flush"}), - ("stdio_flush", {}), - ("stdio_putchar", {"__assert_msg_fail"}), - # printf.c - ("fmt_vfctprintf", {"stdio_putchar"}), - ] - graph_plugin = testutil.GraphProviderPlugin(max_call_depth, graph) - - class SkipPlugin(testutil.NopPlugin): - def skipmodels(self) -> dict[BaseName, SkipModel]: - models = app_plugins.LibMiscPlugin(arg_c_fnames=[]).skipmodels() - assert BaseName("__assert_msg_fail") in models - orig_model = models[BaseName("__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 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 - ) - return models - - def test_filter(name: QName) -> tuple[int, bool]: - if name.base() == BaseName("main"): - return 1, True - return 0, False - - result = analyze.analyze( - ci_fnames=[], - app_func_filters={ - "Main": test_filter, - }, - app=util.PluginApplication( - testutil.nop_location_xform, [graph_plugin, SkipPlugin()] - ), - cfg_max_call_depth=max_call_depth, - ) - - graph_plugin.assert_nstatic(result.groups["Main"].rows[QName("main")].nstatic, exp) +from .analyze import BaseName, QName def test_fct() -> None: - # 1. | a + | b + | c + |* - # 2. | fmt_vsnprintf + | vprintf + | __lm_light_printf + |* + # 1. | a + | b + | c + | + # 2. | fmt_vsnprintf + | vprintf + | __lm_light_printf + | # 3. | fmt_vfctprintf + | fmt_vfctprintf + | fmt_vfctprintf + | # 4. | fmt_state_putchar + | fmt_state_putchar + | fmt_state_putchar + | - # 5. | _out_buffer + | stdio_buffered_printer + | libfmt_light_fct + |* - # 6. | | __assert_msg_fail + | __assert_msg_fail + | - # 7. | | a. __lm_light_printf + | a. __lm_light_printf + | - # 8. | | a. fmt_vfctprintf + | a. fmt_vfctprintf + | - # 9. | | a. fmt_state_putchar + | a. fmt_state_putchar + | - # 10. | | a. libfmt_light_fct + | a. libfmt_light_fct + | - # 11. | | a. __assert_msg_fail + | a. __assert_msg_fail + | - # 12. | | a. __lm_abort + | a. __lm_abort + | - # 7. | | b. __lm_abort | b. __lm_abort | - max_call_depth = 12 + # 5. | _out_buffer + | stdio_buffered_printer + | libfmt_light_fct + | + max_call_depth = 5 exp_a = ["a", "fmt_vsnprintf", "fmt_vfctprintf", "fmt_state_putchar", "_out_buffer"] exp_b = [ "b", @@ -115,13 +25,6 @@ def test_fct() -> None: "fmt_vfctprintf", "fmt_state_putchar", "stdio_buffered_printer", - "__assert_msg_fail", - "__lm_light_printf", - "fmt_vfctprintf", - "fmt_state_putchar", - "libfmt_light_fct", - "__assert_msg_fail", - "__lm_abort", ] exp_c = [ "c", @@ -129,13 +32,6 @@ def test_fct() -> None: "fmt_vfctprintf", "fmt_state_putchar", "libfmt_light_fct", - "__assert_msg_fail", - "__lm_light_printf", - "fmt_vfctprintf", - "fmt_state_putchar", - "libfmt_light_fct", - "__assert_msg_fail", - "__lm_abort", ] graph: typing.Sequence[tuple[str, typing.Collection[str]]] = [ # main.c @@ -154,12 +50,8 @@ def test_fct() -> None: ), # fcts ("_out_buffer", {}), - ("stdio_buffered_printer", {"__assert_msg_fail"}), - ("libfmt_light_fct", {"__assert_msg_fail"}), - # assert.c - ("__assert_msg_fail", {"__lm_light_printf", "__lm_abort"}), - # intercept.c / libfmt/libmisc.c - ("__lm_abort", {}), + ("stdio_buffered_printer", {}), + ("libfmt_light_fct", {}), ] graph_plugin = testutil.GraphProviderPlugin(max_call_depth, graph) @@ -197,43 +89,31 @@ def test_fct() -> None: def test_assert_formatter() -> None: - # _________________________________________________________ - # | | - # | | - # | main | - # | | | - # | _ __wrap_vprintf | - # | / \ | _______________ | - # | | fmt_vfctprintf / \ | - # | | \ fmt_state_printf | | - # | | \____ ____/ | | - # | | \ / | | - # | | _vfctprintf | | - # | | ____/ \____ ^ | - # | | / ?<---snip | | - # | | conv_builtin \ | | - # | | | libfmt_conv_formatter | | - # | | | | | | - # | ^ \ lib9p_msg_Rread_format | | - # | | \ _____________/ | \______/ | - # | | \ / \ | - # | | fmt_state_putchar \ | - # | | ?<-?<--------snip | | - # | | / \_________ | | - # | | / \ | | - # | | stdio_buffered_printer \ | | - # | | \ libfmt_light_fct | | - # | | \ | / | - # | | \_______ | ________/ | - # | | \ | / | - # | | __assert_msg_fail | - # | | ___/ \____ | - # | | snip--->? \ | - # | | / \ | - # | | __lm_light_printf \ | - # | \____________/ __lm_abort | - # | | - # |_________________________________________________________| + # _____________________________________________________ + # | | + # | | + # | main | + # | | | + # | __wrap_vprintf | + # | | _______________ | + # | fmt_vfctprintf / \ | + # | \ fmt_state_printf | | + # | \____ ____/ | | + # | \ / | | + # | _vfctprintf | | + # | ____/ \____ ^ | + # | / ?<---snip | | + # | conv_builtin \ | | + # | | libfmt_conv_formatter | | + # | | | | | + # | \ lib9p_msg_Rread_format | | + # | \___________ __/ \___________/ | + # | \ / | + # | fmt_state_putchar | + # | | | + # | stdio_buffered_printer | + # | | + # |_____________________________________________________| # graph: typing.Sequence[tuple[str, typing.Collection[str]]] = [ ("main", {"vprintf"}), @@ -243,94 +123,31 @@ def test_assert_formatter() -> None: ("_vfctprintf", {"conv_builtin", "libfmt_conv_formatter"}), ("conv_builtin", {"fmt_state_putchar"}), ("libfmt_conv_formatter", {"lib9p_msg_Rread_format"}), - ( - "lib9p_msg_Rread_format", - {"fmt_state_putchar", "__assert_msg_fail", "fmt_state_printf"}, - ), + ("lib9p_msg_Rread_format", {"fmt_state_putchar", "fmt_state_printf"}), ("fmt_state_putchar", {"stdio_buffered_printer", "libfmt_light_fct"}), - ("stdio_buffered_printer", {"__assert_msg_fail"}), - ("libfmt_light_fct", {"__assert_msg_fail"}), - ("__assert_msg_fail", {"__lm_light_printf", "__lm_abort"}), - ("__lm_light_printf", {"fmt_vfctprintf"}), - ("__lm_abort", {}), + ("stdio_buffered_printer", {}), + ("libfmt_light_fct", {}), # wrong fct ] - # fct-determining wrappers have their callees marked with "|": - # - # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 <= call_depth - # - main() ; + - # - __wrap__vprintf() ; + - # |- fmt_vfctprintf() ; + - # | - _vfctprintf() ; + - # | - conv_builtin() ; - # | - fmt_state_putchar() ; - # | - stdio_buffered_printer() ; - # | - __assert_msg_fail() ; - # | - __lm_light_printf() ; - # | |- fmt_vfctprintf() ; - # | | - _vfctprintf() ; - # | | - conv_builtin() ; - # | | - fmt_state_putchar() ; - # | | - stdio_buffered_printer() ; skip (wrong fct) - # | | - libfmt_light_fct() ; - # | | - __assert_msg_fail() ; - # | | - __lm_light_printf() ; skip (nested __assert_msg_fail) - # | | - __lm_abort() ; - # | | - libfmt_conv_formatter() ; skip (fct won't use %v) - # | - __lm_abort() ; - # | - libfmt_light_fct() ; skip (wrong fct) - # | - libfmt_conv_formatter() ; + - # | - lib9p_msg_Rread_format() ; + - # | - fmt_state_putchar() ; - # | - stdio_buffered_printer() ; - # | - __assert_msg_fail() ; - # | - __lm_light_printf() ; - # | |- fmt_vfctprintf() ; - # | | - _vfctprintf() ; - # | | - conv_builtin() ; - # | | - fmt_state_putchar() ; - # | | - stdio_buffered_printer() ; skip (wrong fct) - # | | - libfmt_light_fct() ; - # | | - __assert_msg_fail() ; - # | | - __lm_light_printf() ; skip (neseted __assert_msg_fail) - # | | - __lm_abort() ; - # | | - libfmt_conv_formatter() ; skip (fct won't use %v) - # | - __lm_abort() ; - # | - libfmt_light_fct() ; skip (wrong fct) - # | - __assert_msg_fail() ; - # | - __lm_light_printf() ; - # | |- fmt_vfctprintf() ; - # | | - _vfctprintf() ; - # | | - conv_builtin() ; - # | | - fmt_state_putchar() ; - # | | - stdio_buffered_printer() ; skip (wrong fct) - # | | - libfmt_light_fct() ; - # | | - __assert_msg_fail() ; - # | | - __lm_light_printf() ; skip (nested__assert_msg_fail) - # | | - __lm_abort() ; - # | | - libfmt_conv_formatter() ; skip (formatter won't use %v) - # | - __lm_abort() ; - # | - fmt_state_printf() ; + - # | - _vfctprintf() ; + - # | - conv_builtin() ; + - # | - fmt_state_putchar() ; + - # | - stdio_buffered_printer() ; + - # | - __assert_msg_fail() ; + - # | - __lm_light_printf() ; + - # | |- fmt_vfctprintf() ; + - # | | - _vfctprintf() ; + - # | | - conv_builtin() ; + - # | | - fmt_state_putchar() ; + - # | | - stdio_buffered_printer() ; skip (wrong fct) - # | | - libfmt_light_fct() ; + - # | | - __assert_msg_fail() ; + - # | | - __lm_light_printf() ; skip (neseted __assert_msg_fail) - # | | - __lm_abort() ; + - # | | - libfmt_conv_formatter() ; skip (fct won't use %v) - # | - __lm_abort() ; - # | - libfmt_light_fct() ; skip (wrong fct) - # | - libfmt_conv_formatter() ; skip (formatter won't use %v) - max_call_depth = 20 + # 1 2 3 4 5 6 7 8 9 10 11 <= call_depth + # - main() ; + + # - __wrap__vprintf() ; + + # - fmt_vfctprintf() ; + + # - _vfctprintf() ; + + # - conv_builtin() ; + # - fmt_state_putchar() ; + # - stdio_buffered_printer() ; + # - libfmt_conv_formatter() ; + + # - lib9p_msg_Rread_format() ; + + # - fmt_state_putchar() ; + # - stdio_buffered_printer() ; + # - fmt_state_printf() ; + + # - _vfctprintf() ; + + # - conv_builtin() ; + + # - fmt_state_putchar() ; + + # - stdio_buffered_printer() ; + + # - libfmt_conv_formatter() ; skip (formatter won't use %v) + max_call_depth = 11 exp = [ "main", "__wrap_vprintf", @@ -343,15 +160,6 @@ def test_assert_formatter() -> None: "conv_builtin", "fmt_state_putchar", "stdio_buffered_printer", - "__assert_msg_fail", - "__lm_light_printf", - "fmt_vfctprintf", - "_vfctprintf", - "conv_builtin", - "fmt_state_putchar", - "libfmt_light_fct", - "__assert_msg_fail", - "__lm_abort", ] graph_plugin = testutil.GraphProviderPlugin(max_call_depth, graph) |