test-bus-kernel-bloom.c revision f2769777c8e8ad32b0b19cd540d2f742bda4457f
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer/***
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer This file is part of systemd.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
fff87a35d9e26c0d4ea41273a963c0eb20e18da4Zbigniew Jędrzejewski-Szmek Copyright 2013 Lennart Poettering
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier systemd is free software; you can redistribute it and/or modify it
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer under the terms of the GNU Lesser General Public License as published by
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer the Free Software Foundation; either version 2.1 of the License, or
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer (at your option) any later version.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier systemd is distributed in the hope that it will be useful, but
278d5115470919319c514ea37d7b14e3f7d0580bEvgeny Vereshchagin WITHOUT ANY WARRANTY; without even the implied warranty of
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier Lesser General Public License for more details.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
32d965851d8cbb39f8ee0eeaf76a89e8f5fc174fLennart Poettering You should have received a copy of the GNU Lesser General Public License
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer along with systemd; If not, see <http://www.gnu.org/licenses/>.
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer***/
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
d9890f4ed47c0d565915360d8bae3b7a1428f285Harald Hoyer#include "util.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "log.h"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer#include "sd-bus.h"
c6a77179a4097df355f0f04b8f3260c76b5e515cRonny Chevalier#include "bus-message.h"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer#include "bus-error.h"
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer#include "bus-kernel.h"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier#include "bus-util.h"
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyerstatic void test_one(
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer const char *path,
7b17d413b11bfbdb4442c87b1db25b37ed5162acHarald Hoyer const char *interface,
d9890f4ed47c0d565915360d8bae3b7a1428f285Harald Hoyer const char *member,
d9890f4ed47c0d565915360d8bae3b7a1428f285Harald Hoyer const char *arg0,
d9890f4ed47c0d565915360d8bae3b7a1428f285Harald Hoyer const char *match,
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer bool good) {
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _cleanup_close_ int bus_ref = -1;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _cleanup_free_ char *bus_name = NULL, *address = NULL;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer sd_bus *a, *b;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer int r;
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer bus_ref = bus_kernel_create_bus("deine-mutter", false, &bus_name);
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer if (bus_ref == -ENOENT)
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier exit(EXIT_TEST_SKIP);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_se(bus_ref >= 0);
6b197f2a03fa03a2a853cf726d47be2ea4c623b6Harald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer address = strappend("kernel:path=", bus_name);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_se(address);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = sd_bus_new(&a);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_se(r >= 0);
5c404f1ab8e96efedb983806443ca982a1b2a372Evgeny Vereshchagin
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = sd_bus_new(&b);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_se(r >= 0);
c90feab4ff8bc23d88d4f9c67d9652ba189cb51bMichal Schmidt
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier r = sd_bus_set_address(a, address);
cd949ee7348982d90fb8bdf4a37128928b82925fEvgeny Vereshchagin assert_se(r >= 0);
889a90422dd47284dffa32b9234a6e58991b000cRonny Chevalier
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer r = sd_bus_set_address(b, address);
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack assert_se(r >= 0);
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack r = sd_bus_start(a);
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack assert_se(r >= 0);
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack r = sd_bus_start(b);
6f9d3b08cf3e50d3903282d2ce36244bb86c7b7cDaniel Mack assert_se(r >= 0);
0d6e798a784ef0ba6b95512e4453067b2f84a91aHarald Hoyer
d9890f4ed47c0d565915360d8bae3b7a1428f285Harald Hoyer log_debug("match");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = sd_bus_add_match(b, match, NULL, NULL);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_se(r >= 0);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer log_debug("signal");
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = sd_bus_emit_signal(a, path, interface, member, "s", arg0);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_se(r >= 0);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer r = sd_bus_process(b, &m);
898720b7e9cf3bdf7a93e435cbed5dd6942ecf9bHarald Hoyer assert_se(r >= 0 && (good == !!m));
sd_bus_unref(a);
sd_bus_unref(b);
}
int main(int argc, char *argv[]) {
log_set_max_level(LOG_DEBUG);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo/tuut'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "interface='waldo.com'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "member='Piep'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "member='Pi_ep'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "arg0='foobar'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "arg0='foo_bar'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo',interface='waldo.com',member='Piep',arg0='foobar'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo',interface='waldo.com',member='Piep',arg0='foobar2'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path='/foo/bar/waldo/quux'", false);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path_namespace='/foo/bar/waldo'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path_namespace='/foo/bar'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path_namespace='/foo'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path_namespace='/'", true);
test_one("/foo/bar/waldo", "waldo.com", "Piep", "foobar", "path_namespace='/quux'", false);
return 0;
}