mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 17:20:11 +01:00
We use clang-format for automatic formatting of our source files. Since clang-format is actively maintained software, the actual formatting depends on the used version of clang-format. That is unfortunate and painful, but really unavoidable unless clang-format would be strictly bug-compatible. So the version that we must use is from the current Fedora release, which is also tested by our gitlab-ci. Previously, we were using Fedora 34 with clang-tools-extra-12.0.1-1.fc34.x86_64. As Fedora 35 comes along, we need to update our formatting as Fedora 35 comes with version "13.0.0~rc1-1.fc35". An alternative would be to freeze on version 12, but that has different problems (like, it's cumbersome to rebuild clang 12 on Fedora 35 and it would be cumbersome for our developers which are on Fedora 35 to use a clang that they cannot easily install). The (differently painful) solution is to reformat from time to time, as we switch to a new Fedora (and thus clang) version. Usually we would expect that such a reformatting brings minor changes. But this time, the changes are huge. That is mentioned in the release notes [1] as Makes PointerAligment: Right working with AlignConsecutiveDeclarations. (Fixes https://llvm.org/PR27353) [1] https://releases.llvm.org/13.0.0/tools/clang/docs/ReleaseNotes.html#clang-format
354 lines
10 KiB
C
354 lines
10 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Copyright (C) 2013 Red Hat, Inc.
|
|
*/
|
|
|
|
#include "src/core/nm-default-daemon.h"
|
|
|
|
#include "nm-dcb.h"
|
|
|
|
#include "nm-test-utils-core.h"
|
|
|
|
typedef struct {
|
|
guint num;
|
|
const char *cmds[];
|
|
} DcbExpected;
|
|
|
|
static gboolean
|
|
test_dcb_func(char **argv, guint which, gpointer user_data, GError **error)
|
|
{
|
|
DcbExpected *e = user_data;
|
|
char *f;
|
|
|
|
g_assert(argv[0] == NULL);
|
|
argv[0] = (which == DCBTOOL) ? "dcbtool" : "fcoeadm";
|
|
|
|
f = g_strjoinv(" ", argv);
|
|
if (e->cmds[e->num] == NULL)
|
|
g_assert_cmpstr(f, ==, NULL);
|
|
g_assert_cmpstr(e->cmds[e->num], !=, NULL);
|
|
g_assert_cmpstr(f, ==, e->cmds[e->num++]);
|
|
g_free(f);
|
|
return TRUE;
|
|
}
|
|
|
|
#define DCB_FLAGS_ALL \
|
|
(NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING)
|
|
|
|
static void
|
|
test_dcb_fcoe(void)
|
|
{
|
|
static DcbExpected expected = {
|
|
0,
|
|
{"dcbtool sc eth0 app:fcoe e:1 a:1 w:1",
|
|
"dcbtool sc eth0 app:fcoe appcfg:40",
|
|
"dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
|
|
"dcbtool sc eth0 app:fip e:0 a:0 w:0",
|
|
"dcbtool sc eth0 pfc e:0 a:0 w:0",
|
|
"dcbtool sc eth0 pg e:0",
|
|
NULL},
|
|
};
|
|
NMSettingDcb *s_dcb;
|
|
GError *error = NULL;
|
|
gboolean success;
|
|
|
|
s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
|
|
g_object_set(G_OBJECT(s_dcb),
|
|
NM_SETTING_DCB_APP_FCOE_FLAGS,
|
|
DCB_FLAGS_ALL,
|
|
NM_SETTING_DCB_APP_FCOE_PRIORITY,
|
|
6,
|
|
NULL);
|
|
|
|
success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
|
|
g_assert_no_error(error);
|
|
g_assert(success);
|
|
|
|
g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
|
|
g_object_unref(s_dcb);
|
|
}
|
|
|
|
static void
|
|
test_dcb_iscsi(void)
|
|
{
|
|
static DcbExpected expected = {
|
|
0,
|
|
{"dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
|
|
"dcbtool sc eth0 app:iscsi e:1 a:0 w:1",
|
|
"dcbtool sc eth0 app:iscsi appcfg:08",
|
|
"dcbtool sc eth0 app:fip e:0 a:0 w:0",
|
|
"dcbtool sc eth0 pfc e:0 a:0 w:0",
|
|
"dcbtool sc eth0 pg e:0",
|
|
NULL},
|
|
};
|
|
NMSettingDcb *s_dcb;
|
|
GError *error = NULL;
|
|
gboolean success;
|
|
|
|
s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
|
|
g_object_set(G_OBJECT(s_dcb),
|
|
NM_SETTING_DCB_APP_ISCSI_FLAGS,
|
|
(NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_WILLING),
|
|
NM_SETTING_DCB_APP_ISCSI_PRIORITY,
|
|
3,
|
|
NULL);
|
|
|
|
success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
|
|
g_assert_no_error(error);
|
|
g_assert(success);
|
|
|
|
g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
|
|
g_object_unref(s_dcb);
|
|
}
|
|
|
|
static void
|
|
test_dcb_fip(void)
|
|
{
|
|
static DcbExpected expected = {
|
|
0,
|
|
{"dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
|
|
"dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
|
|
"dcbtool sc eth0 app:fip e:1 a:1 w:0",
|
|
"dcbtool sc eth0 app:fip appcfg:01",
|
|
"dcbtool sc eth0 pfc e:0 a:0 w:0",
|
|
"dcbtool sc eth0 pg e:0",
|
|
NULL},
|
|
};
|
|
NMSettingDcb *s_dcb;
|
|
GError *error = NULL;
|
|
gboolean success;
|
|
|
|
s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
|
|
g_object_set(G_OBJECT(s_dcb),
|
|
NM_SETTING_DCB_APP_FIP_FLAGS,
|
|
(NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE),
|
|
NM_SETTING_DCB_APP_FIP_PRIORITY,
|
|
0,
|
|
NULL);
|
|
|
|
success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
|
|
g_assert_no_error(error);
|
|
g_assert(success);
|
|
|
|
g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
|
|
g_object_unref(s_dcb);
|
|
}
|
|
|
|
static void
|
|
test_dcb_fip_default_prio(void)
|
|
{
|
|
static DcbExpected expected = {
|
|
0,
|
|
{"dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
|
|
"dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
|
|
"dcbtool sc eth0 app:fip e:1 a:1 w:0",
|
|
"dcbtool sc eth0 pfc e:0 a:0 w:0",
|
|
"dcbtool sc eth0 pg e:0",
|
|
NULL},
|
|
};
|
|
NMSettingDcb *s_dcb;
|
|
GError *error = NULL;
|
|
gboolean success;
|
|
|
|
s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
|
|
g_object_set(G_OBJECT(s_dcb),
|
|
NM_SETTING_DCB_APP_FIP_FLAGS,
|
|
(NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE),
|
|
NM_SETTING_DCB_APP_FIP_PRIORITY,
|
|
-1,
|
|
NULL);
|
|
|
|
success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
|
|
g_assert_no_error(error);
|
|
g_assert(success);
|
|
|
|
g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
|
|
g_object_unref(s_dcb);
|
|
}
|
|
|
|
static void
|
|
test_dcb_pfc(void)
|
|
{
|
|
static DcbExpected expected = {
|
|
0,
|
|
{"dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
|
|
"dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
|
|
"dcbtool sc eth0 app:fip e:0 a:0 w:0",
|
|
"dcbtool sc eth0 pfc e:1 a:1 w:1",
|
|
"dcbtool sc eth0 pfc pfcup:01101100",
|
|
"dcbtool sc eth0 pg e:0",
|
|
NULL},
|
|
};
|
|
NMSettingDcb *s_dcb;
|
|
GError *error = NULL;
|
|
gboolean success;
|
|
|
|
s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
|
|
g_object_set(G_OBJECT(s_dcb), NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, DCB_FLAGS_ALL, NULL);
|
|
|
|
nm_setting_dcb_set_priority_flow_control(s_dcb, 0, FALSE);
|
|
nm_setting_dcb_set_priority_flow_control(s_dcb, 1, TRUE);
|
|
nm_setting_dcb_set_priority_flow_control(s_dcb, 2, TRUE);
|
|
nm_setting_dcb_set_priority_flow_control(s_dcb, 3, FALSE);
|
|
nm_setting_dcb_set_priority_flow_control(s_dcb, 4, TRUE);
|
|
nm_setting_dcb_set_priority_flow_control(s_dcb, 5, TRUE);
|
|
nm_setting_dcb_set_priority_flow_control(s_dcb, 6, FALSE);
|
|
nm_setting_dcb_set_priority_flow_control(s_dcb, 7, FALSE);
|
|
|
|
success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
|
|
g_assert_no_error(error);
|
|
g_assert(success);
|
|
|
|
g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
|
|
g_object_unref(s_dcb);
|
|
}
|
|
|
|
static void
|
|
test_dcb_priority_groups(void)
|
|
{
|
|
static DcbExpected expected = {
|
|
0,
|
|
{"dcbtool sc eth0 app:fcoe e:0 a:0 w:0",
|
|
"dcbtool sc eth0 app:iscsi e:0 a:0 w:0",
|
|
"dcbtool sc eth0 app:fip e:0 a:0 w:0",
|
|
"dcbtool sc eth0 pfc e:0 a:0 w:0",
|
|
"dcbtool sc eth0 pg e:1 a:1 w:1"
|
|
" pgid:765f3210"
|
|
" pgpct:10,40,5,10,5,20,7,3"
|
|
" uppct:100,50,33,25,20,16,14,12"
|
|
" strict:01010101"
|
|
" up2tc:01201201",
|
|
NULL},
|
|
};
|
|
NMSettingDcb *s_dcb;
|
|
GError *error = NULL;
|
|
gboolean success;
|
|
guint i;
|
|
|
|
s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
|
|
g_object_set(G_OBJECT(s_dcb), NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, DCB_FLAGS_ALL, NULL);
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
/* Make sure at least one 15/f is present in the group IDs */
|
|
nm_setting_dcb_set_priority_group_id(s_dcb, i, (i == 3) ? 15 : 7 - i);
|
|
nm_setting_dcb_set_priority_bandwidth(s_dcb, i, 100 / (i + 1));
|
|
nm_setting_dcb_set_priority_strict_bandwidth(s_dcb, i, i % 2);
|
|
nm_setting_dcb_set_priority_traffic_class(s_dcb, i, i % 3);
|
|
}
|
|
|
|
nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 0, 10);
|
|
nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 1, 40);
|
|
nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 2, 5);
|
|
nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 3, 10);
|
|
nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 4, 5);
|
|
nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 5, 20);
|
|
nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 6, 7);
|
|
nm_setting_dcb_set_priority_group_bandwidth(s_dcb, 7, 3);
|
|
|
|
success = _dcb_setup("eth0", s_dcb, test_dcb_func, &expected, &error);
|
|
g_assert_no_error(error);
|
|
g_assert(success);
|
|
|
|
g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
|
|
g_object_unref(s_dcb);
|
|
}
|
|
|
|
static void
|
|
test_dcb_cleanup(void)
|
|
{
|
|
static DcbExpected expected = {
|
|
0,
|
|
{"fcoeadm -d eth0",
|
|
"dcbtool sc eth0 app:fcoe e:0",
|
|
"dcbtool sc eth0 app:iscsi e:0",
|
|
"dcbtool sc eth0 app:fip e:0",
|
|
"dcbtool sc eth0 pfc e:0",
|
|
"dcbtool sc eth0 pg e:0",
|
|
"dcbtool sc eth0 dcb off",
|
|
NULL},
|
|
};
|
|
GError *error = NULL;
|
|
gboolean success;
|
|
|
|
success = _fcoe_cleanup("eth0", test_dcb_func, &expected, &error);
|
|
g_assert_no_error(error);
|
|
g_assert(success);
|
|
|
|
success = _dcb_cleanup("eth0", test_dcb_func, &expected, &error);
|
|
g_assert_no_error(error);
|
|
g_assert(success);
|
|
|
|
g_assert_cmpstr(expected.cmds[expected.num], ==, NULL);
|
|
}
|
|
|
|
static void
|
|
test_fcoe_create(void)
|
|
{
|
|
static DcbExpected expected1 = {
|
|
0,
|
|
{"fcoeadm -m fabric -c eth0", NULL},
|
|
};
|
|
static DcbExpected expected2 = {
|
|
0,
|
|
{"fcoeadm -m vn2vn -c eth0", NULL},
|
|
};
|
|
GError *error = NULL;
|
|
gboolean success;
|
|
NMSettingDcb *s_dcb;
|
|
|
|
s_dcb = (NMSettingDcb *) nm_setting_dcb_new();
|
|
g_object_set(G_OBJECT(s_dcb), NM_SETTING_DCB_APP_FCOE_FLAGS, DCB_FLAGS_ALL, NULL);
|
|
|
|
/* Default mode is fabric */
|
|
success = _fcoe_setup("eth0", s_dcb, test_dcb_func, &expected1, &error);
|
|
g_assert_no_error(error);
|
|
g_assert(success);
|
|
|
|
/* Test VN2VN */
|
|
g_object_set(G_OBJECT(s_dcb),
|
|
NM_SETTING_DCB_APP_FCOE_MODE,
|
|
NM_SETTING_DCB_FCOE_MODE_VN2VN,
|
|
NULL);
|
|
success = _fcoe_setup("eth0", s_dcb, test_dcb_func, &expected2, &error);
|
|
g_assert_no_error(error);
|
|
g_assert(success);
|
|
|
|
g_object_unref(s_dcb);
|
|
}
|
|
|
|
static void
|
|
test_fcoe_cleanup(void)
|
|
{
|
|
static DcbExpected expected = {
|
|
0,
|
|
{"fcoeadm -d eth0", NULL},
|
|
};
|
|
GError *error = NULL;
|
|
gboolean success;
|
|
|
|
success = _fcoe_cleanup("eth0", test_dcb_func, &expected, &error);
|
|
g_assert_no_error(error);
|
|
g_assert(success);
|
|
}
|
|
|
|
/*****************************************************************************/
|
|
|
|
NMTST_DEFINE();
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
nmtst_init_assert_logging(&argc, &argv, "INFO", "DEFAULT");
|
|
|
|
g_test_add_func("/dcb/fcoe", test_dcb_fcoe);
|
|
g_test_add_func("/dcb/iscsi", test_dcb_iscsi);
|
|
g_test_add_func("/dcb/fip", test_dcb_fip);
|
|
g_test_add_func("/dcb/fip-default-priority", test_dcb_fip_default_prio);
|
|
g_test_add_func("/dcb/pfc", test_dcb_pfc);
|
|
g_test_add_func("/dcb/priority-groups", test_dcb_priority_groups);
|
|
g_test_add_func("/dcb/cleanup", test_dcb_cleanup);
|
|
g_test_add_func("/fcoe/create", test_fcoe_create);
|
|
g_test_add_func("/fcoe/cleanup", test_fcoe_cleanup);
|
|
|
|
return g_test_run();
|
|
}
|