Пример #1
0
static void*
stream_blocking_thread(void* arg) {
	int iloop;

	socket_t* sock = (socket_t*)arg;

	char buffer_out[317] = {0};
	char buffer_in[317] = {0};

	stream_t* stream = socket_stream(sock);

	for (iloop = 0; !thread_try_wait(0) && iloop < 512; ++iloop) {
		log_infof(HASH_NETWORK, STRING_CONST("UDP write pass %d"), iloop);
		EXPECT_SIZEEQ(stream_write(stream, buffer_out, 127), 127);
		EXPECT_SIZEEQ(stream_write(stream, buffer_out + 127, 180), 180);
		stream_flush(stream);
		EXPECT_SIZEEQ(stream_write(stream, buffer_out + 307, 10), 10);
		stream_flush(stream);
		log_infof(HASH_NETWORK, STRING_CONST("UDP read pass %d"), iloop);
		EXPECT_SIZEEQ(stream_read(stream, buffer_in, 235), 235);
		EXPECT_SIZEEQ(stream_read(stream, buffer_in + 235, 82), 82);
		thread_yield();
	}

	log_debugf(HASH_NETWORK, STRING_CONST("IO complete on socket 0x%llx"), sock);
	stream_deallocate(stream);

	return 0;
}
Пример #2
0
DECLARE_TEST(error, output) {
#if BUILD_ENABLE_LOG
	error_handler_fn handler_error = error_handler();
	log_handler_fn handler_log = log_handler();
	string_const_t shortmsg = string_const(STRING_CONST("Short message with prefix"));
    string_const_t longmsg = string_const(STRING_CONST("Longer message which should be output without a prefix"));

	error_set_handler(ignore_error_handler);
	log_set_handler(log_verify_handler);

    log_enable_stdout(false);
    EXPECT_EQ(log_stdout(), false);
    log_warn(HASH_TEST, WARNING_SUSPICIOUS, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
    EXPECT_EQ(log_stdout(), true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("WARNING [suspicious]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_warn(HASH_TEST, (warning_t)0x1000, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("WARNING [4096]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_prefix(false);
    log_enable_stdout(false);
	log_warn(HASH_TEST, WARNING_SYSTEM_CALL_FAIL, STRING_ARGS(longmsg));
    log_enable_stdout(true);
    log_enable_prefix(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_WARNING);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_error(HASH_TEST, ERROR_DEPRECATED, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("ERROR [deprecated]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_error(HASH_TEST, (error_t)0x1000, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("ERROR [4096]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

	log_enable_prefix(false);
    log_enable_stdout(false);
	log_error(HASH_TEST, ERROR_INVALID_VALUE, STRING_ARGS(longmsg));
    log_enable_stdout(true);
    log_enable_prefix(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_ERROR);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_panic(HASH_TEST, ERROR_DEPRECATED, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("PANIC [deprecated]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_panic(HASH_TEST, (error_t)0x1000, STRING_ARGS(shortmsg));
    log_enable_stdout(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC);
	EXPECT_GE(_last_log_length, shortmsg.length);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(shortmsg), 0), 0);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("PANIC [4096]"), 0), STRING_NPOS);

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

	log_enable_prefix(false);
    log_enable_stdout(false);
	log_panic(HASH_TEST, ERROR_INVALID_VALUE, STRING_ARGS(longmsg));
    log_enable_stdout(true);
    log_enable_prefix(true);
	EXPECT_EQ(_last_log_context, HASH_TEST);
	EXPECT_EQ(_last_log_severity, ERRORLEVEL_PANIC);
	EXPECT_NE(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), STRING_NPOS);
	EXPECT_GT(string_find_string(_last_log_msg, _last_log_length, STRING_ARGS(longmsg), 0), 0);

#  if BUILD_ENABLE_ERROR_CONTEXT
    
	error_context_push(STRING_CONST("one"), STRING_CONST("dataone"));
	error_context_push(STRING_CONST("two"), STRING_CONST("datatwo"));
	error_context_push(STRING_CONST("three"), STRING_CONST("datathree"));

	_last_log_context = 0;
	_last_log_severity = ERRORLEVEL_NONE;
	_last_log_msg = nullptr;
	_last_log_length = 0;

    log_enable_stdout(false);
	log_error_context(HASH_TEST, ERRORLEVEL_INFO);
    log_enable_stdout(true);

    error_context_pop();
    error_context_pop();
    error_context_pop();

	EXPECT_SIZEEQ(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When one: dataone"), 0), STRING_NPOS);
	EXPECT_SIZEEQ(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When two: datatwo"), 0), STRING_NPOS);
	EXPECT_SIZENE(string_find_string(_last_log_msg, _last_log_length, STRING_CONST("When three: datathree"), 0), STRING_NPOS);

#  endif

	log_set_handler(handler_log);
	error_set_handler(handler_error);
#endif
	return 0;
}