diff --git a/tempesta_fw/Makefile b/tempesta_fw/Makefile index 1ec4bac151..e86a14a088 100644 --- a/tempesta_fw/Makefile +++ b/tempesta_fw/Makefile @@ -24,12 +24,4 @@ tempesta_fw-objs = cache.o classifier.o client.o connection.o filter.o gfsm.o \ session.o sock_backend.o sock_frontend.o stress.o addr.o debugfs.o \ pool.o str.o -# FIXME: -# This may be a bit confusing because usually such sub-directories have their -# own Makefile files. We need to decide how to properly integrate these -# sub-directories to the build system. -# -tempesta_fw-objs += t/test_tfw_str.o t/runner.o -tempesta_fw-objs += - -obj-m += log/ classifier/ stress/ sched/ filter/ +obj-m += log/ classifier/ stress/ sched/ filter/ t/ diff --git a/tempesta_fw/main.c b/tempesta_fw/main.c index a928d8d37b..0ec54b2bf1 100644 --- a/tempesta_fw/main.c +++ b/tempesta_fw/main.c @@ -51,12 +51,6 @@ void tfw_connection_exit(void); int tfw_sched_dummy_init(void); void tfw_sched_dummy_exit(void); -#ifdef DEBUG -extern void tfw_run_all_tests(void); -#else -#define tfw_run_all_tests() -#endif - static int __init tfw_init(void) @@ -104,8 +98,6 @@ tfw_init(void) if (r) goto err_connection; - tfw_run_all_tests(); - return 0; err_connection: diff --git a/tempesta_fw/str.c b/tempesta_fw/str.c index 1e25ad6765..087712db6b 100644 --- a/tempesta_fw/str.c +++ b/tempesta_fw/str.c @@ -91,6 +91,7 @@ tfw_str_len(const TfwStr *str) return total_len; } +EXPORT_SYMBOL(tfw_str_len); static bool str_eq_cstr(const TfwStr *str, const char *cstr, int cstr_len, bool ci) diff --git a/tempesta_fw/t/Makefile b/tempesta_fw/t/Makefile index bb15c2d041..96c9ca9601 100644 --- a/tempesta_fw/t/Makefile +++ b/tempesta_fw/t/Makefile @@ -16,8 +16,7 @@ # this program; if not, write to the Free Software Foundation, Inc., 59 # Temple Place - Suite 330, Boston, MA 02111-1307, USA. -EXTRA_CFLAGS += -I$(src)/../sync_socket -I$(src)/../tempesta_db -DDEBUG - -obj-y += runner.o test_tfw_str.o - +EXTRA_CFLAGS += -I$(src)/../ -I$(src)/../../tempesta_db -DDEBUG +obj-m += tfw_test.o +tfw_test-objs = main.o str.o test.o diff --git a/tempesta_fw/t/main.c b/tempesta_fw/t/main.c new file mode 100644 index 0000000000..4b5da540dd --- /dev/null +++ b/tempesta_fw/t/main.c @@ -0,0 +1,54 @@ +/** + * Tempesta FW + * + * Copyright (C) 2012-2014 NatSys Lab. (info@natsys-lab.com). + * + * 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; if not, write to the Free Software Foundation, Inc., 59 + * Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include + +#include "tempesta.h" +#include "test.h" + +MODULE_AUTHOR(TFW_AUTHOR); +MODULE_DESCRIPTION("Tempesta FW tests"); +MODULE_VERSION("0.0.1"); +MODULE_LICENSE("GPL"); + +static int __init +tfw_test_init(void) +{ + int fail_count = 0; + + printk("tfw_test: start\n"); + fail_count = run_all_tests(); + + printk("tfw_test: finish - "); + if (fail_count) + printk("failed %d assertions\n", fail_count); + else + printk("all passed\n"); + + return 0; +} + +void +tfw_test_exit(void) +{ +} + +module_init(tfw_test_init); +module_exit(tfw_test_exit); diff --git a/tempesta_fw/t/run_all_tests.sh b/tempesta_fw/t/run_all_tests.sh new file mode 100755 index 0000000000..f8e877a2f5 --- /dev/null +++ b/tempesta_fw/t/run_all_tests.sh @@ -0,0 +1,9 @@ +#!/bin/bash +# +# A script that simply runs all tests for Tempesta FW. +# +# 2012-2014. Written by NatSys Lab. (info@natsys-lab.com). + +insmod $(dirname $0)/tfw_test.ko +rmmod tfw_test +dmesg | tac | grep -m 1 -B 200 "tfw_test: start" | tac diff --git a/tempesta_fw/t/test_tfw_str.c b/tempesta_fw/t/str.c similarity index 100% rename from tempesta_fw/t/test_tfw_str.c rename to tempesta_fw/t/str.c diff --git a/tempesta_fw/t/runner.c b/tempesta_fw/t/test.c similarity index 82% rename from tempesta_fw/t/runner.c rename to tempesta_fw/t/test.c index 5a202908a1..5f5ae12c16 100644 --- a/tempesta_fw/t/runner.c +++ b/tempesta_fw/t/test.c @@ -18,12 +18,25 @@ * Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#include #include "test.h" +int test_fail_counter = 0; + TEST_SUITE(tfw_str); -void -tfw_run_all_tests(void) +int +run_all_tests(void) { + test_fail_counter = 0; + RUN_TEST_SUITE(tfw_str); + + return test_fail_counter; +} + +void +register_test_failure(void) +{ + ++test_fail_counter; } diff --git a/tempesta_fw/t/test.h b/tempesta_fw/t/test.h index 31aa557b91..b56626093e 100644 --- a/tempesta_fw/t/test.h +++ b/tempesta_fw/t/test.h @@ -28,30 +28,36 @@ #ifndef __TFW_TEST_H__ #define __TFW_TEST_H__ -#include - +int run_all_tests(void); +void register_test_failure(void); #define TEST(unit, assertion) static void test__ ##unit ##__ ##assertion(void) #define RUN_TEST(unit, assertion) test__ ##unit ##__ ##assertion() #define TEST_SUITE(name) void test_suite__##name(void) -#define RUN_TEST_SUITE(name) test_suite__##name() +#define RUN_TEST_SUITE(name) \ +do { \ + printk("RUN_SUITE(%s)\n", #name); \ + test_suite__##name(); \ +} while (0) -#define __FAIL_MSG(...) \ +#define __FAIL(...) \ do { \ - printk("FAIL: %s():%d: ", __func__, __LINE__); \ + printk("FAIL:\n"); \ + printk(" %s():%d\n ", __func__, __LINE__); \ printk(__VA_ARGS__); \ printk("\n"); \ + register_test_failure(); \ } while (0) -#define FAIL() __FAIL_MSG("FAIL()"); +#define FAIL() __FAIL("FAIL()"); #define EXPECT_TRUE(cond) \ do { \ bool _test_val = (cond); \ if (_test_val) \ break; \ - __FAIL_MSG("EXPECT_TRUE(%s) => %d", #cond, _test_val); \ + __FAIL("EXPECT_TRUE(%s) => %d", #cond, _test_val); \ } while (0) #define EXPECT_FALSE(cond) \ @@ -59,7 +65,7 @@ do { \ bool _test_val = (cond); \ if (!_test_val) \ break; \ - __FAIL_MSG("EXPECT_FALSE(%s) => %d", #cond, _test_val); \ + __FAIL("EXPECT_FALSE(%s) => %d", #cond, _test_val); \ } while (0) #define __EXPECT_CMP(name, expr1, expr2, cmp_expr) \ @@ -68,7 +74,7 @@ do { \ unsigned long _val2 = (expr2); \ if (cmp_expr) \ break; \ - __FAIL_MSG("%s(%s, %s) => (%#lx, %#lx)", \ + __FAIL("%s(%s, %s) => (%#lx, %#lx)", \ name, #expr1, #expr2, _val1, _val2); \ } while (0)