TEST_F(test_levin_protocol_handler__hanle_recv_with_invalid_data, handles_unexpected_response)
{
  m_req_head.m_flags = LEVIN_PACKET_RESPONSE;
  prepare_buf();

  ASSERT_FALSE(m_conn->m_protocol_handler.handle_recv(m_buf.data(), m_buf.size()));
}
TEST_F(test_levin_protocol_handler__hanle_recv_with_invalid_data, does_not_handle_data_after_close)
{
  prepare_buf();

  ASSERT_TRUE(m_conn->m_protocol_handler.close());
  ASSERT_FALSE(m_conn->m_protocol_handler.handle_recv(m_buf.data(), m_buf.size()));
}
TEST_F(test_levin_protocol_handler__hanle_recv_with_invalid_data, handles_network_error)
{
  prepare_buf();

  m_conn->send_return(false);
  ASSERT_FALSE(m_conn->m_protocol_handler.handle_recv(m_buf.data(), m_buf.size()));
}
TEST_F(test_levin_protocol_handler__hanle_recv_with_invalid_data, handles_big_cb)
{
  m_req_head.m_cb = max_packet_size + 1;
  prepare_buf();

  ASSERT_FALSE(m_conn->m_protocol_handler.handle_recv(m_buf.data(), m_buf.size()));
}
TEST_F(test_levin_protocol_handler__hanle_recv_with_invalid_data, handles_invalid_signature_for_full_header)
{
  m_req_head.m_signature = LEVIN_SIGNATURE ^ 1;
  prepare_buf();

  ASSERT_FALSE(m_conn->m_protocol_handler.handle_recv(m_buf.data(), m_buf.size()));
}
Exemplo n.º 6
0
int
main(int argc, char *argv[])
{
    progname = get_progname(argv[0]);

    handle_args(argc, argv);

    prepare_buf();

    test_open();

    /* Test using 1 XLOG_BLCKSZ write */
    test_sync(1);

    /* Test using 2 XLOG_BLCKSZ writes */
    test_sync(2);

    test_open_syncs();

    test_file_descriptor_sync();

    test_non_sync();

    unlink(filename);

    return 0;
}
TEST_F(test_levin_protocol_handler__hanle_recv_with_invalid_data, handles_two_requests_at_once)
{
  prepare_buf();
  m_buf.append(m_buf);

  ASSERT_TRUE(m_conn->m_protocol_handler.handle_recv(m_buf.data(), m_buf.size()));
  ASSERT_EQ(2, m_commands_handler.invoke_counter());
}
TEST_F(test_levin_protocol_handler__hanle_recv_with_invalid_data, handles_big_packet_2)
{
  prepare_buf();
  const size_t first_packet_size = sizeof(m_req_head) - 1;

  m_buf.resize(first_packet_size);
  ASSERT_TRUE(m_conn->m_protocol_handler.handle_recv(m_buf.data(), m_buf.size()));

  ASSERT_FALSE(m_conn->m_protocol_handler.handle_recv(m_buf.data(), max_packet_size - m_buf.size() + 1));
}
TEST_F(test_levin_protocol_handler__hanle_recv_with_invalid_data, handles_chunked_body)
{
  prepare_buf();

  size_t buf1_size = sizeof(m_req_head) + (m_buf.size() - sizeof(m_req_head)) / 2;

  std::string buf1 = m_buf.substr(0, buf1_size);
  std::string buf2 = m_buf.substr(buf1_size);
  ASSERT_EQ(m_buf, buf1 + buf2);

  ASSERT_TRUE(m_conn->m_protocol_handler.handle_recv(buf1.data(), buf1.size()));
  ASSERT_EQ(0, m_commands_handler.invoke_counter());

  ASSERT_TRUE(m_conn->m_protocol_handler.handle_recv(buf2.data(), buf2.size()));
  ASSERT_EQ(1, m_commands_handler.invoke_counter());
}
Exemplo n.º 10
0
int
main(int argc, char *argv[])
{
	set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_test_fsync"));
	progname = get_progname(argv[0]);

	handle_args(argc, argv);

	/* Prevent leaving behind the test file */
	pqsignal(SIGINT, signal_cleanup);
	pqsignal(SIGTERM, signal_cleanup);
#ifndef WIN32
	pqsignal(SIGALRM, process_alarm);
#endif
#ifdef SIGHUP
	/* Not defined on win32 */
	pqsignal(SIGHUP, signal_cleanup);
#endif

	prepare_buf();

	test_open();

	/* Test using 1 XLOG_BLCKSZ write */
	test_sync(1);

	/* Test using 2 XLOG_BLCKSZ writes */
	test_sync(2);

	test_open_syncs();

	test_file_descriptor_sync();

	test_non_sync();

	unlink(filename);

	return 0;
}
Exemplo n.º 11
0
static void chew_some_file(int num)
{
	char filename[10];
	int fd, rv;

	buf = mmap(NULL, FILE_SIZE, PROT_READ | PROT_WRITE,
			MAP_PRIVATE | MAP_ANON, 0, 0);
	rv = MMAP_FAILED;
	if (buf == MAP_FAILED)
		goto out_exit;

	sprintf(filename, "chew%d", num);
	fd = open(filename, O_CREAT | O_EXCL | O_RDWR, 0666);
	rv = OPEN_FAILED;
	if (fd == -1)
		goto out_unmap;

	while (!stop) {
		prepare_buf();
		switch (fill_file(fd)) {
		case -1:
			rv = WRITE_FAILED;
			goto out_exit;
		case -2:
			rv = SEEK_FAILED;
			goto out_exit;
		}
		if (fsync(fd) == -1) {
			rv = FSYNC_FAILED;
			goto out_exit;
		}
		if (fsync(fd) == -1) {
			rv = FSYNC_FAILED;
			goto out_exit;
		}
		switch (check_file(fd)) {
		case -1:
			rv = READ_FAILED;
			goto out_exit;
		case -2:
			rv = SEEK_FAILED;
			goto out_exit;
		case 1:
			rv = FILE_CORRUPTED;
			int fd1;
			char str[32];
			// create standard file
			sprintf(str, "standard_%s", filename);
			fd1 = open(str, O_WRONLY | O_CREAT | O_TRUNC, 0666);
			if (write(fd1, buf, FILE_SIZE) != FILE_SIZE)
				err("can't write %s: %m\n", str);
			close(fd1);
			goto out_exit;
		}
	}
	rv = SUCCESS;
	close(fd);
	unlink(filename);
out_unmap:
	munmap(buf, FILE_SIZE);
out_exit:
	exit(rv);
}