mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-02 01:50:14 +01:00
lldp/tests: add test for parsing LLDP frame
This commit is contained in:
parent
4aa657086e
commit
2d50370e07
3 changed files with 56 additions and 2 deletions
|
|
@ -815,6 +815,34 @@ lldp_neighbor_to_variant (LldpNeighbor *neigh)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
GVariant *
|
||||
nmtst_lldp_parse_from_raw (const guint8 *raw_data,
|
||||
gsize raw_len)
|
||||
{
|
||||
nm_auto (sd_lldp_neighbor_unrefp) sd_lldp_neighbor *neighbor_sd = NULL;
|
||||
nm_auto (lldp_neighbor_freep) LldpNeighbor *neigh = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
GVariant *variant;
|
||||
int r;
|
||||
|
||||
g_assert (raw_data);
|
||||
g_assert (raw_len > 0);
|
||||
|
||||
r = sd_lldp_neighbor_from_raw (&neighbor_sd, raw_data, raw_len);
|
||||
g_assert (r >= 0);
|
||||
|
||||
neigh = lldp_neighbor_new (neighbor_sd, &error);
|
||||
g_assert (neigh);
|
||||
g_assert (!error);
|
||||
|
||||
variant = lldp_neighbor_to_variant (neigh);
|
||||
g_assert (variant);
|
||||
|
||||
return g_variant_ref (variant);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
data_changed_notify (NMLldpListener *self, NMLldpListenerPrivate *priv)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,4 +25,7 @@ gboolean nm_lldp_listener_is_running (NMLldpListener *self);
|
|||
|
||||
GVariant *nm_lldp_listener_get_neighbors (NMLldpListener *self);
|
||||
|
||||
GVariant *nmtst_lldp_parse_from_raw (const guint8 *raw_data,
|
||||
gsize raw_len);
|
||||
|
||||
#endif /* __NM_LLDP_LISTENER__ */
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ TEST_RECV_FRAME_DEFINE (_test_recv_data0_frame0,
|
|||
);
|
||||
|
||||
static void
|
||||
_test_recv_data0_check (GMainLoop *loop, NMLldpListener *listener)
|
||||
_test_recv_data0_check_do (GMainLoop *loop, NMLldpListener *listener, const TestRecvFrame *frame)
|
||||
{
|
||||
GVariant *neighbors, *attr;
|
||||
gs_unref_variant GVariant *neighbor = NULL;
|
||||
|
|
@ -151,6 +151,12 @@ _test_recv_data0_check (GMainLoop *loop, NMLldpListener *listener)
|
|||
nm_clear_g_variant (&attr);
|
||||
}
|
||||
|
||||
static void
|
||||
_test_recv_data0_check (GMainLoop *loop, NMLldpListener *listener)
|
||||
{
|
||||
_test_recv_data0_check_do (loop, listener, &_test_recv_data0_frame0);
|
||||
}
|
||||
|
||||
TEST_RECV_DATA_DEFINE (_test_recv_data0, 1, _test_recv_data0_check, &_test_recv_data0_frame0);
|
||||
TEST_RECV_DATA_DEFINE (_test_recv_data0_twice, 1, _test_recv_data0_check, &_test_recv_data0_frame0, &_test_recv_data0_frame0);
|
||||
|
||||
|
|
@ -374,7 +380,7 @@ _test_recv_data2_ttl1_check (GMainLoop *loop, NMLldpListener *listener)
|
|||
gulong notify_id;
|
||||
GVariant *neighbors;
|
||||
|
||||
_test_recv_data0_check (loop, listener);
|
||||
_test_recv_data0_check_do (loop, listener, &_test_recv_data2_frame0_ttl1);
|
||||
|
||||
/* wait for signal. */
|
||||
notify_id = g_signal_connect (listener, "notify::" NM_LLDP_LISTENER_NEIGHBORS,
|
||||
|
|
@ -513,6 +519,19 @@ _test_recv_fixture_teardown (TestRecvFixture *fixture, gconstpointer user_data)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
test_parse_frames (gconstpointer test_data)
|
||||
{
|
||||
const TestRecvFrame *frame = test_data;
|
||||
gs_unref_variant GVariant *v_neighbor = NULL;
|
||||
gs_unref_variant GVariant *attr = NULL;
|
||||
|
||||
v_neighbor = nmtst_lldp_parse_from_raw (frame->frame, frame->frame_len);
|
||||
g_assert (v_neighbor);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
NMTstpSetupFunc const _nmtstp_setup_platform_func = nm_linux_platform_setup;
|
||||
|
||||
void
|
||||
|
|
@ -530,4 +549,8 @@ _nmtstp_setup_tests (void)
|
|||
_TEST_ADD_RECV ("/lldp/recv/0_twice", &_test_recv_data0_twice);
|
||||
_TEST_ADD_RECV ("/lldp/recv/1", &_test_recv_data1);
|
||||
_TEST_ADD_RECV ("/lldp/recv/2_ttl1", &_test_recv_data2_ttl1);
|
||||
|
||||
g_test_add_data_func ("/lldp/parse-frames/0", &_test_recv_data0_frame0, test_parse_frames);
|
||||
g_test_add_data_func ("/lldp/parse-frames/1", &_test_recv_data1_frame0, test_parse_frames);
|
||||
g_test_add_data_func ("/lldp/parse-frames/2", &_test_recv_data2_frame0_ttl1, test_parse_frames);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue