1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
// Copyright (c) Meta Platforms, Inc. and affiliates.
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "test_util.h"
#include "../error.h"
static struct drgn_error *no_recursion_allowed(int *counter)
{
drgn_recursion_guard(0, "recursive call detected");
(*counter)++;
return no_recursion_allowed(counter);
}
static struct drgn_error *limited_recursion_allowed(int *counter)
{
drgn_recursion_guard(10, "maximum recursion depth exceeded");
(*counter)++;
return limited_recursion_allowed(counter);
}
#suite recursion_guard
#test no_recursion
{
int counter = 0;
struct drgn_error *err = no_recursion_allowed(&counter);
ck_assert_ptr_nonnull(err);
ck_assert_int_eq(err->code, DRGN_ERROR_RECURSION);
ck_assert_str_eq(err->message, "recursive call detected");
drgn_error_destroy(err);
ck_assert_int_eq(counter, 1);
}
#test limited_recursion
{
int counter = 0;
struct drgn_error *err = limited_recursion_allowed(&counter);
ck_assert_ptr_nonnull(err);
ck_assert_int_eq(err->code, DRGN_ERROR_RECURSION);
ck_assert_str_eq(err->message, "maximum recursion depth exceeded");
drgn_error_destroy(err);
ck_assert_int_eq(counter, 11);
}
|