summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/avro/tests/test_interop_data.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:19:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-03-09 13:20:02 +0000
commit58daab21cd043e1dc37024a7f99b396788372918 (patch)
tree96771e43bb69f7c1c2b0b4f7374cb74d7866d0cb /fluent-bit/lib/avro/tests/test_interop_data.c
parentReleasing debian version 1.43.2-1. (diff)
downloadnetdata-58daab21cd043e1dc37024a7f99b396788372918.tar.xz
netdata-58daab21cd043e1dc37024a7f99b396788372918.zip
Merging upstream version 1.44.3.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'fluent-bit/lib/avro/tests/test_interop_data.c')
-rw-r--r--fluent-bit/lib/avro/tests/test_interop_data.c141
1 files changed, 141 insertions, 0 deletions
diff --git a/fluent-bit/lib/avro/tests/test_interop_data.c b/fluent-bit/lib/avro/tests/test_interop_data.c
new file mode 100644
index 000000000..4738f3182
--- /dev/null
+++ b/fluent-bit/lib/avro/tests/test_interop_data.c
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied. See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+#include "avro.h"
+#include "avro_private.h"
+#include <dirent.h>
+#include <stddef.h>
+#include <stdio.h>
+
+int should_test(char *d_name)
+{
+ // check filename extension
+ char *ext_pos = strrchr(d_name, '.');
+ if (ext_pos == NULL)
+ {
+ return 0;
+ }
+
+ ptrdiff_t diff = d_name + strlen(d_name) - ext_pos;
+ char *substr = malloc(sizeof(char) * diff);
+ strncpy(substr, ext_pos + 1, diff - 1);
+ *(substr + diff - 1) = '\0';
+ if (strcmp(substr, "avro") != 0)
+ {
+ free(substr);
+ return 0;
+ }
+ free(substr);
+
+ // check compression codec
+ char *codec_pos = strrchr(d_name, '_');
+ if (codec_pos == NULL)
+ {
+ return 1;
+ }
+ if (ext_pos < codec_pos)
+ {
+ return 0;
+ }
+
+ diff = ext_pos - codec_pos;
+ substr = malloc(sizeof(char) * diff);
+ strncpy(substr, codec_pos + 1, diff - 1);
+ *(substr + diff - 1) = '\0';
+ if (strcmp(substr, "deflate") == 0 || strcmp(substr, "snappy") == 0)
+ {
+ free(substr);
+ return 1;
+ }
+ free(substr);
+
+ return 0;
+}
+
+int main(int argc, char *argv[])
+{
+ if (argc != 2)
+ {
+ fprintf(stderr, "%s accepts just one input file\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ DIR *dir;
+ if ((dir = opendir(argv[1])) == NULL)
+ {
+ fprintf(stderr, "The specified path is not a directory: %s\n", argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ struct dirent *ent;
+ while ((ent = readdir(dir)) != NULL)
+ {
+ avro_file_reader_t reader;
+ avro_value_t value;
+
+ if (ent->d_type != DT_REG) continue;
+
+ char *d_name = ent->d_name;
+ size_t d_name_len = strlen(d_name);
+ size_t size = strlen(argv[1]) + d_name_len + 2;
+ char* path = malloc(sizeof(char) * size);
+ sprintf(path, "%s/%s", argv[1], d_name);
+
+ if (!should_test(d_name))
+ {
+ printf("Skipping file: %s\n", path);
+ free(path);
+ continue;
+ }
+ printf("Checking file: %s\n", path);
+
+ if (avro_file_reader(path, &reader))
+ {
+ fprintf(stderr, "Failed to read from a file: %s\n", path);
+ free(path);
+ return EXIT_FAILURE;
+ }
+ avro_schema_t schema = avro_file_reader_get_writer_schema(reader);
+ avro_value_iface_t *iface = avro_generic_class_from_schema(schema);
+ avro_generic_value_new(iface, &value);
+
+ int i, rval;
+ for (i = 0; (rval = avro_file_reader_read_value(reader, &value)) == 0; i++, avro_value_reset(&value));
+ if (rval != EOF)
+ {
+ fprintf(stderr, "Error(%d) occurred while reading file: %s\n", rval, path);
+ free(path);
+ return EXIT_FAILURE;
+ }
+ if (i == 0)
+ {
+ fprintf(stderr, "Input file %s is supposed to be non-empty\n", path);
+ free(path);
+ return EXIT_FAILURE;
+ }
+
+ free(path);
+ avro_value_decref(&value);
+ avro_value_iface_decref(iface);
+ avro_schema_decref(schema);
+ avro_file_reader_close(reader);
+ }
+
+ closedir(dir);
+
+ return EXIT_SUCCESS;
+}