* [Bug 2829] Look at pipe_fds in ntpd.c (did so. perlinger@ntp.org)
* [Bug 2887] stratum -1 config results as showing value 99
- fudge stratum only accepts values [0..16]. perlinger@ntp.org
+* [Bug 2892] Several test cases assume IPv6 capabilities even when
+ IPv6 is disabled in the build. perlinger@ntp.org
+ - Found this already fixed, but validation led to cleanup actions.
* [Bug 2932] Update leapsecond file info in miscopt.html. CWoodbury, HStenn.
* [Bug 2934] tests/ntpd/t-ntp_scanner.c has a magic constant wired in. HMurray
* [Bug 2944] errno is not preserved properly in ntpdate after sendto call.
int
make_mac(
- char *pkt_data,
+ const void *pkt_data,
int pkt_size,
int mac_size,
- struct key *cmp_key,
- char * digest
+ const struct key *cmp_key,
+ void * digest
)
{
u_int len = mac_size;
INIT_SSL();
key_type = keytype_from_text(cmp_key->type, NULL);
EVP_DigestInit(&ctx, EVP_get_digestbynid(key_type));
- EVP_DigestUpdate(&ctx, (u_char *)cmp_key->key_seq, (u_int)cmp_key->key_len);
- EVP_DigestUpdate(&ctx, (u_char *)pkt_data, (u_int)pkt_size);
- EVP_DigestFinal(&ctx, (u_char *)digest, &len);
+ EVP_DigestUpdate(&ctx, (const u_char *)cmp_key->key_seq, (u_int)cmp_key->key_len);
+ EVP_DigestUpdate(&ctx, pkt_data, (u_int)pkt_size);
+ EVP_DigestFinal(&ctx, digest, &len);
return (int)len;
}
-/* Generates a md5 digest of the key specified in keyid concatinated with the
+/* Generates a md5 digest of the key specified in keyid concatenated with the
* ntp packet (exluding the MAC) and compares this digest to the digest in
* the packet's MAC. If they're equal this function returns 1 (packet is
* authentic) or else 0 (not authentic).
*/
int
auth_md5(
- char *pkt_data,
+ const void *pkt_data,
int pkt_size,
int mac_size,
- struct key *cmp_key
+ const struct key *cmp_key
)
{
int hash_len;
int authentic;
char digest[20];
-
+ const u_char *pkt_ptr;
if (mac_size > (int)sizeof(digest))
return 0;
- hash_len = make_mac(pkt_data, pkt_size, sizeof(digest), cmp_key,
+ pkt_ptr = pkt_data;
+ hash_len = make_mac(pkt_ptr, pkt_size, sizeof(digest), cmp_key,
digest);
if (!hash_len)
authentic = FALSE;
else
- authentic = !memcmp(digest, pkt_data + pkt_size + 4,
+ authentic = !memcmp(digest, pkt_ptr + pkt_size + 4,
hash_len);
return authentic;
}
/* #include "sntp-opts.h" */
struct key {
- struct key *next;
- int key_id;
- int key_len;
- char type[10];
- char key_seq[64];
+ struct key * next;
+ int key_id;
+ int key_len;
+ char type[10];
+ char key_seq[64];
};
-int auth_init(const char *keyfile, struct key **keys);
-void get_key(int key_id, struct key **d_key);
-int make_mac(char *pkt_data, int pkt_size, int mac_size, struct key *cmp_key, char *digest);
-int auth_md5(char *pkt_data, int pkt_size, int mac_size, struct key *cmp_key);
+extern int auth_init(const char *keyfile, struct key **keys);
+extern void get_key(int key_id, struct key **d_key);
+extern int make_mac(const void *pkt_data, int pkt_size, int mac_size,
+ const struct key *cmp_key, void *digest);
+extern int auth_md5(const void *pkt_data, int pkt_size, int mac_size,
+ const struct key *cmp_key);
#endif
if (pkt_key != NULL) {
x_pkt->exten[0] = htonl(key_id);
mac_size = 20; /* max room for MAC */
- mac_size = make_mac((char *)x_pkt, pkt_len, mac_size,
+ mac_size = make_mac(x_pkt, pkt_len, mac_size,
pkt_key, (char *)&x_pkt->exten[1]);
if (mac_size > 0)
pkt_len += mac_size + 4;
** keyfile and compare those md5sums.
*/
mac_size = exten_len << 2;
- if (!auth_md5((char *)rpkt, pkt_len - mac_size,
+ if (!auth_md5(rpkt, pkt_len - mac_size,
mac_size - 4, pkt_key)) {
is_authentic = FALSE;
break;
void
-test_MakeMd5Mac(void) {
-
+test_MakeMd5Mac(void)
+{
const char* PKT_DATA = "abcdefgh0123";
const int PKT_LEN = strlen(PKT_DATA);
const char* EXPECTED_DIGEST =
memcpy(&md5.type, "MD5", 4);
TEST_ASSERT_EQUAL(MD5_LENGTH,
- make_mac((char*)PKT_DATA, PKT_LEN, MD5_LENGTH, &md5, actual));
+ make_mac(PKT_DATA, PKT_LEN, MD5_LENGTH, &md5, actual));
TEST_ASSERT_TRUE(memcmp(EXPECTED_DIGEST, actual, MD5_LENGTH) == 0);
}
void
-test_MakeSHA1Mac(void) {
+test_MakeSHA1Mac(void)
+{
#ifdef OPENSSL
+
const char* PKT_DATA = "abcdefgh0123";
const int PKT_LEN = strlen(PKT_DATA);
const char* EXPECTED_DIGEST =
memcpy(&sha1.type, "SHA1", 5);
TEST_ASSERT_EQUAL(SHA1_LENGTH,
- make_mac((char*)PKT_DATA, PKT_LEN, SHA1_LENGTH, &sha1, actual));
+ make_mac(PKT_DATA, PKT_LEN, SHA1_LENGTH, &sha1, actual));
TEST_ASSERT_EQUAL_MEMORY(EXPECTED_DIGEST, actual, SHA1_LENGTH);
+
#else
+
TEST_IGNORE_MESSAGE("OpenSSL not found, skipping...");
+
#endif /* OPENSSL */
}
void
-test_VerifyCorrectMD5(void) {
+test_VerifyCorrectMD5(void)
+{
const char* PKT_DATA =
- "sometestdata" // Data
- "\0\0\0\0" // Key-ID (unused)
- "\xc7\x58\x99\xdd\x99\x32\x0f\x71" // MAC
- "\x2b\x7b\xfe\x4f\xa2\x32\xcf\xac";
+ "sometestdata" /* Data */
+ "\0\0\0\0" /* Key-ID (unused) */
+ "\xc7\x58\x99\xdd\x99\x32\x0f\x71" /* MAC */
+ "\x2b\x7b\xfe\x4f\xa2\x32\xcf\xac";
const int PKT_LEN = 12;
struct key md5;
memcpy(&md5.key_seq, "md5key", md5.key_len);
memcpy(&md5.type, "MD5", 4);
- TEST_ASSERT_TRUE(auth_md5((char*)PKT_DATA, PKT_LEN, MD5_LENGTH, &md5));
+ TEST_ASSERT_TRUE(auth_md5(PKT_DATA, PKT_LEN, MD5_LENGTH, &md5));
}
void
-test_VerifySHA1(void) {
+test_VerifySHA1(void)
+{
#ifdef OPENSSL
+
const char* PKT_DATA =
- "sometestdata" // Data
- "\0\0\0\0" // Key-ID (unused)
- "\xad\x07\xde\x36\x39\xa6\x77\xfa\x5b\xce" // MAC
- "\x2d\x8a\x7d\x06\x96\xe6\x0c\xbc\xed\xe1";
+ "sometestdata" /* Data */
+ "\0\0\0\0" /* Key-ID (unused) */
+ "\xad\x07\xde\x36\x39\xa6\x77\xfa\x5b\xce" /* MAC */
+ "\x2d\x8a\x7d\x06\x96\xe6\x0c\xbc\xed\xe1";
const int PKT_LEN = 12;
struct key sha1;
memcpy(&sha1.key_seq, "sha1key", sha1.key_len);
memcpy(&sha1.type, "SHA1", 5);
- TEST_ASSERT_TRUE(auth_md5((char*)PKT_DATA, PKT_LEN, SHA1_LENGTH, &sha1));
+ TEST_ASSERT_TRUE(auth_md5(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
- * the last bit to make sure verification fails. */
+test_VerifyFailure(void)
+{
+ /* We use a copy of the MD5 verification code, but modify the
+ * last bit to make sure verification fails.
+ */
const char* PKT_DATA =
- "sometestdata" // Data
- "\0\0\0\0" // Key-ID (unused)
- "\xc7\x58\x99\xdd\x99\x32\x0f\x71" // MAC
- "\x2b\x7b\xfe\x4f\xa2\x32\xcf\x00"; // Last byte is wrong!
+ "sometestdata" /* Data */
+ "\0\0\0\0" /* Key-ID (unused) */
+ "\xc7\x58\x99\xdd\x99\x32\x0f\x71" /* MAC */
+ "\x2b\x7b\xfe\x4f\xa2\x32\xcf\x00"; /* Last byte is wrong! */
const int PKT_LEN = 12;
struct key md5;
memcpy(&md5.key_seq, "md5key", md5.key_len);
memcpy(&md5.type, "MD5", 4);
- TEST_ASSERT_FALSE(auth_md5((char*)PKT_DATA, PKT_LEN, MD5_LENGTH, &md5));
+ TEST_ASSERT_FALSE(auth_md5(PKT_DATA, PKT_LEN, MD5_LENGTH, &md5));
}
void
-test_PacketSizeNotMultipleOfFourBytes(void) {
+test_PacketSizeNotMultipleOfFourBytes(void)
+{
const char* PKT_DATA = "123456";
const int PKT_LEN = 6;
char actual[MD5_LENGTH];
memcpy(&md5.key_seq, "md5seq", md5.key_len);
memcpy(&md5.type, "MD5", 4);
- TEST_ASSERT_EQUAL(0, make_mac((char*)PKT_DATA, PKT_LEN, MD5_LENGTH, &md5, actual));
+ TEST_ASSERT_EQUAL(0, make_mac(PKT_DATA, PKT_LEN, MD5_LENGTH, &md5, actual));
}
#include "stdlib.h"
#include "sntptest.h"
-#include "fileHandlingTest.h" //required because of the h.in thingy
+#include "fileHandlingTest.h" /* required because of the h.in thingy */
#include <string.h>
#include <unistd.h>
-/*
-enum DirectoryType {
- INPUT_DIR = 0,
- OUTPUT_DIR = 1
-};
-*/
-//extern const char srcdir[];
-
const char *
-CreatePath(const char* filename, enum DirectoryType argument) {
- const char srcdir[] = SRCDIR_DEF;//"@abs_srcdir@/data/";
- char * path = emalloc (sizeof (char) * (strlen(srcdir) + 256));
-
- //char cwd[1024];
+CreatePath(
+ const char * filename,
+ enum DirectoryType argument
+ )
+{
+ const char srcdir[] = SRCDIR_DEF;//"@abs_srcdir@/data/";
+ size_t plen = sizeof(srcdir) + strlen(filename) + 1;
+ char * path = emalloc(plen);
+ ssize_t retc;
+
+ UNUSED_ARG(argument);
+
+ retc = snprintf(path, plen, "%s%s", srcdir, filename);
+ if (retc <= 0 || (size_t)retc >= plen)
+ exit(1);
+ return path;
+}
- strcpy(path, srcdir);
- strcat(path, filename);
- return path;
+void
+DestroyPath(
+ const char * pathname
+ )
+{
+ /* use a union to get terminally rid of the 'const' attribute */
+ union {
+ const char *ccp;
+ void *vp;
+ } any;
+
+ any.ccp = pathname;
+ free(any.vp);
}
int
-GetFileSize(FILE *file) {
+GetFileSize(
+ FILE * file
+ )
+{
fseek(file, 0L, SEEK_END);
int length = ftell(file);
fseek(file, 0L, SEEK_SET);
bool
-CompareFileContent(FILE* expected, FILE* actual) {
+CompareFileContent(
+ FILE * expected,
+ FILE * actual
+ )
+{
int currentLine = 1;
char actualLine[1024];
void
-ClearFile(const char * filename) {
+ClearFile(
+ const char * filename
+ )
+{
if (!truncate(filename, 0))
exit(1);
}
-
};
#define SRCDIR_DEF "@abs_srcdir@/data/";
-//const char srcdir[] = "@abs_srcdir@/data/";
-
-const char *
-CreatePath(const char* filename, enum DirectoryType argument);
-
-
-int
-GetFileSize(FILE *file);
-
-
-bool
-CompareFileContent(FILE* expected, FILE* actual);
-
-void
-ClearFile(const char * filename) ;
+extern const char * CreatePath(const char* filename,
+ enum DirectoryType argument);
+extern void DestroyPath(const char* pathname);
+extern int GetFileSize(FILE *file);
+extern bool CompareFileContent(FILE* expected, FILE* actual);
+extern void ClearFile(const char * filename) ;
#endif // FILE_HANDLING_TEST_H
bool
-CompareKeys(struct key expected, struct key actual) {
- if (expected.key_id != actual.key_id){
- printf("Expected key_id: %d", expected.key_id);
- printf(" but was: %d\n", actual.key_id);
+CompareKeys(
+ struct key expected,
+ struct key actual
+ )
+{
+ if (expected.key_id != actual.key_id) {
+ printf("Expected key_id: %d but was: %d\n",
+ expected.key_id, actual.key_id);
return FALSE;
}
- if (expected.key_len != actual.key_len){
- printf("Expected key_len: %d", expected.key_len);
- printf(" but was: %d\n", actual.key_len);
+ if (expected.key_len != actual.key_len) {
+ printf("Expected key_len: %d but was: %d\n",
+ expected.key_len, actual.key_len);
return FALSE;
}
- if (strcmp(expected.type, actual.type) != 0){
- printf("Expected key_type: %s", expected.type);
- printf(" but was: %s\n", actual.type);
+ if (strcmp(expected.type, actual.type) != 0) {
+ printf("Expected key_type: %s but was: %s\n",
+ expected.type, actual.type);
return FALSE;
}
- if (memcmp(expected.key_seq, actual.key_seq, expected.key_len) != 0){
+ if (memcmp(expected.key_seq, actual.key_seq, expected.key_len) != 0) {
printf("Key mismatch!\n");
return FALSE;
}
bool
-CompareKeysAlternative(int key_id,
- int key_len,
- const char* type,
- const char* key_seq,
- struct key actual) {
- struct key temp;
+CompareKeysAlternative(
+ int key_id,
+ int key_len,
+ const char * type,
+ const char * key_seq,
+ struct key actual
+ )
+{
+ struct key temp;
temp.key_id = key_id;
temp.key_len = key_len;
void
-test_ReadEmptyKeyFile(void) {
- struct key* keys = NULL;
- const char *path = CreatePath("key-test-empty", INPUT_DIR);
+test_ReadEmptyKeyFile(void)
+{
+ struct key * keys = NULL;
+ const char * path = CreatePath("key-test-empty", INPUT_DIR);
TEST_ASSERT_NOT_NULL(path);
TEST_ASSERT_EQUAL(0, auth_init(path, &keys));
TEST_ASSERT_NULL(keys);
- free((void *)path);
+ DestroyPath(path);
}
void
-test_ReadASCIIKeys(void) {
- struct key* keys = NULL;
- const char *path = CreatePath("key-test-ascii", INPUT_DIR);
+test_ReadASCIIKeys(void)
+{
+ struct key * keys = NULL;
+ struct key * result = NULL;
+ const char * path = CreatePath("key-test-ascii", INPUT_DIR);
TEST_ASSERT_NOT_NULL(path);
TEST_ASSERT_EQUAL(2, auth_init(path, &keys));
TEST_ASSERT_NOT_NULL(keys);
- free((void *)path);
+ DestroyPath(path);
- struct key* result = NULL;
get_key(40, &result);
TEST_ASSERT_NOT_NULL(result);
TEST_ASSERT_TRUE(CompareKeysAlternative(40, 11, "MD5", "asciikeyTwo", *result));
void
-test_ReadHexKeys(void) {
- struct key* keys = NULL;
- const char *path = CreatePath("key-test-hex", INPUT_DIR);
+test_ReadHexKeys(void)
+{
+ struct key * keys = NULL;
+ struct key * result = NULL;
+ const char * path = CreatePath("key-test-hex", INPUT_DIR);
+ char data1[15];
+ char data2[13];
TEST_ASSERT_NOT_NULL(path);
TEST_ASSERT_EQUAL(3, auth_init(path, &keys));
TEST_ASSERT_NOT_NULL(keys);
- free((void *)path);
+ DestroyPath(path);
- struct key* result = NULL;
get_key(10, &result);
TEST_ASSERT_NOT_NULL(result);
TEST_ASSERT_TRUE(CompareKeysAlternative(10, 13, "MD5",
result = NULL;
get_key(20, &result);
TEST_ASSERT_NOT_NULL(result);
- char data1[15]; memset(data1, 0x11, 15);
+
+ memset(data1, 0x11, 15);
TEST_ASSERT_TRUE(CompareKeysAlternative(20, 15, "MD5", data1, *result));
result = NULL;
get_key(30, &result);
TEST_ASSERT_NOT_NULL(result);
- char data2[13]; memset(data2, 0x01, 13);
+
+ memset(data2, 0x01, 13);
TEST_ASSERT_TRUE(CompareKeysAlternative(30, 13, "MD5", data2, *result));
}
void
-test_ReadKeyFileWithComments(void) {
- struct key* keys = NULL;
- const char *path = CreatePath("key-test-comments", INPUT_DIR);
+test_ReadKeyFileWithComments(void)
+{
+ struct key * keys = NULL;
+ struct key * result = NULL;
+ const char * path = CreatePath("key-test-comments", INPUT_DIR);
+ char data[15];
TEST_ASSERT_NOT_NULL(path);
TEST_ASSERT_EQUAL(2, auth_init(path, &keys));
TEST_ASSERT_NOT_NULL(keys);
- free((void *)path);
+ DestroyPath(path);
- struct key* result = NULL;
get_key(10, &result);
TEST_ASSERT_NOT_NULL(result);
- char data[15]; memset(data, 0x01, 15);
+
+ memset(data, 0x01, 15);
TEST_ASSERT_TRUE(CompareKeysAlternative(10, 15, "MD5", data, *result));
result = NULL;
void
-test_ReadKeyFileWithInvalidHex(void) {
- struct key* keys = NULL;
- const char *path = CreatePath("key-test-invalid-hex", INPUT_DIR);
+test_ReadKeyFileWithInvalidHex(void)
+{
+ struct key * keys = NULL;
+ struct key * result = NULL;
+ const char * path = CreatePath("key-test-invalid-hex", INPUT_DIR);
+ char data[15];
TEST_ASSERT_NOT_NULL(path);
TEST_ASSERT_EQUAL(1, auth_init(path, &keys));
TEST_ASSERT_NOT_NULL(keys);
- free((void *)path);
+ DestroyPath(path);
- struct key* result = NULL;
get_key(10, &result);
TEST_ASSERT_NOT_NULL(result);
- char data[15]; memset(data, 0x01, 15);
+
+ memset(data, 0x01, 15);
TEST_ASSERT_TRUE(CompareKeysAlternative(10, 15, "MD5", data, *result));
result = NULL;
- get_key(30, &result); // Should not exist, and result should remain NULL.
+ get_key(30, &result); /* Should not exist, and result should remain NULL. */
TEST_ASSERT_NULL(result);
}
void
-setUp(void) {
+setUp(void)
+{
init_lib();
}
int
-LfpEquality(const l_fp expected, const l_fp actual) {
- if (L_ISEQU(&expected, &actual))
- return TRUE;
- else
- return FALSE;
+LfpEquality(
+ const l_fp expected,
+ const l_fp actual
+ )
+{
+ return !!(L_ISEQU(&expected, &actual));
}
void
-test_GenerateUnauthenticatedPacket(void) {
- struct pkt testpkt;
+test_GenerateUnauthenticatedPacket(void)
+{
+ struct pkt testpkt;
+ struct timeval xmt;
+ l_fp expected_xmt, actual_xmt;
- struct timeval xmt;
GETTIMEOFDAY(&xmt, NULL);
xmt.tv_sec += JAN_1970;
TEST_ASSERT_EQUAL(STRATUM_UNSPEC, PKT_TO_STRATUM(testpkt.stratum));
TEST_ASSERT_EQUAL(8, testpkt.ppoll);
- l_fp expected_xmt, actual_xmt;
TVTOTS(&xmt, &expected_xmt);
NTOHL_FP(&testpkt.xmt, &actual_xmt);
TEST_ASSERT_TRUE(LfpEquality(expected_xmt, actual_xmt));
void
-test_GenerateAuthenticatedPacket(void) {
- struct key testkey;
+test_GenerateAuthenticatedPacket(void)
+{
+ static const int EXPECTED_PKTLEN = LEN_PKT_NOMAC + MAX_MD5_LEN;
+
+ struct key testkey;
+ struct pkt testpkt;
+ struct timeval xmt;
+ l_fp expected_xmt, actual_xmt;
+ char expected_mac[MAX_MD5_LEN];
+
testkey.next = NULL;
testkey.key_id = 30;
testkey.key_len = 9;
memcpy(testkey.key_seq, "123456789", testkey.key_len);
memcpy(testkey.type, "MD5", 3);
- struct pkt testpkt;
-
- struct timeval xmt;
GETTIMEOFDAY(&xmt, NULL);
xmt.tv_sec += JAN_1970;
- const int EXPECTED_PKTLEN = LEN_PKT_NOMAC + MAX_MD5_LEN;
-
TEST_ASSERT_EQUAL(EXPECTED_PKTLEN,
generate_pkt(&testpkt, &xmt, testkey.key_id, &testkey));
TEST_ASSERT_EQUAL(STRATUM_UNSPEC, PKT_TO_STRATUM(testpkt.stratum));
TEST_ASSERT_EQUAL(8, testpkt.ppoll);
- l_fp expected_xmt, actual_xmt;
TVTOTS(&xmt, &expected_xmt);
NTOHL_FP(&testpkt.xmt, &actual_xmt);
TEST_ASSERT_TRUE(LfpEquality(expected_xmt, actual_xmt));
TEST_ASSERT_EQUAL(testkey.key_id, ntohl(testpkt.exten[0]));
- char expected_mac[MAX_MD5_LEN];
- TEST_ASSERT_EQUAL(MAX_MD5_LEN - 4, // Remove the key_id, only keep the mac.
- make_mac((char*)&testpkt, LEN_PKT_NOMAC, MAX_MD5_LEN, &testkey, expected_mac));
+ TEST_ASSERT_EQUAL(MAX_MD5_LEN - 4, /* Remove the key_id, only keep the mac. */
+ make_mac(&testpkt, LEN_PKT_NOMAC, MAX_MD5_LEN, &testkey, expected_mac));
TEST_ASSERT_EQUAL_MEMORY(expected_mac, (char*)&testpkt.exten[1], MAX_MD5_LEN -4);
}
void
-test_OffsetCalculationPositiveOffset(void) {
- struct pkt rpkt;
-
- rpkt.precision = -16; // 0,000015259
+test_OffsetCalculationPositiveOffset(void)
+{
+ struct pkt rpkt;
+ l_fp reftime, tmp;
+ struct timeval dst;
+ double offset, precision, synch_distance;
+
+ rpkt.precision = -16; /* 0,000015259 */
rpkt.rootdelay = HTONS_FP(DTOUFP(0.125));
rpkt.rootdisp = HTONS_FP(DTOUFP(0.25));
- // Synch Distance: (0.125+0.25)/2.0 == 0.1875
- l_fp reftime;
+
+ /* Synch Distance: (0.125+0.25)/2.0 == 0.1875 */
get_systime(&reftime);
HTONL_FP(&reftime, &rpkt.reftime);
- l_fp tmp;
-
- // T1 - Originate timestamp
+ /* T1 - Originate timestamp */
tmp.l_ui = 1000000000UL;
tmp.l_uf = 0UL;
HTONL_FP(&tmp, &rpkt.org);
- // T2 - Receive timestamp
+ /* T2 - Receive timestamp */
tmp.l_ui = 1000000001UL;
tmp.l_uf = 2147483648UL;
HTONL_FP(&tmp, &rpkt.rec);
- // T3 - Transmit timestamp
+ /* T3 - Transmit timestamp */
tmp.l_ui = 1000000002UL;
tmp.l_uf = 0UL;
HTONL_FP(&tmp, &rpkt.xmt);
- // T4 - Destination timestamp as standard timeval
+ /* T4 - Destination timestamp as standard timeval */
tmp.l_ui = 1000000001UL;
tmp.l_uf = 0UL;
- struct timeval dst;
TSTOTV(&tmp, &dst);
dst.tv_sec -= JAN_1970;
- double offset, precision, synch_distance;
offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &synch_distance);
TEST_ASSERT_EQUAL_DOUBLE(1.25, offset);
TEST_ASSERT_EQUAL_DOUBLE(1. / ULOGTOD(16), precision);
- // 1.1250150000000001 ?
+ /* 1.1250150000000001 ? */
TEST_ASSERT_EQUAL_DOUBLE(1.125015, synch_distance);
}
void
-test_OffsetCalculationNegativeOffset(void) {
- struct pkt rpkt;
+test_OffsetCalculationNegativeOffset(void)
+{
+ struct pkt rpkt;
+ l_fp reftime, tmp;
+ struct timeval dst;
+ double offset, precision, synch_distance;
rpkt.precision = -1;
rpkt.rootdelay = HTONS_FP(DTOUFP(0.5));
rpkt.rootdisp = HTONS_FP(DTOUFP(0.5));
- // Synch Distance is (0.5+0.5)/2.0, or 0.5
- l_fp reftime;
+
+ /* Synch Distance is (0.5+0.5)/2.0, or 0.5 */
get_systime(&reftime);
HTONL_FP(&reftime, &rpkt.reftime);
- l_fp tmp;
-
- // T1 - Originate timestamp
+ /* T1 - Originate timestamp */
tmp.l_ui = 1000000001UL;
tmp.l_uf = 0UL;
HTONL_FP(&tmp, &rpkt.org);
- // T2 - Receive timestamp
+ /* T2 - Receive timestamp */
tmp.l_ui = 1000000000UL;
tmp.l_uf = 2147483648UL;
HTONL_FP(&tmp, &rpkt.rec);
- // T3 - Transmit timestamp
+ /*/ T3 - Transmit timestamp */
tmp.l_ui = 1000000001UL;
tmp.l_uf = 2147483648UL;
HTONL_FP(&tmp, &rpkt.xmt);
- // T4 - Destination timestamp as standard timeval
+ /* T4 - Destination timestamp as standard timeval */
tmp.l_ui = 1000000003UL;
tmp.l_uf = 0UL;
- struct timeval dst;
+
TSTOTV(&tmp, &dst);
dst.tv_sec -= JAN_1970;
- double offset, precision, synch_distance;
offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &synch_distance);
TEST_ASSERT_EQUAL_DOUBLE(-1, offset);
void
-test_HandleUnusableServer(void) {
- struct pkt rpkt;
+test_HandleUnusableServer(void)
+{
+ struct pkt rpkt;
sockaddr_u host;
int rpktl;
void
-test_HandleUnusablePacket(void) {
- struct pkt rpkt;
+test_HandleUnusablePacket(void)
+{
+ struct pkt rpkt;
sockaddr_u host;
int rpktl;
void
-test_HandleServerAuthenticationFailure(void) {
- struct pkt rpkt;
+test_HandleServerAuthenticationFailure(void)
+{
+ struct pkt rpkt;
sockaddr_u host;
int rpktl;
void
-test_HandleKodDemobilize(void) {
- const char * HOSTNAME = "192.0.2.1";
- const char * REASON = "DENY";
+test_HandleKodDemobilize(void)
+{
+ static const char * HOSTNAME = "192.0.2.1";
+ static const char * REASON = "DENY";
struct pkt rpkt;
- sockaddr_u host;
- int rpktl;
+ sockaddr_u host;
+ int rpktl;
struct kod_entry * entry;
rpktl = KOD_DEMOBILIZE;
host.sa4.sin_family = AF_INET;
host.sa4.sin_addr.s_addr = inet_addr(HOSTNAME);
- // Test that the KOD-entry is added to the database.
+ /* Test that the KOD-entry is added to the database. */
kod_init_kod_db("/dev/null", TRUE);
TEST_ASSERT_EQUAL(1, handle_pkt(rpktl, &rpkt, &host, HOSTNAME));
void
-test_HandleKodRate(void) {
- struct pkt rpkt;
+test_HandleKodRate(void)
+{
+ struct pkt rpkt;
sockaddr_u host;
int rpktl;
void
-test_HandleCorrectPacket(void) {
- struct pkt rpkt;
+test_HandleCorrectPacket(void)
+{
+ struct pkt rpkt;
sockaddr_u host;
int rpktl;
l_fp now;
- // We don't want our testing code to actually change the system clock.
+ /* We don't want our testing code to actually change the system clock. */
TEST_ASSERT_FALSE(ENABLED_OPT(STEP));
TEST_ASSERT_FALSE(ENABLED_OPT(SLEW));
#include "config.h"
+
+/* need autokey for some of the tests, or the will create buffer overruns. */
+#ifndef AUTOKEY
+# define AUTOKEY 1
+#endif
+
#include "sntptest.h"
#include "networking.h"
#include "ntp_stdlib.h"
void
-PrepareAuthenticationTest(int key_id,
- int key_len,
- const char* type,
- const void* key_seq) {
+PrepareAuthenticationTest(
+ int key_id,
+ int key_len,
+ const char * type,
+ const void * key_seq
+ )
+{
char str[25];
snprintf(str, 25, "%d", key_id);
ActivateOption("-a", str);
void
-PrepareAuthenticationTestMD5(int key_id,
- int key_len,
- const void* key_seq) {
+PrepareAuthenticationTestMD5(
+ int key_id,
+ int key_len,
+ const void * key_seq
+ )
+{
PrepareAuthenticationTest(key_id, key_len, "MD5", key_seq);
}
void
-setUp(void) {
+setUp(void)
+{
sntptest();
restoreKeyDb = false;
/* Initialize the test packet and socket,
- * so they contain at least some valid data. */
+ * so they contain at least some valid data.
+ */
testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING, NTP_VERSION,
MODE_SERVER);
testpkt.stratum = STRATUM_REFCLOCK;
memcpy(&testpkt.refid, "GPS\0", 4);
/* Set the origin timestamp of the received packet to the
- * same value as the transmit timestamp of the sent packet. */
+ * same value as the transmit timestamp of the sent packet.
+ */
l_fp tmp;
tmp.l_ui = 1000UL;
tmp.l_uf = 0UL;
void
-tearDown(void) {
-
+tearDown(void)
+{
if (restoreKeyDb) {
key_cnt = 0;
free(key_ptr);
key_ptr = NULL;
}
- sntptest_destroy(); //only on the final test!! if counter == 0 etc...
+ sntptest_destroy(); /* only on the final test!! if counter == 0 etc... */
}
-
void
-test_TooShortLength(void) {
+test_TooShortLength(void)
+{
TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC - 1,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC - 1,
- MODE_BROADCAST, &testspkt, "UnitTest"));
+ MODE_BROADCAST, &testspkt, "UnitTest"));
}
void
-test_LengthNotMultipleOfFour(void) {
+test_LengthNotMultipleOfFour(void)
+{
TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC + 6,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC + 3,
- MODE_BROADCAST, &testspkt, "UnitTest"));
+ MODE_BROADCAST, &testspkt, "UnitTest"));
}
void
-test_TooShortExtensionFieldLength(void) {
+test_TooShortExtensionFieldLength(void)
+{
/* The lower 16-bits are the length of the extension field.
* This lengths must be multiples of 4 bytes, which gives
- * a minimum of 4 byte extension field length. */
- testpkt.exten[7] = htonl(3); // 3 bytes is too short.
+ * a minimum of 4 byte extension field length.
+ */
+ testpkt.exten[7] = htonl(3); /* 3 bytes is too short. */
/* We send in a pkt_len of header size + 4 byte extension
* header + 24 byte MAC, this prevents the length error to
- * be caught at an earlier stage */
+ * be caught at an earlier stage
+ */
int pkt_len = LEN_PKT_NOMAC + 4 + 24;
TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
process_pkt(&testpkt, &testsock, pkt_len,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_UnauthenticatedPacketReject(void) {
- //sntptest();
- // Activate authentication option
+test_UnauthenticatedPacketReject(void)
+{
+ /* Activate authentication option */
ActivateOption("-a", "123");
TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
int pkt_len = LEN_PKT_NOMAC;
- // We demand authentication, but no MAC header is present.
+ /* We demand authentication, but no MAC header is present. */
TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
process_pkt(&testpkt, &testsock, pkt_len,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_CryptoNAKPacketReject(void) {
- // Activate authentication option
+test_CryptoNAKPacketReject(void)
+{
+ /* Activate authentication option */
ActivateOption("-a", "123");
TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
- int pkt_len = LEN_PKT_NOMAC + 4; // + 4 byte MAC = Crypto-NAK
+ int pkt_len = LEN_PKT_NOMAC + 4; /* + 4 byte MAC = Crypto-NAK */
TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
process_pkt(&testpkt, &testsock, pkt_len,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_AuthenticatedPacketInvalid(void) {
- // Activate authentication option
+test_AuthenticatedPacketInvalid(void)
+{
+ /* Activate authentication option */
PrepareAuthenticationTestMD5(50, 9, "123456789");
TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
- // Prepare the packet.
+ /* Prepare the packet. */
int pkt_len = LEN_PKT_NOMAC;
testpkt.exten[0] = htonl(50);
- int mac_len = make_mac((char*)&testpkt, pkt_len,
- MAX_MD5_LEN, key_ptr,
- (char*)&testpkt.exten[1]);
+ int mac_len = make_mac(&testpkt, pkt_len,
+ MAX_MD5_LEN, key_ptr,
+ &testpkt.exten[1]);
pkt_len += 4 + mac_len;
- // Now, alter the MAC so it becomes invalid.
+ /* Now, alter the MAC so it becomes invalid. */
testpkt.exten[1] += 1;
TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
process_pkt(&testpkt, &testsock, pkt_len,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_AuthenticatedPacketUnknownKey(void) {
- // Activate authentication option
+test_AuthenticatedPacketUnknownKey(void)
+{
+ /* Activate authentication option */
PrepareAuthenticationTestMD5(30, 9, "123456789");
TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
- // Prepare the packet. Observe that the Key-ID expected is 30,
- // but the packet has a key id of 50.
+ /* Prepare the packet. Note that the Key-ID expected is 30, but
+ * the packet has a key id of 50.
+ */
int pkt_len = LEN_PKT_NOMAC;
testpkt.exten[0] = htonl(50);
- int mac_len = make_mac((char*)&testpkt, pkt_len,
- MAX_MD5_LEN, key_ptr,
- (char*)&testpkt.exten[1]);
+ int mac_len = make_mac(&testpkt, pkt_len,
+ MAX_MD5_LEN, key_ptr,
+ &testpkt.exten[1]);
pkt_len += 4 + mac_len;
TEST_ASSERT_EQUAL(SERVER_AUTH_FAIL,
process_pkt(&testpkt, &testsock, pkt_len,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_ServerVersionTooOld(void) {
+test_ServerVersionTooOld(void)
+{
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
- NTP_OLDVERSION - 1,
- MODE_CLIENT);
+ NTP_OLDVERSION - 1,
+ MODE_CLIENT);
TEST_ASSERT_TRUE(PKT_VERSION(testpkt.li_vn_mode) < NTP_OLDVERSION);
int pkt_len = LEN_PKT_NOMAC;
TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
process_pkt(&testpkt, &testsock, pkt_len,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_ServerVersionTooNew(void) {
+test_ServerVersionTooNew(void)
+{
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
- NTP_VERSION + 1,
- MODE_CLIENT);
+ NTP_VERSION + 1,
+ MODE_CLIENT);
TEST_ASSERT_TRUE(PKT_VERSION(testpkt.li_vn_mode) > NTP_VERSION);
int pkt_len = LEN_PKT_NOMAC;
TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
process_pkt(&testpkt, &testsock, pkt_len,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_NonWantedMode(void) {
+test_NonWantedMode(void)
+{
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
- NTP_VERSION,
- MODE_CLIENT);
-
- // The packet has a mode of MODE_CLIENT, but process_pkt expects MODE_SERVER
+ NTP_VERSION,
+ MODE_CLIENT);
+ /* The packet has a mode of MODE_CLIENT, but process_pkt expects
+ * MODE_SERVER
+ */
TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
/* Tests bug 1597 */
void
-test_KoDRate(void) {
+test_KoDRate(void)
+{
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.stratum = STRATUM_PKT_UNSPEC;
TEST_ASSERT_EQUAL(KOD_RATE,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_KoDDeny(void) {
+test_KoDDeny(void)
+{
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.stratum = STRATUM_PKT_UNSPEC;
TEST_ASSERT_EQUAL(KOD_DEMOBILIZE,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_RejectUnsyncedServer(void) {
+test_RejectUnsyncedServer(void)
+{
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC,
- NTP_VERSION,
- MODE_SERVER);
+ NTP_VERSION,
+ MODE_SERVER);
TEST_ASSERT_EQUAL(SERVER_UNUSEABLE,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_RejectWrongResponseServerMode(void) {
+test_RejectWrongResponseServerMode(void)
+{
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
l_fp tmp;
TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_AcceptNoSentPacketBroadcastMode(void) {
+test_AcceptNoSentPacketBroadcastMode(void)
+{
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
void
-test_CorrectUnauthenticatedPacket(void) {
+test_CorrectUnauthenticatedPacket(void)
+{
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
TEST_ASSERT_EQUAL(LEN_PKT_NOMAC,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_CorrectAuthenticatedPacketMD5(void) {
+test_CorrectAuthenticatedPacketMD5(void)
+{
PrepareAuthenticationTestMD5(10, 15, "123456789abcdef");
TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
int pkt_len = LEN_PKT_NOMAC;
- // Prepare the packet.
+ /* Prepare the packet. */
testpkt.exten[0] = htonl(10);
- int mac_len = make_mac((char*)&testpkt, pkt_len,
- MAX_MD5_LEN, key_ptr,
- (char*)&testpkt.exten[1]);
+ int mac_len = make_mac(&testpkt, pkt_len,
+ MAX_MD5_LEN, key_ptr,
+ &testpkt.exten[1]);
pkt_len += 4 + mac_len;
TEST_ASSERT_EQUAL(pkt_len,
process_pkt(&testpkt, &testsock, pkt_len,
- MODE_SERVER, &testspkt, "UnitTest"));
-
+ MODE_SERVER, &testspkt, "UnitTest"));
}
void
-test_CorrectAuthenticatedPacketSHA1(void) {
+test_CorrectAuthenticatedPacketSHA1(void)
+{
PrepareAuthenticationTest(20, 15, "SHA1", "abcdefghijklmno");
TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
int pkt_len = LEN_PKT_NOMAC;
- // Prepare the packet.
+ /* Prepare the packet. */
testpkt.exten[0] = htonl(20);
- int mac_len = make_mac((char*)&testpkt, pkt_len,
- MAX_MAC_LEN, key_ptr,
- (char*)&testpkt.exten[1]);
+ int mac_len = make_mac(&testpkt, pkt_len,
+ MAX_MAC_LEN, key_ptr,
+ &testpkt.exten[1]);
pkt_len += 4 + mac_len;
TEST_ASSERT_EQUAL(pkt_len,
process_pkt(&testpkt, &testsock, pkt_len,
- MODE_SERVER, &testspkt, "UnitTest"));
+ MODE_SERVER, &testspkt, "UnitTest"));
}
{
progname = argv[0];
UnityBegin("packetProcessing.c");
- RUN_TEST(test_TooShortLength, 19);
- RUN_TEST(test_LengthNotMultipleOfFour, 20);
- RUN_TEST(test_TooShortExtensionFieldLength, 21);
- RUN_TEST(test_UnauthenticatedPacketReject, 22);
- RUN_TEST(test_CryptoNAKPacketReject, 23);
- RUN_TEST(test_AuthenticatedPacketInvalid, 24);
- RUN_TEST(test_AuthenticatedPacketUnknownKey, 25);
- RUN_TEST(test_ServerVersionTooOld, 26);
- RUN_TEST(test_ServerVersionTooNew, 27);
- RUN_TEST(test_NonWantedMode, 28);
- RUN_TEST(test_KoDRate, 29);
- RUN_TEST(test_KoDDeny, 30);
- RUN_TEST(test_RejectUnsyncedServer, 31);
- RUN_TEST(test_RejectWrongResponseServerMode, 32);
- RUN_TEST(test_AcceptNoSentPacketBroadcastMode, 33);
- RUN_TEST(test_CorrectUnauthenticatedPacket, 34);
- RUN_TEST(test_CorrectAuthenticatedPacketMD5, 35);
- RUN_TEST(test_CorrectAuthenticatedPacketSHA1, 36);
+ RUN_TEST(test_TooShortLength, 25);
+ RUN_TEST(test_LengthNotMultipleOfFour, 26);
+ RUN_TEST(test_TooShortExtensionFieldLength, 27);
+ RUN_TEST(test_UnauthenticatedPacketReject, 28);
+ RUN_TEST(test_CryptoNAKPacketReject, 29);
+ RUN_TEST(test_AuthenticatedPacketInvalid, 30);
+ RUN_TEST(test_AuthenticatedPacketUnknownKey, 31);
+ RUN_TEST(test_ServerVersionTooOld, 32);
+ RUN_TEST(test_ServerVersionTooNew, 33);
+ RUN_TEST(test_NonWantedMode, 34);
+ RUN_TEST(test_KoDRate, 35);
+ RUN_TEST(test_KoDDeny, 36);
+ RUN_TEST(test_RejectUnsyncedServer, 37);
+ RUN_TEST(test_RejectWrongResponseServerMode, 38);
+ RUN_TEST(test_AcceptNoSentPacketBroadcastMode, 39);
+ RUN_TEST(test_CorrectUnauthenticatedPacket, 40);
+ RUN_TEST(test_CorrectAuthenticatedPacketMD5, 41);
+ RUN_TEST(test_CorrectAuthenticatedPacketSHA1, 42);
return (UnityEnd());
}
#define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_UP)(expected), (_U_SINT)(_UP)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER)
#define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)line)
-#define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((UNITY_PTR_ATTRIBUTE void*)(expected), (UNITY_PTR_ATTRIBUTE void*)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line)
+#define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((UNITY_PTR_ATTRIBUTE const void*)(expected), (UNITY_PTR_ATTRIBUTE const void*)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line)
#define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_PTR_ATTRIBUTE const void*)(expected), (UNITY_PTR_ATTRIBUTE const void*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
#define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_PTR_ATTRIBUTE const void*)(expected), (UNITY_PTR_ATTRIBUTE const void*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT8)
void setUp(void);
extern void test_IPv4AddressOnly(void);
extern void test_IPv4AddressWithPort(void);
-//#ifdef ISC_PLATFORM_HAVEIPV6
extern void test_IPv6AddressOnly(void);
extern void test_IPv6AddressWithPort(void);
-//#endif /* ISC_PLATFORM_HAVEIPV6 */
extern void test_IllegalAddress(void);
extern void test_IllegalCharInPort(void);
-
+/*
+ * NOTE: The IPv6 specific tests are reduced to stubs when IPv6 is
+ * disabled.
+ *
+ * ISC_PLATFORM_HAVEIPV6 checks if system has IPV6 capabilies. WANTIPV6
+ * ISC_PLATFORM_WANTIPV6 can be changed with build --disable-ipv6.
+ *
+ * If we want IPv6 but don't have it, the tests should fail, I think.
+ */
void
setUp(void)
{
init_lib();
-
- return;
}
void
-test_IPv4AddressOnly(void) {
+test_IPv4AddressOnly(void)
+{
const char *str = "192.0.2.1";
sockaddr_u actual;
}
void
-test_IPv4AddressWithPort(void) {
+test_IPv4AddressWithPort(void)
+{
const char *str = "192.0.2.2:2000";
sockaddr_u actual;
void
-test_IPv6AddressOnly(void) {
-
-//#ifdef ISC_PLATFORM_HAVEIPV6 //looks like HAVEIPV6 checks if system has IPV6 capabilies. WANTIPV6 can be changed with build --disable-ipv6
+test_IPv6AddressOnly(void)
+{
#ifdef ISC_PLATFORM_WANTIPV6
+
const struct in6_addr address = {
0x20, 0x01, 0x0d, 0xb8,
- 0x85, 0xa3, 0x08, 0xd3,
- 0x13, 0x19, 0x8a, 0x2e,
- 0x03, 0x70, 0x73, 0x34
+ 0x85, 0xa3, 0x08, 0xd3,
+ 0x13, 0x19, 0x8a, 0x2e,
+ 0x03, 0x70, 0x73, 0x34
};
const char *str = "2001:0db8:85a3:08d3:1319:8a2e:0370:7334";
TEST_ASSERT_TRUE(IsEqual(expected, actual));
#else
+
TEST_IGNORE_MESSAGE("IPV6 disabled in build, skipping.");
+
#endif /* ISC_PLATFORM_HAVEIPV6 */
-
-
}
-
void
-test_IPv6AddressWithPort(void) {
-
+test_IPv6AddressWithPort(void)
+{
#ifdef ISC_PLATFORM_WANTIPV6
const struct in6_addr address = {
0x20, 0x01, 0x0d, 0xb8,
- 0x85, 0xa3, 0x08, 0xd3,
- 0x13, 0x19, 0x8a, 0x2e,
- 0x03, 0x70, 0x73, 0x34
+ 0x85, 0xa3, 0x08, 0xd3,
+ 0x13, 0x19, 0x8a, 0x2e,
+ 0x03, 0x70, 0x73, 0x34
};
const char *str = "[2001:0db8:85a3:08d3:1319:8a2e:0370:7334]:3000";
TEST_ASSERT_TRUE(IsEqual(expected, actual));
#else
+
TEST_IGNORE_MESSAGE("IPV6 disabled in build, skipping.");
+
#endif /* ISC_PLATFORM_HAVEIPV6 */
}
void
-test_IllegalAddress(void) {
+test_IllegalAddress(void)
+{
const char *str = "192.0.2.270:2000";
sockaddr_u actual;
TEST_ASSERT_FALSE(decodenetnum(str, &actual));
}
+
void
-test_IllegalCharInPort(void) {
+test_IllegalCharInPort(void)
+{
/* An illegal port does not make the decodenetnum fail, but instead
* makes it use the standard port.
*/
UnityBegin("decodenetnum.c");
RUN_TEST(test_IPv4AddressOnly, 8);
RUN_TEST(test_IPv4AddressWithPort, 9);
- RUN_TEST(test_IPv6AddressOnly, 11);
- RUN_TEST(test_IPv6AddressWithPort, 12);
- RUN_TEST(test_IllegalAddress, 14);
- RUN_TEST(test_IllegalCharInPort, 15);
+ RUN_TEST(test_IPv6AddressOnly, 10);
+ RUN_TEST(test_IPv6AddressWithPort, 11);
+ RUN_TEST(test_IllegalAddress, 12);
+ RUN_TEST(test_IllegalCharInPort, 13);
return (UnityEnd());
}
progname = argv[0];
UnityBegin("socktoa.c");
RUN_TEST(test_IPv4AddressWithPort, 11);
- RUN_TEST(test_IPv6AddressWithPort, 13);
- RUN_TEST(test_IgnoreIPv6Fields, 14);
- RUN_TEST(test_ScopedIPv6AddressWithPort, 16);
- RUN_TEST(test_HashEqual, 17);
- RUN_TEST(test_HashNotEqual, 18);
+ RUN_TEST(test_IPv6AddressWithPort, 12);
+ RUN_TEST(test_IgnoreIPv6Fields, 13);
+ RUN_TEST(test_ScopedIPv6AddressWithPort, 14);
+ RUN_TEST(test_HashEqual, 15);
+ RUN_TEST(test_HashNotEqual, 16);
return (UnityEnd());
}
void setUp(void);
void test_IPv4AddressWithPort(void);
-//#ifdef ISC_PLATFORM_HAVEIPV6
void test_IPv6AddressWithPort(void);
void test_IgnoreIPv6Fields(void);
-//#endif /* ISC_PLATFORM_HAVEIPV6 */
void test_ScopedIPv6AddressWithPort(void);
void test_HashEqual(void);
void test_HashNotEqual(void);
setUp(void)
{
init_lib();
-
- return;
}
void
-test_IPv4AddressWithPort(void) {
+test_IPv4AddressWithPort(void)
+{
sockaddr_u input = CreateSockaddr4("192.0.2.10", 123);
TEST_ASSERT_EQUAL_STRING("192.0.2.10", socktoa(&input));
void
-test_IPv6AddressWithPort(void) {
-
+test_IPv6AddressWithPort(void)
+{
#ifdef ISC_PLATFORM_WANTIPV6
const struct in6_addr address = {
TEST_ASSERT_EQUAL_STRING(expected_port, sockporttoa(&input));
#else
+
TEST_IGNORE_MESSAGE("IPV6 disabled in build, skipping.");
#endif /* ISC_PLATFORM_HAVEIPV6 */
-
}
void
-test_ScopedIPv6AddressWithPort(void) {
+test_ScopedIPv6AddressWithPort(void)
+{
#ifdef ISC_PLATFORM_HAVESCOPEID
+
const struct in6_addr address = { { {
0xfe, 0x80, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
TEST_ASSERT_EQUAL_STRING(expected, socktoa(&input));
TEST_ASSERT_EQUAL_STRING(expected_port, sockporttoa(&input));
#else
+
TEST_IGNORE_MESSAGE("Skipping because ISC_PLATFORM does not have Scope ID");
+
#endif
}
+
void
-test_HashEqual(void) {
+test_HashEqual(void)
+{
sockaddr_u input1 = CreateSockaddr4("192.00.2.2", 123);
sockaddr_u input2 = CreateSockaddr4("192.0.2.2", 123);
TEST_ASSERT_EQUAL(sock_hash(&input1), sock_hash(&input2));
}
+
void
-test_HashNotEqual(void) {
+test_HashNotEqual(void)
+{
/* These two addresses should not generate the same hash. */
sockaddr_u input1 = CreateSockaddr4("192.0.2.1", 123);
sockaddr_u input2 = CreateSockaddr4("192.0.2.2", 123);
void
-test_IgnoreIPv6Fields(void) {
-
+test_IgnoreIPv6Fields(void)
+{
#ifdef ISC_PLATFORM_WANTIPV6
const struct in6_addr address = {
0x20, 0x01, 0x0d, 0xb8,
- 0x85, 0xa3, 0x08, 0xd3,
- 0x13, 0x19, 0x8a, 0x2e,
- 0x03, 0x70, 0x73, 0x34
+ 0x85, 0xa3, 0x08, 0xd3,
+ 0x13, 0x19, 0x8a, 0x2e,
+ 0x03, 0x70, 0x73, 0x34
};
sockaddr_u input1, input2;
TEST_ASSERT_EQUAL(sock_hash(&input1), sock_hash(&input2));
#else
+
TEST_IGNORE_MESSAGE("IPV6 disabled in build, skipping.");
+
#endif /* ISC_PLATFORM_HAVEIPV6 */
}
-