]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
meson: drop the list of valid net naming schemes
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 Sep 2021 07:33:30 +0000 (09:33 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 Sep 2021 12:22:37 +0000 (14:22 +0200)
We used 'combo' type for the scheme list. For a while we forgot to add
new names, and recently aa0a23ec86 added v241, v243, v245, and v247.
I want to allow defining new values during configuration, which means
that we can't use meson to verify the list of options. So any value is
allowed, but then two tests are added: one that will fail compilation if some
invalid name is given (other than "latest"), and one that converts
DEFAULT_NET_NAMING_SCHEME to a NamingScheme pointer.

meson.build
meson_options.txt
src/shared/netif-naming-scheme.c
src/shared/netif-naming-scheme.h
src/test/meson.build
src/test/test-net-naming-scheme.c [new file with mode: 0644]

index 9db035c3b794c0ab46dab8887a87e331edb8b30f..67695a436820ba0e20de00c229b241d5026635d0 100644 (file)
@@ -709,6 +709,10 @@ endif
 
 default_net_naming_scheme = get_option('default-net-naming-scheme')
 conf.set_quoted('DEFAULT_NET_NAMING_SCHEME', default_net_naming_scheme)
+if default_net_naming_scheme != 'latest'
+        conf.set('_DEFAULT_NET_NAMING_SCHEME_TEST',
+                 'NAMING_' + default_net_naming_scheme.underscorify().to_upper())
+endif
 
 time_epoch = get_option('time-epoch')
 if time_epoch == -1
index dcd3c01ae4f8565b682d78ca35f6ab392cd014fa..15be1959d1f789a7352e6e8f568a1b91f0529460 100644 (file)
@@ -200,8 +200,7 @@ option('fallback-hostname', type : 'string', value : 'localhost',
 option('default-hierarchy', type : 'combo',
        choices : ['legacy', 'hybrid', 'unified'], value : 'unified',
        description : 'default cgroup hierarchy')
-option('default-net-naming-scheme', type : 'combo',
-       choices : ['latest', 'v238', 'v239', 'v240', 'v241', 'v243', 'v245', 'v247', 'v249'],
+option('default-net-naming-scheme', type : 'string', value : 'latest',
        description : 'default net.naming-scheme= value')
 option('status-unit-format-default', type : 'combo',
        choices : ['description', 'name', 'combined'],
index 0a80931b0fcdc4c543bdfd03d211088e429b051a..287a942014b3c6caaf5d15e16f89fc9f2ed9fefa 100644 (file)
@@ -5,6 +5,13 @@
 #include "proc-cmdline.h"
 #include "string-util.h"
 
+#ifdef _DEFAULT_NET_NAMING_SCHEME_TEST
+/* The primary purpose of this check is to verify that _DEFAULT_NET_NAMING_SCHEME_TEST
+ * is a valid identifier. If an invalid name is given during configuration, this will
+ * fail with a name error. */
+assert_cc(_DEFAULT_NET_NAMING_SCHEME_TEST >= 0);
+#endif
+
 static const NamingScheme naming_schemes[] = {
         { "v238", NAMING_V238 },
         { "v239", NAMING_V239 },
@@ -15,10 +22,9 @@ static const NamingScheme naming_schemes[] = {
         { "v247", NAMING_V247 },
         { "v249", NAMING_V249 },
         /* … add more schemes here, as the logic to name devices is updated … */
-        /* also remember to update the list of options in meson_options.txt */
 };
 
-static const NamingScheme* naming_scheme_from_name(const char *name) {
+const NamingScheme* naming_scheme_from_name(const char *name) {
         if (streq(name, "latest"))
                 return naming_schemes + ELEMENTSOF(naming_schemes) - 1;
 
index 119b80178f1ac15c1f3583d155cf65d45b4f307b..f5d040cc090de8dd16fd59f84801302f8c993f73 100644 (file)
@@ -54,6 +54,7 @@ typedef struct NamingScheme {
         NamingSchemeFlags flags;
 } NamingScheme;
 
+const NamingScheme* naming_scheme_from_name(const char *name);
 const NamingScheme* naming_scheme(void);
 
 static inline bool naming_scheme_has(NamingSchemeFlags flags) {
index f58cf2d8436e256d639b9ebbb32241976328b4ef..0223086c6907ce7f0fbff5a1b856e91f76e34054 100644 (file)
@@ -429,6 +429,8 @@ tests += [
 
         [['src/test/test-firewall-util.c']],
 
+        [['src/test/test-net-naming-scheme.c']],
+
         [['src/test/test-netlink-manual.c'],
          [],
          [libkmod],
diff --git a/src/test/test-net-naming-scheme.c b/src/test/test-net-naming-scheme.c
new file mode 100644 (file)
index 0000000..693b2f6
--- /dev/null
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+
+#include "netif-naming-scheme.h"
+#include "string-util.h"
+#include "tests.h"
+
+static void test_default_net_naming_scheme(void) {
+        log_info("/* %s */", __func__);
+
+        const NamingScheme *n;
+        assert_se(n = naming_scheme_from_name(DEFAULT_NET_NAMING_SCHEME));
+        log_info("default → %s", n->name);
+}
+
+static void test_naming_scheme_conversions(void) {
+        log_info("/* %s */", __func__);
+
+        const NamingScheme *n;
+        assert_se(n = naming_scheme_from_name("latest"));
+        log_info("latest → %s", n->name);
+
+        assert_se(n = naming_scheme_from_name("v238"));
+        assert_se(streq(n->name, "v238"));
+}
+
+int main(int argc, char **argv) {
+        test_setup_logging(LOG_INFO);
+
+        test_default_net_naming_scheme();
+        test_naming_scheme_conversions();
+}