2
* Copyright © 2011 Intel Corporation
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29
#include <sys/types.h>
35
#include "intel_bufmgr.h"
36
#include "intel_chipset.h"
38
#define HW_OFFSET 0x12300000
43
fprintf(stderr, "usage:\n");
44
fprintf(stderr, " test_decode <batch>\n");
45
fprintf(stderr, " test_decode <batch> -dump\n");
50
read_file(const char *filename, void **ptr, size_t *size)
55
fd = open(filename, O_RDONLY);
57
errx(1, "couldn't open `%s'", filename);
61
errx(1, "couldn't stat `%s'", filename);
64
*ptr = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
65
if (*ptr == MAP_FAILED)
66
errx(1, "couldn't map `%s'", filename);
72
dump_batch(struct drm_intel_decode *ctx, const char *batch_filename)
77
read_file(batch_filename, &batch_ptr, &batch_size);
79
drm_intel_decode_set_batch_pointer(ctx, batch_ptr, HW_OFFSET,
81
drm_intel_decode_set_output_file(ctx, stdout);
83
drm_intel_decode(ctx);
87
compare_batch(struct drm_intel_decode *ctx, const char *batch_filename)
90
void *ptr, *ref_ptr, *batch_ptr;
91
size_t size, ref_size, batch_size;
92
const char *ref_suffix = "-ref.txt";
95
ref_filename = malloc(strlen(batch_filename) + strlen(ref_suffix) + 1);
96
sprintf(ref_filename, "%s%s", batch_filename, ref_suffix);
98
/* Read the batch and reference. */
99
read_file(batch_filename, &batch_ptr, &batch_size);
100
read_file(ref_filename, &ref_ptr, &ref_size);
102
/* Set up our decode output in memory, because I don't want to
103
* figure out how to output to a file in a safe and sane way
104
* inside of an automake project's test infrastructure.
106
#ifdef HAVE_OPEN_MEMSTREAM
107
out = open_memstream((char **)&ptr, &size);
109
fprintf(stderr, "platform lacks open_memstream, skipping.\n");
113
drm_intel_decode_set_batch_pointer(ctx, batch_ptr, HW_OFFSET,
115
drm_intel_decode_set_output_file(ctx, out);
117
drm_intel_decode(ctx);
119
if (strcmp(ref_ptr, ptr) != 0) {
120
fprintf(stderr, "Decode mismatch with reference `%s'.\n",
122
fprintf(stderr, "You can dump the new output using:\n");
123
fprintf(stderr, " test_decode \"%s\" -dump\n", batch_filename);
133
infer_devid(const char *batch_filename)
144
{ "gen5", PCI_CHIP_ILD_G },
145
{ "gen6", PCI_CHIP_SANDYBRIDGE_GT2 },
146
{ "gen7", PCI_CHIP_IVYBRIDGE_GT2 },
151
for (i = 0; chipsets[i].name != NULL; i++) {
152
if (strstr(batch_filename, chipsets[i].name))
153
return chipsets[i].devid;
156
fprintf(stderr, "Couldn't guess chipset id from batch filename `%s'.\n",
158
fprintf(stderr, "Must be contain one of:\n");
159
for (i = 0; chipsets[i].name != NULL; i++) {
160
fprintf(stderr, " %s\n", chipsets[i].name);
166
main(int argc, char **argv)
169
struct drm_intel_decode *ctx;
175
devid = infer_devid(argv[1]);
177
ctx = drm_intel_decode_context_alloc(devid);
180
if (strcmp(argv[2], "-dump") == 0)
181
dump_batch(ctx, argv[1]);
185
compare_batch(ctx, argv[1]);
188
drm_intel_decode_context_free(ctx);