summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-11-09 14:26:42 +0100
committerGitHub <noreply@github.com>2017-11-09 14:26:42 +0100
commit4deff0b92b5bb746c9b52c9eddb84d45650f3763 (patch)
treea07091c1631c41167c44d445fabe985fe321f45e /src
parentf7576eb9fd05bb663e4ef62bef00a6faa8d00970 (diff)
parent3fcf65c35253e5f54906f5784f2695f3ce94ceb5 (diff)
downloadsystemd-4deff0b92b5bb746c9b52c9eddb84d45650f3763.tar.gz
Merge pull request #7280 from yuwata/fix-7270-2
test-event: do not work in assert()
Diffstat (limited to 'src')
-rw-r--r--src/libsystemd-network/sd-dhcp6-client.c2
-rw-r--r--src/libsystemd-network/test-ndisc-rs.c2
-rw-r--r--src/libsystemd/sd-event/test-event.c10
-rw-r--r--src/test/test-parse-util.c54
4 files changed, 61 insertions, 7 deletions
diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index eba0c8bcbb..d55d0c80cc 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -431,7 +431,7 @@ static int client_send_message(sd_dhcp6_client *client, usec_t time_now) {
if (r < 0)
return r;
- assert (client->duid_len);
+ assert(client->duid_len);
r = dhcp6_option_append(&opt, &optlen, SD_DHCP6_OPTION_CLIENTID,
client->duid_len, &client->duid);
if (r < 0)
diff --git a/src/libsystemd-network/test-ndisc-rs.c b/src/libsystemd-network/test-ndisc-rs.c
index c3e1a8e340..95c9311fc2 100644
--- a/src/libsystemd-network/test-ndisc-rs.c
+++ b/src/libsystemd-network/test-ndisc-rs.c
@@ -202,7 +202,7 @@ int icmp6_bind_router_advertisement(int index) {
int icmp6_receive(int fd, void *iov_base, size_t iov_len,
struct in6_addr *dst, triple_timestamp *timestamp) {
- assert (read (fd, iov_base, iov_len) == (ssize_t)iov_len);
+ assert_se(read (fd, iov_base, iov_len) == (ssize_t)iov_len);
if (timestamp)
triple_timestamp_get(timestamp);
diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c
index 1a581ae23e..9fa544ab0a 100644
--- a/src/libsystemd/sd-event/test-event.c
+++ b/src/libsystemd/sd-event/test-event.c
@@ -317,11 +317,11 @@ static void test_rtqueue(void) {
assert_se(sd_event_source_set_priority(v, -10) >= 0);
- assert(sigqueue(getpid_cached(), SIGRTMIN+2, (union sigval) { .sival_int = 1 }) >= 0);
- assert(sigqueue(getpid_cached(), SIGRTMIN+3, (union sigval) { .sival_int = 2 }) >= 0);
- assert(sigqueue(getpid_cached(), SIGUSR2, (union sigval) { .sival_int = 3 }) >= 0);
- assert(sigqueue(getpid_cached(), SIGRTMIN+3, (union sigval) { .sival_int = 4 }) >= 0);
- assert(sigqueue(getpid_cached(), SIGUSR2, (union sigval) { .sival_int = 5 }) >= 0);
+ assert_se(sigqueue(getpid_cached(), SIGRTMIN+2, (union sigval) { .sival_int = 1 }) >= 0);
+ assert_se(sigqueue(getpid_cached(), SIGRTMIN+3, (union sigval) { .sival_int = 2 }) >= 0);
+ assert_se(sigqueue(getpid_cached(), SIGUSR2, (union sigval) { .sival_int = 3 }) >= 0);
+ assert_se(sigqueue(getpid_cached(), SIGRTMIN+3, (union sigval) { .sival_int = 4 }) >= 0);
+ assert_se(sigqueue(getpid_cached(), SIGUSR2, (union sigval) { .sival_int = 5 }) >= 0);
assert_se(n_rtqueue == 0);
assert_se(last_rtqueue_sigval == 0);
diff --git a/src/test/test-parse-util.c b/src/test/test-parse-util.c
index 1b29b2ea87..c0abc8130a 100644
--- a/src/test/test-parse-util.c
+++ b/src/test/test-parse-util.c
@@ -79,6 +79,9 @@ static void test_parse_pid(void) {
r = parse_pid("junk", &pid);
assert_se(r == -EINVAL);
+
+ r = parse_pid("", &pid);
+ assert_se(r == -EINVAL);
}
static void test_parse_mode(void) {
@@ -98,6 +101,8 @@ static void test_parse_mode(void) {
static void test_parse_size(void) {
uint64_t bytes;
+ assert_se(parse_size("", 1024, &bytes) == -EINVAL);
+
assert_se(parse_size("111", 1024, &bytes) == 0);
assert_se(bytes == 111);
@@ -257,6 +262,10 @@ static void test_parse_range(void) {
assert_se(lower == 9999);
assert_se(upper == 9999);
+ assert_se(parse_range("-123", &lower, &upper) == -EINVAL);
+ assert_se(lower == 9999);
+ assert_se(upper == 9999);
+
assert_se(parse_range("-111-123", &lower, &upper) == -EINVAL);
assert_se(lower == 9999);
assert_se(upper == 9999);
@@ -370,6 +379,15 @@ static void test_safe_atolli(void) {
r = safe_atolli("junk", &l);
assert_se(r == -EINVAL);
+
+ r = safe_atolli("123x", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atolli("12.3", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atolli("", &l);
+ assert_se(r == -EINVAL);
}
static void test_safe_atou16(void) {
@@ -398,6 +416,12 @@ static void test_safe_atou16(void) {
r = safe_atou16("123x", &l);
assert_se(r == -EINVAL);
+
+ r = safe_atou16("12.3", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atou16("", &l);
+ assert_se(r == -EINVAL);
}
static void test_safe_atoi16(void) {
@@ -431,6 +455,12 @@ static void test_safe_atoi16(void) {
r = safe_atoi16("123x", &l);
assert_se(r == -EINVAL);
+
+ r = safe_atoi16("12.3", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atoi16("", &l);
+ assert_se(r == -EINVAL);
}
static void test_safe_atou64(void) {
@@ -459,6 +489,12 @@ static void test_safe_atou64(void) {
r = safe_atou64("123x", &l);
assert_se(r == -EINVAL);
+
+ r = safe_atou64("12.3", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atou64("", &l);
+ assert_se(r == -EINVAL);
}
static void test_safe_atoi64(void) {
@@ -492,6 +528,12 @@ static void test_safe_atoi64(void) {
r = safe_atoi64("123x", &l);
assert_se(r == -EINVAL);
+
+ r = safe_atoi64("12.3", &l);
+ assert_se(r == -EINVAL);
+
+ r = safe_atoi64("", &l);
+ assert_se(r == -EINVAL);
}
static void test_safe_atod(void) {
@@ -513,6 +555,9 @@ static void test_safe_atod(void) {
strtod("0,5", &e);
assert_se(*e == ',');
+ r = safe_atod("", &d);
+ assert_se(r == -EINVAL);
+
/* Check if this really is locale independent */
if (setlocale(LC_NUMERIC, "de_DE.utf8")) {
@@ -525,6 +570,9 @@ static void test_safe_atod(void) {
errno = 0;
assert_se(fabs(strtod("0,5", &e) - 0.5) < 0.00001);
+
+ r = safe_atod("", &d);
+ assert_se(r == -EINVAL);
}
/* And check again, reset */
@@ -540,6 +588,9 @@ static void test_safe_atod(void) {
errno = 0;
strtod("0,5", &e);
assert_se(*e == ',');
+
+ r = safe_atod("", &d);
+ assert_se(r == -EINVAL);
}
static void test_parse_percent(void) {
@@ -558,6 +609,7 @@ static void test_parse_percent(void) {
assert_se(parse_percent("%%") == -EINVAL);
assert_se(parse_percent("%1") == -EINVAL);
assert_se(parse_percent("1%%") == -EINVAL);
+ assert_se(parse_percent("3.2%") == -EINVAL);
}
static void test_parse_percent_unbounded(void) {
@@ -596,6 +648,8 @@ static void test_parse_nice(void) {
static void test_parse_dev(void) {
dev_t dev;
+ assert_se(parse_dev("", &dev) == -EINVAL);
+ assert_se(parse_dev("junk", &dev) == -EINVAL);
assert_se(parse_dev("0", &dev) == -EINVAL);
assert_se(parse_dev("5", &dev) == -EINVAL);
assert_se(parse_dev("5:", &dev) == -EINVAL);