unit-tests: Added bliss_fft test suite
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 30 Oct 2014 13:31:26 +0000 (14:31 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Sat, 29 Nov 2014 13:51:15 +0000 (14:51 +0100)
src/libstrongswan/plugins/bliss/.gitignore [new file with mode: 0644]
src/libstrongswan/plugins/bliss/Makefile.am
src/libstrongswan/plugins/bliss/bliss_tests.c [new file with mode: 0644]
src/libstrongswan/plugins/bliss/bliss_tests.h [new file with mode: 0644]
src/libstrongswan/plugins/bliss/suites/test_bliss_fft.c [new file with mode: 0644]

diff --git a/src/libstrongswan/plugins/bliss/.gitignore b/src/libstrongswan/plugins/bliss/.gitignore
new file mode 100644 (file)
index 0000000..94f77f0
--- /dev/null
@@ -0,0 +1 @@
+bliss_tests
index e73ffb0..5ecf03e 100644 (file)
@@ -20,3 +20,23 @@ libstrongswan_bliss_la_SOURCES = \
        bliss_fft_params.h bliss_fft_params.c
 
 libstrongswan_bliss_la_LDFLAGS = -module -avoid-version
+
+TESTS = bliss_tests
+
+check_PROGRAMS = $(TESTS)
+
+bliss_tests_SOURCES = \
+       suites/test_bliss_fft.c \
+       bliss_fft_params.c \
+       bliss_fft.c \
+       bliss_tests.h bliss_tests.c
+
+bliss_tests_CFLAGS = \
+       -I$(top_srcdir)/src/libstrongswan \
+       -I$(top_srcdir)/src/libstrongswan/tests \
+       @COVERAGE_CFLAGS@
+
+bliss_tests_LDFLAGS = @COVERAGE_LDFLAGS@
+bliss_tests_LDADD = \
+       $(top_builddir)/src/libstrongswan/libstrongswan.la \
+       $(top_builddir)/src/libstrongswan/tests/libtest.la
diff --git a/src/libstrongswan/plugins/bliss/bliss_tests.c b/src/libstrongswan/plugins/bliss/bliss_tests.c
new file mode 100644 (file)
index 0000000..5d355ae
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2014 Andreas Steffen
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * 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.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+#include <test_runner.h>
+
+#include <library.h>
+
+/* declare test suite constructors */
+#define TEST_SUITE(x) test_suite_t* x();
+#include "bliss_tests.h"
+#undef TEST_SUITE
+
+static test_configuration_t tests[] = {
+#define TEST_SUITE(x) \
+       { .suite = x, },
+#include "bliss_tests.h"
+       { .suite = NULL, }
+};
+
+static bool test_runner_init(bool init)
+{
+       if (!init)
+       {
+               lib->processor->set_threads(lib->processor, 0);
+               lib->processor->cancel(lib->processor);
+       }
+       return TRUE;
+}
+
+int main(int argc, char *argv[])
+{
+       return test_runner_run("bliss", tests, test_runner_init);
+}
diff --git a/src/libstrongswan/plugins/bliss/bliss_tests.h b/src/libstrongswan/plugins/bliss/bliss_tests.h
new file mode 100644 (file)
index 0000000..4c3e10b
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2014 Andreas Steffen
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * 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.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+TEST_SUITE(bliss_fft_suite_create)
+
diff --git a/src/libstrongswan/plugins/bliss/suites/test_bliss_fft.c b/src/libstrongswan/plugins/bliss/suites/test_bliss_fft.c
new file mode 100644 (file)
index 0000000..009aaf8
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (C) 2014 Andreas Steffen
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * 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.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * 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.
+ */
+
+#include "test_suite.h"
+
+#include <bliss_fft.h>
+
+static bliss_fft_params_t *fft_params[] = {
+       &bliss_fft_17_8,
+       &bliss_fft_12289_512
+};
+
+START_TEST(test_bliss_fft_impulse)
+{
+       bliss_fft_t *fft;
+       uint16_t n = fft_params[_i]->n;
+       uint32_t x[n], X[n];
+       int i;
+
+       for (i = 0; i < n; i++)
+       {
+               x[i] = 0;
+       }
+       x[0] = 1;
+       fft = bliss_fft_create(fft_params[_i]);
+       fft->transform(fft, x, X, FALSE);
+
+       for (i = 0; i < n; i++)
+       {
+               ck_assert(X[i] == 1);
+       }
+       fft->transform(fft, X, x, TRUE);
+
+       for (i = 0; i < n; i++)
+       {
+               ck_assert(x[i] == (i == 0));
+       }
+       fft->destroy(fft);
+}
+END_TEST
+
+START_TEST(test_bliss_fft_wrap)
+{
+       bliss_fft_t *fft;
+       uint16_t n = fft_params[_i]->n;
+       uint16_t q = fft_params[_i]->q;
+       uint32_t x[n],y[n], X[n], Y[n];
+       int i, j;
+
+       for (i = 0; i < n; i++)
+       {
+               x[i] = i;
+               y[i] = 0;
+       }
+       fft = bliss_fft_create(fft_params[_i]);
+       ck_assert(fft->get_size(fft) == n);
+       ck_assert(fft->get_modulus(fft) == q); 
+       fft->transform(fft, x, X, FALSE);
+
+       for (j = 0; j < n; j++)
+       {
+               y[j] = 1;
+               fft->transform(fft, y, Y, FALSE);
+
+               for (i = 0; i < n; i++)
+               {
+                       Y[i] = (X[i] * Y[i]) % q;
+               }
+               fft->transform(fft, Y, Y, TRUE);
+
+               for (i = 0; i < n; i++)
+               {
+                       ck_assert(Y[i] == ( i < j ? q - n - i + j : i - j));
+               }
+               y[j] = 0;
+       }
+       fft->destroy(fft);  
+}
+END_TEST
+
+Suite *bliss_fft_suite_create()
+{
+       Suite *s;
+       TCase *tc;
+
+       s = suite_create("bliss_fft");
+
+       tc = tcase_create("impulse");
+       tcase_add_loop_test(tc, test_bliss_fft_impulse, 0, countof(fft_params));
+       suite_add_tcase(s, tc);
+
+       tc = tcase_create("negative_wrap");
+       tcase_add_loop_test(tc, test_bliss_fft_wrap, 0, countof(fft_params));
+       suite_add_tcase(s, tc);
+
+       return s;
+}