[PATCH libdrm 2/4] drmSL: Split tests to a separate file

2015-03-22 Thread Emil Velikov
On 20/03/15 22:10, Jan Vesely wrote:

Considering that a separate commit removes the test from xf86drmSL.c can
you add some information in here. "This moves the test from "


> Signed-off-by: Jan Vesely 
> ---
>  .gitignore|   1 +
>  tests/Makefile.am |   3 +-
>  tests/drmsltest.c | 172 
> ++
>  3 files changed, 175 insertions(+), 1 deletion(-)
>  create mode 100644 tests/drmsltest.c
> 
> diff --git a/.gitignore b/.gitignore
> index 06cc928..9c6ecd7 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -75,6 +75,7 @@ via.kld
>  tests/auth
>  tests/dristat
>  tests/drmstat
> +tests/drmsltest
Perhaps we can omit the trailing test -> tests/drmsl ?

>  tests/getclient
>  tests/getstats
>  tests/getversion
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 10f54e3..ca0f3c7 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -59,7 +59,8 @@ TESTS = \
>   getstats\
>   setversion  \
>   updatedraw  \
> - name_from_fd
> + name_from_fd\
> + drmsltest
>  
Can we try to keep this alphabetically sorted ?

I haven't verified that the code movement, although it seems that you've
nuked the trailing whitespace :-)

With the above comments addressed:

Acked-by: Emil Velikov 

-Emil



[PATCH libdrm 2/4] drmSL: Split tests to a separate file

2015-03-20 Thread Jan Vesely
Signed-off-by: Jan Vesely 
---
 .gitignore|   1 +
 tests/Makefile.am |   3 +-
 tests/drmsltest.c | 172 ++
 3 files changed, 175 insertions(+), 1 deletion(-)
 create mode 100644 tests/drmsltest.c

diff --git a/.gitignore b/.gitignore
index 06cc928..9c6ecd7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -75,6 +75,7 @@ via.kld
 tests/auth
 tests/dristat
 tests/drmstat
+tests/drmsltest
 tests/getclient
 tests/getstats
 tests/getversion
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 10f54e3..ca0f3c7 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -59,7 +59,8 @@ TESTS =   \
getstats\
setversion  \
updatedraw  \
-   name_from_fd
+   name_from_fd\
+   drmsltest

 check_PROGRAMS += $(TESTS)

diff --git a/tests/drmsltest.c b/tests/drmsltest.c
new file mode 100644
index 000..d193008
--- /dev/null
+++ b/tests/drmsltest.c
@@ -0,0 +1,172 @@
+/* xf86drmSL.c -- Skip list support
+ * Created: Mon May 10 09:28:13 1999 by faith at precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ * 
+ * Authors: Rickard E. (Rik) Faith 
+ *
+ * DESCRIPTION
+ *
+ * This file contains a straightforward skip list implementation.n
+ *
+ * FUTURE ENHANCEMENTS
+ *
+ * REFERENCES
+ *
+ * [Pugh90] William Pugh.  Skip Lists: A Probabilistic Alternative to
+ * Balanced Trees. CACM 33(6), June 1990, pp. 668-676.
+ *
+ */
+
+#include 
+#include 
+#include 
+
+#include "xf86drm.h"
+
+static void print(void* list)
+{
+unsigned long key;
+void  *value;
+
+if (drmSLFirst(list, &key, &value)) {
+   do {
+   printf("key = %5lu, value = %p\n", key, value);
+   } while (drmSLNext(list, &key, &value));
+}
+}
+
+static double do_time(int size, int iter)
+{
+void   *list;
+inti, j;
+unsigned long  keys[100];
+unsigned long  previous;
+unsigned long  key;
+void   *value;
+struct timeval start, stop;
+double usec;
+void   *ranstate;
+
+list = drmSLCreate();
+ranstate = drmRandomCreate(12345);
+
+for (i = 0; i < size; i++) {
+   keys[i] = drmRandom(ranstate);
+   drmSLInsert(list, keys[i], NULL);
+}
+
+previous = 0;
+if (drmSLFirst(list, &key, &value)) {
+   do {
+   if (key <= previous) {
+   printf( "%lu !< %lu\n", previous, key);
+   }
+   previous = key;
+   } while (drmSLNext(list, &key, &value));
+}
+
+gettimeofday(&start, NULL);
+for (j = 0; j < iter; j++) {
+   for (i = 0; i < size; i++) {
+   if (drmSLLookup(list, keys[i], &value))
+   printf("Error %lu %d\n", keys[i], i);
+   }
+}
+gettimeofday(&stop, NULL);
+
+usec = (double)(stop.tv_sec * 100 + stop.tv_usec
+   - start.tv_sec * 100 - start.tv_usec) / (size * iter);
+
+printf("%0.2f microseconds for list length %d\n", usec, size);
+
+drmRandomDouble(ranstate);
+drmSLDestroy(list);
+
+return usec;
+}
+
+static void print_neighbors(void *list, unsigned long key)
+{
+unsigned long prev_key = 0;
+unsigned long next_key = 0;
+void  *prev_value;
+void  *next_value;
+int   retval;
+
+retval = drmSLLookupNeighbors(list, key,
+ &prev_key, &prev_value,
+ &next_key, &next_value);
+printf("Neighbors of %5lu: %d %5lu %5lu\n",
+  key, retval, prev_key, next_key);
+}
+
+int main(void)
+{
+void*list;
+double   usec, usec2, usec3, usec4;
+
+list = dr