From eac2b0042e1fc8490b1c230acb377733647fa554 Mon Sep 17 00:00:00 2001 From: tmatis Date: Wed, 3 Apr 2024 21:59:16 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20count=20of=20testable=20fu?= =?UTF-8?q?nctions=20when=20there=20more=20than=20two=20iteration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- host/srcs/function_footprint/function_footprint.c | 7 ++++--- host/srcs/functions_test/functions_test.c | 3 ++- host/srcs/functions_test/functions_test.h | 3 +++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/host/srcs/function_footprint/function_footprint.c b/host/srcs/function_footprint/function_footprint.c index 4859d94..643aeb6 100644 --- a/host/srcs/function_footprint/function_footprint.c +++ b/host/srcs/function_footprint/function_footprint.c @@ -20,6 +20,7 @@ #include #include "../events/event_utils.h" #include "../backtrace/backtrace.h" +#include "../functions_test/functions_test.h" define_btree_functions(t_allocation, cmp_t_allocation); define_btree_functions(t_function_call_footprint, cmp_t_function_call_footprint); @@ -131,9 +132,9 @@ void remove_allocation(btree_t_function_call_footprint **function_tree, void *pt */ static size_t count_tests(t_function_call_footprint *test_elem) { - if (test_elem->should_test) - return 1; - return 0; + if (!test_elem->should_test) + return 0; + return REQUIRED_ITERATIONS(test_elem); } /** diff --git a/host/srcs/functions_test/functions_test.c b/host/srcs/functions_test/functions_test.c index 9231342..88c2680 100644 --- a/host/srcs/functions_test/functions_test.c +++ b/host/srcs/functions_test/functions_test.c @@ -305,7 +305,8 @@ static void function_test_callback(t_function_call_footprint *function_info) { if (!function_info->should_test) return; - _function_test_count++; + int to_increment = REQUIRED_ITERATIONS(function_info); + _function_test_count += to_increment; function_test(function_info, 0); if (function_info->call_count > 1) function_test(function_info, 1); diff --git a/host/srcs/functions_test/functions_test.h b/host/srcs/functions_test/functions_test.h index ed483f2..fa4f728 100644 --- a/host/srcs/functions_test/functions_test.h +++ b/host/srcs/functions_test/functions_test.h @@ -21,6 +21,9 @@ #include "../functions_fetch/functions_fetch.h" #include "../time/time.h" +// 2 iterations are required to test a function that has been called at least twice +#define REQUIRED_ITERATIONS(function_info) (function_info->call_count > 1) ? 2 : 1 + typedef struct { size_t nb_total_tests;