Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: internal: log_event_encoder: Add test code #7584

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/msgpack-c/include/msgpack/sbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,24 @@ static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len)
void* tmp;
size_t nsize = (sbuf->alloc) ?
sbuf->alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;

printf("A:sbuf->alloc=%zu sbuf->size=%zu len=%zu nsize=%zu\n",sbuf->alloc, sbuf->size, len, nsize);
while(nsize < sbuf->size + len) {
size_t tmp_nsize = nsize * 2;
printf("AA:sbuf->alloc=%zu sbuf->size=%zu len=%zu nsize=%zu\n",sbuf->alloc, sbuf->size, len, nsize);
if (tmp_nsize <= nsize) {
printf("AB:sbuf->alloc=%zu sbuf->size=%zu len=%zu nsize=%zu\n",sbuf->alloc, sbuf->size, len, nsize);
nsize = sbuf->size + len;
break;
}
nsize = tmp_nsize;
printf("AC:sbuf->alloc=%zu sbuf->size=%zu len=%zu nsize=%zu\n",sbuf->alloc, sbuf->size, len, nsize);
}

printf("B:sbuf->alloc=%zu sbuf->size=%zu len=%zu nsize=%zu\n",sbuf->alloc, sbuf->size, len, nsize);
tmp = realloc(sbuf->data, nsize);
if(!tmp) { return -1; }
if(!tmp) {
printf("C:sbuf->alloc=%zu sbuf->size=%zu len=%zu nsize=%zu\n",sbuf->alloc, sbuf->size, len, nsize);
return -1;
}

sbuf->data = (char*)tmp;
sbuf->alloc = nsize;
Expand Down
12 changes: 12 additions & 0 deletions src/flb_log_event_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ int flb_log_event_encoder_emit_raw_record(struct flb_log_event_encoder *context,
{
int result;

if (context == NULL) {
return FLB_EVENT_ENCODER_ERROR_INVALID_CONTEXT;
}

if (buffer == NULL || length == 0) {
return FLB_EVENT_ENCODER_ERROR_INVALID_ARGUMENT;
}

result = msgpack_pack_str_body(&context->packer, buffer, length);

if (result != 0) {
Expand Down Expand Up @@ -229,6 +237,10 @@ int flb_log_event_encoder_emit_record(struct flb_log_event_encoder *context)

int flb_log_event_encoder_reset_record(struct flb_log_event_encoder *context)
{
if (context == NULL) {
return FLB_EVENT_ENCODER_ERROR_INVALID_CONTEXT;
}

flb_log_event_encoder_dynamic_field_reset(&context->metadata);
flb_log_event_encoder_dynamic_field_reset(&context->body);
flb_log_event_encoder_dynamic_field_reset(&context->root);
Expand Down
18 changes: 15 additions & 3 deletions src/flb_log_event_encoder_primitives.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ int flb_log_event_encoder_append_value(
if (result == FLB_EVENT_ENCODER_SUCCESS) {
if (value_type == FLB_LOG_EVENT_STRING_LENGTH_VALUE_TYPE) {
result = msgpack_pack_str(&field->packer, value_length);
if (result != 0) {
flb_error("result=%d len=%d", result, value_length);
}
}
else if (value_type == FLB_LOG_EVENT_BINARY_LENGTH_VALUE_TYPE) {
result = msgpack_pack_bin(&field->packer, value_length);
Expand All @@ -78,6 +81,10 @@ int flb_log_event_encoder_append_value(
result = msgpack_pack_str_body(&field->packer,
value_buffer,
value_length);
if (result != 0) {
flb_errno();
flb_error("result=%d str=%s strp=%p len=%zu", result, value_buffer, value_buffer, value_length);
}
}
else if (value_type == FLB_LOG_EVENT_BINARY_BODY_VALUE_TYPE) {
result = msgpack_pack_bin_body(&field->packer,
Expand Down Expand Up @@ -565,22 +572,27 @@ int flb_log_event_encoder_append_values_unsafe(
result == FLB_EVENT_ENCODER_SUCCESS ;
processed_values++) {
value_type = va_arg(arguments, int);

flb_error("value_type=%d", value_type);
if (value_type == FLB_LOG_EVENT_APPEND_TERMINATOR_VALUE_TYPE) {
break;
}
else if (value_type == FLB_LOG_EVENT_STRING_LENGTH_VALUE_TYPE) {
size_t size = va_arg(arguments, size_t);
flb_error("length_value_type: size=%zu", size);
result = flb_log_event_encoder_append_string_length(context,
target_field,
va_arg(arguments, size_t));
size);
}
else if (value_type == FLB_LOG_EVENT_STRING_BODY_VALUE_TYPE) {
size_t size;
buffer_address = va_arg(arguments, char *);
size = va_arg(arguments, size_t);
flb_error("sizeof(size)=%zu size=%zu", sizeof(size), size);

result = flb_log_event_encoder_append_string_body(context,
target_field,
buffer_address,
va_arg(arguments, size_t));
size);
}
else if (value_type == FLB_LOG_EVENT_BINARY_LENGTH_VALUE_TYPE) {
result = flb_log_event_encoder_append_binary_length(context,
Expand Down
1 change: 1 addition & 0 deletions tests/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ set(UNIT_TESTS_FILES
parser_logfmt.c
env.c
log.c
log_event_encoder.c
processor.c
)

Expand Down
Loading