summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2018-05-02 16:47:35 +0200
committerThierry Reding <treding@nvidia.com>2018-05-02 18:05:01 +0200
commitde896186051e6a400d7071d529bfe23597a0cce5 (patch)
treeadcfb67e97ccf20776e33a1ae515caa4ad1905ab
parente17cc8b82c85a2c71bc887299729adc55bf78e6c (diff)
tests: tegra: Add syncpt-wait test
This is a very simple sanity test to check whether or not a syncpt can be incremented by a host1x client. This uses gr2d on Tegra20 through Tegra114 and VIC on Tegra124 and later. Signed-off-by: Thierry Reding <treding@nvidia.com>
-rw-r--r--tests/tegra/Makefile.am7
-rw-r--r--tests/tegra/meson.build9
-rw-r--r--tests/tegra/syncpt-wait.c139
3 files changed, 153 insertions, 2 deletions
diff --git a/tests/tegra/Makefile.am b/tests/tegra/Makefile.am
index 102ec559..2a67e671 100644
--- a/tests/tegra/Makefile.am
+++ b/tests/tegra/Makefile.am
@@ -29,12 +29,15 @@ LDADD = \
if HAVE_INSTALL_TESTS
bin_PROGRAMS = \
tegra-openclose \
- tegra-gr2d-fill
+ tegra-gr2d-fill \
+ tegra-syncpt-wait
else
noinst_PROGRAMS = \
tegra-openclose \
- tegra-gr2d-fill
+ tegra-gr2d-fill \
+ tegra-syncpt-wait
endif
tegra_openclose_SOURCES = openclose.c
tegra_gr2d_fill_SOURCES = gr2d-fill.c
+tegra_syncpt_wait_SOURCES = syncpt-wait.c
diff --git a/tests/tegra/meson.build b/tests/tegra/meson.build
index 793d308e..9e859f61 100644
--- a/tests/tegra/meson.build
+++ b/tests/tegra/meson.build
@@ -58,3 +58,12 @@ gr2d_fill = executable(
link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra],
install : with_install_tests,
)
+
+syncpt_wait = executable(
+ 'tegra-syncpt-wait',
+ files('syncpt-wait.c'),
+ include_directories : [inc_root, inc_drm, inc_tegra],
+ c_args : warn_c_args,
+ link_with : [libdrm, libdrm_tegra, libdrm_test, libdrm_test_tegra],
+ install : with_install_tests,
+)
diff --git a/tests/tegra/syncpt-wait.c b/tests/tegra/syncpt-wait.c
new file mode 100644
index 00000000..b314a991
--- /dev/null
+++ b/tests/tegra/syncpt-wait.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright © 2018 NVIDIA Corporation
+ *
+ * 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 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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.
+ */
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "tegra.h"
+
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
+static int channel_open(struct drm_tegra_channel **channel,
+ struct drm_tegra *drm)
+{
+ static const struct {
+ enum drm_tegra_class class;
+ const char *name;
+ } classes[] = {
+ { DRM_TEGRA_VIC, "VIC" },
+ { DRM_TEGRA_GR2D, "GR2D" },
+ };
+ unsigned int i;
+ int err;
+
+ for (i = 0; i < ARRAY_SIZE(classes); i++) {
+ err = drm_tegra_channel_open(channel, drm, classes[i].class);
+ if (err < 0) {
+ fprintf(stderr, "failed to open channel to %s: %s\n",
+ classes[i].name, strerror(-err));
+ continue;
+ }
+
+ break;
+ }
+
+ return err;
+}
+
+int main(int argc, char *argv[])
+{
+ const char *device = "/dev/dri/renderD128";
+ struct drm_tegra_channel *channel;
+ struct drm_tegra_pushbuf *pushbuf;
+ unsigned int num_syncpoints;
+ struct drm_tegra_job *job;
+ struct drm_tegra *drm;
+ int fd, err;
+
+ if (argc > 1)
+ device = argv[1];
+
+ fd = open(device, O_RDWR);
+ if (fd < 0) {
+ fprintf(stderr, "open() failed: %s\n", strerror(errno));
+ return 1;
+ }
+
+ err = drm_tegra_new(&drm, fd);
+ if (err < 0) {
+ fprintf(stderr, "failed to open Tegra device: %s\n", strerror(-err));
+ close(fd);
+ return 1;
+ }
+
+ err = channel_open(&channel, drm);
+ if (err < 0) {
+ fprintf(stderr, "failed to open channel: %s\n", strerror(-err));
+ return 1;
+ }
+
+ num_syncpoints = drm_tegra_channel_get_syncpoints(channel);
+ printf("channel opened: %u syncpoints\n", num_syncpoints);
+
+ err = drm_tegra_job_new(&job, channel);
+ if (err < 0) {
+ fprintf(stderr, "failed to create job: %s\n", strerror(-err));
+ return 1;
+ }
+
+ err = drm_tegra_pushbuf_new(&pushbuf, job);
+ if (err < 0) {
+ fprintf(stderr, "failed to create push buffer: %s\n", strerror(-err));
+ return 1;
+ }
+
+ err = drm_tegra_pushbuf_prepare(pushbuf, 4);
+ if (err < 0) {
+ fprintf(stderr, "failed to prepare push buffer: %s\n", strerror(-err));
+ return 1;
+ }
+
+ err = drm_tegra_pushbuf_sync(pushbuf, 0, 1, DRM_TEGRA_SYNC_COND_IMMEDIATE);
+ if (err < 0) {
+ fprintf(stderr, "failed to push syncpoint: %s\n", strerror(-err));
+ return 1;
+ }
+
+ err = drm_tegra_job_submit(job, 1000);
+ if (err < 0) {
+ fprintf(stderr, "failed to submit job: %s\n", strerror(-err));
+ return 1;
+ }
+
+ err = drm_tegra_job_wait(job);
+ if (err < 0) {
+ fprintf(stderr, "failed to wait for job: %s\n", strerror(-err));
+ return 1;
+ }
+
+ drm_tegra_pushbuf_free(pushbuf);
+ drm_tegra_job_free(job);
+
+ drm_tegra_channel_close(channel);
+ drm_tegra_close(drm);
+ close(fd);
+
+ return 0;
+}