mirror of
				https://github.com/tiagovignatti/intel-gpu-tools.git
				synced 2025-11-04 12:07:12 +00:00 
			
		
		
		
	tests/gem_flink: check flink lifetime rules
flink names may not be destroyed while there's still a userspace handle around. Test this by - exporting an flink name from fd2 - open a gem bo from that name in fd - close fd2, then open a new drm file (so that the original handle disappears) - check whether the same flink name still works
This commit is contained in:
		
							parent
							
								
									d8df90dc6b
								
							
						
					
					
						commit
						6daae8bcb6
					
				@ -115,6 +115,41 @@ test_bad_open(int fd)
 | 
				
			|||||||
	assert(ret == -1 && errno == ENOENT);
 | 
						assert(ret == -1 && errno == ENOENT);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void
 | 
				
			||||||
 | 
					test_flink_lifetime(int fd)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct drm_i915_gem_create create;
 | 
				
			||||||
 | 
						struct drm_gem_flink flink;
 | 
				
			||||||
 | 
						struct drm_gem_open gem_open;
 | 
				
			||||||
 | 
						int ret, fd2;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						printf("Testing flink lifetime.\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						fd2 = drm_open_any();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						memset(&create, 0, sizeof(create));
 | 
				
			||||||
 | 
						create.size = 16 * 1024;
 | 
				
			||||||
 | 
						ret = ioctl(fd2, DRM_IOCTL_I915_GEM_CREATE, &create);
 | 
				
			||||||
 | 
						assert(ret == 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						flink.handle = create.handle;
 | 
				
			||||||
 | 
						ret = ioctl(fd2, DRM_IOCTL_GEM_FLINK, &flink);
 | 
				
			||||||
 | 
						assert(ret == 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						gem_open.name = flink.name;
 | 
				
			||||||
 | 
						ret = ioctl(fd, DRM_IOCTL_GEM_OPEN, &gem_open);
 | 
				
			||||||
 | 
						assert(ret == 0);
 | 
				
			||||||
 | 
						assert(gem_open.handle != 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						close(fd2);
 | 
				
			||||||
 | 
						fd2 = drm_open_any();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						gem_open.name = flink.name;
 | 
				
			||||||
 | 
						ret = ioctl(fd2, DRM_IOCTL_GEM_OPEN, &gem_open);
 | 
				
			||||||
 | 
						assert(ret == 0);
 | 
				
			||||||
 | 
						assert(gem_open.handle != 0);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main(int argc, char **argv)
 | 
					int main(int argc, char **argv)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int fd;
 | 
						int fd;
 | 
				
			||||||
@ -131,6 +166,8 @@ int main(int argc, char **argv)
 | 
				
			|||||||
		test_bad_flink(fd);
 | 
							test_bad_flink(fd);
 | 
				
			||||||
	if (drmtest_run_subtest("bad-open"))
 | 
						if (drmtest_run_subtest("bad-open"))
 | 
				
			||||||
		test_bad_open(fd);
 | 
							test_bad_open(fd);
 | 
				
			||||||
 | 
						if (drmtest_run_subtest("flink-lifetime"))
 | 
				
			||||||
 | 
							test_bad_open(fd);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user