From: Damir Tomic Date: Sat, 20 Jun 2015 12:32:03 +0000 (+0200) Subject: run-crypto.c: X-Git-Tag: NTP_4_3_43~2^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc63f03a73e27fa52eb91eabef4c2b0657715546;p=thirdparty%2Fntp.git run-crypto.c: new file Makefile.am: minor rearrange crypto.c: minor fix with #define, now works even without openSSL bk: 55855d43OXBFr8O11LlpBJCATuV2kg --- diff --git a/sntp/tests/Makefile.am b/sntp/tests/Makefile.am index 01f5d05f4..523d32341 100644 --- a/sntp/tests/Makefile.am +++ b/sntp/tests/Makefile.am @@ -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 diff --git a/sntp/tests/crypto.c b/sntp/tests/crypto.c index a51275205..254469e63 100644 --- a/sntp/tests/crypto.c +++ b/sntp/tests/crypto.c @@ -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 index 000000000..c5dbaf64d --- /dev/null +++ b/sntp/tests/run-crypto.c @@ -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 +#include + +//=======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()); +}