From: Damir Tomic Date: Wed, 5 Aug 2015 14:53:22 +0000 (+0200) Subject: Makefile.am: X-Git-Tag: NTP_4_3_72~2^2~20^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f6c60207f30f18b756af77ff9cf3b6415d6e0d9;p=thirdparty%2Fntp.git Makefile.am: new file added ntpq dir added a new test, test-log t-log.c: removed the 2nd test because only one open_logfile per program can be used (segfault otherwise) run-t-log.c: new file, HAS ISSUES WITH CONST CHAR *progname. bk: 55c223626A2M_5ooVNuNKYVIvdoj8w --- diff --git a/sntp/tests/Makefile.am b/sntp/tests/Makefile.am index 49ea18327..9a2e19458 100644 --- a/sntp/tests/Makefile.am +++ b/sntp/tests/Makefile.am @@ -15,6 +15,7 @@ run_unity = cd $(srcdir) && ruby ../unity/auto/generate_test_runner.rb #EXTRA_PROGRAMS += test-packetHandling test-packetProcessing check_PROGRAMS = \ + test-log \ test-crypto \ test-keyFile \ test-kodDatabase \ @@ -173,6 +174,12 @@ test_crypto_SOURCES = \ $(top_builddir)/version.c \ $(NULL) +test_log_SOURCES = \ + t-log.c \ + run-t-log.c \ + $(top_builddir)/version.c \ + $(NULL) + $(srcdir)/run-kodFile.c: $(srcdir)/kodFile.c $(std_unity_list) $(run_unity) kodFile.c run-kodFile.c @@ -198,6 +205,10 @@ $(srcdir)/run-utilities.c: $(srcdir)/utilities.c $(std_unity_list) $(srcdir)/run-crypto.c: $(srcdir)/crypto.c $(std_unity_list) $(run_unity) crypto.c run-crypto.c +$(srcdir)/run-t-log.c: $(srcdir)/t-log.c $(std_unity_list) + $(run_unity) t-log.c run-t-log.c + + #$(srcdir)/../version.c: $(srcdir)/../version.c # gcc -o version.o ../version.c diff --git a/sntp/tests/run-t-log.c b/sntp/tests/run-t-log.c new file mode 100644 index 000000000..2c70df55b --- /dev/null +++ b/sntp/tests/run-t-log.c @@ -0,0 +1,56 @@ +/* AUTOGENERATED FILE. DO NOT EDIT. */ + +//=======Test Runner Used To Run Each Test Below===== +#define RUN_TEST(TestFunc, TestLineNum) \ +{ \ + Unity.CurrentTestName = #TestFunc; \ + Unity.CurrentTestLineNumber = TestLineNum; \ + Unity.NumberOfTests++; \ + if (TEST_PROTECT()) \ + { \ + setUp(); \ + TestFunc(); \ + } \ + if (TEST_PROTECT() && !TEST_IS_IGNORED) \ + { \ + tearDown(); \ + } \ + UnityConcludeTest(); \ +} + +//=======Automagically Detected Files To Include===== +#include "unity.h" +#include +#include +#include "config.h" +#include "ntp_types.h" +#include "log.h" + +//=======External Functions This Runner Calls===== +extern void setUp(void); +extern void tearDown(void); +extern void testChangePrognameInMysyslog(void); +extern void testWriteInCustomLogfile(void); + + +//=======Test Reset Option===== +void resetTest(void); +void resetTest(void) +{ + tearDown(); + setUp(); +} + +const char *progname; + + +//=======MAIN===== +int main(int argc, char *argv[]) +{ + progname = argv[0]; + UnityBegin("t-log.c"); + RUN_TEST(testChangePrognameInMysyslog, 9); + RUN_TEST(testWriteInCustomLogfile, 32); + + return (UnityEnd()); +} diff --git a/sntp/tests/t-log.c b/sntp/tests/t-log.c new file mode 100644 index 000000000..cc4373534 --- /dev/null +++ b/sntp/tests/t-log.c @@ -0,0 +1,66 @@ +#include "config.h" +#include "unity.h" +#include "ntp_types.h" + +//#include "sntptest.h" +//#include "crypto.h" +#include "log.h" + +void testChangePrognameInMysyslog(void); +//void testOpenLogfileTest(void); + + +//in var/log/syslog (may differ depending on your OS), logged name of the program will be "TEST_PROGNAME". + +void testChangePrognameInMysyslog(void){ + sntp_init_logging("TEST_PROGNAME"); + msyslog(LOG_ERR, "TESTING sntp_init_logging()"); //%m will print the last errno? +} + +//writes log files in your own file instead of syslog! (MAY BE USEFUL TO SUPPRESS ERROR MESSAGES!) +/* +void testOpenLogfileTest(void){ + sntp_init_logging("TEST_PROGNAME2"); //this name is consistent through the entire program unless changed + open_logfile("testLogfile.log"); + //open_logfile("/var/log/syslog"); //this gives me "Permission Denied" when i do %m + + msyslog(LOG_ERR, "Cannot open log file %s","abcXX"); + //msyslog(LOG_INFO, "%s", "eee"); +} +*/ + +//multiple cleanup_log() causes segfault. Probably the reason it's static. Opening multiple open_logfile(name) will cause segfault x.x I'm guessing it's not intended to be changed. Cleanup after unity test doesn't fix it, looks like. Tried using counter's to only call atexit once, didn't help??? + +void testWriteInCustomLogfile(void){ + char testString[256] = "12345 ABC"; + char testName[256] = "TEST_PROGNAME3"; + + remove("testLogfile2.log"); + + sntp_init_logging(testName); + open_logfile("testLogfile2.log"); // ./ causing issues + //sntp_init_logging(testName); + + + msyslog(LOG_ERR, testString); + FILE * f = fopen("testLogfile2.log","r"); + char line[256]; + + //should be only 1 line + while (fgets(line, sizeof(line), f)) { + printf("%s", line); + } + + + char* x = strstr(line,testName); + + TEST_ASSERT_TRUE( x != NULL); + + x = strstr(line,testString); + TEST_ASSERT_TRUE( x != NULL); + + //fclose(f); //using this will also cause segfault, because at the end, log.c will call (using atexit(func) function) cleanup_log(void)-> fclose(syslog_file); After the 1st fclose, syslog_file = NULL, and is never reset + //TEST_ASSERT_EQUAL_STRING(testString,line); //doesn't work, line is dynamic because the process name is random. +} + + diff --git a/tests/Makefile.am b/tests/Makefile.am index 75890a42c..fb43cbaaa 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -12,6 +12,7 @@ SUBDIRS += \ bug-2803 \ libntp \ sec-2853 \ + ntpq \ $(NULL) DIST_SUBDIRS += \ @@ -20,5 +21,6 @@ DIST_SUBDIRS += \ ntpd \ sandbox \ sec-2853 \ + ntpq \ $(NULL) diff --git a/tests/ntpq/Makefile.am b/tests/ntpq/Makefile.am new file mode 100644 index 000000000..d0e75965b --- /dev/null +++ b/tests/ntpq/Makefile.am @@ -0,0 +1,146 @@ +NULL = +BUILT_SOURCES = +CLEANFILES = + +std_unity_list = \ + $(top_srcdir)/sntp/unity/auto/generate_test_runner.rb \ + $(NULL) + +run_unity = cd $(srcdir) && ruby ../../sntp/unity/auto/generate_test_runner.rb + +check_PROGRAMS = \ + test-ntp_scanner \ + test-ntp_signd \ + $(NULL) + + +LDADD = \ + $(top_builddir)/ntpd/libntpd.a \ + $(top_builddir)/libntp/libntp.a \ + $(LDADD_LIBNTP) \ + $(PTHREAD_LIBS) \ + $(LDADD_NTP) \ + $(GTEST_LDFLAGS) \ + $(GTEST_LIBS) \ + $(NULL) + +unity_tests_LDADD = \ + $(LDADD) \ + $(top_builddir)/sntp/unity/libunity.a \ + $(LIBM) \ + $(NULL) + +AM_CFLAGS = $(CFLAGS_NTP) +AM_CXXFLAGS = $(GTEST_CXXFLAGS) + +AM_CPPFLAGS += -I$(top_srcdir)/ntpq + +AM_CPPFLAGS = $(NTP_INCS) +#AM_CPPFLAGS += -I$(top_srcdir)/sntp +#AM_CPPFLAGS += -I$(top_srcdir)/ntpd +#AM_CPPFLAGS += -I$(top_srcdir)/tests/libntp +AM_CPPFLAGS += $(GTEST_CPPFLAGS) +AM_CPPFLAGS += $(CPPFLAGS_NTP) +AM_CPPFLAGS += -DUNITY_INCLUDE_CONFIG_H +AM_CPPFLAGS += -I$(top_srcdir)/sntp/unity + +AM_LDFLAGS = $(LDFLAGS_NTP) + +tests_SOURCES = $(top_srcdir)/sntp/tests_main.cpp \ + t-ntp_signd.c \ + $(NULL) + +BUILT_SOURCES += \ + $(srcdir)/run-rc_cmdlength.c \ + $(srcdir)/run-t-ntp_signd.c \ + $(NULL) + +noinst_HEADERS = g_ntpdtest.h \ + $(srcdir)/../libntp/test-libntp.h \ + $(srcdir)/../libntp/sockaddrtest.h \ + $(NULL) + +### +test_ntp_signd_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + -Iwhy.h \ + $(NULL) + +test_ntp_signd_LDADD = \ + $(unity_tests_LDADD) \ + $(top_builddir)/ntpd/libntpd.a \ + $(unity_tests_LDADD) \ + $(top_builddir)/ntpd/ntp_config.o \ + $(top_builddir)/ntpd/ntp_io.o \ + $(NULL) + +# $(top_builddir)/ntpd/ntp_signd.o #not needed if you #include the file.c + +test_ntp_signd_SOURCES = \ + t-ntp_signd.c \ + run-t-ntp_signd.c \ + $(srcdir)/../libntp/test-libntp.c \ + $(srcdir)/../../ntpd/ntp_signd.c \ + $(NULL) + +$(srcdir)/run-t-ntp_signd.c: $(srcdir)/t-ntp_signd.c $(std_unity_list) + $(run_unity) t-ntp_signd.c run-t-ntp_signd.c + +### +test_ntp_scanner_CFLAGS = \ + -I$(top_srcdir)/sntp/unity \ + $(NULL) + +test_ntp_scanner_LDADD = \ + $(unity_tests_LDADD) \ + $(top_builddir)/ntpd/ntp_scanner.o \ + $(NULL) + +test_ntp_scanner_SOURCES = \ + ntp_scanner.c \ + run-ntp_scanner.c \ + $(srcdir)/../libntp/test-libntp.c \ + $(NULL) + +$(srcdir)/run-ntp_scanner.c: $(srcdir)/ntp_scanner.c $(std_unity_list) + $(run_unity) ntp_scanner.c run-ntp_scanner.c + + + +TESTS = + +if !NTP_CROSSCOMPILE +TESTS += $(check_PROGRAMS) +endif + +## check-libntp.mf - automake fragment +## slightly adapted for deeper directory + +BUILT_SOURCES += check-libntpd check-libntp check-libunity +CLEANFILES += check-libntpd check-libntp check-libunity + +check-libntpd: ../../ntpd/libntpd.a + @echo stamp > $@ + +../../ntpd/libntpd.a: + cd ../../ntpd && $(MAKE) $(AM_MAKEFLAGS) libntpd.a + + +check-libntp: ../../libntp/libntp.a + @echo stamp > $@ + +../../libntp/libntp.a: + cd ../../libntp && $(MAKE) $(AM_MAKEFLAGS) libntp.a + + +check-libunity: ../../sntp/unity/libunity.a + @echo stamp > $@ + +../../sntp/unity/libunity.a: + cd ../../sntp/unity && $(MAKE) $(AM_MAKEFLAGS) libunity.a + +$(top_builddir)/ntpd/ntpdsim-ntp_prio_q.o: + cd ../../ntpd/ && $(MAKE) $(AM_MAKEFLAGS) ntpdsim-ntp_prio_q.o + +include $(top_srcdir)/depsver.mf +include $(top_srcdir)/includes.mf