Skip to content

Commit

Permalink
🐛 fix count of testable functions when there more than two iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
froz42 committed Apr 3, 2024
1 parent ba31d20 commit eac2b00
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 4 additions & 3 deletions host/srcs/function_footprint/function_footprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <stdio.h>
#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);
Expand Down Expand Up @@ -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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion host/srcs/functions_test/functions_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions host/srcs/functions_test/functions_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit eac2b00

Please sign in to comment.