From: Damien Lespiau <damien.lespiau@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH 1/2] tests: Add a helper to generate raw batches
Date: Fri, 13 Dec 2013 18:15:46 +0000 [thread overview]
Message-ID: <1386958547-11068-2-git-send-email-damien.lespiau@intel.com> (raw)
In-Reply-To: <1386958547-11068-1-git-send-email-damien.lespiau@intel.com>
These batches can be used to test the CS parser in libdrm. Let's start
by generating a MI_FLUSH_DW command that flushes a DWord (as opposed to
a QWord).
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
tests/.gitignore | 1 +
tests/Makefile.sources | 1 +
tests/generate_test_batches.c | 109 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 111 insertions(+)
create mode 100644 tests/generate_test_batches.c
diff --git a/tests/.gitignore b/tests/.gitignore
index 8a00364..f6e2cf8 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -97,6 +97,7 @@ gen3_render_linear_blits
gen3_render_mixed_blits
gen3_render_tiledx_blits
gen3_render_tiledy_blits
+generate_test_batches
igt_fork_helper
igt_list_only
igt_no_exit
diff --git a/tests/Makefile.sources b/tests/Makefile.sources
index e286a7c..493fa4e 100644
--- a/tests/Makefile.sources
+++ b/tests/Makefile.sources
@@ -1,6 +1,7 @@
noinst_PROGRAMS = \
gem_stress \
ddi_compute_wrpll \
+ generate_test_batches \
$(TESTS_progs) \
$(TESTS_progs_M) \
$(HANG) \
diff --git a/tests/generate_test_batches.c b/tests/generate_test_batches.c
new file mode 100644
index 0000000..997ce37
--- /dev/null
+++ b/tests/generate_test_batches.c
@@ -0,0 +1,109 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <assert.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "drmtest.h"
+#include "intel_batchbuffer.h"
+#include "gen8_render.h"
+#include "intel_reg.h"
+#include "i830_reg.h"
+
+#define ALIGN(x, y) (((x) + (y)-1) & ~((y)-1))
+
+static uint32_t
+batch_used(struct intel_batchbuffer *batch)
+{
+ return batch->ptr - batch->buffer;
+}
+
+static void dump_batch(struct intel_batchbuffer *batch,
+ const char *filename)
+{
+ int fd;
+
+ fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (fd == -1) {
+ fprintf(stderr, "Couldn't open %s: %s", filename,
+ strerror(errno));
+ return;
+ }
+
+ write(fd, batch->buffer, batch_used(batch));
+ close(fd);
+}
+
+static uint32_t
+batch_align(struct intel_batchbuffer *batch, uint32_t align)
+{
+ uint32_t offset;
+
+ offset = batch_used(batch);
+ offset = ALIGN(offset, align);
+ batch->ptr = batch->buffer + offset;
+ return offset;
+}
+
+static void batch_start(struct intel_batchbuffer *batch)
+{
+ batch_align(batch, 8);
+}
+
+static void batch_finish(struct intel_batchbuffer *batch, const char *filename)
+{
+ uint32_t batch_end;
+
+ batch_end = batch_align(batch, 8);
+ assert(batch_end < 4095);
+
+ dump_batch(batch, filename);
+
+ intel_batchbuffer_reset(batch);
+}
+
+static void emit_mi_flush_dw(struct intel_batchbuffer *batch)
+{
+ batch_start(batch);
+
+ OUT_BATCH(MI_FLUSH_DW | (4-2));
+ OUT_BATCH(0xdead0000 | 1 << 2);
+ OUT_BATCH(0);
+ OUT_BATCH(0);
+
+ /*
+ * Add a random command after MI_FLUSH_DW to make sure we continue
+ * decoding correctly
+ */
+
+ OUT_BATCH(MI_STORE_DWORD_IMM);
+ OUT_RELOC(batch->bo, I915_GEM_DOMAIN_INSTRUCTION,
+ I915_GEM_DOMAIN_INSTRUCTION, 0xbeef00);
+ OUT_BATCH(0);
+ OUT_BATCH(0xf00);
+
+ batch_finish(batch, "gen8-2d-mi-flush-dw-len-4.batch");
+}
+
+static struct gen_batches {
+ int drm_fd;
+ uint32_t devid;
+ drm_intel_bufmgr *bufmgr;
+} data;
+
+int main(int argc, char **argv)
+{
+ struct intel_batchbuffer *batch = NULL;
+
+ data.drm_fd = drm_open_any_render();
+ data.devid = intel_get_drm_devid(data.drm_fd);
+ data.bufmgr = drm_intel_bufmgr_gem_init(data.drm_fd, 4096);
+ igt_assert(data.bufmgr);
+
+ batch = intel_batchbuffer_alloc(data.bufmgr, data.devid);
+ igt_assert(batch);
+
+ emit_mi_flush_dw(batch);
+}
--
1.8.3.1
next prev parent reply other threads:[~2013-12-13 18:16 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-13 18:15 Generate raw batches for unit testing the decoder Damien Lespiau
2013-12-13 18:15 ` Damien Lespiau [this message]
2013-12-13 18:15 ` [PATCH 2/2] generate_test_batches: Add a MI_LOAD_REGISTER_IMM test batch Damien Lespiau
2013-12-16 10:53 ` Generate raw batches for unit testing the decoder Damien Lespiau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1386958547-11068-2-git-send-email-damien.lespiau@intel.com \
--to=damien.lespiau@intel.com \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox