Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LEDGER_ASSERT improvments and CX_ASSERT addition #504

Merged
merged 5 commits into from
Jan 24, 2024

Conversation

xchapron-ledger
Copy link
Contributor

@xchapron-ledger xchapron-ledger commented Jan 15, 2024

Description

Add some documentation for LEDGER_ASSERT
Allow printf like usage of LEDGER_ASSERT for error message
Minor cleanup on CX includes
Add CX_ASSERT macro

Changes include

  • Bugfix (non-breaking change that solves an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (change that is not backwards-compatible and/or changes current functionality)
  • Tests
  • Documentation
  • Other (for changes that might not fit in any category)

@xchapron-ledger xchapron-ledger force-pushed the xch/cx-assert branch 2 times, most recently from 80d5665 to 6cae869 Compare January 18, 2024 10:43
@codecov-commenter
Copy link

codecov-commenter commented Jan 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3a12ddd) 60.42% compared to head (69c8890) 60.42%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #504   +/-   ##
=======================================
  Coverage   60.42%   60.42%           
=======================================
  Files          12       12           
  Lines        1660     1660           
=======================================
  Hits         1003     1003           
  Misses        657      657           
Flag Coverage Δ
unittests 60.42% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xchapron-ledger xchapron-ledger force-pushed the xch/cx-assert branch 3 times, most recently from b9f60d6 to 8616507 Compare January 18, 2024 14:44
@xchapron-ledger xchapron-ledger marked this pull request as ready for review January 18, 2024 14:45
@xchapron-ledger
Copy link
Contributor Author

xchapron-ledger commented Jan 18, 2024

EDIT: not used anymore, but we never know, it might be useful at some point?

For future, here is the script used to generate most of the PR (except includes and formatting):

for file in files:
    print("Working on:", file)

    with open(file, "r") as f:
        iterator = iter(f.readlines())

    with open(file, "w") as fout:
        line = next(iterator)
        while line:
            content = None

            if line.startswith("WARN_UNUSED_RESULT cx_err_t"):
                content = line
                while ";" not in content:
                    content += next(iterator)

            if content:
                fout.write(content)
                fout.write("\n")

                starters, params = content.split("(")

                # Extract params names and create a string with the list without the types
                assert params.endswith(");\n")
                params = params.replace(");\n", "")
                params_list = params.replace("\n", " ").replace("*", "").split(",")
                params_value = ", ".join([x.strip().split(" ")[-1] for x in params_list])

                # Extract func_name and create new_func_name
                func_name = starters.replace("\n", " ").split(" ")[-1]
                if func_name.endswith("_no_throw"):
                    new_func_name = func_name.replace("_no_throw", "_assert")
                else:
                    new_func_name = func_name + "_assert"

                fout.write(f"/**\n * @brief {func_name} version which doesn't return in case of failure.\n *\n * See #{func_name}\n */")
                fout.write("\n")

                fout.write("static inline void " + new_func_name + "(")
                fout.write(params)
                fout.write(")\n")

                fout.write("{\n")
                fout.write(f"    LEDGER_ASSERT({func_name}({params_value}) == CX_OK,\n")
                fout.write(f"                  \"{func_name}\");\n")
                fout.write("}\n")
            else:
                fout.write(line)

            try:
                line = next(iterator)
            except StopIteration:
                print("End of file")
                line = None

@xchapron-ledger xchapron-ledger force-pushed the xch/cx-assert branch 7 times, most recently from 36a4590 to 6ce2cab Compare January 23, 2024 13:42
@xchapron-ledger xchapron-ledger changed the title Xch/cx assert LEDGER_ASSERT improvments and CX_ASSERT addition Jan 23, 2024
@xchapron-ledger xchapron-ledger merged commit 886d8f9 into master Jan 24, 2024
157 of 161 checks passed
@xchapron-ledger xchapron-ledger deleted the xch/cx-assert branch January 24, 2024 09:30
This was referenced Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants