All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] kfifo: implement missing __kfifo_skip_r()
@ 2010-08-12 15:32 Andrea Righi
  2010-08-12 15:32 ` [PATCH 2/2] kfifo: add kfifo_skip() testcase Andrea Righi
  2010-08-12 20:45 ` [PATCH 1/2] kfifo: implement missing __kfifo_skip_r() Stefani Seibold
  0 siblings, 2 replies; 6+ messages in thread
From: Andrea Righi @ 2010-08-12 15:32 UTC (permalink / raw)
  To: Stefani Seibold
  Cc: Greg Kroah-Hartman, Mauro Carvalho Chehab, Andi Kleen, linux-kernel

kfifo_skip() is currently broken, due to the missing of the internal
helper function. Add it.

Signed-off-by: Andrea Righi <arighi@develer.com>
---
 include/linux/kfifo.h |    2 ++
 kernel/kfifo.c        |    9 +++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
index 311f875..4aa95f2 100644
--- a/include/linux/kfifo.h
+++ b/include/linux/kfifo.h
@@ -836,6 +836,8 @@ extern void __kfifo_dma_out_finish_r(struct __kfifo *fifo, size_t recsize);
 
 extern unsigned int __kfifo_len_r(struct __kfifo *fifo, size_t recsize);
 
+extern void __kfifo_skip_r(struct __kfifo *fifo, size_t recsize);
+
 extern unsigned int __kfifo_out_peek_r(struct __kfifo *fifo,
 	void *buf, unsigned int len, size_t recsize);
 
diff --git a/kernel/kfifo.c b/kernel/kfifo.c
index 02192dd..06d6eee 100644
--- a/kernel/kfifo.c
+++ b/kernel/kfifo.c
@@ -504,6 +504,15 @@ unsigned int __kfifo_out_r(struct __kfifo *fifo, void *buf,
 }
 EXPORT_SYMBOL(__kfifo_out_r);
 
+void __kfifo_skip_r(struct __kfifo *fifo, size_t recsize)
+{
+	unsigned int n;
+
+	n = __kfifo_peek_n(fifo, recsize);
+	fifo->out += n + recsize;
+}
+EXPORT_SYMBOL(__kfifo_skip_r);
+
 int __kfifo_from_user_r(struct __kfifo *fifo, const void __user *from,
 	unsigned long len, unsigned int *copied, size_t recsize)
 {
-- 
1.7.0.4


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

* [PATCH 2/2] kfifo: add kfifo_skip() testcase
  2010-08-12 15:32 [PATCH 1/2] kfifo: implement missing __kfifo_skip_r() Andrea Righi
@ 2010-08-12 15:32 ` Andrea Righi
  2010-08-12 20:46   ` Stefani Seibold
  2010-08-12 21:22   ` Andrew Morton
  2010-08-12 20:45 ` [PATCH 1/2] kfifo: implement missing __kfifo_skip_r() Stefani Seibold
  1 sibling, 2 replies; 6+ messages in thread
From: Andrea Righi @ 2010-08-12 15:32 UTC (permalink / raw)
  To: Stefani Seibold
  Cc: Greg Kroah-Hartman, Mauro Carvalho Chehab, Andi Kleen, linux-kernel

Add a testcase for kfifo_skip() to the byte stream fifo example.

Signed-off-by: Andrea Righi <arighi@develer.com>
---
 samples/kfifo/bytestream-example.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c
index 642eef3..2e3a7a8 100644
--- a/samples/kfifo/bytestream-example.c
+++ b/samples/kfifo/bytestream-example.c
@@ -73,6 +73,10 @@ static int __init testfunc(void)
 	ret = kfifo_in(&test, buf, ret);
 	printk(KERN_INFO "ret: %d\n", ret);
 
+	/* skip first element of the fifo */
+	printk(KERN_INFO "skip 1st element\n");
+	kfifo_skip(&test);
+
 	/* put values into the fifo until is full */
 	for (i = 20; kfifo_put(&test, &i); i++)
 		;
-- 
1.7.0.4


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

* Re: [PATCH 1/2] kfifo: implement missing __kfifo_skip_r()
  2010-08-12 15:32 [PATCH 1/2] kfifo: implement missing __kfifo_skip_r() Andrea Righi
  2010-08-12 15:32 ` [PATCH 2/2] kfifo: add kfifo_skip() testcase Andrea Righi
@ 2010-08-12 20:45 ` Stefani Seibold
  1 sibling, 0 replies; 6+ messages in thread
From: Stefani Seibold @ 2010-08-12 20:45 UTC (permalink / raw)
  To: Andrea Righi
  Cc: Greg Kroah-Hartman, Mauro Carvalho Chehab, Andi Kleen, linux-kernel


kfifo_skip() is currently broken, due to the missing of the internal
helper function. Add it.

Signed-off-by: Andrea Righi <arighi@develer.com>
Acked-by: Stefani Seibold <stefani@seibold.net>
---
 include/linux/kfifo.h |    2 ++
 kernel/kfifo.c        |    9 +++++++++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/include/linux/kfifo.h b/include/linux/kfifo.h
index 311f875..4aa95f2 100644
--- a/include/linux/kfifo.h
+++ b/include/linux/kfifo.h
@@ -836,6 +836,8 @@ extern void __kfifo_dma_out_finish_r(struct __kfifo *fifo, size_t recsize);
 
 extern unsigned int __kfifo_len_r(struct __kfifo *fifo, size_t recsize);
 
+extern void __kfifo_skip_r(struct __kfifo *fifo, size_t recsize);
+
 extern unsigned int __kfifo_out_peek_r(struct __kfifo *fifo,
 	void *buf, unsigned int len, size_t recsize);
 
diff --git a/kernel/kfifo.c b/kernel/kfifo.c
index 02192dd..06d6eee 100644
--- a/kernel/kfifo.c
+++ b/kernel/kfifo.c
@@ -504,6 +504,15 @@ unsigned int __kfifo_out_r(struct __kfifo *fifo, void *buf,
 }
 EXPORT_SYMBOL(__kfifo_out_r);
 
+void __kfifo_skip_r(struct __kfifo *fifo, size_t recsize)
+{
+	unsigned int n;
+
+	n = __kfifo_peek_n(fifo, recsize);
+	fifo->out += n + recsize;
+}
+EXPORT_SYMBOL(__kfifo_skip_r);
+
 int __kfifo_from_user_r(struct __kfifo *fifo, const void __user *from,
 	unsigned long len, unsigned int *copied, size_t recsize)
 {



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

* Re: [PATCH 2/2] kfifo: add kfifo_skip() testcase
  2010-08-12 15:32 ` [PATCH 2/2] kfifo: add kfifo_skip() testcase Andrea Righi
@ 2010-08-12 20:46   ` Stefani Seibold
  2010-08-12 21:22   ` Andrew Morton
  1 sibling, 0 replies; 6+ messages in thread
From: Stefani Seibold @ 2010-08-12 20:46 UTC (permalink / raw)
  To: Andrea Righi
  Cc: Greg Kroah-Hartman, Mauro Carvalho Chehab, Andi Kleen, linux-kernel

Add a testcase for kfifo_skip() to the byte stream fifo example.

Signed-off-by: Andrea Righi <arighi@develer.com>
Acked-by: Stefani Seibold <stefani@seibold.net>
---
 samples/kfifo/bytestream-example.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c
index 642eef3..2e3a7a8 100644
--- a/samples/kfifo/bytestream-example.c
+++ b/samples/kfifo/bytestream-example.c
@@ -73,6 +73,10 @@ static int __init testfunc(void)
 	ret = kfifo_in(&test, buf, ret);
 	printk(KERN_INFO "ret: %d\n", ret);
 
+	/* skip first element of the fifo */
+	printk(KERN_INFO "skip 1st element\n");
+	kfifo_skip(&test);
+
 	/* put values into the fifo until is full */
 	for (i = 20; kfifo_put(&test, &i); i++)
 		;



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

* Re: [PATCH 2/2] kfifo: add kfifo_skip() testcase
  2010-08-12 15:32 ` [PATCH 2/2] kfifo: add kfifo_skip() testcase Andrea Righi
  2010-08-12 20:46   ` Stefani Seibold
@ 2010-08-12 21:22   ` Andrew Morton
  2010-08-12 22:28     ` Andrea Righi
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2010-08-12 21:22 UTC (permalink / raw)
  To: Andrea Righi
  Cc: Stefani Seibold, Greg Kroah-Hartman, Mauro Carvalho Chehab,
	Andi Kleen, linux-kernel

On Thu, 12 Aug 2010 17:32:38 +0200
Andrea Righi <arighi@develer.com> wrote:

> Add a testcase for kfifo_skip() to the byte stream fifo example.
> 
> Signed-off-by: Andrea Righi <arighi@develer.com>
> ---
>  samples/kfifo/bytestream-example.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
> 
> diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c
> index 642eef3..2e3a7a8 100644
> --- a/samples/kfifo/bytestream-example.c
> +++ b/samples/kfifo/bytestream-example.c
> @@ -73,6 +73,10 @@ static int __init testfunc(void)
>  	ret = kfifo_in(&test, buf, ret);
>  	printk(KERN_INFO "ret: %d\n", ret);
>  
> +	/* skip first element of the fifo */
> +	printk(KERN_INFO "skip 1st element\n");
> +	kfifo_skip(&test);
> +
>  	/* put values into the fifo until is full */
>  	for (i = 20; kfifo_put(&test, &i); i++)
>  		;

hm, that's not a very good test harness.  A better one would check that
the resulting kfifo actually contains the expected items in the
expected order.  AFACIT this will "pass" even if kfifo_skip() is a
no-op, or execs nethack or something.

Oh well, it's more than we usually get.

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

* Re: [PATCH 2/2] kfifo: add kfifo_skip() testcase
  2010-08-12 21:22   ` Andrew Morton
@ 2010-08-12 22:28     ` Andrea Righi
  0 siblings, 0 replies; 6+ messages in thread
From: Andrea Righi @ 2010-08-12 22:28 UTC (permalink / raw)
  To: Andrew Morton, Stefani Seibold
  Cc: Greg Kroah-Hartman, Mauro Carvalho Chehab, Andi Kleen, linux-kernel

On Thu, Aug 12, 2010 at 02:22:11PM -0700, Andrew Morton wrote:
> On Thu, 12 Aug 2010 17:32:38 +0200
> Andrea Righi <arighi@develer.com> wrote:
> 
> > Add a testcase for kfifo_skip() to the byte stream fifo example.
> > 
> > Signed-off-by: Andrea Righi <arighi@develer.com>
> > ---
> >  samples/kfifo/bytestream-example.c |    4 ++++
> >  1 files changed, 4 insertions(+), 0 deletions(-)
> > 
> > diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c
> > index 642eef3..2e3a7a8 100644
> > --- a/samples/kfifo/bytestream-example.c
> > +++ b/samples/kfifo/bytestream-example.c
> > @@ -73,6 +73,10 @@ static int __init testfunc(void)
> >  	ret = kfifo_in(&test, buf, ret);
> >  	printk(KERN_INFO "ret: %d\n", ret);
> >  
> > +	/* skip first element of the fifo */
> > +	printk(KERN_INFO "skip 1st element\n");
> > +	kfifo_skip(&test);
> > +
> >  	/* put values into the fifo until is full */
> >  	for (i = 20; kfifo_put(&test, &i); i++)
> >  		;
> 
> hm, that's not a very good test harness.  A better one would check that
> the resulting kfifo actually contains the expected items in the
> expected order.  AFACIT this will "pass" even if kfifo_skip() is a
> no-op, or execs nethack or something.
> 
> Oh well, it's more than we usually get.

Agreed. Something like this is probably more meaningful.

---
kfifo: add explicit error checking in byte stream example

Provide a static array of expected items that kfifo should contain at
the end of the test to validate it.

Signed-off-by: Andrea Righi <arighi@develer.com>
---
 samples/kfifo/bytestream-example.c |   33 +++++++++++++++++++++++++++------
 1 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/samples/kfifo/bytestream-example.c b/samples/kfifo/bytestream-example.c
index 2e3a7a8..a94e694 100644
--- a/samples/kfifo/bytestream-example.c
+++ b/samples/kfifo/bytestream-example.c
@@ -44,10 +44,17 @@ static struct kfifo test;
 static DECLARE_KFIFO(test, unsigned char, FIFO_SIZE);
 #endif
 
+static unsigned char expected_result[FIFO_SIZE] = {
+	 3,  4,  5,  6,  7,  8,  9,  0,
+	 1, 20, 21, 22, 23, 24, 25, 26,
+	27, 28, 29, 30, 31, 32, 33, 34,
+	35, 36, 37, 38, 39, 40, 41, 42,
+};
+
 static int __init testfunc(void)
 {
 	unsigned char	buf[6];
-	unsigned char	i;
+	unsigned char	i, j;
 	unsigned int	ret;
 
 	printk(KERN_INFO "byte stream fifo test start\n");
@@ -83,10 +90,19 @@ static int __init testfunc(void)
 
 	printk(KERN_INFO "queue len: %u\n", kfifo_len(&test));
 
-	/* print out all values in the fifo */
-	while (kfifo_get(&test, &i))
-		printk("%d ", i);
-	printk("\n");
+	/* check the correctness of all values in the fifo */
+	j = 0;
+	while (kfifo_get(&test, &i)) {
+		if (i != expected_result[j++]) {
+			printk(KERN_WARNING "value mismatch: test failed\n");
+			return -EIO;
+		}
+	}
+	if (j != ARRAY_SIZE(expected_result)) {
+		printk(KERN_WARNING "size mismatch: test failed\n");
+		return -EIO;
+	}
+	printk(KERN_INFO "test passed\n");
 
 	return 0;
 }
@@ -142,7 +158,12 @@ static int __init example_init(void)
 #else
 	INIT_KFIFO(test);
 #endif
-	testfunc();
+	if (testfunc() < 0) {
+#ifdef DYNAMIC
+		kfifo_free(&test);
+#endif
+		return -EIO;
+	}
 
 	if (proc_create(PROC_FIFO, 0, NULL, &fifo_fops) == NULL) {
 #ifdef DYNAMIC


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

end of thread, other threads:[~2010-08-12 22:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-12 15:32 [PATCH 1/2] kfifo: implement missing __kfifo_skip_r() Andrea Righi
2010-08-12 15:32 ` [PATCH 2/2] kfifo: add kfifo_skip() testcase Andrea Righi
2010-08-12 20:46   ` Stefani Seibold
2010-08-12 21:22   ` Andrew Morton
2010-08-12 22:28     ` Andrea Righi
2010-08-12 20:45 ` [PATCH 1/2] kfifo: implement missing __kfifo_skip_r() Stefani Seibold

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.