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

Support argument parsing in L3's core l3_dump.py utility. #31

Merged
merged 2 commits into from
Apr 27, 2024

Conversation

gapisback
Copy link
Collaborator

@gapisback gapisback commented Apr 27, 2024

This PR includes couple of commits to add support for argument parsing to l3_dump.py script:

  • Makefile: Update all references to l3_dump.py with symbol L3_DUMP
  • [Py] l3_dump.py: Support command-line arguments

This commit enhances the L3 dumping tool, l3_dump.py to support command-line arguments.

Macintosh:[285] $ ./l3_dump.py
usage: l3_dump.py [-h] --log-file <log-file-name> --binary <program-binary> [--verbose] [--debug]
l3_dump.py: error: the following arguments are required: --log-file, --binary

Corresponding changes are made to Makefile and test-code to invoke this Python script with required command-line arguments.

NOTE to reviewer:

Just examine the last 2 commits ( refactoring and parser-support ) in this PR. They build on top of previous 2 commits that are bundled in this PR but will be checked-in separately.

With all the refactoring, pytests-addition and Mac/OSX-support done in previous dev work, the actual task of refactoring the l3_dump.py to add --argument-parsing was very easy!

@@ -116,6 +116,9 @@ L3_SRCDIR := $(SRCDIR)
L3_INCDIR := $(INCDIR)
USE_CASES := use-cases

# Name of L3 dump utility that unpacks L3 log-entries
L3_DUMP := l3_dump.py
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No major logic-change. Just use this symbol in this file rather than the hard-coded Python tool's name.

@@ -118,6 +118,8 @@ USE_CASES := use-cases

# Name of L3 dump utility that unpacks L3 log-entries
L3_DUMP := l3_dump.py
L3_DUMP_ARG_LOG_FILE := --log-file
L3_DUMP_ARG_BINARY := --binary
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specify Make-symbols for the required command-line flags.

@@ -636,42 +638,36 @@ run-c-tests: all-c-tests
@echo '---- Run C unit-tests: ----'
./$(C_UNIT_TEST_BIN)
@echo
./$(L3_DUMP)
python3 $(L3_DUMP) $(L3_DUMP_ARG_LOG_FILE) $(L3_C_DATA) $(L3_DUMP_ARG_BINARY) ./$(C_UNIT_TEST_BIN)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace all instances of calls to this tool to now specify the required command-line flags.

Makefile Outdated
@@ -636,42 +638,36 @@ run-c-tests: all-c-tests
@echo '---- Run C unit-tests: ----'
./$(C_UNIT_TEST_BIN)
@echo
./$(L3_DUMP)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are deleted because with built-in argument parsing, by just running the tool by itself, we will get a usage error and a hard-failure:

Macintosh:[295] $ ./l3_dump.py
usage: l3_dump.py [-h] --log-file <log-file-name> --binary <program-binary> [--verbose] [--debug]
l3_dump.py: error: the following arguments are required: --log-file, --binary

Macintosh:[296] $ echo $?
2

This breaks test-execution, so deleted this call.

, default=False
, help='Show verbose progress messages')

parser.add_argument('--debug', dest='debug_script'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added args --verbose and --debug in anticipation of using them in future. I will add test cases to exercise these in future revisions.

@gapisback gapisback marked this pull request as ready for review April 27, 2024 12:32
@gapisback gapisback requested a review from gregthelaw April 27, 2024 12:32
Aditya Gurajada added 2 commits April 27, 2024 11:49
This commit refactors Makefile to replace use of hard-coded
`l3_dump.py` with a symbol, L3_DUMP .
No other logi changes are done with this commit.
This commit enhances the L3 dumping tool, `l3_dump.py` to support
command-line arguments.

---
Macintosh:[285] $ ./l3_dump.py
usage: l3_dump.py [-h] --log-file <log-file-name> --binary <program-binary> [--verbose] [--debug]
l3_dump.py: error: the following arguments are required: --log-file, --binary
---

Corresponding changes are made to `Makefile` and test-code to invoke
this Python script with required command-line arguments.
@gapisback gapisback force-pushed the gapisback/Pyargs-parser branch from a35ea24 to 02412a5 Compare April 27, 2024 18:51
@gapisback gapisback merged commit ff1e385 into main Apr 27, 2024
4 checks passed
@gapisback gapisback deleted the gapisback/Pyargs-parser branch April 27, 2024 18:55
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.

2 participants