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

fix the output formatting of table mode #30

Merged
merged 5 commits into from
Mar 13, 2022
Merged

Conversation

rohoog
Copy link

@rohoog rohoog commented Mar 12, 2022

See issue #29

Sorry I'm not familiar with this more pythonic .format method; I used the trusty old printf style 'interpolation' instead.

@rohoog
Copy link
Author

rohoog commented Mar 12, 2022

Looks like the failures are due to upper/lower case hex. This should not be an issue, but I will change %x to %X to get the same casing as before.

@Nicoretti
Copy link
Owner

Nicoretti commented Mar 12, 2022

Hi @rohoog,

thanks for creating a PR to address #29, really appreciate it.
A question from my side, could you add a regression test for the issue at hand?
(So we can be sure the behavior will stay correct in the future)

You can have a look at cli_test.py to get an idea how such a test could look like.

Regarding the python format string vs printf style, I rather would like to keep the format string one, but I will be happy to help you out there if you want me to. In case you want to dig into it by yourself first these links may help:

At first glance I think the alignment within the format string is the issue <
(We may just need to remove or replace it with the appropriate alignment)

best
Nico

@rohoog
Copy link
Author

rohoog commented Mar 12, 2022

I am not such a python guru as you might think...
The way to test such things is to use the table exporting, put it in a file (or pipe) and read it back in as the contents of the _lookup of the TableBasedCrcRegister and compare the result of CRC remainder from the built-in generated table (which works fine) and the remainder using the table read back from the file. This way you can easily cover all cases (although one case is enough to detect the bug).

@Nicoretti
Copy link
Owner

Nicoretti commented Mar 12, 2022

@rohoog
I don't think covering all cases is needed, but having the use case which exposed the bug would be nice to have.
I think this can be done similarly like in the test by just adjusting the expected_output and the argv which
have been used.

I am not such a python guru as you might think...

No problem I will guide you if you are interested in getting your PR integrated.
If you feel overwhelmed or just want to get the issue out of the way I recommend you fix it in your fork and use that one for
now. I try to address the issue as soon as I can make some time for it.

@rohoog
Copy link
Author

rohoog commented Mar 12, 2022

Could it even be that the expected output for the crc8 poly 0x1D is actually wrong? So that just fixing that one will 'test' it properly? I see no values starting with 0x0 (except for 0x00), while there should definitely be some.
I mean just inserting the (now correctly) outputted table for that polynomial is sufficient. I think it is a bit /wrong/ to test like that... but that is another discussion.

@rohoog
Copy link
Author

rohoog commented Mar 12, 2022

OK done that as well.

crc.py Outdated Show resolved Hide resolved
@rohoog
Copy link
Author

rohoog commented Mar 12, 2022

Implementation result driven testing instead of test driven development.... 😕

@Nicoretti
Copy link
Owner

Nicoretti commented Mar 12, 2022

Implementation result driven testing instead of test driven development.... confused

I need to hit the bed now. As soon as I can I will validate that outputted tables are correct.
If we validate that the output is correct, then add it and keep them as test I rather would say it's a
"snapshot" based "integration" test. Similar to what cram and prysk are doing.

If we only would add without checking I agree it would not really a "test".

@rohoog
Copy link
Author

rohoog commented Mar 12, 2022

Hurray! Success!

crc.py Outdated Show resolved Hide resolved
@@ -29,38 +29,38 @@ def test_table_subcommand_with_no_additional_arguments(self):

def test_table_generation_for_width_8_and_poly_0x1D(self):
expected_output = io.StringIO(inspect.cleandoc("""
Copy link
Owner

Choose a reason for hiding this comment

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

I have checked the table, looks like the one you added is correct. Apparently this test was setup incorrectly.

crc.py Outdated Show resolved Hide resolved
@Nicoretti Nicoretti linked an issue Mar 13, 2022 that may be closed by this pull request
@Nicoretti Nicoretti merged commit 6fd0a6f into Nicoretti:master Mar 13, 2022
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.

lookup table generation output is wrong
2 participants