Пример #1
0
/* check that a write is carried through to file */
void test_mapping_write_is_carried_through_to_file(void)
{
	vm_map_t map;
	w_size_t pos;
	const w_size_t num_pages = 10;
	const w_size_t num_frames = 4;
	char tmp;
	w_boolean_t byte_found = FALSE;
	w_size_t page_offset;
	w_size_t i;

	vmsim_init();
	w_set_exception_handler(vmsim_test_segv_handler);
	vm_alloc(num_pages, num_frames, &map);
	zero_file(map.ram_handle, num_frames * p_sz);

	pos = get_random_byte_mapping_position(num_pages);

	((char *) map.start)[pos] = MAGIC;

	w_sync_mapping(map.start, num_pages);

	page_offset = pos % p_sz;
	for (i = 0; i < num_frames; i++) {
		tmp = read_byte_from_file(map.ram_handle,
					  i * p_sz + page_offset);
		if (tmp == MAGIC)
			byte_found = TRUE;
	}

	vm_free(map.start);
	vmsim_cleanup();

	basic_test(byte_found == TRUE);
}
Пример #2
0
int create_control_files(char *mnt)
{
	char *control_dir = eyefi_file_on(RDIR, mnt);
	int ret = 0;
	enum eyefi_file file;

	ret = mkdir(control_dir, 0644);
	debug_printf(1, "making control directory: '%s', errno: %d\n", control_dir, errno);
	free(control_dir);
	if ((ret != 0) && (errno != EEXIST)) {
		perror("unable to create Eye-Fi control directory");
		return errno;
	}
	for (file = REQC; file <= RSPM; file++) {
		ret = zero_file(file, mnt);
		debug_printf(2, "trying to create control file: '%s', ret: %d\n",
				eyefi_file_name(file), ret);
		if (ret) {
			perror("unable to create control file");
			goto out;
		}
	}
out:
	return ret;
}
Пример #3
0
/* test swap out */
void test_swap_out(void)
{
	vm_map_t map;
	const w_size_t num_pages = 10;
	const w_size_t num_frames = 4;
	char tmp;
	w_size_t i;
	w_size_t j;
	w_size_t *offset_array;
	w_size_t match_count = 0;

	vmsim_init();
	w_set_exception_handler(vmsim_test_segv_handler);
	vm_alloc(num_pages, num_frames, &map);

	/* zero swap for further checking */
	zero_file(map.swap_handle, num_pages * p_sz);

	offset_array = malloc((num_frames + 1) * sizeof(*offset_array));

	/*
	 * at most num_frame pages will be backed by RAM
	 * the (num_frame + 1)-th access will result in a swap out
	 */
	for (i = 0; i < num_frames + 1; i++) {
		offset_array[i] = get_random_byte_mapping_position(1);
		*((char *) map.start + i * p_sz + offset_array[i]) = MAGIC;
	}

	/* sync ram file to ensure proper swap out */
	w_sync_mapping(map.start, num_pages);

	/* go through swap to look for swapped pages */
	for (i = 0; i < num_pages; i++) {
		for (j = 0; j < num_frames + 1; j++) {
			w_size_t offset = i * p_sz + offset_array[j];

			tmp = read_byte_from_file(map.swap_handle, offset);
			if (tmp == MAGIC) {
				dlog(LOG_DEBUG, "match found, frame index:"
					"%u, offset: %u\n", i, offset);
				match_count++;
				break;
			}
		}
	}

	dlog(LOG_DEBUG, "match count: %u\n", match_count);

	vm_free(map.start);
	vmsim_cleanup();
	free(offset_array);

	basic_test(match_count > 0);
}
Пример #4
0
static int prep_file(void)
{
	int ret, fd, flags = O_RDWR;
	off_t length = blocksize*num_blocks;

	if (rank)
		goto open_after;

	flags |= prep_open_flags;

	fd = open(filename, flags, S_IROTH|S_IRGRP|S_IRUSR|S_IWUSR);
	if (fd == -1) {
		ret = errno;
		abort_printf("Error %d opening file \"%s\": %s\n",
			     ret, filename, strerror(ret));
	}

	do_mmap(fd, length);

	zero_file(fd, length);

	ret = MPI_Barrier(MPI_COMM_WORLD);
	if (ret != MPI_SUCCESS)
		abort_printf("Prep MPI_Barrier failed: %d\n", ret);

	goto populate;

open_after:
	ret = MPI_Barrier(MPI_COMM_WORLD);
	if (ret != MPI_SUCCESS)
		abort_printf("Prep MPI_Barrier failed: %d\n", ret);

	fd = open(filename, flags);
	if (fd == -1) {
		ret = errno;
		abort_printf("Error %d opening file \"%s\": %s\n",
			     ret, filename, strerror(ret));
	}

	do_mmap(fd, length);

populate:
	if (pre_populate) {
		int i;
		char *b = mapped_area;

		for(i = 0; i < num_blocks; i++) {
			memcpy(local_pattern, b, blocksize);
			b += blocksize;
		}
	}

	return fd;
}
Пример #5
0
void test_mapping_multiple_writes_do_not_overwrite_ram(void)
{
	vm_map_t map;
	const w_size_t num_pages = 10;
	const w_size_t num_frames = 4;
	char tmp;
	w_size_t i;
	w_size_t j;
	w_size_t *offset_array;
	w_size_t match_count = 0;

	vmsim_init();
	w_set_exception_handler(vmsim_test_segv_handler);
	vm_alloc(num_pages, num_frames, &map);
	zero_file(map.ram_handle, num_frames * p_sz);

	offset_array = malloc(num_pages * sizeof(*offset_array));

	for (i = 0; i < num_pages; i++) {
		offset_array[i] = get_random_byte_mapping_position(1);
		*((char *) map.start + i * p_sz + offset_array[i]) = MAGIC;
	}

	w_sync_mapping(map.start, num_pages);

	for (i = 0; i < num_frames; i++) {
		for (j = 0; j < num_pages; j++) {
			w_size_t offset = i * p_sz + offset_array[j];

			tmp = read_byte_from_file(map.ram_handle, offset);
			if (tmp == MAGIC) {
				dlog(LOG_DEBUG, "match found, frame index:"
					"%u, offset: %u\n", i, offset);
				match_count++;
				break;
			}
		}
	}

	dlog(LOG_DEBUG, "match count: %u\n", match_count);

	vm_free(map.start);
	vmsim_cleanup();
	free(offset_array);

	basic_test(match_count == num_frames);
}