From ab430161eefa7f84b57d8220334490237d7ee493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 11 Jul 2017 16:08:30 -0400 Subject: libudev: unused variable --- src/libudev/libudev.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libudev/libudev.c b/src/libudev/libudev.c index 5f2225f402..d7b82a758f 100644 --- a/src/libudev/libudev.c +++ b/src/libudev/libudev.c @@ -94,7 +94,6 @@ _public_ void udev_set_userdata(struct udev *udev, void *userdata) { **/ _public_ struct udev *udev_new(void) { struct udev *udev; - _cleanup_fclose_ FILE *f = NULL; udev = new0(struct udev, 1); if (!udev) { -- cgit v1.2.1 From 00d82c81db80cfd7655fe076593d4f65703d9bf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 12 Jul 2017 21:25:17 +0000 Subject: meson: add option to configure "slow" tests on/off This is just the meson part, no functional change. Use meson -D slow-tests=yes to set the default, or SYSTEMD_SLOW_TESTS=yes build/test-foobar for just one test. Setting the default is more useful for installed tests. --- meson.build | 2 ++ meson_options.txt | 2 ++ 2 files changed, 4 insertions(+) diff --git a/meson.build b/meson.build index 20b27c8600..61b9e76f90 100644 --- a/meson.build +++ b/meson.build @@ -1026,6 +1026,8 @@ want_tests = get_option('tests') install_tests = get_option('install-tests') tests = [] +conf.set10('SYSTEMD_SLOW_TESTS_DEFAULT', get_option('slow-tests')) + ##################################################################### if get_option('efi') diff --git a/meson_options.txt b/meson_options.txt index 1594fec41f..71e357f15b 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -252,5 +252,7 @@ option('zshcompletiondir', type : 'string', option('tests', type : 'combo', choices : ['true', 'unsafe'], description : 'enable extra tests with =unsafe') +option('slow-tests', type : 'boolean', value : 'false', + description : 'run the slow tests by default') option('install-tests', type : 'boolean', value : 'false', description : 'install test executables') -- cgit v1.2.1 From 3d14a30082fecba2d95e3d0e099ff58b65aa7949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 12 Jul 2017 20:55:00 +0000 Subject: test-hashmap: use $SYSTEMD_SLOW_TESTS variable test-hashmap is a very good test, but it gets in the way when one wants to compile and quickly test changes. --- src/test/test-hashmap-plain.c | 73 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/src/test/test-hashmap-plain.c b/src/test/test-hashmap-plain.c index 1bd5c02f87..0471cd2f2f 100644 --- a/src/test/test-hashmap-plain.c +++ b/src/test/test-hashmap-plain.c @@ -18,17 +18,23 @@ ***/ #include "alloc-util.h" +#include "env-util.h" #include "hashmap.h" +#include "log.h" #include "string-util.h" #include "strv.h" #include "util.h" +static bool arg_slow = false; + void test_hashmap_funcs(void); static void test_hashmap_replace(void) { Hashmap *m; char *val1, *val2, *val3, *val4, *val5, *r; + log_info("%s", __func__); + m = hashmap_new(&string_hash_ops); val1 = strdup("val1"); @@ -67,6 +73,8 @@ static void test_hashmap_copy(void) { Hashmap *m, *copy; char *val1, *val2, *val3, *val4, *r; + log_info("%s", __func__); + val1 = strdup("val1"); assert_se(val1); val2 = strdup("val2"); @@ -103,6 +111,8 @@ static void test_hashmap_get_strv(void) { char **strv; char *val1, *val2, *val3, *val4; + log_info("%s", __func__); + val1 = strdup("val1"); assert_se(val1); val2 = strdup("val2"); @@ -139,6 +149,8 @@ static void test_hashmap_move_one(void) { Hashmap *m, *n; char *val1, *val2, *val3, *val4, *r; + log_info("%s", __func__); + val1 = strdup("val1"); assert_se(val1); val2 = strdup("val2"); @@ -178,6 +190,8 @@ static void test_hashmap_move(void) { Hashmap *m, *n; char *val1, *val2, *val3, *val4, *r; + log_info("%s", __func__); + val1 = strdup("val1"); assert_se(val1); val2 = strdup("val2"); @@ -220,6 +234,8 @@ static void test_hashmap_update(void) { Hashmap *m; char *val1, *val2, *r; + log_info("%s", __func__); + m = hashmap_new(&string_hash_ops); val1 = strdup("old_value"); assert_se(val1); @@ -250,6 +266,8 @@ static void test_hashmap_put(void) { void *val2 = (void*) "val 2"; _cleanup_free_ char* key1 = NULL; + log_info("%s", __func__); + assert_se(hashmap_ensure_allocated(&m, &string_hash_ops) >= 0); assert_se(m); @@ -268,6 +286,8 @@ static void test_hashmap_remove(void) { _cleanup_hashmap_free_ Hashmap *m = NULL; char *r; + log_info("%s", __func__); + r = hashmap_remove(NULL, "key 1"); assert_se(r == NULL); @@ -296,6 +316,8 @@ static void test_hashmap_remove2(void) { char val2[] = "val 2"; void *r, *r2; + log_info("%s", __func__); + r = hashmap_remove2(NULL, "key 1", &r2); assert_se(r == NULL); @@ -326,6 +348,8 @@ static void test_hashmap_remove_value(void) { char val1[] = "val 1"; char val2[] = "val 2"; + log_info("%s", __func__); + r = hashmap_remove_value(NULL, "key 1", val1); assert_se(r == NULL); @@ -358,6 +382,8 @@ static void test_hashmap_remove_and_put(void) { int valid; char *r; + log_info("%s", __func__); + m = hashmap_new(&string_hash_ops); assert_se(m); @@ -392,6 +418,8 @@ static void test_hashmap_remove_and_replace(void) { void *r; int i, j; + log_info("%s", __func__); + m = hashmap_new(&trivial_hash_ops); assert_se(m); @@ -443,6 +471,8 @@ static void test_hashmap_ensure_allocated(void) { Hashmap *m; int valid_hashmap; + log_info("%s", __func__); + m = hashmap_new(&string_hash_ops); valid_hashmap = hashmap_ensure_allocated(&m, &string_hash_ops); @@ -464,6 +494,8 @@ static void test_hashmap_foreach_key(void) { "key 3\0" "key 4\0"; + log_info("%s", __func__); + m = hashmap_new(&string_hash_ops); NULSTR_FOREACH(key, key_table) @@ -494,6 +526,8 @@ static void test_hashmap_foreach(void) { char *val1, *val2, *val3, *val4, *s; unsigned count; + log_info("%s", __func__); + val1 = strdup("my val1"); assert_se(val1); val2 = strdup("my val2"); @@ -544,6 +578,8 @@ static void test_hashmap_merge(void) { Hashmap *n; char *val1, *val2, *val3, *val4, *r; + log_info("%s", __func__); + val1 = strdup("my val1"); assert_se(val1); val2 = strdup("my val2"); @@ -577,6 +613,8 @@ static void test_hashmap_contains(void) { Hashmap *m; char *val1; + log_info("%s", __func__); + val1 = strdup("my val"); assert_se(val1); @@ -597,6 +635,8 @@ static void test_hashmap_isempty(void) { Hashmap *m; char *val1; + log_info("%s", __func__); + val1 = strdup("my val"); assert_se(val1); @@ -614,6 +654,8 @@ static void test_hashmap_size(void) { Hashmap *m; char *val1, *val2, *val3, *val4; + log_info("%s", __func__); + val1 = strdup("my val"); assert_se(val1); val2 = strdup("my val"); @@ -644,6 +686,8 @@ static void test_hashmap_get(void) { char *r; char *val; + log_info("%s", __func__); + val = strdup("my val"); assert_se(val); @@ -671,6 +715,8 @@ static void test_hashmap_get2(void) { char key_orig[] = "Key 1"; void *key_copy; + log_info("%s", __func__); + val = strdup("my val"); assert_se(val); @@ -710,14 +756,15 @@ static void test_hashmap_many(void) { Hashmap *h; unsigned i, j; void *v, *k; - static const struct { + const struct { const struct hash_ops *ops; unsigned n_entries; } tests[] = { - { .ops = NULL, .n_entries = 1 << 20 }, - { .ops = &crippled_hashmap_ops, .n_entries = 1 << 14 }, + { .ops = NULL, .n_entries = arg_slow ? 1 << 20 : 240 }, + { .ops = &crippled_hashmap_ops, .n_entries = arg_slow ? 1 << 14 : 140 }, }; + log_info("%s (%s)", __func__, arg_slow ? "slow" : "fast"); for (j = 0; j < ELEMENTSOF(tests); j++) { assert_se(h = hashmap_new(tests[j].ops)); @@ -748,6 +795,8 @@ static void test_hashmap_many(void) { static void test_hashmap_first(void) { _cleanup_hashmap_free_ Hashmap *m = NULL; + log_info("%s", __func__); + m = hashmap_new(&string_hash_ops); assert_se(m); @@ -765,6 +814,8 @@ static void test_hashmap_first(void) { static void test_hashmap_first_key(void) { _cleanup_hashmap_free_ Hashmap *m = NULL; + log_info("%s", __func__); + m = hashmap_new(&string_hash_ops); assert_se(m); @@ -782,6 +833,8 @@ static void test_hashmap_first_key(void) { static void test_hashmap_steal_first_key(void) { _cleanup_hashmap_free_ Hashmap *m = NULL; + log_info("%s", __func__); + m = hashmap_new(&string_hash_ops); assert_se(m); @@ -797,6 +850,8 @@ static void test_hashmap_steal_first(void) { int seen[3] = {}; char *val; + log_info("%s", __func__); + m = hashmap_new(&string_hash_ops); assert_se(m); @@ -815,6 +870,8 @@ static void test_hashmap_steal_first(void) { static void test_hashmap_clear_free_free(void) { _cleanup_hashmap_free_ Hashmap *m = NULL; + log_info("%s", __func__); + m = hashmap_new(&string_hash_ops); assert_se(m); @@ -829,6 +886,8 @@ static void test_hashmap_clear_free_free(void) { static void test_hashmap_reserve(void) { _cleanup_hashmap_free_ Hashmap *m = NULL; + log_info("%s", __func__); + m = hashmap_new(&string_hash_ops); assert_se(hashmap_reserve(m, 1) == 0); @@ -844,6 +903,14 @@ static void test_hashmap_reserve(void) { } void test_hashmap_funcs(void) { + int r; + + log_parse_environment(); + log_open(); + + r = getenv_bool("SYSTEMD_SLOW_TESTS"); + arg_slow = r >= 0 ? r : SYSTEMD_SLOW_TESTS_DEFAULT; + test_hashmap_copy(); test_hashmap_get_strv(); test_hashmap_move_one(); -- cgit v1.2.1 From 245d3d3c9535d8413dca2e6da6c74373c21d037e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 12 Jul 2017 21:02:05 +0000 Subject: test-compress-benchmark: look at $SYSTEMD_SLOW_TESTS --- src/journal/test-compress-benchmark.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/journal/test-compress-benchmark.c b/src/journal/test-compress-benchmark.c index 4fb93ded73..2a0ef634a5 100644 --- a/src/journal/test-compress-benchmark.c +++ b/src/journal/test-compress-benchmark.c @@ -19,6 +19,7 @@ #include "alloc-util.h" #include "compress.h" +#include "env-util.h" #include "macro.h" #include "parse-util.h" #include "random-util.h" @@ -32,7 +33,7 @@ typedef int (decompress_t)(const void *src, uint64_t src_size, #if defined(HAVE_XZ) || defined(HAVE_LZ4) -static usec_t arg_duration = 2 * USEC_PER_SEC; +static usec_t arg_duration; static size_t arg_start; #define MAX_SIZE (1024*1024LU) @@ -158,6 +159,7 @@ static void test_compress_decompress(const char* label, const char* type, int main(int argc, char *argv[]) { #if defined(HAVE_XZ) || defined(HAVE_LZ4) const char *i; + int r; log_set_max_level(LOG_INFO); @@ -166,7 +168,15 @@ int main(int argc, char *argv[]) { assert_se(safe_atou(argv[1], &x) >= 0); arg_duration = x * USEC_PER_SEC; + } else { + bool slow; + + r = getenv_bool("SYSTEMD_SLOW_TESTS"); + slow = r >= 0 ? r : SYSTEMD_SLOW_TESTS_DEFAULT; + + arg_duration = slow ? 2 * USEC_PER_SEC : USEC_PER_SEC / 50; } + if (argc == 3) (void) safe_atozu(argv[2], &arg_start); else -- cgit v1.2.1 From da1e72f4823e42aa11e9c48e8105083d05433dfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 12 Jul 2017 21:11:04 +0000 Subject: test-watchdog: wait just one cycle unless $SYSTEMD_SLOW_TESTS Also, if we fail to set the watchdog, run through the rest of the test without waiting. I think it's useful to still start the commands to test the error paths, but we can do it quickly. --- src/test/test-watchdog.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/test/test-watchdog.c b/src/test/test-watchdog.c index e3c19647fc..276b803cc2 100644 --- a/src/test/test-watchdog.c +++ b/src/test/test-watchdog.c @@ -19,22 +19,32 @@ #include +#include "env-util.h" #include "log.h" #include "watchdog.h" int main(int argc, char *argv[]) { - usec_t t = 10 * USEC_PER_SEC; - unsigned i; + usec_t t; + unsigned i, count; int r; + bool slow; log_set_max_level(LOG_DEBUG); log_parse_environment(); + r = getenv_bool("SYSTEMD_SLOW_TESTS"); + slow = r >= 0 ? r : SYSTEMD_SLOW_TESTS_DEFAULT; + + t = slow ? 10 * USEC_PER_SEC : 1 * USEC_PER_SEC; + count = slow ? 5 : 3; + r = watchdog_set_timeout(&t); if (r < 0) log_warning_errno(r, "Failed to open watchdog: %m"); + if (r == -EPERM) + t = 0; - for (i = 0; i < 5; i++) { + for (i = 0; i < count; i++) { log_info("Pinging..."); r = watchdog_ping(); if (r < 0) -- cgit v1.2.1 From 86d060892988975be937e713c5dfdff1a1ffa4a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 12 Jul 2017 21:41:41 +0000 Subject: test-resolved-packet: skip most of the loop We want to test the edge cases, but testing all the values in between is mostly pointless and slow on slow architectures (>1s on rpi). --- src/resolve/resolved-dns-packet.c | 1 - src/resolve/resolved-dns-packet.h | 8 ++++++-- src/resolve/test-resolved-packet.c | 3 +++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index 49a04615d4..bf879475d4 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -28,7 +28,6 @@ #define EDNS0_OPT_DO (1<<15) -#define DNS_PACKET_SIZE_START 512u assert_cc(DNS_PACKET_SIZE_START > DNS_PACKET_HEADER_SIZE) typedef struct DnsPacketRewinder { diff --git a/src/resolve/resolved-dns-packet.h b/src/resolve/resolved-dns-packet.h index a65d6d38cf..d4c6b3c9cb 100644 --- a/src/resolve/resolved-dns-packet.h +++ b/src/resolve/resolved-dns-packet.h @@ -56,10 +56,14 @@ struct DnsPacketHeader { #define UDP_PACKET_HEADER_SIZE (sizeof(struct iphdr) + sizeof(struct udphdr)) /* The various DNS protocols deviate in how large a packet can grow, - but the TCP transport has a 16bit size field, hence that appears to - be the absolute maximum. */ + * but the TCP transport has a 16bit size field, hence that appears to + * be the absolute maximum. */ #define DNS_PACKET_SIZE_MAX 0xFFFFu +/* The default size to use for allocation when we don't know how large + * the packet will turn out to be. */ +#define DNS_PACKET_SIZE_START 512u + /* RFC 1035 say 512 is the maximum, for classic unicast DNS */ #define DNS_PACKET_UNICAST_SIZE_MAX 512u diff --git a/src/resolve/test-resolved-packet.c b/src/resolve/test-resolved-packet.c index 1b0041214b..cf886b1bf2 100644 --- a/src/resolve/test-resolved-packet.c +++ b/src/resolve/test-resolved-packet.c @@ -31,6 +31,9 @@ static void test_dns_packet_new(void) { log_debug("dns_packet_new: %zu → %zu", i, p->allocated); assert_se(p->allocated >= MIN(DNS_PACKET_SIZE_MAX, i)); + + if (i > DNS_PACKET_SIZE_START + 10 && i < DNS_PACKET_SIZE_MAX - 10) + i = MIN(i * 2, DNS_PACKET_SIZE_MAX - 10); } assert_se(dns_packet_new(&p2, DNS_PROTOCOL_DNS, DNS_PACKET_SIZE_MAX + 1) == -EFBIG); -- cgit v1.2.1 From f06dcdca6ae0c2113d04615758d00932385be2dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 12 Jul 2017 22:01:46 +0000 Subject: test-daemon: sleep just a little bit by default With previous commits, test-daemon is one of the slowest tests. Under normal circumstances, the notifications go nowhere anyway, because the test process does not have privileges. The timeout can be specified as an argument. This is useful to e.g. test handling of the notifications, which is much easier with a longer timeout. --- src/test/test-daemon.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/test/test-daemon.c b/src/test/test-daemon.c index a7cb426282..e5887cc06a 100644 --- a/src/test/test-daemon.c +++ b/src/test/test-daemon.c @@ -21,11 +21,20 @@ #include "sd-daemon.h" +#include "parse-util.h" #include "strv.h" int main(int argc, char*argv[]) { _cleanup_strv_free_ char **l = NULL; int n, i; + usec_t duration = USEC_PER_SEC / 10; + + if (argc >= 2) { + unsigned x; + + assert_se(safe_atou(argv[1], &x) >= 0); + duration = x * USEC_PER_SEC; + } n = sd_listen_fds_with_names(false, &l); if (n < 0) { @@ -38,27 +47,27 @@ int main(int argc, char*argv[]) { sd_notify(0, "STATUS=Starting up"); - sleep(1); + usleep(duration); sd_notify(0, "STATUS=Running\n" "READY=1"); - sleep(1); + usleep(duration); sd_notify(0, "STATUS=Reloading\n" "RELOADING=1"); - sleep(1); + usleep(duration); sd_notify(0, "STATUS=Running\n" "READY=1"); - sleep(1); + usleep(duration); sd_notify(0, "STATUS=Quitting\n" "STOPPING=1"); - sleep(1); + usleep(duration); return EXIT_SUCCESS; } -- cgit v1.2.1