[PATCH 4/4] Add tests for bitvec_unhex function

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/OpenBSC@lists.osmocom.org/.

Holger Freyther holger at freyther.de
Sat Jan 30 09:09:39 UTC 2016


> On 28 Jan 2016, at 12:28, suraev at alumni.ntnu.no wrote:
> 
> From: Max <msuraev at sysmocom.de>


Dear Max,

one can put fix and testcase into the same commit, if you decide to
split it up then first commit the testcase with an expected failure
and then when you fix things, fix the test result. This will show/track
the change in behavior.


In my initial review I had asked for a stronger post condition and I
still think this applies to the test. I see we have one truncation
test but I don't see a test that checks how many bits have been taken
from the hexstring.


> 
> ---
> tests/bitvec/bitvec_test.c  | 16 ++++++++++++++++
> tests/bitvec/bitvec_test.ok | 15 +++++++++++++++
> 2 files changed, 31 insertions(+)
> 
> diff --git a/tests/bitvec/bitvec_test.c b/tests/bitvec/bitvec_test.c
> index 624e334..789df75 100644
> --- a/tests/bitvec/bitvec_test.c
> +++ b/tests/bitvec/bitvec_test.c
> @@ -55,8 +55,24 @@ static void test_byte_ops()
> 	printf("=== end %s ===\n", __func__);
> }
> 
> +static void test_unhex(const char *hex)
> +{
> +	struct bitvec b;
> +	uint8_t d[64] = {0};
> +	b.data = d;
> +	b.data_len = sizeof(d);
> +	b.cur_bit = 0;
> +	printf("%d -=>\n", bitvec_unhex(&b, hex));
> +	printf("%s\n%s\n", osmo_hexdump_nospc(d, 64), osmo_hexdump_nospc((const unsigned char *)hex, 23));
> +}
> +
> int main(int argc, char **argv)
> {
> 	test_byte_ops();
> +	test_unhex("48282407a6a074227201000b2b2b2b2b2b2b2b2b2b2b2b");
> +	test_unhex("47240c00400000000000000079eb2ac9402b2b2b2b2b2b");
> +	test_unhex("47283c367513ba333004242b2b2b2b2b2b2b2b2b2b2b2b");
> +	test_unhex("DEADFACE000000000000000000000000000000BEEFFEED");
> +	test_unhex("FFFFFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB");
> 	return 0;
> }
> diff --git a/tests/bitvec/bitvec_test.ok b/tests/bitvec/bitvec_test.ok
> index 1f329af..8d944bc 100644
> --- a/tests/bitvec/bitvec_test.ok
> +++ b/tests/bitvec/bitvec_test.ok
> @@ -1,2 +1,17 @@
> === start test_byte_ops ===
> === end test_byte_ops ===
> +1 -=>
> +48282407a6a074227201000b2b2b2b2b2b2b2b2b2b2b2b0000000000000000000000000000000000000000000000000000000000000000000000000000000000
> +48282407a6a074227201000b2b2b2b2b2b2b2b2b2b2b2b0000000000000000000000000000000000000000000000000000000000000000000000000000000000
> +1 -=>
> +47240c00400000000000000079eb2ac9402b2b2b2b2b2b0000000000000000000000000000000000000000000000000000000000000000000000000000000000
> +47240c00400000000000000079eb2ac9402b2b2b2b2b2b0000000000000000000000000000000000000000000000000000000000000000000000000000000000
> +1 -=>
> +47283c367513ba333004242b2b2b2b2b2b2b2b2b2b2b2b0000000000000000000000000000000000000000000000000000000000000000000000000000000000
> +47283c367513ba333004242b2b2b2b2b2b2b2b2b2b2b2b0000000000000000000000000000000000000000000000000000000000000000000000000000000000
> +1 -=>
> +deadface000000000000000000000000000000beeffeed0000000000000000000000000000000000000000000000000000000000000000000000000000000000
> +deadface000000000000000000000000000000beeffeed0000000000000000000000000000000000000000000000000000000000000000000000000000000000
> +0 -=>
> +fffffaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> +fffffaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> -- 
> 2.5.0
> 




More information about the OpenBSC mailing list