* Generate raw batches for unit testing the decoder
@ 2013-12-13 18:15 Damien Lespiau
2013-12-13 18:15 ` [PATCH 1/2] tests: Add a helper to generate raw batches Damien Lespiau
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Damien Lespiau @ 2013-12-13 18:15 UTC (permalink / raw)
To: intel-gfx
libdrm has a way to unit-test the CS decoder: test_decode can decode a raw
batch and compare it to a reference output.
However, one still needs to genarate the raw, binary, batches to feed to
test_decode. This couple of patches do exactly that.
--
Damien
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH 1/2] tests: Add a helper to generate raw batches 2013-12-13 18:15 Generate raw batches for unit testing the decoder Damien Lespiau @ 2013-12-13 18:15 ` Damien Lespiau 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 2 siblings, 0 replies; 4+ messages in thread From: Damien Lespiau @ 2013-12-13 18:15 UTC (permalink / raw) To: intel-gfx 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 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] generate_test_batches: Add a MI_LOAD_REGISTER_IMM test batch 2013-12-13 18:15 Generate raw batches for unit testing the decoder Damien Lespiau 2013-12-13 18:15 ` [PATCH 1/2] tests: Add a helper to generate raw batches Damien Lespiau @ 2013-12-13 18:15 ` Damien Lespiau 2013-12-16 10:53 ` Generate raw batches for unit testing the decoder Damien Lespiau 2 siblings, 0 replies; 4+ messages in thread From: Damien Lespiau @ 2013-12-13 18:15 UTC (permalink / raw) To: intel-gfx Signed-off-by: Damien Lespiau <damien.lespiau@intel.com> --- tests/generate_test_batches.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/generate_test_batches.c b/tests/generate_test_batches.c index 997ce37..41f883d 100644 --- a/tests/generate_test_batches.c +++ b/tests/generate_test_batches.c @@ -87,6 +87,25 @@ static void emit_mi_flush_dw(struct intel_batchbuffer *batch) batch_finish(batch, "gen8-2d-mi-flush-dw-len-4.batch"); } +#define MI_LOAD_REGISTER_IMM (0x22<<23) + +/* + * Make sure we correctly print out addresses when the address field only + * specificies a number of bits (eg. 22:3). The value to decode is then: + * val << 3 + * and not just the raw field value. + */ +static void emit_mi_load_register_imm(struct intel_batchbuffer *batch) +{ + batch_start(batch); + + OUT_BATCH(MI_LOAD_REGISTER_IMM | (3-2)); + OUT_BATCH(0x0000227c); + OUT_BATCH(0); + + batch_finish(batch, "gen8-3d-partial-addresses.batch"); +} + static struct gen_batches { int drm_fd; uint32_t devid; @@ -106,4 +125,5 @@ int main(int argc, char **argv) igt_assert(batch); emit_mi_flush_dw(batch); + emit_mi_load_register_imm(batch); } -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: Generate raw batches for unit testing the decoder 2013-12-13 18:15 Generate raw batches for unit testing the decoder Damien Lespiau 2013-12-13 18:15 ` [PATCH 1/2] tests: Add a helper to generate raw batches Damien Lespiau 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 ` Damien Lespiau 2 siblings, 0 replies; 4+ messages in thread From: Damien Lespiau @ 2013-12-16 10:53 UTC (permalink / raw) To: intel-gfx On Fri, Dec 13, 2013 at 06:15:45PM +0000, Damien Lespiau wrote: > libdrm has a way to unit-test the CS decoder: test_decode can decode a raw > batch and compare it to a reference output. > > However, one still needs to genarate the raw, binary, batches to feed to > test_decode. This couple of patches do exactly that. Chris noted that it's weird to have those in igt to test code in libdrm. While this is true, I didn't want to create yet another copy of the command definitions we'd have to synchronize by hand (lacking a better solution). I don't mind keeping them in a branch, so let's just discard those. -- Damien ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-12-16 10:53 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-12-13 18:15 Generate raw batches for unit testing the decoder Damien Lespiau 2013-12-13 18:15 ` [PATCH 1/2] tests: Add a helper to generate raw batches Damien Lespiau 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox