summaryrefslogtreecommitdiff
path: root/src/test/test-engine.c
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2021-11-09 15:26:28 -0800
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-11-10 10:52:08 +0100
commit899acf5c2d4b89caa891d05ccfa4be828a999c2d (patch)
tree542704b65d167750da9a4d9e72616e22d947e16b /src/test/test-engine.c
parent4d544a0c879a2f1a983cc5e6960c4a53fa565772 (diff)
downloadsystemd-899acf5c2d4b89caa891d05ccfa4be828a999c2d.tar.gz
core: replace slice dependencies as they get added
Defines a "UNIT_DEPENDENCY_SLICE_PROPERTY" UnitDependencyMask type that is used when adding slices to the dependencies hashmap. This type is used to remove slice dependencies when they get overridden by new ones. Fixes #20182
Diffstat (limited to 'src/test/test-engine.c')
-rw-r--r--src/test/test-engine.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/test/test-engine.c b/src/test/test-engine.c
index 880af36fb5..673c665612 100644
--- a/src/test/test-engine.c
+++ b/src/test/test-engine.c
@@ -8,6 +8,7 @@
#include "manager-dump.h"
#include "rm-rf.h"
#include "service.h"
+#include "slice.h"
#include "special.h"
#include "strv.h"
#include "tests.h"
@@ -75,7 +76,8 @@ int main(int argc, char *argv[]) {
_cleanup_(sd_bus_error_free) sd_bus_error err = SD_BUS_ERROR_NULL;
_cleanup_(manager_freep) Manager *m = NULL;
Unit *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL, *g = NULL,
- *h = NULL, *i = NULL, *a_conj = NULL, *unit_with_multiple_dashes = NULL, *stub = NULL;
+ *h = NULL, *i = NULL, *a_conj = NULL, *unit_with_multiple_dashes = NULL, *stub = NULL,
+ *tomato = NULL, *sauce = NULL, *fruit = NULL, *zupa = NULL;
Job *j;
int r;
@@ -260,5 +262,32 @@ int main(int argc, char *argv[]) {
verify_dependency_atoms();
+ /* Test adding multiple Slice= dependencies; only the last should remain */
+ assert_se(unit_new_for_name(m, sizeof(Service), "tomato.service", &tomato) >= 0);
+ assert_se(unit_new_for_name(m, sizeof(Slice), "sauce.slice", &sauce) >= 0);
+ assert_se(unit_new_for_name(m, sizeof(Slice), "fruit.slice", &fruit) >= 0);
+ assert_se(unit_new_for_name(m, sizeof(Slice), "zupa.slice", &zupa) >= 0);
+
+ unit_set_slice(tomato, sauce);
+ unit_set_slice(tomato, fruit);
+ unit_set_slice(tomato, zupa);
+
+ assert_se(UNIT_GET_SLICE(tomato) == zupa);
+ assert_se(!unit_has_dependency(tomato, UNIT_ATOM_IN_SLICE, sauce));
+ assert_se(!unit_has_dependency(tomato, UNIT_ATOM_IN_SLICE, fruit));
+ assert_se(unit_has_dependency(tomato, UNIT_ATOM_IN_SLICE, zupa));
+
+ assert_se(!unit_has_dependency(tomato, UNIT_ATOM_REFERENCES, sauce));
+ assert_se(!unit_has_dependency(tomato, UNIT_ATOM_REFERENCES, fruit));
+ assert_se(unit_has_dependency(tomato, UNIT_ATOM_REFERENCES, zupa));
+
+ assert_se(!unit_has_dependency(sauce, UNIT_ATOM_SLICE_OF, tomato));
+ assert_se(!unit_has_dependency(fruit, UNIT_ATOM_SLICE_OF, tomato));
+ assert_se(unit_has_dependency(zupa, UNIT_ATOM_SLICE_OF, tomato));
+
+ assert_se(!unit_has_dependency(sauce, UNIT_ATOM_REFERENCED_BY, tomato));
+ assert_se(!unit_has_dependency(fruit, UNIT_ATOM_REFERENCED_BY, tomato));
+ assert_se(unit_has_dependency(zupa, UNIT_ATOM_REFERENCED_BY, tomato));
+
return 0;
}