mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-14 18:27:21 +00:00
tests: yank asprintfrr duplicate
I think this one predates the existence of asprintfrr. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
This commit is contained in:
parent
bd90faea56
commit
da63485331
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "plist.h"
|
#include "plist.h"
|
||||||
|
#include "printfrr.h"
|
||||||
#include "bgpd/bgpd.h"
|
#include "bgpd/bgpd.h"
|
||||||
#include "bgpd/bgp_attr.h"
|
#include "bgpd/bgp_attr.h"
|
||||||
#include "bgpd/bgp_regex.h"
|
#include "bgpd/bgp_regex.h"
|
||||||
@ -44,8 +45,9 @@
|
|||||||
if ((T)->state != TEST_SUCCESS || (C)) \
|
if ((T)->state != TEST_SUCCESS || (C)) \
|
||||||
break; \
|
break; \
|
||||||
(T)->state = TEST_ASSERT_ERROR; \
|
(T)->state = TEST_ASSERT_ERROR; \
|
||||||
(T)->error = str_printf("assertion failed: %s (%s:%d)", (#C), \
|
(T)->error = \
|
||||||
__FILE__, __LINE__); \
|
asprintfrr(MTYPE_TMP, "assertion failed: %s (%s:%d)", \
|
||||||
|
(#C), __FILE__, __LINE__); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TEST_ASSERT_EQ(T, A, B) \
|
#define TEST_ASSERT_EQ(T, A, B) \
|
||||||
@ -53,9 +55,11 @@
|
|||||||
if ((T)->state != TEST_SUCCESS || ((A) == (B))) \
|
if ((T)->state != TEST_SUCCESS || ((A) == (B))) \
|
||||||
break; \
|
break; \
|
||||||
(T)->state = TEST_ASSERT_ERROR; \
|
(T)->state = TEST_ASSERT_ERROR; \
|
||||||
(T)->error = str_printf( \
|
(T)->error = asprintfrr( \
|
||||||
"assertion failed: %s[%d] == [%d]%s (%s:%d)", (#A), \
|
MTYPE_TMP, \
|
||||||
(A), (B), (#B), __FILE__, __LINE__); \
|
"assertion failed: %s[%lld] == [%lld]%s (%s:%d)", \
|
||||||
|
(#A), (long long)(A), (long long)(B), (#B), __FILE__, \
|
||||||
|
__LINE__); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define TEST_HANDLER_MAX 5
|
#define TEST_HANDLER_MAX 5
|
||||||
@ -212,44 +216,6 @@ static struct test_peer_family test_default_families[] = {
|
|||||||
{.afi = AFI_IP6, .safi = SAFI_MULTICAST},
|
{.afi = AFI_IP6, .safi = SAFI_MULTICAST},
|
||||||
};
|
};
|
||||||
|
|
||||||
static char *str_vprintf(const char *fmt, va_list ap)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
int buf_size = 0;
|
|
||||||
char *buf = NULL;
|
|
||||||
va_list apc;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
va_copy(apc, ap);
|
|
||||||
ret = vsnprintf(buf, buf_size, fmt, apc);
|
|
||||||
va_end(apc);
|
|
||||||
|
|
||||||
if (ret >= 0 && ret < buf_size)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (ret >= 0)
|
|
||||||
buf_size = ret + 1;
|
|
||||||
else
|
|
||||||
buf_size *= 2;
|
|
||||||
|
|
||||||
buf = XREALLOC(MTYPE_TMP, buf, buf_size);
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *str_printf(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
char *buf;
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
buf = str_vprintf(fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_ATTR_HANDLER_DECL(advertisement_interval, v_routeadv, 10, 20);
|
TEST_ATTR_HANDLER_DECL(advertisement_interval, v_routeadv, 10, 20);
|
||||||
TEST_STR_ATTR_HANDLER_DECL(password, password, "FRR-Peer", "FRR-Group");
|
TEST_STR_ATTR_HANDLER_DECL(password, password, "FRR-Peer", "FRR-Group");
|
||||||
TEST_ATTR_HANDLER_DECL(local_as, change_local_as, 1, 2);
|
TEST_ATTR_HANDLER_DECL(local_as, change_local_as, 1, 2);
|
||||||
@ -724,6 +690,7 @@ static bool is_attr_type_global(enum test_peer_attr_type at)
|
|||||||
return at == PEER_AT_GLOBAL_FLAG || at == PEER_AT_GLOBAL_CUSTOM;
|
return at == PEER_AT_GLOBAL_FLAG || at == PEER_AT_GLOBAL_CUSTOM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRINTFRR(2, 3)
|
||||||
static void test_log(struct test *test, const char *fmt, ...)
|
static void test_log(struct test *test, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -734,10 +701,11 @@ static void test_log(struct test *test, const char *fmt, ...)
|
|||||||
|
|
||||||
/* Store formatted log message. */
|
/* Store formatted log message. */
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
listnode_add(test->log, str_vprintf(fmt, ap));
|
listnode_add(test->log, vasprintfrr(MTYPE_TMP, fmt, ap));
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRINTFRR(2, 3)
|
||||||
static void test_execute(struct test *test, const char *fmt, ...)
|
static void test_execute(struct test *test, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@ -751,12 +719,12 @@ static void test_execute(struct test *test, const char *fmt, ...)
|
|||||||
|
|
||||||
/* Format command string with variadic arguments. */
|
/* Format command string with variadic arguments. */
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
cmd = str_vprintf(fmt, ap);
|
cmd = vasprintfrr(MTYPE_TMP, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
if (!cmd) {
|
if (!cmd) {
|
||||||
test->state = TEST_INTERNAL_ERROR;
|
test->state = TEST_INTERNAL_ERROR;
|
||||||
test->error =
|
test->error = asprintfrr(
|
||||||
str_printf("could not format command string [%s]", fmt);
|
MTYPE_TMP, "could not format command string [%s]", fmt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -764,7 +732,8 @@ static void test_execute(struct test *test, const char *fmt, ...)
|
|||||||
vline = cmd_make_strvec(cmd);
|
vline = cmd_make_strvec(cmd);
|
||||||
if (vline == NULL) {
|
if (vline == NULL) {
|
||||||
test->state = TEST_INTERNAL_ERROR;
|
test->state = TEST_INTERNAL_ERROR;
|
||||||
test->error = str_printf(
|
test->error = asprintfrr(
|
||||||
|
MTYPE_TMP,
|
||||||
"tokenizing command string [%s] returned empty result",
|
"tokenizing command string [%s] returned empty result",
|
||||||
cmd);
|
cmd);
|
||||||
XFREE(MTYPE_TMP, cmd);
|
XFREE(MTYPE_TMP, cmd);
|
||||||
@ -776,7 +745,8 @@ static void test_execute(struct test *test, const char *fmt, ...)
|
|||||||
ret = cmd_execute_command(vline, test->vty, NULL, 0);
|
ret = cmd_execute_command(vline, test->vty, NULL, 0);
|
||||||
if (ret != CMD_SUCCESS) {
|
if (ret != CMD_SUCCESS) {
|
||||||
test->state = TEST_COMMAND_ERROR;
|
test->state = TEST_COMMAND_ERROR;
|
||||||
test->error = str_printf(
|
test->error = asprintfrr(
|
||||||
|
MTYPE_TMP,
|
||||||
"execution of command [%s] has failed with code [%d]",
|
"execution of command [%s] has failed with code [%d]",
|
||||||
cmd, ret);
|
cmd, ret);
|
||||||
}
|
}
|
||||||
@ -786,6 +756,7 @@ static void test_execute(struct test *test, const char *fmt, ...)
|
|||||||
XFREE(MTYPE_TMP, cmd);
|
XFREE(MTYPE_TMP, cmd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRINTFRR(2, 0)
|
||||||
static void test_config(struct test *test, const char *fmt, bool invert,
|
static void test_config(struct test *test, const char *fmt, bool invert,
|
||||||
va_list ap)
|
va_list ap)
|
||||||
{
|
{
|
||||||
@ -800,12 +771,12 @@ static void test_config(struct test *test, const char *fmt, bool invert,
|
|||||||
|
|
||||||
/* Format matcher string with variadic arguments. */
|
/* Format matcher string with variadic arguments. */
|
||||||
va_copy(apc, ap);
|
va_copy(apc, ap);
|
||||||
matcher = str_vprintf(fmt, apc);
|
matcher = vasprintfrr(MTYPE_TMP, fmt, apc);
|
||||||
va_end(apc);
|
va_end(apc);
|
||||||
if (!matcher) {
|
if (!matcher) {
|
||||||
test->state = TEST_INTERNAL_ERROR;
|
test->state = TEST_INTERNAL_ERROR;
|
||||||
test->error =
|
test->error = asprintfrr(
|
||||||
str_printf("could not format matcher string [%s]", fmt);
|
MTYPE_TMP, "could not format matcher string [%s]", fmt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -818,11 +789,13 @@ static void test_config(struct test *test, const char *fmt, bool invert,
|
|||||||
matched = !!strstr(config, matcher);
|
matched = !!strstr(config, matcher);
|
||||||
if (!matched && !invert) {
|
if (!matched && !invert) {
|
||||||
test->state = TEST_CONFIG_ERROR;
|
test->state = TEST_CONFIG_ERROR;
|
||||||
test->error = str_printf("expected config [%s] to be present",
|
test->error = asprintfrr(MTYPE_TMP,
|
||||||
|
"expected config [%s] to be present",
|
||||||
matcher);
|
matcher);
|
||||||
} else if (matched && invert) {
|
} else if (matched && invert) {
|
||||||
test->state = TEST_CONFIG_ERROR;
|
test->state = TEST_CONFIG_ERROR;
|
||||||
test->error = str_printf("expected config [%s] to be absent",
|
test->error = asprintfrr(MTYPE_TMP,
|
||||||
|
"expected config [%s] to be absent",
|
||||||
matcher);
|
matcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -831,6 +804,7 @@ static void test_config(struct test *test, const char *fmt, bool invert,
|
|||||||
XFREE(MTYPE_TMP, config);
|
XFREE(MTYPE_TMP, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRINTFRR(2, 3)
|
||||||
static void test_config_present(struct test *test, const char *fmt, ...)
|
static void test_config_present(struct test *test, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -840,6 +814,7 @@ static void test_config_present(struct test *test, const char *fmt, ...)
|
|||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRINTFRR(2, 3)
|
||||||
static void test_config_absent(struct test *test, const char *fmt, ...)
|
static void test_config_absent(struct test *test, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -886,8 +861,8 @@ static void test_initialize(struct test *test)
|
|||||||
test->bgp = bgp_get_default();
|
test->bgp = bgp_get_default();
|
||||||
if (!test->bgp) {
|
if (!test->bgp) {
|
||||||
test->state = TEST_INTERNAL_ERROR;
|
test->state = TEST_INTERNAL_ERROR;
|
||||||
test->error =
|
test->error = asprintfrr(
|
||||||
str_printf("could not retrieve default bgp instance");
|
MTYPE_TMP, "could not retrieve default bgp instance");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -901,7 +876,8 @@ static void test_initialize(struct test *test)
|
|||||||
}
|
}
|
||||||
if (!test->peer) {
|
if (!test->peer) {
|
||||||
test->state = TEST_INTERNAL_ERROR;
|
test->state = TEST_INTERNAL_ERROR;
|
||||||
test->error = str_printf(
|
test->error = asprintfrr(
|
||||||
|
MTYPE_TMP,
|
||||||
"could not retrieve instance of bgp peer [%s]",
|
"could not retrieve instance of bgp peer [%s]",
|
||||||
cfg.peer_address);
|
cfg.peer_address);
|
||||||
return;
|
return;
|
||||||
@ -911,7 +887,8 @@ static void test_initialize(struct test *test)
|
|||||||
test->group = peer_group_lookup(test->bgp, cfg.peer_group);
|
test->group = peer_group_lookup(test->bgp, cfg.peer_group);
|
||||||
if (!test->group) {
|
if (!test->group) {
|
||||||
test->state = TEST_INTERNAL_ERROR;
|
test->state = TEST_INTERNAL_ERROR;
|
||||||
test->error = str_printf(
|
test->error = asprintfrr(
|
||||||
|
MTYPE_TMP,
|
||||||
"could not retrieve instance of bgp peer-group [%s]",
|
"could not retrieve instance of bgp peer-group [%s]",
|
||||||
cfg.peer_group);
|
cfg.peer_group);
|
||||||
return;
|
return;
|
||||||
@ -1081,7 +1058,8 @@ static void test_custom(struct test *test, struct test_peer_attr *pa,
|
|||||||
if (test->state != TEST_SUCCESS) {
|
if (test->state != TEST_SUCCESS) {
|
||||||
test->state = TEST_CUSTOM_ERROR;
|
test->state = TEST_CUSTOM_ERROR;
|
||||||
handler_error = test->error;
|
handler_error = test->error;
|
||||||
test->error = str_printf("custom handler failed: %s",
|
test->error = asprintfrr(MTYPE_TMP,
|
||||||
|
"custom handler failed: %s",
|
||||||
handler_error);
|
handler_error);
|
||||||
XFREE(MTYPE_TMP, handler_error);
|
XFREE(MTYPE_TMP, handler_error);
|
||||||
}
|
}
|
||||||
@ -1123,8 +1101,8 @@ static void test_process(struct test *test, struct test_peer_attr *pa,
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
test->state = TEST_INTERNAL_ERROR;
|
test->state = TEST_INTERNAL_ERROR;
|
||||||
test->error =
|
test->error = asprintfrr(
|
||||||
str_printf("invalid attribute type: %d", pa->type);
|
MTYPE_TMP, "invalid attribute type: %d", pa->type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1149,8 +1127,8 @@ static void test_peer_attr(struct test *test, struct test_peer_attr *pa)
|
|||||||
type = str_from_attr_type(pa->type);
|
type = str_from_attr_type(pa->type);
|
||||||
if (!type) {
|
if (!type) {
|
||||||
test->state = TEST_INTERNAL_ERROR;
|
test->state = TEST_INTERNAL_ERROR;
|
||||||
test->error =
|
test->error = asprintfrr(
|
||||||
str_printf("invalid attribute type: %d", pa->type);
|
MTYPE_TMP, "invalid attribute type: %d", pa->type);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1485,11 +1463,11 @@ int main(void)
|
|||||||
|
|
||||||
/* Build test description string. */
|
/* Build test description string. */
|
||||||
if (pa->afi && pa->safi)
|
if (pa->afi && pa->safi)
|
||||||
desc = str_printf("peer\\%s-%s\\%s",
|
desc = asprintfrr(MTYPE_TMP, "peer\\%s-%s\\%s",
|
||||||
str_from_afi(pa->afi),
|
str_from_afi(pa->afi),
|
||||||
str_from_safi(pa->safi), pa->cmd);
|
str_from_safi(pa->safi), pa->cmd);
|
||||||
else
|
else
|
||||||
desc = str_printf("peer\\%s", pa->cmd);
|
desc = asprintfrr(MTYPE_TMP, "peer\\%s", pa->cmd);
|
||||||
|
|
||||||
/* Initialize new test instance. */
|
/* Initialize new test instance. */
|
||||||
test = test_new(desc, pa->o.use_ibgp, pa->o.use_iface_peer);
|
test = test_new(desc, pa->o.use_ibgp, pa->o.use_iface_peer);
|
||||||
|
Loading…
Reference in New Issue
Block a user