NULL =
BUILT_SOURCES =
-CLEANFILES = kod-output-blank kod-output-single kod-output-multiple
+CLEANFILES = kod-output-blank kod-output-single kod-output-multiple debug-output-lfp-dec debug-output-lfp-bin debug-output-pkt
DISTCLEANFILES = kod-output-blank kod-output-single kod-output-multiple
EXTRA_PROGRAMS =
test-kodDatabase \
test-kodFile \
test-networking \
+ test-utilities \
$(NULL)
if GTEST_AVAILABLE
g_networking.cpp \
packetHandling.cpp \
packetProcessing.cpp \
- utilities.cpp \
+ g_utilities.cpp \
$(NULL)
noinst_HEADERS = \
data/kod-test-empty \
$(NULL)
-CLEANFILES = \
+CLEANFILES += \
data/kod-output-multiple \
data/kod-output-single \
data/debug-output-pkt \
unity_tests_LDADD = \
$(LDADD) \
$(top_builddir)/unity/libunity.a \
+ $(LIBM) \
$(NULL)
AM_CFLAGS = $(CFLAGS_NTP)
$(srcdir)/run-kodDatabase.c \
$(srcdir)/run-kodFile.c \
$(srcdir)/run-networking.c \
+ $(srcdir)/run-utilities.c \
$(NULL)
$(unity_tests_LDADD) \
$(NULL)
-test_keyFile_SOURCES = \
- keyFile.c \
- run-keyFile.c \
- $(top_builddir)/version.c \
- $(NULL)
-
-$(srcdir)/run-keyFile.c: $(srcdir)/keyFile.c $(std_unity_list)
- $(run_unity) keyFile.c run-keyFile.c
-
-
test_kodDatabase_CFLAGS = \
-I$(top_srcdir)/unity \
$(NULL)
$(unity_tests_LDADD) \
$(NULL)
-test_kodDatabase_SOURCES = \
- kodDatabase.c \
- run-kodDatabase.c \
- $(top_builddir)/version.c \
- $(NULL)
-
-$(srcdir)/run-kodDatabase.c: $(srcdir)/kodDatabase.c $(std_unity_list)
- $(run_unity) kodDatabase.c run-kodDatabase.c
-
-
test_kodFile_CFLAGS = \
-I$(top_srcdir)/unity \
$(NULL)
$(unity_tests_LDADD) \
$(NULL)
-test_kodFile_SOURCES = \
- kodFile.c \
- run-kodFile.c \
- $(top_builddir)/version.c \
+test_networking_CFLAGS = \
+ -I$(top_srcdir)/unity \
$(NULL)
-# ../version.c
-
-$(srcdir)/run-kodFile.c: $(srcdir)/kodFile.c $(std_unity_list)
- $(run_unity) kodFile.c run-kodFile.c
+test_networking_LDADD = \
+ $(unity_tests_LDADD) \
+ $(NULL)
-test_networking_CFLAGS = \
+test_utilities_CFLAGS = \
-I$(top_srcdir)/unity \
$(NULL)
-test_networking_LDADD = \
+test_utilities_LDADD = \
+ $(LDADD) \
$(unity_tests_LDADD) \
$(NULL)
+
test_networking_SOURCES = \
networking.c \
run-networking.c \
$(top_builddir)/version.c \
$(NULL)
+test_kodDatabase_SOURCES = \
+ kodDatabase.c \
+ run-kodDatabase.c \
+ $(top_builddir)/version.c \
+ $(NULL)
+
+test_keyFile_SOURCES = \
+ keyFile.c \
+ run-keyFile.c \
+ $(top_builddir)/version.c \
+ $(NULL)
+
+test_kodFile_SOURCES = \
+ kodFile.c \
+ run-kodFile.c \
+ $(top_builddir)/version.c \
+ $(NULL)
+# ../version.c
+
+test_utilities_SOURCES = \
+ utilities.c \
+ run-utilities.c \
+ $(NULL)
+
+
+$(srcdir)/run-kodFile.c: $(srcdir)/kodFile.c $(std_unity_list)
+ $(run_unity) kodFile.c run-kodFile.c
+
+$(srcdir)/run-keyFile.c: $(srcdir)/keyFile.c $(std_unity_list)
+ $(run_unity) keyFile.c run-keyFile.c
+
+$(srcdir)/run-kodDatabase.c: $(srcdir)/kodDatabase.c $(std_unity_list)
+ $(run_unity) kodDatabase.c run-kodDatabase.c
+
$(srcdir)/run-networking.c: $(srcdir)/networking.c $(std_unity_list)
$(run_unity) networking.c run-networking.c
+$(srcdir)/run-utilities.c: $(srcdir)/utilities.c $(std_unity_list)
+ $(run_unity) utilities.c run-utilities.c
#$(srcdir)/../version.c: $(srcdir)/../version.c
# gcc -o version.o ../version.c
--- /dev/null
+--------------------------------------------------------------------------------
+0: 00000000 1: 00000000 2: 00000000 3: 00111111 4: 00000000 5: 00000000 6: 00000000 7: 01111111
+--------------------------------------------------------------------------------
--- /dev/null
+--------------------------------------------------------------------------------
+0: 0 1: 0 2: 24 3: 166 4: 0 5: 4 6: 181 7: 22
+--------------------------------------------------------------------------------
--- /dev/null
+--------------------------------------------------------------------------------
+0: 24 1: 0 2: 0 3: 0 4: 0 5: 0 6: 0 7: 0
+8: 0 9: 0 10: 0 11: 0 12: 0 13: 0 14: 0 15: 0
+16: 0 17: 0 18: 0 19: 0 20: 0 21: 0 22: 0 23: 0
+24: 0 25: 0 26: 0 27: 0 28: 0 29: 0 30: 0 31: 0
+32: 0 33: 0 34: 0 35: 0 36: 0 37: 0 38: 0 39: 0
+40: 0 41: 0 42: 0 43: 8 44: 7f 45: ff 46: ff 47: ff
+--------------------------------------------------------------------------------
--- /dev/null
+/* 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 <setjmp.h>
+#include <stdio.h>
+
+//=======External Functions This Runner Calls=====
+extern void setUp(void);
+extern void tearDown(void);
+void resetTest(void);
+extern void test_IPv4Address();
+extern void test_IPv6Address();
+extern void test_SetLiVnMode1();
+extern void test_SetLiVnMode2();
+extern void test_PktOutput();
+extern void test_LfpOutputBinaryFormat();
+extern void test_LfpOutputDecimalFormat();
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+ tearDown();
+ setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+ progname = argv[0];
+ Unity.TestFile = "utilities.c";
+ UnityBegin("utilities.c");
+ RUN_TEST(test_IPv4Address, 68);
+ RUN_TEST(test_IPv6Address, 78);
+ RUN_TEST(test_SetLiVnMode1, 98);
+ RUN_TEST(test_SetLiVnMode2, 111);
+ RUN_TEST(test_PktOutput, 126);
+ RUN_TEST(test_LfpOutputBinaryFormat, 146);
+ RUN_TEST(test_LfpOutputDecimalFormat, 162);
+
+ return (UnityEnd());
+}
--- /dev/null
+#include "config.h"
+
+#include "sntptest.h"
+#include "fileHandlingTest.h"
+
+#include "main.h"
+#include "utilities.h"
+#include "math.h"
+
+#include "unity.h"
+
+const char * Version = "stub unit test Version string";
+
+
+
+sockaddr_u CreateSockaddr4(const char* address) {
+ sockaddr_u s;
+ s.sa4.sin_family = AF_INET;
+ s.sa4.sin_addr.s_addr = inet_addr(address);
+ SET_PORT(&s, 123);
+
+ return s;
+}
+
+struct addrinfo CreateAddrinfo( sockaddr_u* sock) {
+ struct addrinfo a;
+ a.ai_family = sock->sa.sa_family;
+ a.ai_addrlen = SIZEOF_SOCKADDR(a.ai_family);
+ a.ai_addr = &sock->sa;
+ return a;
+}
+
+
+bool outputFileOpened;
+FILE* outputFile;
+
+//debugUtilitiesTest() : outputFileOpened(false) {}
+
+void InitDebugTest(const char * filename) {
+ // Clear the contents of the current file.
+ // Open the output file
+ outputFile = fopen(filename, "w+");
+ TEST_ASSERT_TRUE(outputFile != NULL);
+ outputFileOpened = true;
+}
+
+// Closes outputFile, and compare contents.
+void FinishDebugTest(const char * expected,
+ const char * actual) {
+ if (outputFileOpened)
+ fclose(outputFile);
+
+ FILE * e = fopen(expected,"rb");
+ FILE * a = fopen(actual,"rb");
+ TEST_ASSERT_TRUE(e != NULL);
+ TEST_ASSERT_TRUE(a != NULL);
+
+ CompareFileContent(e, a);
+}
+
+
+/*
+ * These tests are essentially a copy of the tests for socktoa()
+ * in libntp. If sntp switches to using that functions, these
+ * tests can be removed.
+ */
+
+void test_IPv4Address() {
+ const char* ADDR = "192.0.2.10";
+
+ sockaddr_u input = CreateSockaddr4(ADDR);
+ struct addrinfo inputA = CreateAddrinfo(&input);
+
+ TEST_ASSERT_EQUAL_STRING(ADDR, ss_to_str(&input));
+ TEST_ASSERT_EQUAL_STRING(ADDR, addrinfo_to_str(&inputA));
+}
+
+void test_IPv6Address() {
+ const struct in6_addr address = {
+ 0x20, 0x01, 0x0d, 0xb8,
+ 0x85, 0xa3, 0x08, 0xd3,
+ 0x13, 0x19, 0x8a, 0x2e,
+ 0x03, 0x70, 0x73, 0x34
+ };
+ const char * expected = "2001:db8:85a3:8d3:1319:8a2e:370:7334";
+ sockaddr_u input;
+ struct addrinfo inputA;
+
+ memset(&input, 0, sizeof(input));
+ input.sa6.sin6_family = AF_INET6;
+ input.sa6.sin6_addr = address;
+ TEST_ASSERT_EQUAL_STRING(expected, ss_to_str(&input));
+
+ inputA = CreateAddrinfo(&input);
+ TEST_ASSERT_EQUAL_STRING(expected, addrinfo_to_str(&inputA));
+}
+
+void test_SetLiVnMode1() {
+ struct pkt expected;
+ expected.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
+ NTP_VERSION,
+ MODE_SERVER);
+
+ struct pkt actual;
+ set_li_vn_mode(&actual, LEAP_NOWARNING, NTP_VERSION,
+ MODE_SERVER);
+
+ TEST_ASSERT_EQUAL(expected.li_vn_mode, actual.li_vn_mode);
+}
+
+void test_SetLiVnMode2() {
+ struct pkt expected;
+ expected.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC,
+ NTP_OLDVERSION,
+ MODE_BROADCAST);
+
+ struct pkt actual;
+ set_li_vn_mode(&actual, LEAP_NOTINSYNC, NTP_OLDVERSION,
+ MODE_BROADCAST);
+
+ TEST_ASSERT_EQUAL(expected.li_vn_mode, actual.li_vn_mode);
+}
+
+/* Debug utilities tests */
+
+void test_PktOutput() {
+ char * filename = "debug-output-pkt";//CreatePath("debug-output-pkt", OUTPUT_DIR);
+ InitDebugTest(filename);
+
+ struct pkt testpkt;
+ memset(&testpkt, 0, sizeof(struct pkt));
+ testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
+ NTP_VERSION,
+ MODE_SERVER);
+
+ l_fp test;
+ test.l_ui = 8;
+ test.l_uf = 2147483647; // Lots of ones.
+ HTONL_FP(&test, &testpkt.xmt);
+
+ pkt_output(&testpkt, LEN_PKT_NOMAC, outputFile);
+
+ FinishDebugTest(CreatePath("debug-input-pkt", INPUT_DIR), filename);
+}
+
+void test_LfpOutputBinaryFormat() {
+ char * filename = "debug-output-lfp-bin";//CreatePath("debug-output-lfp-bin", OUTPUT_DIR);
+ InitDebugTest(filename);
+
+ l_fp test;
+ test.l_ui = 63; // 00000000 00000000 00000000 00111111
+ test.l_uf = 127; // 00000000 00000000 00000000 01111111
+
+ l_fp network;
+ HTONL_FP(&test, &network);
+
+ l_fp_output_bin(&network, outputFile);
+
+ FinishDebugTest(CreatePath("debug-input-lfp-bin", INPUT_DIR), filename);
+}
+
+void test_LfpOutputDecimalFormat() {
+ char * filename = "debug-output-lfp-dec"; //CreatePath("debug-output-lfp-dec", OUTPUT_DIR);
+ InitDebugTest(filename);
+
+ l_fp test;
+ test.l_ui = 6310; // 0x000018A6
+ test.l_uf = 308502; // 0x00004B516
+
+ l_fp network;
+ HTONL_FP(&test, &network);
+
+ l_fp_output_dec(&network, outputFile);
+
+ FinishDebugTest(CreatePath("debug-input-lfp-dec", INPUT_DIR), filename);
+}
+
output.puts("\n//=======External Functions This Runner Calls=====")
output.puts("extern void setUp(void);")
output.puts("extern void tearDown(void);")
+ output.puts("void resetTest(void);")
tests.each do |test|
output.puts("extern void #{test[:name]}(#{test[:call]});")
end
#include <timevalops.h>
#include "unity.h"
-#include "bug-2803.h"
+//#include "bug-2803.h"
/* microseconds per second */
#define MICROSECONDS 1000000
-
+int simpleTest(void);
+void setUp(void);
+void tearDown(void);
+//void test_main(void);
static int verbose = 1; // if not 0, also print results if test passed
static int exit_on_err = 0; // if not 0, exit if test failed
+++ /dev/null
-#include <config.h>
-
-#include <stdio.h>
-#include <sys/time.h>
-
-#include <ntp_fp.h>
-#include <timevalops.h>
-
-#include "unity.h"
-
-int simpleTest(void);
-void setUp(void);
-void tearDown(void);
-void test_main(void);
//=======External Functions This Runner Calls=====
extern void setUp(void);
extern void tearDown(void);
-extern void test_main(void );
void resetTest(void);
+extern void test_main(void );
+
//=======Test Reset Option=====
void resetTest()
progname = argv[0];
Unity.TestFile = "bug-2803.c";
UnityBegin("bug-2803.c");
- RUN_TEST(test_main, 117);
+ RUN_TEST(test_main, 18);
return (UnityEnd());
}