diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2019-09-02 17:11:05 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2019-09-09 18:57:37 +0200 |
commit | 391895d13174f6c8c329e3b8d0a66a89828e542d (patch) | |
tree | 90071d5da9bb641559da44c79af4619d25300997 /src/initrd/tests | |
parent | a9777d9178993ba5dc100d1ee91df5f70fee0efa (diff) | |
download | NetworkManager-lr/initrd-ofw.tar.gz |
initrd: add devicetree supportlr/initrd-ofw
This adds capability to hand over the network configuration from
OpenFirmware (and potentially other boot loaders with openfirmware
support such as U-Boot) to NetworkManager.
It's done analogously to ACPI/iBFT. In fact, the same ip=ibft command
line option is used, adding a more general ip=fw alias. This probably
deserves some documentation, but I'm not adding any at this time.
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/257
Diffstat (limited to 'src/initrd/tests')
21 files changed, 157 insertions, 0 deletions
diff --git a/src/initrd/tests/meson.build b/src/initrd/tests/meson.build index 20cf6af23b..6a508d3d8b 100644 --- a/src/initrd/tests/meson.build +++ b/src/initrd/tests/meson.build @@ -1,4 +1,5 @@ test_units = [ + 'test-dt-reader', 'test-ibft-reader', 'test-cmdline-reader', ] diff --git a/src/initrd/tests/sysfs-dt-tftp/firmware/devicetree/base/chosen/bootpath b/src/initrd/tests/sysfs-dt-tftp/firmware/devicetree/base/chosen/bootpath Binary files differnew file mode 100644 index 0000000000..6f069ae0fc --- /dev/null +++ b/src/initrd/tests/sysfs-dt-tftp/firmware/devicetree/base/chosen/bootpath diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/bootp-request b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/bootp-request Binary files differnew file mode 100644 index 0000000000..034d423ee3 --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/bootp-request diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/bootp-response b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/bootp-response Binary files differnew file mode 100644 index 0000000000..25982d6f42 --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/bootp-response diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/bootpath b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/bootpath Binary files differnew file mode 100644 index 0000000000..db88070270 --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/bootpath diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/broadcast-ip b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/broadcast-ip new file mode 100644 index 0000000000..7bde8641b9 --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/broadcast-ip @@ -0,0 +1 @@ +ÿÿÿÿ
\ No newline at end of file diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/client-ip b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/client-ip new file mode 100644 index 0000000000..f108ba9b39 --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/client-ip @@ -0,0 +1,2 @@ + ++
\ No newline at end of file diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/client-name b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/client-name Binary files differnew file mode 100644 index 0000000000..fe0f76b8ed --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/client-name diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/domain-name b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/domain-name Binary files differnew file mode 100644 index 0000000000..b34f9f968e --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/domain-name diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/gateway-ip b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/gateway-ip new file mode 100644 index 0000000000..f036183536 --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/gateway-ip @@ -0,0 +1,2 @@ + ++þ
\ No newline at end of file diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/name b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/name Binary files differnew file mode 100644 index 0000000000..f3e5805251 --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/name diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/netmask-ip b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/netmask-ip Binary files differnew file mode 100644 index 0000000000..d441cd83fc --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/netmask-ip diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/root-path b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/root-path Binary files differnew file mode 100644 index 0000000000..f76dd238ad --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/root-path diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/server-ip b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/server-ip new file mode 100644 index 0000000000..a2a4b2e8de --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/server-ip @@ -0,0 +1,2 @@ + +&
\ No newline at end of file diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/tftp-file b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/tftp-file Binary files differnew file mode 100644 index 0000000000..c0e0e3303e --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/tftp-file diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/vendor-options b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/vendor-options Binary files differnew file mode 100644 index 0000000000..f76dd238ad --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/chosen/vendor-options diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/device_type b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/device_type Binary files differnew file mode 100644 index 0000000000..df3c9d9f4c --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/device_type diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/local-mac-address b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/local-mac-address new file mode 100644 index 0000000000..c983e75212 --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/local-mac-address @@ -0,0 +1 @@ +¬>åØ
\ No newline at end of file diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/mac-address b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/mac-address new file mode 100644 index 0000000000..c983e75212 --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/mac-address @@ -0,0 +1 @@ +¬>åØ
\ No newline at end of file diff --git a/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/name b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/name Binary files differnew file mode 100644 index 0000000000..88eaddfe14 --- /dev/null +++ b/src/initrd/tests/sysfs-dt/firmware/devicetree/base/ethernet/name diff --git a/src/initrd/tests/test-dt-reader.c b/src/initrd/tests/test-dt-reader.c new file mode 100644 index 0000000000..20f455476e --- /dev/null +++ b/src/initrd/tests/test-dt-reader.c @@ -0,0 +1,147 @@ +/* NetworkManager initrd configuration generator + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + * Copyright 2014 - 2018 Red Hat, Inc. + */ + +#include "nm-default.h" + +#include <stdio.h> +#include <stdarg.h> +#include <unistd.h> +#include <netinet/ether.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <sys/socket.h> + +#include "nm-core-internal.h" +#include "NetworkManagerUtils.h" + +#include "../nm-initrd-generator.h" + +#include "nm-test-utils-core.h" + +static void +test_read_dt_ofw (void) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + const char *mac_address; + + connection = nmi_dt_reader_parse (TEST_INITRD_DIR "/sysfs-dt"); + g_assert (connection); + nmtst_assert_connection_verifies (connection); + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "OpenFirmware Connection"); + g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, 0); + g_assert (nm_setting_connection_get_autoconnect (s_con)); + + s_wired = nm_connection_get_setting_wired (connection); + g_assert (s_wired); + mac_address = nm_setting_wired_get_mac_address (s_wired); + g_assert (mac_address); + g_assert (nm_utils_hwaddr_matches (mac_address, -1, "ac:7f:3e:e5:d8:d8", -1)); + g_assert (!nm_setting_wired_get_duplex (s_wired)); + g_assert_cmpint (nm_setting_wired_get_speed (s_wired), ==, 0); + g_assert_cmpint (nm_setting_wired_get_mtu (s_wired), ==, 0); + + s_ip4 = nm_connection_get_setting_ip4_config (connection); + g_assert (s_ip4); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + g_assert_cmpstr (nm_setting_ip_config_get_dhcp_hostname (s_ip4), ==, "demiurge"); + + s_ip6 = nm_connection_get_setting_ip6_config (connection); + g_assert (s_ip6); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); + + g_object_unref (connection); +} + +static void +test_read_dt_slof (void) +{ + NMConnection *connection; + NMSettingConnection *s_con; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress *ip4_addr; + + connection = nmi_dt_reader_parse (TEST_INITRD_DIR "/sysfs-dt-tftp"); + g_assert (connection); + nmtst_assert_connection_verifies (connection); + + s_con = nm_connection_get_setting_connection (connection); + g_assert (s_con); + g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME); + g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "OpenFirmware Connection"); + g_assert_cmpint (nm_setting_connection_get_timestamp (s_con), ==, 0); + g_assert (nm_setting_connection_get_autoconnect (s_con)); + + s_wired = nm_connection_get_setting_wired (connection); + g_assert (s_wired); + g_assert (!nm_setting_wired_get_mac_address (s_wired)); + g_assert_cmpstr (nm_setting_wired_get_duplex (s_wired), ==, "half"); + g_assert_cmpint (nm_setting_wired_get_speed (s_wired), ==, 10); + g_assert_cmpint (nm_setting_wired_get_mtu (s_wired), ==, 0); + + s_ip4 = nm_connection_get_setting_ip4_config (connection); + g_assert (s_ip4); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + g_assert_cmpint (nm_setting_ip_config_get_num_addresses (s_ip4), ==, 1); + ip4_addr = nm_setting_ip_config_get_address (s_ip4, 0); + g_assert (ip4_addr); + g_assert_cmpstr (nm_ip_address_get_address (ip4_addr), ==, "192.168.32.2"); + g_assert_cmpint (nm_ip_address_get_prefix (ip4_addr), ==, 16); + + g_assert_cmpstr (nm_setting_ip_config_get_gateway (s_ip4), ==, "192.168.32.1"); + + s_ip6 = nm_connection_get_setting_ip6_config (connection); + g_assert (s_ip6); + g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DISABLED); + + g_object_unref (connection); +} + +static void +test_read_dt_none (void) +{ + NMConnection *connection; + + connection = nmi_dt_reader_parse (TEST_INITRD_DIR "/sysfs"); + g_assert (!connection); +} + +NMTST_DEFINE (); + +int main (int argc, char **argv) +{ + nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); + + g_test_add_func ("/initrd/dt/ofw", test_read_dt_ofw); + g_test_add_func ("/initrd/dt/slof", test_read_dt_slof); + g_test_add_func ("/initrd/dt/none", test_read_dt_none); + + return g_test_run (); +} |