]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
run-crypto.c:
authorDamir Tomic <viperus@ntp.org>
Sat, 20 Jun 2015 12:32:03 +0000 (14:32 +0200)
committerDamir Tomic <viperus@ntp.org>
Sat, 20 Jun 2015 12:32:03 +0000 (14:32 +0200)
  new file
Makefile.am:
  minor rearrange
crypto.c:
  minor fix with #define, now works even without openSSL

bk: 55855d43OXBFr8O11LlpBJCATuV2kg

sntp/tests/Makefile.am
sntp/tests/crypto.c
sntp/tests/run-crypto.c [new file with mode: 0644]

index 01f5d05f4483971d8fe30a7de0f5f8bd438db983..523d32341052dc43e6f490e203e8889d706fd7f0 100644 (file)
@@ -119,23 +119,6 @@ BUILT_SOURCES +=                   \
        $(srcdir)/run-utilities.c       \
        $(NULL)
 
-test_crypto_CFLAGS =                   \
-       -I$(top_srcdir)/unity           \
-       $(NULL)
-
-test_crypto_LDADD =                    \
-       $(unity_tests_LDADD)            \
-       $(NULL)
-
-test_crypto_SOURCES =                  \
-       crypto.c                        \
-       run-crypto.c                    \
-       $(top_builddir)/version.c       \
-       $(NULL)
-
-$(srcdir)/run-crypto.c: $(srcdir)/crypto.c $(std_unity_list)
-       $(run_unity) crypto.c run-crypto.c
-
 test_keyFile_CFLAGS =                  \
        -I$(top_srcdir)/unity           \
        $(NULL)
@@ -173,10 +156,16 @@ test_utilities_CFLAGS =                   \
        $(NULL)
 
 test_utilities_LDADD =                 \
-       $(LDADD)                        \
        $(unity_tests_LDADD)            \
        $(NULL)
 
+test_crypto_CFLAGS =                   \
+       -I$(top_srcdir)/unity           \
+       $(NULL)
+
+test_crypto_LDADD =                    \
+       $(unity_tests_LDADD)            \
+       $(NULL)
 
 test_networking_SOURCES =              \
        networking.c                    \
@@ -208,6 +197,12 @@ test_utilities_SOURCES =           \
        run-utilities.c                 \
        $(NULL)
 
+test_crypto_SOURCES =                  \
+       crypto.c                        \
+       run-crypto.c                    \
+       $(top_builddir)/version.c       \
+       $(NULL)
+
 
 $(srcdir)/run-kodFile.c: $(srcdir)/kodFile.c $(std_unity_list)
        $(run_unity) kodFile.c run-kodFile.c
@@ -224,6 +219,9 @@ $(srcdir)/run-networking.c: $(srcdir)/networking.c $(std_unity_list)
 $(srcdir)/run-utilities.c: $(srcdir)/utilities.c $(std_unity_list)
        $(run_unity) utilities.c run-utilities.c
 
+$(srcdir)/run-crypto.c: $(srcdir)/crypto.c $(std_unity_list)
+       $(run_unity) crypto.c run-crypto.c
+
 #$(srcdir)/../version.c: $(srcdir)/../version.c
 #      gcc -o version.o ../version.c
 
index a51275205d12ac41d04bc8ba18e4521bc617af6c..254469e63a94119469407f0b23e677b6baac0c2f 100644 (file)
@@ -29,8 +29,9 @@ void test_MakeMd5Mac(void) {
        TEST_ASSERT_TRUE(memcmp(EXPECTED_DIGEST, actual, MD5_LENGTH) == 0);
 }
 
-#ifdef OPENSSL
+
 void test_MakeSHA1Mac(void) {
+#ifdef OPENSSL
        const char* PKT_DATA = "abcdefgh0123";
        const int PKT_LEN = strlen(PKT_DATA);
        const char* EXPECTED_DIGEST =
@@ -49,8 +50,11 @@ void test_MakeSHA1Mac(void) {
                          make_mac((char*)PKT_DATA, PKT_LEN, SHA1_LENGTH, &sha1, actual));
 
        TEST_ASSERT_TRUE(memcmp(EXPECTED_DIGEST, actual, SHA1_LENGTH) == 0);
-}
+#else
+       TEST_IGNORE_MESSAGE("OpenSSL not found, skipping...");
 #endif /* OPENSSL */
+}
+
 
 void test_VerifyCorrectMD5(void) {
        const char* PKT_DATA =
@@ -70,8 +74,9 @@ void test_VerifyCorrectMD5(void) {
        TEST_ASSERT_TRUE(auth_md5((char*)PKT_DATA, PKT_LEN, MD5_LENGTH, &md5));
 }
 
-#ifdef OPENSSL
+
 void test_VerifySHA1(void) {
+#ifdef OPENSSL
        const char* PKT_DATA =
                "sometestdata"          // Data
                "\0\0\0\0"                      // Key-ID (unused)
@@ -87,8 +92,10 @@ void test_VerifySHA1(void) {
        memcpy(&sha1.type, "SHA1", 5);
 
        TEST_ASSERT_TRUE(auth_md5((char*)PKT_DATA, PKT_LEN, SHA1_LENGTH, &sha1));
-}
+#else
+       TEST_IGNORE_MESSAGE("OpenSSL not found, skipping...");
 #endif /* OPENSSL */
+}
 
 void test_VerifyFailure(void) {
        /* We use a copy of the MD5 verification code, but modify
diff --git a/sntp/tests/run-crypto.c b/sntp/tests/run-crypto.c
new file mode 100644 (file)
index 0000000..c5dbaf6
--- /dev/null
@@ -0,0 +1,62 @@
+/* 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_MakeMd5Mac(void);
+extern void test_MakeSHA1Mac(void);
+extern void test_VerifyCorrectMD5(void);
+extern void test_VerifySHA1(void);
+extern void test_VerifyFailure(void);
+extern void test_PacketSizeNotMultipleOfFourBytes(void);
+
+
+//=======Test Reset Option=====
+void resetTest()
+{
+  tearDown();
+  setUp();
+}
+
+char *progname;
+
+
+//=======MAIN=====
+int main(int argc, char *argv[])
+{
+  progname = argv[0];
+  Unity.TestFile = "crypto.c";
+  UnityBegin("crypto.c");
+  RUN_TEST(test_MakeMd5Mac, 11);
+  RUN_TEST(test_MakeSHA1Mac, 33);
+  RUN_TEST(test_VerifyCorrectMD5, 59);
+  RUN_TEST(test_VerifySHA1, 78);
+  RUN_TEST(test_VerifyFailure, 100);
+  RUN_TEST(test_PacketSizeNotMultipleOfFourBytes, 120);
+
+  return (UnityEnd());
+}