summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2018-10-26 15:25:25 +0200
committerDavid Lamparter <equinox@diac24.net>2019-12-06 15:13:32 +0100
commit96673e067d0c4d89cb3e6df44978853a6bda99ac (patch)
treede593ca36c161c5c2855e83a4d9da62367c59311 /tests
parentlib: rename memory_vty.c to lib_vty.c (diff)
downloadfrr-96673e067d0c4d89cb3e6df44978853a6bda99ac.tar.xz
frr-96673e067d0c4d89cb3e6df44978853a6bda99ac.zip
lib: add frr_version_cmp()
This just compares 2 version strings. Signed-off-by: David Lamparter <equinox@diac24.net>
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/lib/test_versioncmp.c66
-rw-r--r--tests/lib/test_versioncmp.py6
-rw-r--r--tests/subdir.am6
4 files changed, 79 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 6252cea82..5414cb8cc 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -45,6 +45,7 @@
/lib/test_timer_performance
/lib/test_ttable
/lib/test_typelist
+/lib/test_versioncmp
/lib/test_zlog
/lib/test_zmq
/ospf6d/test_lsdb
diff --git a/tests/lib/test_versioncmp.c b/tests/lib/test_versioncmp.c
new file mode 100644
index 000000000..bb819e36f
--- /dev/null
+++ b/tests/lib/test_versioncmp.c
@@ -0,0 +1,66 @@
+/*
+ * frr_version_cmp() tests
+ * Copyright (C) 2018 David Lamparter for NetDEF, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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 General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <zebra.h>
+#include <defaults.h>
+
+static const char *rel(int x)
+{
+ if (x < 0)
+ return "<";
+ if (x > 0)
+ return ">";
+ return "==";
+}
+
+static int fail;
+
+static void compare(const char *a, const char *b, int expect)
+{
+ int result = frr_version_cmp(a, b);
+
+ if (expect == result)
+ printf("\"%s\" %s \"%s\"\n", a, rel(result), b);
+ else {
+ printf("\"%s\" %s \"%s\", expected %s!\n", a, rel(result), b,
+ rel(expect));
+ fail = 1;
+ }
+}
+
+int main(int argc, char **argv)
+{
+ compare("", "", 0);
+ compare("1", "1", 0);
+ compare("1.0", "1.00", 0);
+ compare("10.0", "1", 1);
+ compare("10.0", "2", 1);
+ compare("2.1", "10.0", -1);
+ compare("1.1.1", "1.1.0", 1);
+ compare("1.0a", "1.0", 1);
+ compare("1.0a", "1.0b", -1);
+ compare("1.0a10", "1.0a2", 1);
+ compare("1.00a2", "1.0a2", 0);
+ compare("1.00a2", "1.0a3", -1);
+ compare("1.0-dev", "1.0", 1);
+ compare("1.0~foo", "1.0", -1);
+ compare("1.0~1", "1.0~0", 1);
+ compare("1.00~1", "1.0~0", 1);
+ printf("final tally: %s\n", fail ? "FAILED" : "ok");
+ return fail;
+}
diff --git a/tests/lib/test_versioncmp.py b/tests/lib/test_versioncmp.py
new file mode 100644
index 000000000..099075700
--- /dev/null
+++ b/tests/lib/test_versioncmp.py
@@ -0,0 +1,6 @@
+import frrtest
+
+class TestVersionCmp(frrtest.TestMultiOut):
+ program = './test_versioncmp'
+
+TestVersionCmp.exit_cleanly()
diff --git a/tests/subdir.am b/tests/subdir.am
index 270c0811b..d87d34894 100644
--- a/tests/subdir.am
+++ b/tests/subdir.am
@@ -69,6 +69,7 @@ check_PROGRAMS = \
tests/lib/test_timer_performance \
tests/lib/test_ttable \
tests/lib/test_typelist \
+ tests/lib/test_versioncmp \
tests/lib/test_zlog \
tests/lib/test_graph \
tests/lib/cli/test_cli \
@@ -293,6 +294,10 @@ tests_lib_test_typelist_CFLAGS = $(TESTS_CFLAGS)
tests_lib_test_typelist_CPPFLAGS = $(TESTS_CPPFLAGS)
tests_lib_test_typelist_LDADD = $(ALL_TESTS_LDADD)
tests_lib_test_typelist_SOURCES = tests/lib/test_typelist.c tests/helpers/c/prng.c
+tests_lib_test_versioncmp_CFLAGS = $(TESTS_CFLAGS)
+tests_lib_test_versioncmp_CPPFLAGS = $(TESTS_CPPFLAGS)
+tests_lib_test_versioncmp_LDADD = $(ALL_TESTS_LDADD)
+tests_lib_test_versioncmp_SOURCES = tests/lib/test_versioncmp.c
tests_lib_test_zlog_CFLAGS = $(TESTS_CFLAGS)
tests_lib_test_zlog_CPPFLAGS = $(TESTS_CPPFLAGS)
tests_lib_test_zlog_LDADD = $(ALL_TESTS_LDADD)
@@ -344,6 +349,7 @@ EXTRA_DIST += \
tests/lib/test_ttable.py \
tests/lib/test_ttable.refout \
tests/lib/test_typelist.py \
+ tests/lib/test_versioncmp.py \
tests/lib/test_zlog.py \
tests/lib/test_graph.py \
tests/lib/test_graph.refout \