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

Reformat the output of BIGNUMS where test cases fail. #3465

Closed
wants to merge 6 commits into from

Conversation

paulidale
Copy link
Contributor

  • tests are added or updated

Change the output from BIGNUM tests so they match the suggestions in #3341

# ERROR: (BIGNUM) 'a == b' failed @ test/test_test.c:403
# --- a
# +++ b
#                                                                     offset
# -  12345678901234 5678901234567890 1234567890123456 7890121234567890:  128
# -1234567890123456 7890123456789012 3456789012123456 7890123456789012:   96
# -3456789012345678 9012345678901212 3456789012345678 9012345678901234:   64
# -5678901234567890 1212345678901234 5678901234567890 1234567890123456:   32
# +                   12345678901234 5678901234567890 1234567890123456:   32
#  ^^^^^^^^^^^^^^^^ ^^                                                
# -7890121234567890 1234567890123456 7890123456789012 3456789012ffffff:    0
# +7890121234567890 1234567890123456 7890123456789012 3456789013987657:    0
#                                                              ^^^^^^^

The offset on the right is in bytes.

Extra test cases to display some of the output edge cases have been added.

@paulidale
Copy link
Contributor Author

That example isn't the best. The caret highlighting is per character (i.e. digit) not per byte (pair of digits).

@levitte
Copy link
Member

levitte commented May 15, 2017

I'm wondering of the highlight at the beginning is really necessary when the two number have different sizes. How about this?

# ERROR: (BIGNUM) 'a == b' failed @ test/test_test.c:403
# --- a
# +++ b
#                                                                     offset
# -  12345678901234 5678901234567890 1234567890123456 7890121234567890:  128
# -1234567890123456 7890123456789012 3456789012123456 7890123456789012:   96
# -3456789012345678 9012345678901212 3456789012345678 9012345678901234:   64
# -5678901234567890 1212345678901234 5678901234567890 1234567890123456:   32
# +                   12345678901234 5678901234567890 1234567890123456:   32
# -7890121234567890 1234567890123456 7890123456789012 3456789012ffffff:    0
# +7890121234567890 1234567890123456 7890123456789012 3456789013987657:    0
#                                                              ^^^^^^^

@paulidale
Copy link
Contributor Author

Okay, that's an improvement.
Change committed.

test/test_test.c Outdated
int r;
BIGNUM *a = NULL, *b = NULL, *c = NULL, *d = NULL;
const char as[] = "1234567890123456789012345678901234567890123456789012"
"1234567890123456789012345678901234567890123456789012"
Copy link
Contributor

Choose a reason for hiding this comment

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

Jagged formatting. I mean it looks like one white space is missing here and in number of other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, missed these.

test/test_test.c Outdated
BN_hex2bn(&a, as);
BN_hex2bn(&b, bs);
BN_hex2bn(&c, cs);
BN_hex2bn(&d, ds);
Copy link
Contributor

Choose a reason for hiding this comment

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

What if either of BN_hex2bn fails?

@dot-asm
Copy link
Contributor

dot-asm commented May 16, 2017

How about this?

Seconded.

Change committed.

# ERROR: (BIGNUM) 'a == b' failed @ test/test_test.c:403
# --- a
# +++ b
#                                                                     offset
# -  12345678901234 5678901234567890 1234567890123456 7890121234567890:  128
# -1234567890123456 7890123456789012 3456789012123456 7890123456789012:   96
# -3456789012345678 9012345678901212 3456789012345678 9012345678901234:   64
# -5678901234567890 1212345678901234 5678901234567890 1234567890123456:   32
# +                   12345678901234 5678901234567890 1234567890123456:   32
#                                                                     
# -7890121234567890 1234567890123456 7890123456789012 3456789012ffffff:    0
# +7890121234567890 1234567890123456 7890123456789012 3456789013987657:    0
#                                                              ^^^^^^^

Empty line in the middle is unnecessary/confusing...

@dot-asm
Copy link
Contributor

dot-asm commented May 16, 2017

How about this?

On side note one can wonder if it makes sense to apply this even to string and memory comparisons, i.e. excess data not being marked with carets. For example right now it reads

# ERROR: (string) 'q == r' failed @ test/test_test.c:372
# --- q
# +++ r
#    0:- '1234567890klmnopqrs01234567890EFGHIJKLM0123456789XYZ'
#    0:+ '1234567890123456789012345678901234567890123456789012abcdefghijkl'
#                   ^^^^^^^^^           ^^^^^^^^^          ^^^^^^^^^^^^^^^
#   64:+ 'mnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY+12345678901234567890123A'
#  128:+ 'BC78901234567890123456789012'

and question is if following would be more appropriate

# ERROR: (string) 'q == r' failed @ test/test_test.c:372
# --- q
# +++ r
#    0:- '1234567890klmnopqrs01234567890EFGHIJKLM0123456789XYZ'
#    0:+ '1234567890123456789012345678901234567890123456789012abcdefghijkl'
#                   ^^^^^^^^^           ^^^^^^^^^          ^^^
#   64:+ 'mnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY+12345678901234567890123A'
#  128:+ 'BC78901234567890123456789012'

One can also wonder if following would tell the story better

# ERROR: (string) 'q == r' failed @ test/test_test.c:372
# --- q
# +++ r
#    0:- '1234567890klmnopqrs01234567890EFGHIJKLM0123456789XYZ'
#    0:+ '1234567890123456789012345678901234567890123456789012'
#                   ^^^^^^^^^           ^^^^^^^^^          ^^^
#   52:+ 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY+123456789012'
#  116:+ '34567890123ABC78901234567890123456789012'

@dot-asm
Copy link
Contributor

dot-asm commented May 16, 2017

Just in case it wasn't clear, "side note" means that no modifications are expected.

@dot-asm
Copy link
Contributor

dot-asm commented May 16, 2017

But on related note, I don't quite see the value of # c is negative here and there...

I also wonder what do others think of comparison to NULL. More specifically if it makes sense to print any additional information besides 'b == NULL' failed. I mean right now it reads

# ERROR: (BIGNUM) 'b == NULL' failed @ test/test_test.c:405
# --- b
# +++ NULL
#                                                                     offset
# -                   12345678901234 5678901234567890 1234567890123456:   32
# -7890121234567890 1234567890123456 7890123456789012 3456789013987657:    0
# +                                                               NULL:    0
#                                                                 ^^^^

And question is if it's sufficient if first line alone is sufficient.

@dot-asm
Copy link
Contributor

dot-asm commented May 16, 2017

I also wonder what do others think of comparison to NULL.

This applies to other cases as well, i.e. not specifically to BN. On the other hand one can probably argue that it's not the presence of these methods that is "problem" but their usage. I mean it can be test programmer's choice to use TEST_ptr_op when deemed more appropriate...

@levitte
Copy link
Member

levitte commented May 16, 2017

I agree that the comparison with NULL doesn't need a dump. It should be clear enough from the error line,

@levitte
Copy link
Member

levitte commented May 16, 2017

Ah, wait... if the comparison is A == B and one of the variables turn out to have the value NULL, then it makes sense to display the content difference somehow. An immediate NULL value can be seen as a special case, and I wonder if treating it separately is worth the effort...

@dot-asm
Copy link
Contributor

dot-asm commented May 16, 2017

comparison to NULL

Basically what looks strange is caret marking for NULL, i.e. as if N, U, L, L were digits.

not specifically to BN.

In cases other than BN, NULL is actually not marked with carets or even dignified with offset, e,g,

# ERROR: (string) 'NULL == buf' failed @ test/test_test.c:244
# --- NULL
# +++ buf
#      - NULL
#    0:+ 'abc'

I'd say it should be same even here, i.e.

# ERROR: (BIGNUM) 'b == NULL' failed @ test/test_test.c:405
# --- b
# +++ NULL
#                                                                     offset
# -                   12345678901234 5678901234567890 1234567890123456:   32
# -7890121234567890 1234567890123456 7890123456789012 3456789013987657:    0
# +                                                               NULL

@dot-asm
Copy link
Contributor

dot-asm commented May 16, 2017

Regarding 'offset'. It seems that 'position' would be more appropriate term. Trouble of course is that it refers to digit position and in this case digit is nibble. But looking at nibble indices is not really handy. So it would probably be appropriate to explicitly say 'byte position' or 'bit position' (naturally multiplying byte position by 8). [As already discussed elsewhere I'd vote for latter, i.e. bit position.]

@paulidale
Copy link
Contributor Author

Ah, wait... if the comparison is A == B and one of the variables turn out to have the value NULL, then it makes sense to display the content difference somehow. An immediate NULL value can be seen as a special case, and I wonder if treating it separately is worth the effort...

Exactly why it works as it does. Is trying to detect if the text version of the argument is NULL worthwhile? What about detecting (NULL) or any number of alternatives? It seems like it would be too hard to do in general but the specific case of NULL might be worthwhile. I'd argue one of the TEST_ptr functions should be used instead.

The # c is negative was an earlier attempt to handle signs which I dropped.

I think the side note about highlighting memory and string dumps should go in another ticket. It is a valid point.

@paulidale
Copy link
Contributor Author

Still WIP, there is a problem where blank lines are produced which I'm looking into...

@paulidale
Copy link
Contributor Author

Ready now.

@levitte
Copy link
Member

levitte commented May 17, 2017

Exactly why it works as it does. Is trying to detect if the text version of the argument is NULL worthwhile? What about detecting (NULL) or any number of alternatives? It seems like it would be too hard to do in general but the specific case of NULL might be worthwhile.

Nah, I think that'd be way over the top. There's only so much a framework should do.

I'd argue one of the TEST_ptr functions should be used instead.

Yup, I agree.

@dot-asm
Copy link
Contributor

dot-asm commented May 17, 2017

NULL should be marked with + here:

# ERROR: (BIGNUM) 'b == NULL' failed @ test/test_test.c:409
# --- b
# +++ NULL
#                                                               bit position
# -                   12345678901234 5678901234567890 1234567890123456:  256
# -7890121234567890 1234567890123456 7890123456789012 3456789013987657:    0
# -                                                               NULL

@dot-asm
Copy link
Contributor

dot-asm commented May 17, 2017

I find output on 32-bit systems kind of odd. Because it's forced to 7 limbs per line and as result positions end up being 224, 448, 672, 896, etc. It's cool, but I think platform-neutral output would be more appropriate. Personally I don't really care much for spaces, but injecting spaces at 64-bit boundaries can be considered as suitable for either platform. Because it's rather about [overall] output readability [and uniformity] than BN internals such as limb size. In other words I'd like to suggest to drop dependency on BN_BYTES and produce output as if it was 8.

@levitte
Copy link
Member

levitte commented May 17, 2017

In other words I'd like to suggest to drop dependency on BN_BYTES and produce output as if it was 8.

I second that

Fix copy paste and forget to edit typo.
@paulidale
Copy link
Contributor Author

These two changes are done.

@dot-asm
Copy link
Contributor

dot-asm commented May 18, 2017

Something got lost in the middle. Currently it reads

# ERROR: (BIGNUM) 'a == b' failed @ test/test_test.c:407
# --- a
# +++ b
#                                                               bit position
#    12345678901234 5678901234567890 1234567890123456 7890121234567890: 1024
#  1234567890123456 7890123456789012 3456789012123456 7890123456789012:  768
#  3456789012345678 9012345678901212 3456789012345678 9012345678901234:  512
#  5678901234567890 1212345678901234 5678901234567890 1234567890123456:  256
# -7890121234567890 1234567890123456 7890123456789012 3456789012ffffff:    0
# +7890121234567890 1234567890123456 7890123456789012 3456789013987657:    0
#                                                              ^^^^^^^

while expected output is

# ERROR: (BIGNUM) 'a == b' failed @ test/test_test.c:407
# --- a
# +++ b
#                                                               bit position
# -  12345678901234 5678901234567890 1234567890123456 7890121234567890: 1024
# -1234567890123456 7890123456789012 3456789012123456 7890123456789012:  768
# -3456789012345678 9012345678901212 3456789012345678 9012345678901234:  512
# -5678901234567890 1212345678901234 5678901234567890 1234567890123456:  256
# +                   12345678901234 5678901234567890 1234567890123456:  256
# -7890121234567890 1234567890123456 7890123456789012 3456789012ffffff:    0
# +7890121234567890 1234567890123456 7890123456789012 3456789013987657:    0
#                                                              ^^^^^^^

@paulidale
Copy link
Contributor Author

Drat the highlighting change. I'll figure this one out in the morning. Sleep time now.

Well caught BTW.

@paulidale
Copy link
Contributor Author

That output looks like this now:

    # ERROR: (BIGNUM) 'a == b' failed @ test/test_test.c:407
    # --- a
    # +++ b
    #                                                               bit position
    # -  12345678901234 5678901234567890 1234567890123456 7890121234567890: 1024
    # -1234567890123456 7890123456789012 3456789012123456 7890123456789012:  768
    # -3456789012345678 9012345678901212 3456789012345678 9012345678901234:  512
    # -5678901234567890 1212345678901234 5678901234567890 1234567890123456:  256
    # +                   12345678901234 5678901234567890 1234567890123456:  256
    # -7890121234567890 1234567890123456 7890123456789012 3456789012ffffff:    0
    # +7890121234567890 1234567890123456 7890123456789012 3456789013987657:    0
    #                                                              ^^^^^^^

Copy link
Contributor

@dot-asm dot-asm left a comment

Choose a reason for hiding this comment

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

Commits will be squashed to one.

@dot-asm
Copy link
Contributor

dot-asm commented May 19, 2017

Merged. Thanks!

levitte pushed a commit that referenced this pull request May 19, 2017
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from #3465)
@dot-asm dot-asm closed this May 19, 2017
@paulidale paulidale deleted the bn-pretty branch May 21, 2017 21:40
paulidale added a commit to paulidale/openssl that referenced this pull request May 21, 2017
… in openssl#3465

Don't highlight excess when comparing unequal length strings.

Clean up the NULL / empty string display.
@paulidale paulidale mentioned this pull request May 21, 2017
1 task
paulidale added a commit to paulidale/openssl that referenced this pull request May 21, 2017
Excess bytes, when one block is longer than the other, are not explicitly
highlighted.

The NULL / zero length block output has been cleaned up.
@paulidale paulidale mentioned this pull request May 21, 2017
1 task
levitte pushed a commit that referenced this pull request May 22, 2017
Excess bytes, when one block is longer than the other, are not explicitly
highlighted.

The NULL / zero length block output has been cleaned up.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from #3515)
levitte pushed a commit that referenced this pull request May 22, 2017
… in #3465

Don't highlight excess when comparing unequal length strings.

Clean up the NULL / empty string display.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from #3514)
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