From 586f3d106eba81263a9276e9d4cad9b011ebbf0b Mon Sep 17 00:00:00 2001 From: Seppe Degryse <80254822+Griezn@users.noreply.github.com> Date: Sun, 17 Nov 2024 23:54:57 +0100 Subject: [PATCH] Fixed memory leak in test --- benchmark/translator.py | 61 ----------------------------------------- tests/dataTests.cpp | 13 +++++++-- 2 files changed, 11 insertions(+), 63 deletions(-) delete mode 100644 benchmark/translator.py diff --git a/benchmark/translator.py b/benchmark/translator.py deleted file mode 100644 index 8f96765..0000000 --- a/benchmark/translator.py +++ /dev/null @@ -1,61 +0,0 @@ -import csv -import struct -from datetime import datetime - -# Define the mapping of garage codes to numerical values -garage_codes = { - "BRUUNS": 0, - "BUSGADEHUSET": 1, - "KALKVAERKSVEJ": 2, - "MAGASIN": 3, - "NORREPORT": 4, - "SALLING": 5, - "SCANDCENTER": 6, - "SKOLEBAKKEN": 7 -} - -# Define the mapping of attribute names to integer identifiers -attribute_ids = { - "vehicle_count": 0, - "update_time": 1, - "total_spaces": 2, - "garage_code": 3 -} - -# Convert a datetime string to a numerical timestamp -def convert_to_timestamp(date_str): - try: - # Try parsing with fractional seconds - dt = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S.%f") - except ValueError: - # Fall back to parsing without fractional seconds - dt = datetime.strptime(date_str, "%Y-%m-%d %H:%M:%S") - return int(dt.timestamp()) - - -# File names -input_filename = "AarhusParkingData.stream" -output_filename = "output_triples.bin" - -# Define the struct format string -# 'i' is for integers (4 bytes each): int _id, int attribute_type, int value -triple_struct_format = "iii" - -with open(input_filename, mode="r") as infile, open(output_filename, mode="wb") as outfile: - reader = csv.DictReader(infile) - - for row in reader: - _id = int(row["_id"]) - vehicle_count = int(row["vehiclecount"]) - update_time = convert_to_timestamp(row["updatetime"]) - total_spaces = int(row["totalspaces"]) - garage_code = garage_codes[row["garagecode"]] - stream_time = convert_to_timestamp(row["streamtime"]) - - # Write each triple separately - outfile.write(struct.pack(triple_struct_format, _id, attribute_ids["vehicle_count"], vehicle_count)) - outfile.write(struct.pack(triple_struct_format, _id, attribute_ids["update_time"], update_time)) - outfile.write(struct.pack(triple_struct_format, _id, attribute_ids["total_spaces"], total_spaces)) - outfile.write(struct.pack(triple_struct_format, _id, attribute_ids["garage_code"], garage_code)) - -print(f"Data has been successfully written to {output_filename} in triple format.") diff --git a/tests/dataTests.cpp b/tests/dataTests.cpp index 28b5f75..ed3c841 100644 --- a/tests/dataTests.cpp +++ b/tests/dataTests.cpp @@ -152,11 +152,17 @@ TEST(DataTests, test_file_source) sink_t *gsink = create_generator_sink(); sink_t *fsink = create_generator_sink(); - gsink->push_next(gsink, gsource->get_next(gsource)); - fsink->push_next(fsink, fsource->get_next(fsource)); + data_t *next_gdata = gsource->get_next(gsource); + data_t *next_fdata = fsource->get_next(fsource); + + gsink->push_next(gsink, next_gdata); + fsink->push_next(fsink, next_fdata); ASSERT_TRUE(ARR_EQ(gsink->buffer.data, fsink->buffer.data, gsink->buffer.size)); + free(next_gdata); + free(next_fdata); + free_generator_source(gsource); free_file_source(fsource); free(gsink); // not the normal because it is still the array allocated int he lib @@ -193,6 +199,9 @@ TEST(DataTests, test_file_source_inc) ASSERT_TRUE(ARR_EQ(gsink->buffer.data + 2*increment, fsink->buffer.data, increment)); + free(next_gdata); + free(next_fdata); + free_generator_source(gsource); free_file_source(fsource); free(gsink); // not the normal because it is still the array allocated int he lib