All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] unit: Add test-casese for l_ringbuf_append function
@ 2020-01-21  8:17 =?unknown-8bit?q?Przemys=C5=82aw?= Fierek
  2020-01-24 20:41 ` Denis Kenzior
  0 siblings, 1 reply; 2+ messages in thread
From: =?unknown-8bit?q?Przemys=C5=82aw?= Fierek @ 2020-01-21  8:17 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 3395 bytes --]

This patch adds unit-tests for previously submitted `l_ringbuf_append`
function.
---
 unit/test-ringbuf.c | 83 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 82 insertions(+), 1 deletion(-)

diff --git a/unit/test-ringbuf.c b/unit/test-ringbuf.c
index 906161b..ce2c5f9 100644
--- a/unit/test-ringbuf.c
+++ b/unit/test-ringbuf.c
@@ -131,6 +131,86 @@ static void test_printf(const void *data)
 	l_ringbuf_free(rb);
 }
 
+static void test_append(const void *unused)
+{
+	static uint8_t data[6] = {1, 2, 3, 4, 5, 6};
+	static size_t rb_size = 12;
+	static size_t rb_capa = 16;
+	static size_t len_no_wrap;
+	static ssize_t appended, space_left;
+	static 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 uint8_t expected_data1[14] = {3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4};
+	static uint8_t expected_data2[2] = {5, 6};
+	static uint8_t data[6] = {1, 2, 3, 4, 5, 6};
+	static size_t rb_size = 12;
+	static size_t rb_capa = 16;
+	static size_t len_no_wrap;
+	static ssize_t appended, space_left;
+	static 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 +218,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] 2+ messages in thread

* Re: [PATCH] unit: Add test-casese for l_ringbuf_append function
  2020-01-21  8:17 [PATCH] unit: Add test-casese for l_ringbuf_append function =?unknown-8bit?q?Przemys=C5=82aw?= Fierek
@ 2020-01-24 20:41 ` Denis Kenzior
  0 siblings, 0 replies; 2+ messages in thread
From: Denis Kenzior @ 2020-01-24 20:41 UTC (permalink / raw)
  To: ell

[-- Attachment #1: Type: text/plain, Size: 3851 bytes --]

Hi Przemysław,

On 1/21/20 2:17 AM, Przemysław Fierek wrote:
> This patch adds unit-tests for previously submitted `l_ringbuf_append`
> function.
> ---
>   unit/test-ringbuf.c | 83 ++++++++++++++++++++++++++++++++++++++++++++-
>   1 file changed, 82 insertions(+), 1 deletion(-)
> 
> diff --git a/unit/test-ringbuf.c b/unit/test-ringbuf.c
> index 906161b..ce2c5f9 100644
> --- a/unit/test-ringbuf.c
> +++ b/unit/test-ringbuf.c
> @@ -131,6 +131,86 @@ static void test_printf(const void *data)
>   	l_ringbuf_free(rb);
>   }
>   
> +static void test_append(const void *unused)
> +{
> +	static uint8_t data[6] = {1, 2, 3, 4, 5, 6};
> +	static size_t rb_size = 12;
> +	static size_t rb_capa = 16;

static const?

> +	static size_t len_no_wrap;
> +	static ssize_t appended, space_left;

one variable per line please

> +	static void *rb_data;

Why are all these static?

> +	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 uint8_t expected_data1[14] = {3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4};

80 char line limit exceeded

> +	static uint8_t expected_data2[2] = {5, 6};
> +	static uint8_t data[6] = {1, 2, 3, 4, 5, 6};
> +	static size_t rb_size = 12;
> +	static size_t rb_capa = 16;

static const?

> +	static size_t len_no_wrap;
> +	static ssize_t appended, space_left;
> +	static void *rb_data;

Why static?

> +	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 +218,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();
> -
>   }
> 

Regards,
-Denis

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-24 20:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-21  8:17 [PATCH] unit: Add test-casese for l_ringbuf_append function =?unknown-8bit?q?Przemys=C5=82aw?= Fierek
2020-01-24 20:41 ` Denis Kenzior

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.