* [PATCH v2] unit: Add test-casese for l_ringbuf_append function
@ 2020-01-27 6:53 =?unknown-8bit?q?Przemys=C5=82aw?= Fierek
2020-01-27 20:37 ` Denis Kenzior
0 siblings, 1 reply; 3+ messages in thread
From: =?unknown-8bit?q?Przemys=C5=82aw?= Fierek @ 2020-01-27 6:53 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 3488 bytes --]
This patch adds unit-tests for previously submitted `l_ringbuf_append`
function. Second version contains fixes from the code review.
---
unit/test-ringbuf.c | 86 ++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 85 insertions(+), 1 deletion(-)
diff --git a/unit/test-ringbuf.c b/unit/test-ringbuf.c
index 906161b..e18206f 100644
--- a/unit/test-ringbuf.c
+++ b/unit/test-ringbuf.c
@@ -131,6 +131,89 @@ static void test_printf(const void *data)
l_ringbuf_free(rb);
}
+static void test_append(const void *unused)
+{
+ static const uint8_t data[6] = {1, 2, 3, 4, 5, 6};
+ static const size_t rb_size = 12;
+ static const size_t rb_capa = 16;
+ size_t len_no_wrap;
+ ssize_t appended;
+ ssize_t space_left;
+ void *rb_data;
+ struct l_ringbuf *rb;
+
+ rb = l_ringbuf_new(rb_size);
+ assert(rb != NULL);
+ assert(l_ringbuf_capacity(rb) == rb_capa);
+
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == sizeof(data));
+
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == sizeof(data));
+
+ space_left = minsize(l_ringbuf_avail(rb), sizeof(data));
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == space_left);
+
+ rb_data = l_ringbuf_peek(rb, 0, &len_no_wrap);
+ assert(memcmp(rb_data, data, sizeof(data)) == 0);
+ l_ringbuf_drain(rb, sizeof(data));
+
+ rb_data = l_ringbuf_peek(rb, 0, &len_no_wrap);
+ assert(memcmp(rb_data, data, sizeof(data)) == 0);
+ l_ringbuf_drain(rb, sizeof(data));
+
+ rb_data = l_ringbuf_peek(rb, 0, &len_no_wrap);
+ assert(memcmp(rb_data, data, len_no_wrap) == 0);
+ l_ringbuf_drain(rb, len_no_wrap);
+
+ l_ringbuf_free(rb);
+}
+
+static void test_append2(const void *unused)
+{
+ static const uint8_t expected_data1[14] = {3, 4, 5, 6, 1, 2, 3, 4, 5,
+ 6, 1, 2, 3, 4};
+ static const uint8_t expected_data2[2] = {5, 6};
+ static const uint8_t data[6] = {1, 2, 3, 4, 5, 6};
+ static const size_t rb_size = 12;
+ static const size_t rb_capa = 16;
+ size_t len_no_wrap;
+ ssize_t appended;
+ ssize_t space_left;
+ void *rb_data;
+ struct l_ringbuf *rb;
+
+ rb = l_ringbuf_new(rb_size);
+ assert(rb != NULL);
+ assert(l_ringbuf_capacity(rb) == rb_capa);
+
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == sizeof(data));
+
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == sizeof(data));
+
+ space_left = minsize(l_ringbuf_avail(rb), sizeof(data));
+ l_ringbuf_drain(rb, sizeof(data) - space_left);
+
+ appended = l_ringbuf_append(rb, data, sizeof(data));
+ assert(appended == sizeof(data));
+
+ rb_data = l_ringbuf_peek(rb, 0, &len_no_wrap);
+ assert(len_no_wrap == sizeof(expected_data1));
+ assert(memcmp(expected_data1, rb_data, len_no_wrap) == 0);
+
+ l_ringbuf_drain(rb, len_no_wrap);
+
+ rb_data = l_ringbuf_peek(rb, 0, &len_no_wrap);
+ assert(len_no_wrap == sizeof(expected_data2));
+ assert(memcmp(expected_data2, rb_data, len_no_wrap) == 0);
+
+ l_ringbuf_free(rb);
+}
+
int main(int argc, char *argv[])
{
l_test_init(&argc, &argv);
@@ -138,7 +221,8 @@ int main(int argc, char *argv[])
l_test_add("/ringbuf/power2", test_power2, NULL);
l_test_add("/ringbuf/alloc", test_alloc, NULL);
l_test_add("/ringbuf/printf", test_printf, NULL);
+ l_test_add("/ringbuf/append", test_append, NULL);
+ l_test_add("/ringbuf/append2", test_append2, NULL);
return l_test_run();
-
}
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] unit: Add test-casese for l_ringbuf_append function
2020-01-27 6:53 [PATCH v2] unit: Add test-casese for l_ringbuf_append function =?unknown-8bit?q?Przemys=C5=82aw?= Fierek
@ 2020-01-27 20:37 ` Denis Kenzior
2020-01-28 9:54 ` =?unknown-8bit?q?Przemys=C5=82aw?= Fierek
0 siblings, 1 reply; 3+ messages in thread
From: Denis Kenzior @ 2020-01-27 20:37 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 932 bytes --]
Hi Przemysław,
On 1/27/20 12:53 AM, Przemysław Fierek wrote:
> This patch adds unit-tests for previously submitted `l_ringbuf_append`
> function. Second version contains fixes from the code review.
The second sentence is really a change log / metadata and should not be
in the commit description. Put such stuff where it belongs: after '---'...
>
> ---
> unit/test-ringbuf.c | 86 ++++++++++++++++++++++++++++++++++++++++++++-
> 1 file changed, 85 insertions(+), 1 deletion(-)
>
...in other words: here
<snip>
> +static void test_append2(const void *unused)
> +{
> + static const uint8_t expected_data1[14] = {3, 4, 5, 6, 1, 2, 3, 4, 5,
> + 6, 1, 2, 3, 4};
No mixed tab & space indentation please. Always use tabs. Also, we
prefer space after '{' and before '}'.
Applied after slight wordsmithing of the commit description and minor
coding style cleanups.
Regards,
-Denis
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] unit: Add test-casese for l_ringbuf_append function
2020-01-27 20:37 ` Denis Kenzior
@ 2020-01-28 9:54 ` =?unknown-8bit?q?Przemys=C5=82aw?= Fierek
0 siblings, 0 replies; 3+ messages in thread
From: =?unknown-8bit?q?Przemys=C5=82aw?= Fierek @ 2020-01-28 9:54 UTC (permalink / raw)
To: ell
[-- Attachment #1: Type: text/plain, Size: 1227 bytes --]
Hi Denis,
Thank you for review. I will keep in mind your recommendations when I
will want to submit another patches.
Regards,
Przemek
On 27.01.2020 21:37, Denis Kenzior wrote:
> Hi Przemysław,
>
> On 1/27/20 12:53 AM, Przemysław Fierek wrote:
>> This patch adds unit-tests for previously submitted `l_ringbuf_append`
>> function. Second version contains fixes from the code review.
>
> The second sentence is really a change log / metadata and should not
> be in the commit description. Put such stuff where it belongs: after
> '---'...
>
>>
>> ---
>> unit/test-ringbuf.c | 86 ++++++++++++++++++++++++++++++++++++++++++++-
>> 1 file changed, 85 insertions(+), 1 deletion(-)
>>
>
> ...in other words: here
>
> <snip>
>
>> +static void test_append2(const void *unused)
>> +{
>> + static const uint8_t expected_data1[14] = {3, 4, 5, 6, 1, 2, 3,
>> 4, 5,
>> + 6, 1, 2, 3, 4};
>
> No mixed tab & space indentation please. Always use tabs. Also, we
> prefer space after '{' and before '}'.
>
> Applied after slight wordsmithing of the commit description and minor
> coding style cleanups.
>
> Regards,
> -Denis
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-28 9:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-27 6:53 [PATCH v2] unit: Add test-casese for l_ringbuf_append function =?unknown-8bit?q?Przemys=C5=82aw?= Fierek
2020-01-27 20:37 ` Denis Kenzior
2020-01-28 9:54 ` =?unknown-8bit?q?Przemys=C5=82aw?= Fierek
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.