* [PATCH babeltrace 1/1] Fix: test_bitfield: extend coverage: 0-len signed write/read
@ 2019-05-29 19:36 Mathieu Desnoyers
0 siblings, 0 replies; 2+ messages in thread
From: Mathieu Desnoyers @ 2019-05-29 19:36 UTC (permalink / raw)
To: jgalar; +Cc: lttng-dev
By convention, a 0-len bitfield write is a no-op, and a 0-len read
sets the value of the output to 0.
So we can "encode" the value 0 over a length of 0 bit. Cover this
in the test-cases for signed types. It is already covered for the
unsigned test-cases.
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ib6038b98167ef2cfa8c504d7ac29498e71827b38
---
tests/lib/test_bitfield.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/tests/lib/test_bitfield.c b/tests/lib/test_bitfield.c
index 5188335b..05547c07 100644
--- a/tests/lib/test_bitfield.c
+++ b/tests/lib/test_bitfield.c
@@ -391,7 +391,9 @@ void run_test_signed_write(int src_i, long long src_ll)
long long readval;
unsigned int s, l;
- if (src_i & 0x80000000U)
+ if (!src_i)
+ nrbits_i = 0; /* The number of bits needed to represent 0 is 0. */
+ else if (src_i & 0x80000000U)
nrbits_i = fls_u32(~src_i) + 1; /* Find least significant bit conveying sign */
else
nrbits_i = fls_u32(src_i) + 1; /* Keep sign at 0 */
@@ -442,7 +444,9 @@ void run_test_signed_write(int src_i, long long src_ll)
}
pass(SIGNED_INT_WRITE_TEST_DESC_FMT_STR, src_i);
- if (src_ll & 0x8000000000000000ULL)
+ if (!src_ll)
+ nrbits_ll = 0; /* The number of bits needed to represent 0 is 0. */
+ else if (src_ll & 0x8000000000000000ULL)
nrbits_ll = fls_u64(~src_ll) + 1; /* Find least significant bit conveying sign */
else
nrbits_ll = fls_u64(src_ll) + 1; /* Keep sign at 0 */
@@ -507,7 +511,9 @@ void run_test_signed_read(int src_i, long long src_ll)
long long readval_ll;
unsigned int s, l;
- if (src_i & 0x80000000U)
+ if (!src_i)
+ nrbits_i = 0; /* The number of bits needed to represent 0 is 0. */
+ else if (src_i & 0x80000000U)
nrbits_i = fls_u32(~src_i) + 1; /* Find least significant bit conveying sign */
else
nrbits_i = fls_u32(src_i) + 1; /* Keep sign at 0 */
@@ -558,6 +564,8 @@ void run_test_signed_read(int src_i, long long src_ll)
}
pass(SIGNED_INT_READ_TEST_DESC_FMT_STR, src_i);
+ if (!src_ll)
+ nrbits_ll = 0; /* The number of bits needed to represent 0 is 0. */
if (src_ll & 0x8000000000000000ULL)
nrbits_ll = fls_u64(~src_ll) + 1; /* Find least significant bit conveying sign */
else
--
2.11.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH babeltrace 1/1] Fix: test_bitfield: extend coverage: 0-len signed write/read
[not found] <20190529193625.24465-1-mathieu.desnoyers@efficios.com>
@ 2019-05-29 20:56 ` Jérémie Galarneau
0 siblings, 0 replies; 2+ messages in thread
From: Jérémie Galarneau @ 2019-05-29 20:56 UTC (permalink / raw)
To: Mathieu Desnoyers; +Cc: lttng-dev, jgalar
Merged in master and stable-2.0.
Thanks!
Jérémie
On Wed, May 29, 2019 at 03:36:25PM -0400, Mathieu Desnoyers wrote:
> By convention, a 0-len bitfield write is a no-op, and a 0-len read
> sets the value of the output to 0.
>
> So we can "encode" the value 0 over a length of 0 bit. Cover this
> in the test-cases for signed types. It is already covered for the
> unsigned test-cases.
>
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> Change-Id: Ib6038b98167ef2cfa8c504d7ac29498e71827b38
> ---
> tests/lib/test_bitfield.c | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> diff --git a/tests/lib/test_bitfield.c b/tests/lib/test_bitfield.c
> index 5188335b..05547c07 100644
> --- a/tests/lib/test_bitfield.c
> +++ b/tests/lib/test_bitfield.c
> @@ -391,7 +391,9 @@ void run_test_signed_write(int src_i, long long src_ll)
> long long readval;
> unsigned int s, l;
>
> - if (src_i & 0x80000000U)
> + if (!src_i)
> + nrbits_i = 0; /* The number of bits needed to represent 0 is 0. */
> + else if (src_i & 0x80000000U)
> nrbits_i = fls_u32(~src_i) + 1; /* Find least significant bit conveying sign */
> else
> nrbits_i = fls_u32(src_i) + 1; /* Keep sign at 0 */
> @@ -442,7 +444,9 @@ void run_test_signed_write(int src_i, long long src_ll)
> }
> pass(SIGNED_INT_WRITE_TEST_DESC_FMT_STR, src_i);
>
> - if (src_ll & 0x8000000000000000ULL)
> + if (!src_ll)
> + nrbits_ll = 0; /* The number of bits needed to represent 0 is 0. */
> + else if (src_ll & 0x8000000000000000ULL)
> nrbits_ll = fls_u64(~src_ll) + 1; /* Find least significant bit conveying sign */
> else
> nrbits_ll = fls_u64(src_ll) + 1; /* Keep sign at 0 */
> @@ -507,7 +511,9 @@ void run_test_signed_read(int src_i, long long src_ll)
> long long readval_ll;
> unsigned int s, l;
>
> - if (src_i & 0x80000000U)
> + if (!src_i)
> + nrbits_i = 0; /* The number of bits needed to represent 0 is 0. */
> + else if (src_i & 0x80000000U)
> nrbits_i = fls_u32(~src_i) + 1; /* Find least significant bit conveying sign */
> else
> nrbits_i = fls_u32(src_i) + 1; /* Keep sign at 0 */
> @@ -558,6 +564,8 @@ void run_test_signed_read(int src_i, long long src_ll)
> }
> pass(SIGNED_INT_READ_TEST_DESC_FMT_STR, src_i);
>
> + if (!src_ll)
> + nrbits_ll = 0; /* The number of bits needed to represent 0 is 0. */
> if (src_ll & 0x8000000000000000ULL)
> nrbits_ll = fls_u64(~src_ll) + 1; /* Find least significant bit conveying sign */
> else
> --
> 2.11.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-05-29 20:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-29 19:36 [PATCH babeltrace 1/1] Fix: test_bitfield: extend coverage: 0-len signed write/read Mathieu Desnoyers
[not found] <20190529193625.24465-1-mathieu.desnoyers@efficios.com>
2019-05-29 20:56 ` Jérémie Galarneau
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.