Esempio n. 1
0
int main(void) {
	int i;
	int shmid;
	setup_display();
	shm_unlink(SHMOBJ_PATH);
	transfer_pixmap = (char*)malloc(DISPLAY_WIDTH * DISPLAY_HEIGHT);
	pixmap = (char*)malloc(DISPLAY_WIDTH * DISPLAY_HEIGHT);
	int shared_seg_size = DISPLAY_WIDTH * DISPLAY_HEIGHT;

	key_t key = ftok("/tmp/foo", 'A');
	shmid = shmget (key,shared_seg_size,IPC_CREAT|0600);
	if (shmid==-1) {
	    perror("shmget");
	    exit(1);
	  }

	pixmap = shmat(shmid, 0, 0);

	memset(transfer_pixmap, 0, DISPLAY_WIDTH * DISPLAY_HEIGHT);
	memset(pixmap, 0, DISPLAY_WIDTH * DISPLAY_HEIGHT);

	int x, y;

	while (1) {
		pixmap_to_strange_pixmap();
		push_foo();
	}

}
Esempio n. 2
0
int main(void)
{
	char *buffer;
	const char *p;
	size_t len, left;
	struct foo *foo, *foo2;

	/* This is how many tests you plan to run */
	plan_tests(17);

	/* Valgrind will make sure we don't read padding! */
	foo = malloc(sizeof(*foo));
	foo->vu64 = 0x01020304050607ULL;
	foo->vu32 = 0x08090a0b;
	foo->vu16 = 0x0c0d;
	foo->vu8 = 0x0e;
	foo->vuchar = 0x0f;
	foo->vs64 = -0x1011121314151617LL;
	foo->vs32 = -0x18191a1b;
	foo->vs16 = -0x1c1d;
	foo->vs8 = -0x1e;
	foo->vchar = -0x1f;
	memset(foo->bytes, 0x20, sizeof(foo->bytes));
	strcpy(foo->bytes, "This is a test");

	buffer = malloc(1);
	len = 0;
	ok1(push_foo(&buffer, &len, foo));
	ok1(len <= sizeof(*foo));

	/* Triggers valgrind's uninitialized value warning */
	ok1(!memchr(buffer, 0x21, len));

	p = buffer;
	left = len;
	foo2 = malloc(sizeof(*foo2));
	ok1(pull_foo(&p, &left, foo2));
	ok1(left == 0);
	ok1(p == buffer + len);
	ok1(foo_equal(foo, foo2));

	/* Too-small for pull, it should fail and set ptr/len to 0 */
	p = buffer;
	left = 0;
	ok1(!pull_u64(&p, &left, &foo2->vu64));
	ok1(p == NULL && left == 0);
	/* Shouldn't change field! */
	ok1(foo_equal(foo, foo2));

	left = 7;
	ok1(!pull_u64(&p, &left, &foo2->vu64));
	ok1(p == NULL && left == 0);
	/* Shouldn't change field! */
	ok1(foo_equal(foo, foo2));

	/* Discard should work. */
	left = len;
	ok1(pull_bytes(&p, &left, NULL, sizeof(foo->bytes)));
	ok1(left == len - sizeof(foo->bytes));

	/* Push failures should be clean. */
	push_set_realloc(fail_reallocfn);
	p = buffer;
	left = len;
	ok1(!push_u64(&buffer, &left, foo->vu64));
	ok1(p == buffer && left == len);

	free(buffer);
	free(foo);
	free(foo2);

	/* This exits depending on whether all tests passed */
	return exit_status();
}