]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: make sure that the default naming scheme name maps back to itself 29588/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 16 Oct 2023 10:53:10 +0000 (12:53 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 16 Oct 2023 19:21:54 +0000 (21:21 +0200)
We were testing the that C constant is defined, but we weren't actually testing
that the string name maps back to itself. This would catch the issue fixed by
the grandparent commit.

The test for the default name is moved to the test file to keep the tests
together. The define is renamed to not have "_TEST" in the name. The issue here
is complicated by the fact that we allow downstreams to inject additional
fields, so we don't know the name of the default scheme if it not set with
-Ddefault-net-naming-scheme=, so _DEFAULT_NET_NAMING_SCHEME[_TEST] is not
defined in all cases, but at least in principle it could be used in other
places. If it exists, it is fully valid.

meson.build
src/shared/netif-naming-scheme.c
src/test/test-net-naming-scheme.c

index 5b6b928276261379d918c38bfef21bfd6c45ee90..77684b5caf092e5ce59de9c386742aff8b0a9f63 100644 (file)
@@ -767,10 +767,12 @@ conf.set('EXTRA_NET_NAMING_SCHEMES', ' '.join(extra_net_naming_schemes))
 conf.set('EXTRA_NET_NAMING_MAP', ' '.join(extra_net_naming_map))
 
 default_net_naming_scheme = get_option('default-net-naming-scheme')
-conf.set_quoted('DEFAULT_NET_NAMING_SCHEME', default_net_naming_scheme)
+conf.set_quoted('DEFAULT_NET_NAMING_SCHEME', default_net_naming_scheme,
+                description : 'Default naming scheme as a string')
 if default_net_naming_scheme != 'latest'
-        conf.set('_DEFAULT_NET_NAMING_SCHEME_TEST',
-                 'NAMING_' + default_net_naming_scheme.underscorify().to_upper())
+        conf.set('_DEFAULT_NET_NAMING_SCHEME',
+                 'NAMING_' + default_net_naming_scheme.underscorify().to_upper(),
+                 description : 'Default naming scheme as a constant')
 endif
 
 time_epoch = get_option('time-epoch')
index 7fe19d4877581b166af43542a68f22ff12b2b196..fbaf5c5a6081fe97b6bb74b7671115e6bef690ef 100644 (file)
@@ -6,13 +6,6 @@
 #include "string-util.h"
 #include "string-table.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 },
index 0766170757ea2f2cb277eae2cb120205d351149f..f7ec5a6d72fd558df281fbf9337375b49b5fc894 100644 (file)
@@ -4,10 +4,19 @@
 #include "string-util.h"
 #include "tests.h"
 
+#ifdef _DEFAULT_NET_NAMING_SCHEME
+/* 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 >= 0);
+#endif
+
 TEST(default_net_naming_scheme) {
         const NamingScheme *n;
         assert_se(n = naming_scheme_from_name(DEFAULT_NET_NAMING_SCHEME));
         log_info("default → %s", n->name);
+
+        assert_se(naming_scheme_from_name(n->name) == n);
 }
 
 TEST(naming_scheme_conversions) {