etnaviv: Add libdrm tests as of 922d92994267743266024ecceb734ce0ebbca808
authorGuido Günther <agx@sigxcpu.org>
Mon, 3 Jun 2019 09:12:01 +0000 (11:12 +0200)
committerGuido Günther <agx@sigxcpu.org>
Wed, 5 Jun 2019 08:58:05 +0000 (08:58 +0000)
Signed-off-by: Guido Günther <guido.gunther@puri.sm>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
src/etnaviv/drm/tests/etnaviv_bo_cache_test.c [new file with mode: 0644]
src/etnaviv/drm/tests/etnaviv_cmd_stream_test.c [new file with mode: 0644]

diff --git a/src/etnaviv/drm/tests/etnaviv_bo_cache_test.c b/src/etnaviv/drm/tests/etnaviv_bo_cache_test.c
new file mode 100644 (file)
index 0000000..7fb0629
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2016 Etnaviv Project
+ *
+ * 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
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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:
+ *    Christian Gmeiner <christian.gmeiner@gmail.com>
+ */
+
+#undef NDEBUG
+#include <assert.h>
+
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "xf86drm.h"
+#include "etnaviv_drmif.h"
+#include "etnaviv_drm.h"
+
+static void test_cache(struct etna_device *dev)
+{
+       struct etna_bo *bo, *tmp;
+
+       /* allocate and free some bo's with same size - we must
+        * get the same bo over and over. */
+       printf("testing bo cache ... ");
+
+       bo = tmp = etna_bo_new(dev, 0x100, ETNA_BO_UNCACHED);
+       assert(bo);
+       etna_bo_del(bo);
+
+       for (unsigned i = 0; i < 100; i++) {
+               tmp = etna_bo_new(dev, 0x100, ETNA_BO_UNCACHED);
+               etna_bo_del(tmp);
+               assert(tmp == bo);
+       }
+
+       printf("ok\n");
+}
+
+static void test_size_rounding(struct etna_device *dev)
+{
+       struct etna_bo *bo;
+
+       printf("testing size rounding ... ");
+
+       bo = etna_bo_new(dev, 15, ETNA_BO_UNCACHED);
+       assert(etna_bo_size(bo) == 4096);
+       etna_bo_del(bo);
+
+       bo = etna_bo_new(dev, 4096, ETNA_BO_UNCACHED);
+       assert(etna_bo_size(bo) == 4096);
+       etna_bo_del(bo);
+
+       bo = etna_bo_new(dev, 4100, ETNA_BO_UNCACHED);
+       assert(etna_bo_size(bo) == 8192);
+       etna_bo_del(bo);
+
+       printf("ok\n");
+}
+
+int main(int argc, char *argv[])
+{
+       struct etna_device *dev;
+
+       drmVersionPtr version;
+       int fd, ret = 0;
+
+       fd = open(argv[1], O_RDWR);
+       if (fd < 0)
+               return 1;
+
+       version = drmGetVersion(fd);
+       if (version) {
+               printf("Version: %d.%d.%d\n", version->version_major,
+                      version->version_minor, version->version_patchlevel);
+               printf("  Name: %s\n", version->name);
+               printf("  Date: %s\n", version->date);
+               printf("  Description: %s\n", version->desc);
+               drmFreeVersion(version);
+       }
+
+       dev = etna_device_new(fd);
+       if (!dev) {
+               ret = 2;
+               goto out;
+       }
+
+       test_cache(dev);
+       test_size_rounding(dev);
+
+       etna_device_del(dev);
+
+out:
+       close(fd);
+
+       return ret;
+}
diff --git a/src/etnaviv/drm/tests/etnaviv_cmd_stream_test.c b/src/etnaviv/drm/tests/etnaviv_cmd_stream_test.c
new file mode 100644 (file)
index 0000000..b650aae
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2015 Etnaviv Project
+ *
+ * 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
+ * THE AUTHORS OR COPYRIGHT HOLDERS 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:
+ *    Christian Gmeiner <christian.gmeiner@gmail.com>
+ */
+
+#undef NDEBUG
+#include <assert.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "etnaviv_drmif.h"
+
+static void test_avail()
+{
+       struct etna_cmd_stream *stream;
+
+       printf("testing etna_cmd_stream_avail ... ");
+
+       /* invalid size */
+       stream = etna_cmd_stream_new(NULL, 0, NULL, NULL);
+       assert(stream == NULL);
+
+       stream = etna_cmd_stream_new(NULL, 4, NULL, NULL);
+       assert(stream);
+       assert(etna_cmd_stream_avail(stream) == 2);
+       etna_cmd_stream_del(stream);
+
+       stream = etna_cmd_stream_new(NULL, 20, NULL, NULL);
+       assert(stream);
+       assert(etna_cmd_stream_avail(stream) == 18);
+       etna_cmd_stream_del(stream);
+
+       /* odd number of 32 bit words */
+       stream = etna_cmd_stream_new(NULL, 1, NULL, NULL);
+       assert(stream);
+       assert(etna_cmd_stream_avail(stream) == 0);
+       etna_cmd_stream_del(stream);
+
+       stream = etna_cmd_stream_new(NULL, 23, NULL, NULL);
+       assert(stream);
+       assert(etna_cmd_stream_avail(stream) == 22);
+       etna_cmd_stream_del(stream);
+
+       printf("ok\n");
+}
+
+static void test_emit()
+{
+       struct etna_cmd_stream *stream;
+
+       printf("testing etna_cmd_stream_emit ... ");
+
+       stream = etna_cmd_stream_new(NULL, 6, NULL, NULL);
+       assert(stream);
+       assert(etna_cmd_stream_avail(stream) == 4);
+
+       etna_cmd_stream_emit(stream, 0x1);
+       assert(etna_cmd_stream_avail(stream) == 3);
+
+       etna_cmd_stream_emit(stream, 0x2);
+       assert(etna_cmd_stream_avail(stream) == 2);
+
+       etna_cmd_stream_emit(stream, 0x3);
+       assert(etna_cmd_stream_avail(stream) == 1);
+
+       etna_cmd_stream_del(stream);
+
+       printf("ok\n");
+}
+
+static void test_offset()
+{
+       struct etna_cmd_stream *stream;
+
+       printf("testing etna_cmd_stream_offset ... ");
+
+       stream = etna_cmd_stream_new(NULL, 6, NULL, NULL);
+       assert(etna_cmd_stream_offset(stream) == 0);
+
+       etna_cmd_stream_emit(stream, 0x1);
+       assert(etna_cmd_stream_offset(stream) == 1);
+
+       etna_cmd_stream_emit(stream, 0x2);
+       assert(etna_cmd_stream_offset(stream) == 2);
+
+       etna_cmd_stream_emit(stream, 0x3);
+       etna_cmd_stream_emit(stream, 0x4);
+       assert(etna_cmd_stream_offset(stream) == 4);
+
+       etna_cmd_stream_del(stream);
+
+       printf("ok\n");
+}
+
+int main(int argc, char *argv[])
+{
+       test_avail();
+       test_emit();
+       test_offset();
+
+       return 0;
+}