mbohun
3/9/2015 - 11:47 PM

race bug test

race bug test

    void run(pid_t pid)
    {
    	int n;
    	int status;
    	int fd;
    	char *buffer;
    	buffer = memalign(BUFFER_ALIGN, BUFFER_SIZE);
    	n = snprintf(buffer, BUFFER_SIZE, "%d\n", pid);
    	fd = open(CGPATH "/test/tasks", O_WRONLY);
    	write(fd, buffer, n);
    	close(fd);
    	if (fork() > 0) {
    		fd = open("/dev/sda", O_RDONLY | O_DIRECT);
    		read(fd, buffer, 512);
    		close(fd);
    		wait(&status);
    	} else {
    		fd = open(CGPATH "/test/blkio.throttle.io_serviced", O_RDONLY);
    		n = read(fd, buffer, BUFFER_SIZE);
    		close(fd);
    	}
    	free(buffer);
    	exit(0);
    }
    
    void test(void)
    {
    	int status;
    	mkdir(CGPATH "/test", 0666);
    	if (fork() > 0)
    		wait(&status);
    	else
    		run(getpid());
    	rmdir(CGPATH "/test");
    }
    
    int main(int argc, char **argv)
    {
    	int i;
    	for (i = 0; i < NR_TESTS; i++)
    		test();
    	return 0;
    }