kokke / tiny-bignum-c

Small portable multiple-precision unsigned integer arithmetic in C
The Unlicense
424 stars 85 forks source link

(core dumped) test #33

Closed wir19 closed 2 years ago

wir19 commented 2 years ago

./test_random 3 0100 80 02

test_random: bn.c:104: bignum_from_string: Assertion `(nbytes % (sizeof(uint32_t) * 2)) == 0 && "string length must be a multiple of (sizeof(DTYPE) * 2) characters"' failed.
Aborted (core dumped)
kokke commented 2 years ago

Hi @wir19

Did you see the error message?

You are basically "using it wrong". test_random expects to be called in the following manner:

test_random <OP> <LHS> <RHS> <RESULT>

Where is the operand (enum), is the left-hand-side, is the right-hand-side and the expected results.

The function with the failing assertion is bignum_from_string which is used for testing only. It has a requirement that the input-strings are of even length and of a certain length (see the error message). You are passing inputs that do uphold this requirement - thus the failed assertion.

https://github.com/kokke/tiny-bignum-c/issues/25 reports the very same issue.

xor256 commented 2 years ago

did You run this file and read example? ./test_random without parameter ;-)

second run this make clean all test

================================================================================
factorial(100) using Python = 1b30964ec395dc24069528d54bbda40d16e966ef9a70eb21b5b2943a321cdf10391745570cca9420c6ecb3b72ed2ee8b02ea2735c61a000000000000000000000000
factorial(100) using bignum = 1b30964ec395dc24069528d54bbda40d16e966ef9a70eb21b5b2943a321cdf10391745570cca9420c6ecb3b72ed2ee8b02ea2735c61a000000000000000000000000
================================================================================

Running test cases from error log (cases that failed during development).

0/0 tests passed.
kokke commented 2 years ago

Hi @xor256

I don't understand what you are trying to say - can you rephrase/explain further?

xor256 commented 2 years ago

Please run test_random without any parameters

You can read exactly this example. (You wrote "Did you see the error message?" ok, Did You read program help?)

./test_random 3 0100 80 02 is from help information when You run this program without parameter.

second trouble is 'make test' generate errors (look above)

kokke commented 2 years ago

Maybe I'm misunderstanding you @xor256 , but you're not supposed to run test_random without any parameters.

The python script inserts relevant parameters in the Makefile - which leads to your second trouble:

make clean all test works fine on the machines I have available for testing. Here's a snippet of the output from one such machine:

$ make clean all test

================================================================================

Running "golden" tests (parsed using from_int):

[TEXT OMITTED]

152/152 tests successful.

================================================================================

Running hand-picked test cases:

3/3 tests successful.

================================================================================

Loading numbers from strings and from int.
Verifying comparison function.
Verifying to_string function.
Verifying increment + decrement functions.

Tests successful.

================================================================================
factorial(100) using Python = 1b30964ec395dc24069528d54bbda40d16e966ef9a70eb21b5b2943a321cdf10391745570cca9420c6ecb3b72ed2ee8b02ea2735c61a000000000000000000000000
factorial(100) using bignum = 1b30964ec395dc24069528d54bbda40d16e966ef9a70eb21b5b2943a321cdf10391745570cca9420c6ecb3b72ed2ee8b02ea2735c61a000000000000000000000000
================================================================================

Running test cases from error log (cases that failed during development).

1005/1005 tests passed.

================================================================================

Running 1000 random tests (parsed using from_string):

[TEXT OMITTED]

1000/1000 random tests passed.

================================================================================

So I guess it's a difference in our environments that is causing the trouble.

Using an Alpine docker-container

docker run --rm -it alpine

... this works for me:

apk add git musl-dev make gcc python2
cd /tmp
git clone https://github.com/kokke/tiny-bignum-c.git
cd tiny-bignum-c
make clean all test
kokke commented 2 years ago

Could be an issue of Python2 vs Python3 - #29 alludes to that

xor256 commented 2 years ago

Maybe I'm misunderstanding you @xor256 , but you're not supposed to run test_random without any parameters. https://github.com/kokke/tiny-bignum-c/blob/master/tests/randomized.c 14 line , 3 = div\n\nExample:\n %s 3 0100 80 02\n\n [divide 0x0100 by 0x80

kokke commented 2 years ago

Maybe I'm misunderstanding you @xor256 , but you're not supposed to run test_random without any parameters. https://github.com/kokke/tiny-bignum-c/blob/master/tests/randomized.c 14 line , 3 = div\n\nExample:\n %s 3 0100 80 02\n\n [divide 0x0100 by 0x80

Does this https://github.com/kokke/tiny-bignum-c/commit/f5586b4280d35c2f3d01a81db651bf9ea06c7cf4 address your objections ?

I did not expect the test-code to be scrutinized to this degree :) Thanks for helping me find the issue @xor256

kokke commented 2 years ago

@xor256 I noticed that you responded with "thumbs-down" and "eyes" to my responses. Can you please put a few more words on that? Otherwise, I'm not sure what exactly you are objecting against :(

xor256 commented 2 years ago

The thumbs down is unfortunately a certain attitude of yours. "it's all good why do you have a grudge, I'm not wrong" eyes always mean "I'm looking" or "looking".


[ OK ] 262144 >> 18 = 1 [ OK ] 524288 >> 19 = 1 [ OK ] 1048576 >> 20 = 1

152/152 tests successful.

================================================================================

Running hand-picked test cases:

3/3 tests successful.

================================================================================

Loading numbers from strings and from int. Verifying comparison function. Verifying to_string function. Verifying increment + decrement functions.

Tests successful.

================================================================================ factorial(100) using Python = 1b30964ec395dc24069528d54bbda40d16e966ef9a70eb21b5b2943a321cdf10391745570cca9420c6ecb3b72ed2ee8b02ea2735c61a000000000000000000000000 factorial(100) using bignum = 1b30964ec395dc24069528d54bbda40d16e966ef9a70eb21b5b2943a321cdf10391745570cca9420c6ecb3b72ed2ee8b02ea2735c61a000000000000000000000000

Running test cases from error log (cases that failed during development).

0/0 tests passed.

================================================================================ File "./scripts/test_rand.py", line 123 expected = int(math.sqrt(oper1)); ^ TabError: inconsistent use of tabs and spaces in indentation make: *** [Makefile:31: test] Błąd 1

uname -a Linux 5.11.22-100.fc32.x86_64 #1 SMP Wed May 19 18:58:25 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

fedora

python -v .... Python 3.8.10 (default, May 4 2021, 00:00:00) [GCC 10.2.1 20201125 (Red Hat 10.2.1-9)] on linux ...

kokke commented 2 years ago

Could be an issue of Python2 vs Python3 - #29 alludes to that

Yup, that's the problem. The old scripts are not python3-compatible as is. Run them under python2 or consider upgrading them to python3.

The thumbs down is unfortunately a certain attitude of yours.

That did not help me understand what you are objecting to.

xor256 commented 2 years ago

That did not help me understand what you are objecting to. This is my suggestion to not write so aggressively. "Ah why didn't you read the documentation because you used the wrong input" but I just read the documentation. (The other thing is that you closed the thread)

meybe using Ruby not python? no python no problem ;-)

kokke commented 2 years ago

This is my suggestion to not write so aggressively. "Ah why didn't you read the documentation because you used the wrong input" but I just read the documentation. (The other thing is that you closed the thread)

I had not understood that "make clean all test" failed, so I thought "why are you even running this stuff manually? just use the makefile as described". There was not a lot of description text to go by. Again: thank you for helping me understand the real issue here.

The "usage-text" describing how to call test_rand was valid only for the smallest word-size. The assertion-failure text says it much better, so I'll just keep that instead.

meybe using Ruby not python? no python no problem ;-)

Haha of course :P The Python2 vs Python3 issue was not on my mind 4-5 years ago when I wrote this code. It should be updated to be Python3-compatible.