[Git][NTPsec/ntpsec][master] 5 commits: Add output dir fir tests and add more flexible test option passing.

Amar Takhar gitlab at mg.gitlab.com
Fri Nov 20 21:10:59 UTC 2015


Amar Takhar pushed to branch master at NTPsec / ntpsec


Commits:
7cf738ee by Amar Takhar at 2015-11-20T15:16:43Z
Add output dir fir tests and add more flexible test option passing.

- - - - -
c650d4a3 by Amar Takhar at 2015-11-20T15:31:40Z
Add kodFile.c to ntpdig tests.

- - - - -
ce33665f by Amar Takhar at 2015-11-20T16:08:14Z
Remove debug print that snuck in.

- - - - -
b3dcc884 by Amar Takhar at 2015-11-20T16:09:19Z
    Add partial work for nameresolution.c

      * This was useless as resolve_hosts was only in 4.2.6 sntp.

- - - - -
83cb3da6 by Amar Takhar at 2015-11-20T16:10:07Z
Remove nameresolution.(c|cpp) as it tests a deleted function.

- - - - -


5 changed files:

- pylib/waf.py
- tests/common/tests_main.c
- tests/ntpdig/kodFile.c
- − tests/ntpdig/nameresolution.cpp
- tests/wscript


Changes:

=====================================
pylib/waf.py
=====================================
--- a/pylib/waf.py
+++ b/pylib/waf.py
@@ -73,9 +73,9 @@ def ntp_test(ctx, **kwargs):
 	bldnode = ctx.bldnode.abspath()
 	tg = ctx(**kwargs)
 
-	if hasattr(tg, "test_data"):
-		test_data = tg.test_data
-	else:
-		test_data = None
+	args = ["%s/tests/%s" % (bldnode, tg.target), "-v"]
 
-	tg.ut_exec = ["%s/tests/%s" % (bldnode, tg.target), "-v", tg.test_data]
+	if hasattr(tg, "test_args"):
+		args += tg.test_args
+
+	tg.ut_exec = args


=====================================
tests/common/tests_main.c
=====================================
--- a/tests/common/tests_main.c
+++ b/tests/common/tests_main.c
@@ -29,7 +29,7 @@ static void RunAllTests(void)
 	RUN_TEST_GROUP(crypto);
 	RUN_TEST_GROUP(keyFile);
 	RUN_TEST_GROUP(kodDatabase);
-//	RUN_TEST_GROUP(kodFile);
+	RUN_TEST_GROUP(kodFile);
 	RUN_TEST_GROUP(packetHandling);
 #endif
 


=====================================
tests/ntpdig/kodFile.c
=====================================
--- a/tests/ntpdig/kodFile.c
+++ b/tests/ntpdig/kodFile.c
@@ -90,7 +90,7 @@ TEST(kodFile, WriteEmptyFile) {
 	 * Open file and ensure that the filesize is 0 bytes.
 	 */
 	is = fopen(kod_db_file, "wb");
-	TEST_ASSERT_NULL(is);
+	TEST_ASSERT_NOT_NULL(is);
 	TEST_ASSERT_FALSE(ferror(is));
 
 	TEST_ASSERT_EQUAL(0, GetFileSize(is));
@@ -120,11 +120,11 @@ TEST(kodFile, WriteFileWithSingleEntry) {
 	 * Open file and compare sizes.
 	 */
 	actual = fopen(kod_db_file, "rb");
-	TEST_ASSERT_NULL(actual);
+	TEST_ASSERT_NOT_NULL(actual);
 	TEST_ASSERT_FALSE(ferror(actual));
 	expected_file = CreatePath("kod-expected-single", INPUT_DIR);;
 	expected = fopen(expected_file, "rb");
-	TEST_ASSERT_NULL(expected);
+	TEST_ASSERT_NOT_NULL(expected);
 	TEST_ASSERT_FALSE(ferror(expected));
 
 	TEST_ASSERT_EQUAL(GetFileSize(expected), GetFileSize(actual));
@@ -162,11 +162,11 @@ TEST(kodFile, WriteFileWithMultipleEntries) {
 	 * Open file and compare sizes and content.
 	 */
 	actual = fopen(kod_db_file, "rb");
-	TEST_ASSERT_NULL(actual);
+	TEST_ASSERT_NOT_NULL(actual);
 	TEST_ASSERT_FALSE(ferror(actual));
-	expected_file = CreatePath("kod-expected-single", INPUT_DIR);;
+	expected_file = CreatePath("kod-expected-multiple", INPUT_DIR);;
 	expected = fopen(expected_file, "rb");
-	TEST_ASSERT_NULL(expected);
+	TEST_ASSERT_NOT_NULL(expected);
 	TEST_ASSERT_FALSE(ferror(expected));
 
 	TEST_ASSERT_EQUAL(GetFileSize(expected), GetFileSize(actual));
@@ -178,3 +178,12 @@ TEST(kodFile, WriteFileWithMultipleEntries) {
 	free((void*) kod_db_file);
 	free((void*) expected_file);
 }
+
+TEST_GROUP_RUNNER(kodFile) {
+	RUN_TEST_CASE(kodFile, ReadEmptyFile);
+	RUN_TEST_CASE(kodFile, ReadCorrectFile);
+	RUN_TEST_CASE(kodFile, ReadFileWithBlankLines);
+	RUN_TEST_CASE(kodFile, WriteEmptyFile);
+	RUN_TEST_CASE(kodFile, WriteFileWithSingleEntry);
+	RUN_TEST_CASE(kodFile, WriteFileWithMultipleEntries);
+}


=====================================
tests/ntpdig/nameresolution.cpp deleted
=====================================
--- a/tests/ntpdig/nameresolution.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-extern "C" {
-#include "unity.h"
-#include "unity_fixture.h"
-}
-
-TEST_GROUP(nameresolution);
-
-TEST_SETUP(nameresolution) {}
-
-TEST_TEAR_DOWN(nameresolution) {}
-
-#include "ntpdigtest.h"
-
-extern "C" {
-#include "networking.h"
-};
-
-class networkingTest : public ntpdigtest {
-protected:
-	bool CompareAddrinfo(const char* host,
-											   int family, int flags,
-											   const addrinfo& actual) {
-		if (family != actual.ai_family)
-			return false
-				<< "Family mismatch, expected: " << family
-				<< " but was: " << actual.ai_family;
-		sockaddr_u* sock = new sockaddr_u;
-		void* expectedaddr = NULL, *actualaddr = NULL;
-		int size = 0, addrsize = 0;
-		if (family == AF_INET) {
-			expectedaddr = &sock->sa4.sin_addr;
-			actualaddr = &((sockaddr_u*)actual.ai_addr)->sa4.sin_addr;
-			size = sizeof(sock->sa4);
-			addrsize = sizeof(sock->sa4.sin_addr);
-		} else {
-			expectedaddr = &sock->sa6.sin6_addr;
-			actualaddr = &((sockaddr_u*)actual.ai_addr)->sa6.sin6_addr;
-			size = sizeof(sock->sa6);
-			addrsize = sizeof(sock->sa6.sin6_addr);
-		}
-		sock->sa.sa_family = family;
-
-		if (inet_pton(family, host, expectedaddr) != 1)
-			return false
-				<< "inet_pton failed!";
-
-		if (flags != actual.ai_flags)
-			return false
-				<< "Flags mismatch, expected: " << flags
-				<< " but was: " << actual.ai_flags;
-
-		if (size != actual.ai_addrlen)
-			return false
-				<< "Address length mismatch, expected: " << size
-				<< " but was: " << actual.ai_addrlen;
-
-		if (memcmp(expectedaddr, actualaddr, addrsize) != 0)
-			return false
-				<< "Address mismatch";
-		return true;
-	}
-};
-
-TEST(networking, ResolveSingleAddress) {
-	const char* HOSTS[1] = {"192.0.2.1"};
-	const int HOSTCOUNT = COUNTOF(HOSTS);
-
-	addrinfo** actual = NULL;
-
-	TEST_ASSERT_EQUAL(1, resolve_hosts(HOSTS, HOSTCOUNT, &actual, PF_UNSPEC));
-
-	TEST_ASSERT_TRUE(actual != NULL);
-	TEST_ASSERT_TRUE(CompareAddrinfo(HOSTS[0], AF_INET, 0, **actual));
-}
-
-TEST(networking, ResolveMultipleAddresses) {
-	const char* HOSTS[3] = {"192.0.2.1", "192.0.2.5", "192.0.2.10"};
-	const int HOSTCOUNT = COUNTOF(HOSTS);
-
-	addrinfo** actual = NULL;
-
-	TEST_ASSERT_EQUAL(3, resolve_hosts(HOSTS, HOSTCOUNT, &actual, PF_UNSPEC));
-
-	TEST_ASSERT_TRUE(actual != NULL);
-	for (int i=0; i<HOSTCOUNT; i++) {
-		TEST_ASSERT_TRUE(CompareAddrinfo(HOSTS[i], AF_INET, 0, *actual[i]))
-			<< "Failed for host number " << i;
-	}
-}
-
-TEST(networking, ResolveIPv6Address) {
-	const char* HOSTS[1] = {"2001:0DB8:AC10:FE01:0:0:0:0"};
-	const int HOSTCOUNT = COUNTOF(HOSTS);
-
-	addrinfo** actual = NULL;
-
-	TEST_ASSERT_EQUAL(1, resolve_hosts(HOSTS, HOSTCOUNT, &actual, PF_UNSPEC));
-	TEST_ASSERT_TRUE(actual != NULL);
-
-	TEST_ASSERT_TRUE(CompareAddrinfo(HOSTS[0], AF_INET6, 0, **actual));
-}
-
-TEST(networking, ResolveIPv6InvalidComparision) {
-	const char* HOSTS[1] = {"2001:0DB8:AC10:FE01::"};
-	const char* INVALID = "2001:0db8:ac10:fe01:0:1:0:0";
-	const int HOSTCOUNT = COUNTOF(HOSTS);
-
-	addrinfo** actual = NULL;
-
-	TEST_ASSERT_EQUAL(1, resolve_hosts(HOSTS, HOSTCOUNT, &actual, PF_UNSPEC));
-	TEST_ASSERT_TRUE(actual != NULL);
-
-	TEST_ASSERT_FALSE(CompareAddrinfo(INVALID, AF_INET6, 0, **actual));
-}
-
-TEST(networking, ResolveMixedAddressTypes) {
-	const char* HOSTS[4] = {"2001:0db8:ac10:fe01::", "192.0.2.10",
-							"192.0.2.30", "2001:ab0:1000::"};
-	const int FAMILIES[4] = {AF_INET6, AF_INET, AF_INET, AF_INET6};
-	const int HOSTCOUNT = COUNTOF(HOSTS);
-
-	addrinfo** actual = NULL;
-
-	TEST_ASSERT_EQUAL(4, resolve_hosts(HOSTS, HOSTCOUNT, &actual, PF_UNSPEC));
-	TEST_ASSERT_TRUE(actual != NULL);
-
-	for (int i=0; i<HOSTCOUNT; i++) {
-		TEST_ASSERT_TRUE(CompareAddrinfo(HOSTS[i], FAMILIES[i], 0, *actual[i]))
-			<< "Failed for host number " << i;
-	}
-}
-
-TEST(networking, ResolveInvalidAddress) {
-	const char* HOSTS[1] = {"192.258.2.1"};
-	const int HOSTCOUNT = COUNTOF(HOSTS);
-
-	addrinfo** actual = NULL;
-
-	TEST_ASSERT_EQUAL(0, resolve_hosts(HOSTS, HOSTCOUNT, &actual, PF_UNSPEC));
-}
-
-TEST(networking, ResolveMixedAddressValidity) {
-	const char* HOSTS[3] = {"2001:52ij:130:1::", "192.0.2.13", "192.0.257.1"};
-	const int HOSTCOUNT = COUNTOF(HOSTS);
-
-	addrinfo** actual = NULL;
-
-	TEST_ASSERT_EQUAL(1, resolve_hosts(HOSTS, HOSTCOUNT, &actual, PF_UNSPEC));
-	TEST_ASSERT_TRUE(actual != NULL);
-
-	TEST_ASSERT_TRUE(CompareAddrinfo(HOSTS[1], AF_INET, 0, **actual));
-}
-
-TEST(networking, ResolveIgnoringIPv6) {
-	const char* HOSTS[4] = {"2001:0db8:ac10:fe01::", "192.0.2.10",
-							"192.0.2.30", "2001:ab0:1000::"};
-	const int FAMILIES[4] = {AF_INET6, AF_INET, AF_INET, AF_INET6};
-	const int HOSTCOUNT = COUNTOF(HOSTS);
-
-	addrinfo** actual = NULL;
-
-	TEST_ASSERT_EQUAL(2, resolve_hosts(HOSTS, HOSTCOUNT, &actual, AF_INET));
-	TEST_ASSERT_TRUE(actual != NULL);
-
-	TEST_ASSERT_TRUE(CompareAddrinfo(HOSTS[1], FAMILIES[1], 0, *actual[0]));
-	TEST_ASSERT_TRUE(CompareAddrinfo(HOSTS[2], FAMILIES[2], 0, *actual[1]));
-}
-
-TEST(networking, ResolveIgnoringIPv4) {
-	const char* HOSTS[4] = {"2001:0db8:ac10:fe01::", "192.0.2.10",
-							"192.0.2.30", "2001:ab0:1000::"};
-	const int FAMILIES[4] = {AF_INET6, AF_INET, AF_INET, AF_INET6};
-	const int HOSTCOUNT = COUNTOF(HOSTS);
-
-	addrinfo** actual = NULL;
-
-	TEST_ASSERT_EQUAL(2, resolve_hosts(HOSTS, HOSTCOUNT, &actual, AF_INET6));
-	TEST_ASSERT_TRUE(actual != NULL);
-
-	TEST_ASSERT_TRUE(CompareAddrinfo(HOSTS[0], FAMILIES[0], 0, *actual[0]));
-	TEST_ASSERT_TRUE(CompareAddrinfo(HOSTS[3], FAMILIES[3], 0, *actual[1]));
-}


=====================================
tests/wscript
=====================================
--- a/tests/wscript
+++ b/tests/wscript
@@ -26,7 +26,7 @@ def build(ctx):
 		"ntpdig/fileHandlingTest.c",
 		"ntpdig/keyFile.c",
 		"ntpdig/kodDatabase.c",
-#		"ntpdig/kodFile.c",
+		"ntpdig/kodFile.c",
 #		"ntpdig/networking.c",
 		"ntpdig/packetHandling.c",
 	] + common_source
@@ -43,7 +43,7 @@ def build(ctx):
 		],
 		use			= "unity ntpdig_obj ntp isc M",
         source      = ntpdig_source,
-		test_data	= "%s/tests/ntpdig/data/" % srcnode,
+		test_args	= ["%s/tests/ntpdig/data/" % srcnode, "%s/tests/ntpdig/" % bldnode]
 	)
 
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/deb812550f5373780aefc65266ea7cb01bbeb584...83cb3da6e017dcc82b2bc756be713481ea9f0e8f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151120/63b011fe/attachment.html>


More information about the vc mailing list