@@ -94,21 +94,16 @@ check_bo(struct intel_batchbuffer *batch, struct igt_buf *buf, uint32_t val)
dri_bo_unmap(linear);
}
-int main(int argc, char **argv)
+static void run_test (int fd, int count)
{
drm_intel_bufmgr *bufmgr;
struct intel_batchbuffer *batch;
uint32_t *start_val;
struct igt_buf *buf;
uint32_t start = 0;
- int i, j, fd, count;
+ int i, j;
uint32_t devid;
- igt_simple_init(argc, argv);
-
- igt_skip_on_simulation();
-
- fd = drm_open_any();
devid = intel_get_drm_devid(fd);
render_copy = igt_get_render_copyfunc(devid);
@@ -124,23 +119,6 @@ int main(int argc, char **argv)
drm_intel_bufmgr_gem_set_vma_cache_size(bufmgr, 32);
batch = intel_batchbuffer_alloc(bufmgr, devid);
- count = 0;
- if (argc > 1)
- count = atoi(argv[1]);
- if (count == 0)
- count = 3 * gem_aperture_size(fd) / SIZE / 2;
- else if (count < 2) {
- igt_warn("count must be >= 2\n");
- return 1;
- }
-
- if (count > intel_get_total_ram_mb() * 9 / 10) {
- count = intel_get_total_ram_mb() * 9 / 10;
- igt_info("not enough RAM to run test, reducing buffer count\n");
- }
-
- igt_info("Using %d 1MiB buffers\n", count);
-
linear = drm_intel_bo_alloc(bufmgr, "linear", WIDTH*HEIGHT*4, 0);
if (snoop) {
gem_set_caching(fd, linear->handle, 1);
@@ -211,5 +189,46 @@ int main(int argc, char **argv)
for (i = 0; i < count; i++)
check_bo(batch, &buf[i], start_val[i]);
+ /* release resources */
+ drm_intel_bo_unreference(linear);
+ for (i = 0; i < count; i++) {
+ drm_intel_bo_unreference(buf[i].bo);
+ }
+ intel_batchbuffer_free(batch);
+ drm_intel_bufmgr_destroy(bufmgr);
+}
+
+
+int main(int argc, char **argv)
+{
+ int fd = 0;
+ int count = 0;
+
+ igt_subtest_init(argc, argv);
+ igt_fixture {
+ fd = drm_open_any();
+ }
+
+ igt_subtest("basic") {
+ run_test(fd, 2);
+ }
+
+ /* the rest of the tests are too long for simulation */
+ igt_skip_on_simulation();
+
+ igt_subtest("apperture-thrash") {
+ count = 3 * gem_aperture_size(fd) / SIZE / 2;
+ intel_require_memory(count, SIZE, CHECK_RAM);
+ run_test(fd, count);
+ }
+
+ igt_subtest("swap-thrash") {
+ uint64_t swap_mb = intel_get_total_swap_mb();
+ igt_require(swap_mb > 0);
+ count = ((intel_get_avail_ram_mb() + (swap_mb / 2)) * 1024*1024) / SIZE;
+ intel_require_memory(count, SIZE, CHECK_RAM | CHECK_SWAP);
+ run_test(fd, count);
+ }
+
igt_exit();
}