mirror of
https://github.com/systemd/systemd.git
synced 2025-03-22 06:50:18 +03:00
Merge pull request #6365 from keszybz/fast-tests
Make tests faster by default
This commit is contained in:
commit
896bbe7611
@ -1034,6 +1034,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')
|
||||
|
@ -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')
|
||||
|
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -19,22 +19,32 @@
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user