[systemd-commits] 3 commits - .gitignore Makefile.am src/test

Tom Gundersen tomegun at kemper.freedesktop.org
Mon Jun 23 17:43:34 PDT 2014


 .gitignore                |    1 
 Makefile.am               |   11 +++
 src/test/test-ratelimit.c |   49 +++++++++++++++++
 src/test/test-unit-name.c |  127 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 186 insertions(+), 2 deletions(-)

New commits:
commit 5549f483d06d2e5c91da76b5780c5f0e217b472e
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date:   Mon Jun 23 21:28:23 2014 +0200

    build-sys: do not run coverage if build failed

diff --git a/Makefile.am b/Makefile.am
index 0e4edf7..37a164e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1635,7 +1635,7 @@ test_conf_files_LDADD = \
 .PHONY: coverage lcov-run lcov-report coverage-sync
 
 # run lcov from scratch, always
-coverage:
+coverage: all
 	$(MAKE) lcov-run
 	$(MAKE) lcov-report
 

commit e80cde5e969e050c6eaab425fc46bbe55e857f24
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date:   Mon Jun 23 21:28:22 2014 +0200

    tests: add test-ratelimit

diff --git a/.gitignore b/.gitignore
index e42fbcb..36c67e2 100644
--- a/.gitignore
+++ b/.gitignore
@@ -190,6 +190,7 @@
 /test-ns
 /test-path-util
 /test-prioq
+/test-ratelimit
 /test-replace-var
 /test-resolve
 /test-ring
diff --git a/Makefile.am b/Makefile.am
index 20b6082..0e4edf7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1247,7 +1247,8 @@ tests += \
 	test-fdset \
 	test-conf-files \
 	test-capability \
-	test-async
+	test-async \
+	test-ratelimit
 
 EXTRA_DIST += \
 	test/sched_idle_bad.service \
@@ -1370,6 +1371,12 @@ test_fdset_SOURCES = \
 test_fdset_LDADD = \
 	libsystemd-core.la
 
+test_ratelimit_SOURCES = \
+	src/test/test-ratelimit.c
+
+test_ratelimit_LDADD = \
+	libsystemd-shared.la
+
 test_util_SOURCES = \
 	src/test/test-util.c
 
diff --git a/src/test/test-ratelimit.c b/src/test/test-ratelimit.c
new file mode 100644
index 0000000..b7f6dfe
--- /dev/null
+++ b/src/test/test-ratelimit.c
@@ -0,0 +1,49 @@
+/***
+  This file is part of systemd
+
+  Copyright 2014 Ronny Chevalier
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <unistd.h>
+
+#include "ratelimit.h"
+#include "time-util.h"
+#include "macro.h"
+
+static void test_ratelimit_test(void) {
+        int i;
+        RATELIMIT_DEFINE(ratelimit, 1 * USEC_PER_SEC, 10);
+
+        for (i = 0; i < 10; i++) {
+                assert_se(ratelimit_test(&ratelimit));
+        }
+        assert_se(!ratelimit_test(&ratelimit));
+        sleep(1);
+        for (i = 0; i < 10; i++) {
+                assert_se(ratelimit_test(&ratelimit));
+        }
+
+        RATELIMIT_INIT(ratelimit, 0, 10);
+        for (i = 0; i < 10000; i++) {
+                assert_se(ratelimit_test(&ratelimit));
+        }
+}
+
+int main(int argc, char *argv[]) {
+        test_ratelimit_test();
+
+        return 0;
+}

commit 068ae9fb7c313b2ae080b542e8be85e8555c4709
Author: Ronny Chevalier <chevalier.ronny at gmail.com>
Date:   Mon Jun 23 21:28:21 2014 +0200

    tests: add tests to test-unit-name
    
    add tests for:
      - unit_instance_is_valid
      - unit_prefix_is_valid
      - unit_name_change_suffix
      - unit_name_build
      - unit_name_is_instance
      - build_subslice
      - unit_name_to_instance
      - unit_name_escape

diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c
index fff3e16..9179081 100644
--- a/src/test/test-unit-name.c
+++ b/src/test/test-unit-name.c
@@ -5,6 +5,7 @@
 
   Copyright 2012 Lennart Poettering
   Copyright 2013 Zbigniew Jędrzejewski-Szmek
+  Copyright 2014 Ronny Chevalier
 
   systemd is free software; you can redistribute it and/or modify it
   under the terms of the GNU Lesser General Public License as published by
@@ -193,9 +194,135 @@ static int test_unit_printf(void) {
         return 0;
 }
 
+static void test_unit_instance_is_valid(void) {
+        assert_se(unit_instance_is_valid("fooBar"));
+        assert_se(unit_instance_is_valid("foo-bar"));
+        assert_se(unit_instance_is_valid("foo.stUff"));
+        assert_se(unit_instance_is_valid("fOo123.stuff"));
+        assert_se(unit_instance_is_valid("@f_oo123.Stuff"));
+
+        assert_se(!unit_instance_is_valid("$¢£"));
+        assert_se(!unit_instance_is_valid(""));
+        assert_se(!unit_instance_is_valid("foo bar"));
+        assert_se(!unit_instance_is_valid("foo/bar"));
+}
+
+static void test_unit_prefix_is_valid(void) {
+        assert_se(unit_prefix_is_valid("fooBar"));
+        assert_se(unit_prefix_is_valid("foo-bar"));
+        assert_se(unit_prefix_is_valid("foo.stUff"));
+        assert_se(unit_prefix_is_valid("fOo123.stuff"));
+        assert_se(unit_prefix_is_valid("foo123.Stuff"));
+
+        assert_se(!unit_prefix_is_valid("$¢£"));
+        assert_se(!unit_prefix_is_valid(""));
+        assert_se(!unit_prefix_is_valid("foo bar"));
+        assert_se(!unit_prefix_is_valid("foo/bar"));
+        assert_se(!unit_prefix_is_valid("@foo-bar"));
+}
+
+static void test_unit_name_change_suffix(void) {
+        char *r;
+
+        r = unit_name_change_suffix("foo.bar", ".service");
+        assert_se(r);
+        assert_se(streq(r, "foo.service"));
+        free(r);
+
+        r = unit_name_change_suffix("foo at stuff.bar", ".boo");
+        assert_se(r);
+        assert_se(streq(r, "foo at stuff.boo"));
+        free(r);
+}
+
+static void test_unit_name_build(void) {
+        char *r;
+
+        r = unit_name_build("foo", "bar", ".service");
+        assert_se(r);
+        assert_se(streq(r, "foo at bar.service"));
+        free(r);
+
+        r = unit_name_build("fo0-stUff_b", "bar", ".mount");
+        assert_se(r);
+        assert_se(streq(r, "fo0-stUff_b at bar.mount"));
+        free(r);
+
+        r = unit_name_build("foo", NULL, ".service");
+        assert_se(r);
+        assert_se(streq(r, "foo.service"));
+        free(r);
+}
+
+static void test_unit_name_is_instance(void) {
+        assert_se(unit_name_is_instance("a at b.service"));
+        assert_se(unit_name_is_instance("a-c_c01Aj at b05Dii_-oioi.service"));
+
+        assert_se(!unit_name_is_instance("a.service"));
+        assert_se(!unit_name_is_instance("junk"));
+        assert_se(!unit_name_is_instance(""));
+}
+
+static void test_build_subslice(void) {
+        char *a;
+        char *b;
+
+        assert_se(build_subslice("-.slice", "foo", &a) >= 0);
+        assert_se(build_subslice(a, "bar", &b) >= 0);
+        free(a);
+        assert_se(build_subslice(b, "barfoo", &a) >= 0);
+        free(b);
+        assert_se(build_subslice(a, "foobar", &b) >= 0);
+        free(a);
+        assert_se(streq(b, "foo-bar-barfoo-foobar.slice"));
+        free(b);
+
+        assert_se(build_subslice("foo.service", "bar", &a) < 0);
+        assert_se(build_subslice("foo", "bar", &a) < 0);
+}
+
+static void test_unit_name_to_instance(void) {
+        char *instance;
+        int r;
+
+        r = unit_name_to_instance("foo at bar.service", &instance);
+        assert_se(r >= 0);
+        assert_se(streq(instance, "bar"));
+        free(instance);
+
+        r = unit_name_to_instance("fo0-stUff_b at b.e", &instance);
+        assert_se(r >= 0);
+        assert_se(streq(instance, "b"));
+        free(instance);
+
+        r = unit_name_to_instance("foo.bar", &instance);
+        assert_se(r >= 0);
+        assert_se(!instance);
+
+        r = unit_name_to_instance("fooj at unk", &instance);
+        assert_se(r < 0);
+}
+
+static void test_unit_name_escape(void) {
+        _cleanup_free_ char *r;
+
+        r = unit_name_escape("ab+-c.a/bc at foo.service");
+        assert_se(r);
+        assert_se(streq(r, "ab\\x2b\\x2dc.a-bc\\x40foo.service"));
+}
+
 int main(int argc, char* argv[]) {
         int rc = 0;
         test_replacements();
         TEST_REQ_RUNNING_SYSTEMD(rc = test_unit_printf());
+        test_unit_instance_is_valid();
+        test_unit_prefix_is_valid();
+        test_unit_name_change_suffix();
+        test_unit_name_build();
+        test_unit_name_is_instance();
+        test_build_subslice();
+        test_unit_name_to_instance();
+        test_unit_name_escape();
+
         return rc;
 }



More information about the systemd-commits mailing list