summaryrefslogtreecommitdiff
path: root/tests/radeon_bo_test.c
blob: bfbf6be178915d8d5228bd1bef068b6cde5b0242 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
 * Copyright © 2008 Red Hat
 *
 * 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:
 *    Dave Airlie
 *
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <inttypes.h>
#include <errno.h>
#include <sys/stat.h>
#include "drm.h"
#include "radeon_drm.h"
#include "radeon_bo_gem.h"

#define OBJECT_SIZE 16384

int main(int argc, char **argv)
{
	int fd;
	struct drm_radeon_gem_create create;
	struct drm_radeon_gem_mmap mmap;
	struct drm_gem_close unref;
	uint8_t expected[OBJECT_SIZE];
	uint8_t buf[OBJECT_SIZE];
	uint8_t *addr;
	int ret;
	int handle;
	struct radeon_bo_manager *bom;
	struct radeon_bo *bo;
	int i;

	fd = drm_open_any();

	bom = radeon_bo_manager_gem_ctor(fd);
	if (!bom) {
		fprintf(stderr,"failed to setup bom\n");
		exit(-2);
	}

	bo = radeon_bo_open(bom, 0, OBJECT_SIZE, 0, 0, 0);
	if (!bo) {
		fprintf(stderr,"failed to open bo\n");
		exit(-2);
	}

	ret = radeon_bo_map(bo, 1);
	if (ret) {
		fprintf(stderr,"failed to map bo\n");
		exit(-2);
	}
	
	addr = bo->ptr;

#if 0
	printf("Testing contents of newly created object.\n");
	memset(expected, 0, sizeof(expected));
	assert(memcmp(addr, expected, sizeof(expected)) == 0);
#endif

	/* fill the buffer with something, then migrate in out */
	memset(expected, 0xaa, sizeof(expected));
	memset(addr, 0xaa, OBJECT_SIZE);

	if (memcmp(addr, expected, sizeof(expected)))
	  fprintf(stderr,"0xaa failed to match up\n");

	for (i = 0; i < 15000; i++) {
	ret = radeon_gem_set_domain(bo, 0, RADEON_GEM_DOMAIN_VRAM);
	if (ret) {
	  fprintf(stderr,"set domain failed\n");
	  break;
	}
	
	if (memcmp(addr, expected, sizeof(expected))) {
	  fprintf(stderr,"0xaa failed to match up -post VRAM move\n");
	  break;
	}

	ret = radeon_gem_set_domain(bo, 0, RADEON_GEM_DOMAIN_GTT);
	if (ret) {
	  fprintf(stderr,"set domain failed\n");
	  break;
	}
	if (memcmp(addr, expected, sizeof(expected))) {
	  fprintf(stderr,"0xaa failed to match up -post GTT move\n");
	  break;
	}
        }
	radeon_bo_unref(bo);

	radeon_bo_manager_gem_dtor(bom);
	close(fd);

	return 0;
}