Ejemplo n.º 1
0
void compaction_2() {
	t_swap* swap = create_swap("./spec/config_file_test.txt");
	initialize_program(swap, 0, 2, "asd");
	initialize_program(swap, 1, 3, "qwe");
	initialize_program(swap, 2, 1, "iop");
	initialize_program(swap, 3, 1, "mnb");
	remove_program(swap, 0);
	remove_program(swap, 2);
	int first_page_location = check_space_available(swap, 6);
	t_pages_table* table_1 = list_get(swap->pages_table_list, 0);
	t_pages_table* table_2 = list_get(swap->pages_table_list, 1);
	CU_ASSERT_EQUAL(*(table_1->pages_location), 0);
	CU_ASSERT_EQUAL(*(table_2->pages_location), 15);
	CU_ASSERT_EQUAL(*(swap->bitmap), 1);
	CU_ASSERT_EQUAL(*(swap->bitmap + 1), 1);
	CU_ASSERT_EQUAL(*(swap->bitmap + 2), 1);
	CU_ASSERT_EQUAL(*(swap->bitmap + 3), 1);
	CU_ASSERT_EQUAL(*(swap->bitmap + 4), 0);
	CU_ASSERT_EQUAL(*(swap->bitmap + 5), 0);
	CU_ASSERT_EQUAL(*(swap->bitmap + 6), 0);
	CU_ASSERT_EQUAL(*(swap->bitmap + 7), 0);
	CU_ASSERT_EQUAL(*(swap->bitmap + 8), 0);
	CU_ASSERT_EQUAL(*(swap->bitmap + 9), 0);
	char* page_1 = read_swap_file(swap, 0);
	char* page_4 = read_swap_file(swap, 15);
	CU_ASSERT_NSTRING_EQUAL(page_1, "qwe", 3);
	CU_ASSERT_NSTRING_EQUAL(page_4, "mnb", 3);
	CU_ASSERT_EQUAL(first_page_location, 4);
}
Ejemplo n.º 2
0
/**
 * wait_on_program
 *
 * Arguments: <program_id>
 *
 * Wait for the specified program to complete and exit.
 **/
static int wait_on_program(int argc, char **argv)
{
	struct program *prog;
	int program_id;
	int rc;

	program_id = strtoul(argv[1], NULL, 0);
	if (program_id <= 0) {
		LOG_ERROR("program ID must be a positive integer.");
		return EINVAL;
	}

	prog = find_program(program_id);
	if (!prog) {
		LOG_ERROR("Can't find program with ID %d.", program_id);
		return EINVAL;
	}

	waitpid(prog->pid, &rc, 0);

	/* The program has exitted, but if there was a context loaded on that
	 * process, it will still have the latest counts available to read.
	 */

	remove_program(prog);
	free(prog);

	LOG_INFO("Waited for program %d to complete.", program_id);

	return 0;
}
Ejemplo n.º 3
0
void remove_program_2() {
	t_swap* swap = create_swap("./spec/config_file_test.txt");
	initialize_program(swap, 1, 2, "1234567890");
	initialize_program(swap, 2, 3, "123456789012345");
	remove_program(swap, 2);
	CU_ASSERT_EQUAL(swap->pages_table_list->elements_count, 1);
}
Ejemplo n.º 4
0
void remove_program_1() {
	t_swap* swap = create_swap("./spec/config_file_test.txt");
	initialize_program(swap, 1, 2, "1234567890");
	initialize_program(swap, 2, 3, "123456789012345");
	remove_program(swap, 2);
	CU_ASSERT_EQUAL(*(swap->bitmap), 1);
	CU_ASSERT_EQUAL(*(swap->bitmap + 1), 1);
	CU_ASSERT_EQUAL(*(swap->bitmap + 2), 0);
	CU_ASSERT_EQUAL(*(swap->bitmap + 3), 0);
	CU_ASSERT_EQUAL(*(swap->bitmap + 4), 0);
}