* tests/ntpd/ function parameter list cleanup. Damir Tomić.
* sntp/unity/unity_config.h: handle stdint.h. Harlan Stenn.
* sntp/unity/unity_internals.h: handle *INTPTR_MAX on old Solaris. H.Stenn.
-* tests/libntp/timevalops.c and timespecops.c fixd error printing. D.Tomić.
+* tests/libntp/timevalops.c and timespecops.c fixed error printing. D.Tomić.
* tests/libntp/ improvements in code and fixed error printing. Damir Tomić.
* tests/libntp: a_md5encrypt.c, authkeys.c, buftvtots.c, calendar.c, caljulian.c,
caltontp.c, clocktime.c, humandate.c, hextolfp.c, decodenetnum.c - fixed
* tests/libntp/vi64ops.c removed an unnecessary comment, fixed formatting.
* tests/libntp/ymd3yd.c removed an empty function and an unnecessary include,
fixed formatting. Tomasz Flendrich
+* tests/libntp/timespecops.c fixed formatting, fixed the order of includes,
+ removed unnecessary comments, cleanup. Tomasz Flendrich
+* tests/libntp/timevalops.c fixed the order of includes, deleted unnecessary
+ comments, cleanup. Tomasz Flendrich
+* tests/libntp/sockaddrtest.h making it agree to NTP's conventions of formatting.
+ Tomasz Flendrich
+* tests/libntp/lfptest.h cleanup. Tomasz Flendrich
+* tests/libntp/test-libntp.c fix formatting. Tomasz Flendrich
+* sntp/tests/crypto.c is now using proper Unity's assertions, fixed formatting.
+ Tomasz Flendrich
+* sntp/tests/kodDatabase.c added consts, deleted empty function,
+ fixed formatting. Tomasz Flendrich
+* sntp/tests/kodFile.c cleanup, fixed formatting. Tomasz Flendrich
+* sntp/tests/packetHandling.c is now using proper Unity's assertions,
+ fixed formatting, deleted unused variable. Tomasz Flendrich
+* sntp/tests/keyFile.c is now using proper Unity's assertions, fixed formatting.
+ Tomasz Flendrich
+* sntp/tests/packetProcessing.c changed from sprintf to snprintf,
+ fixed formatting. Tomasz Flendrich
+* sntp/tests/utilities.c is now using proper Unity's assertions, changed
+ the order of includes, fixed formatting, removed unnecessary comments.
+ Tomasz Flendrich
+* sntp/tests/sntptest.h fixed formatting. Tomasz Flendrich
+* sntp/tests/fileHandlingTest.h.in fixed a possible buffer overflow problem,
+ made one function do its job, deleted unnecessary prints, fixed formatting.
+ Tomasz Flendrich
* sntp/unity/Makefile.am added a missing header. Tomasz Flendrich
* sntp/unity/unity_config.h: Distribute it. Harlan Stenn.
* sntp/libevent/evconfig-private.h: remove generated filefrom SCM. H.Stenn.
#define SHA1_LENGTH 20
-void test_MakeMd5Mac(void) {
+void
+test_MakeMd5Mac(void) {
const char* PKT_DATA = "abcdefgh0123";
const int PKT_LEN = strlen(PKT_DATA);
}
-void test_MakeSHA1Mac(void) {
+void
+test_MakeSHA1Mac(void) {
#ifdef OPENSSL
const char* PKT_DATA = "abcdefgh0123";
const int PKT_LEN = strlen(PKT_DATA);
TEST_ASSERT_EQUAL(SHA1_LENGTH,
make_mac((char*)PKT_DATA, PKT_LEN, SHA1_LENGTH, &sha1, actual));
- TEST_ASSERT_TRUE(memcmp(EXPECTED_DIGEST, actual, SHA1_LENGTH) == 0);
+ TEST_ASSERT_EQUAL_MEMORY(EXPECTED_DIGEST, actual, SHA1_LENGTH);
#else
TEST_IGNORE_MESSAGE("OpenSSL not found, skipping...");
#endif /* OPENSSL */
}
-void test_VerifyCorrectMD5(void) {
+void
+test_VerifyCorrectMD5(void) {
const char* PKT_DATA =
"sometestdata" // Data
"\0\0\0\0" // Key-ID (unused)
}
-void test_VerifySHA1(void) {
+void
+test_VerifySHA1(void) {
#ifdef OPENSSL
const char* PKT_DATA =
"sometestdata" // Data
#endif /* OPENSSL */
}
-void test_VerifyFailure(void) {
+void
+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 =
TEST_ASSERT_FALSE(auth_md5((char*)PKT_DATA, PKT_LEN, MD5_LENGTH, &md5));
}
-void test_PacketSizeNotMultipleOfFourBytes(void) {
+
+void
+test_PacketSizeNotMultipleOfFourBytes(void) {
const char* PKT_DATA = "123456";
const int PKT_LEN = 6;
char actual[MD5_LENGTH];
TEST_ASSERT_EQUAL(0, make_mac((char*)PKT_DATA, PKT_LEN, MD5_LENGTH, &md5, actual));
}
-
OUTPUT_DIR = 1
};
-const char * CreatePath(const char* filename, enum DirectoryType argument) {
-
- char * path = malloc (sizeof (char) * 256);
-
- /*
- if (m_params.size() >= argument + 1) {
- path = m_params[argument];
- }
- if (path[path.size()-1] != DIR_SEP && !path.empty()) {
- path.append(1, DIR_SEP);
- }
- */
- //strcpy(path,filename);
- //path.append(filename);
-
- //return path;
+const char *
+CreatePath(const char* filename, enum DirectoryType argument) {
+ const char srcdir[] = "@abs_srcdir@/data/";
+ char * path = malloc (sizeof (char) * (strlen(srcdir) + 256));
char cwd[1024];
- if (getcwd(cwd, sizeof(cwd)) != NULL)
- printf("Current working dir: %s\n", cwd);
-
- printf("builddir is <@builddir@>\n");
- printf("abs_srcdir is <@abs_srcdir@>\n");
- strcpy(path,"@abs_srcdir@/data/");
- //strcpy(path,"");
- strcat(path,filename);
- printf("PATH IS : %s\n",path);
+ strcpy(path, srcdir);
+ strcat(path, filename);
+
return path;
}
-int GetFileSize(FILE *file) {
+int
+GetFileSize(FILE *file) {
fseek(file, 0L, SEEK_END);
int length = ftell(file);
fseek(file, 0L, SEEK_SET);
-
- //int initial = file.tellg();
-
- //file.seekg(0, ios::end);
- //int length = file.tellg();
- //file.seekg(initial);
return length;
}
-bool CompareFileContent(FILE* expected, FILE* actual) {
+
+bool
+CompareFileContent(FILE* expected, FILE* actual) {
int currentLine = 1;
char actualLine[1024];
&& ( (fgets(expectedLine, lenExp, expected)) != NULL )
) {
- //printf("%s",actualLine);
- //printf("%s",expectedLine);
if( strcmp(actualLine,expectedLine) !=0 ){
printf("Comparision failed on line %d",currentLine);
return FALSE;
}
- //I removed this and modified the test kodFile.c, because there shouldn't be any ASSERTs in .h files!
- //TEST_ASSERT_EQUAL_STRING(actualLine,expectedLine);//EXPECT_EQ(expectedLine, actualLine) << "Comparision failed on line " << currentLine;
currentLine++;
}
return TRUE;
}
-void ClearFile(const char * filename) {
- FILE * clear = fopen(filename, "w");//ios::trunc); //similar to truncate, I GUESS???!
-
- //I removed this because there shouldn't be any ASSERTs in .h files!
- //TEST_ASSERT_TRUE(clear != NULL);
- fclose(clear);
+
+void
+ClearFile(const char * filename) {
+ if (!truncate(filename, 0))
+ exit(1);
}
#include "unity.h"
-//typedef int bool;
-
-bool CompareKeys(struct key expected, struct key actual) {
+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);
return TRUE;
}
-bool CompareKeysAlternative(int key_id,
+
+bool
+CompareKeysAlternative(int key_id,
int key_len,
const char* type,
const char* key_seq,
}
-void test_ReadEmptyKeyFile(void) {
+void
+test_ReadEmptyKeyFile(void) {
struct key* keys = NULL;
TEST_ASSERT_EQUAL(0, auth_init(CreatePath("key-test-empty", INPUT_DIR), &keys));
-
- TEST_ASSERT_TRUE(keys == NULL);
+ TEST_ASSERT_NULL(keys);
}
-void test_ReadASCIIKeys(void) {
+
+void
+test_ReadASCIIKeys(void) {
struct key* keys = NULL;
TEST_ASSERT_EQUAL(2, auth_init(CreatePath("key-test-ascii", INPUT_DIR), &keys));
- TEST_ASSERT_TRUE(keys != NULL);
+ TEST_ASSERT_NOT_NULL(keys);
struct key* result = NULL;
get_key(40, &result);
- TEST_ASSERT_TRUE(result != NULL);
+ TEST_ASSERT_NOT_NULL(result);
TEST_ASSERT_TRUE(CompareKeysAlternative(40, 11, "MD5", "asciikeyTwo", *result));
result = NULL;
get_key(50, &result);
- TEST_ASSERT_TRUE(result != NULL);
+ TEST_ASSERT_NOT_NULL(result);
TEST_ASSERT_TRUE(CompareKeysAlternative(50, 11, "MD5", "asciikeyOne", *result));
}
-void test_ReadHexKeys(void) {
+
+void
+test_ReadHexKeys(void) {
struct key* keys = NULL;
TEST_ASSERT_EQUAL(3, auth_init(CreatePath("key-test-hex", INPUT_DIR), &keys));
- TEST_ASSERT_TRUE(keys != NULL);
+ TEST_ASSERT_NOT_NULL(keys);
struct key* result = NULL;
get_key(10, &result);
- TEST_ASSERT_TRUE(result != NULL);
+ TEST_ASSERT_NOT_NULL(result);
TEST_ASSERT_TRUE(CompareKeysAlternative(10, 13, "MD5",
"\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89", *result));
result = NULL;
get_key(20, &result);
- TEST_ASSERT_TRUE(result != NULL);
+ TEST_ASSERT_NOT_NULL(result);
char data1[15]; memset(data1, 0x11, 15);
TEST_ASSERT_TRUE(CompareKeysAlternative(20, 15, "MD5", data1, *result));
result = NULL;
get_key(30, &result);
- TEST_ASSERT_TRUE(result != NULL);
+ TEST_ASSERT_NOT_NULL(result);
char data2[13]; memset(data2, 0x01, 13);
TEST_ASSERT_TRUE(CompareKeysAlternative(30, 13, "MD5", data2, *result));
}
-void test_ReadKeyFileWithComments(void) {
+
+void
+test_ReadKeyFileWithComments(void) {
struct key* keys = NULL;
TEST_ASSERT_EQUAL(2, auth_init(CreatePath("key-test-comments", INPUT_DIR), &keys));
- TEST_ASSERT_TRUE(keys != NULL);
+ TEST_ASSERT_NOT_NULL(keys);
struct key* result = NULL;
get_key(10, &result);
- TEST_ASSERT_TRUE(result != NULL);
+ TEST_ASSERT_NOT_NULL(result);
char data[15]; memset(data, 0x01, 15);
TEST_ASSERT_TRUE(CompareKeysAlternative(10, 15, "MD5", data, *result));
result = NULL;
get_key(34, &result);
- TEST_ASSERT_TRUE(result != NULL);
+ TEST_ASSERT_NOT_NULL(result);
TEST_ASSERT_TRUE(CompareKeysAlternative(34, 3, "MD5", "xyz", *result));
}
-void test_ReadKeyFileWithInvalidHex(void) {
+
+void
+test_ReadKeyFileWithInvalidHex(void) {
struct key* keys = NULL;
TEST_ASSERT_EQUAL(1, auth_init(CreatePath("key-test-invalid-hex", INPUT_DIR), &keys));
- TEST_ASSERT_TRUE(keys != NULL);
+ TEST_ASSERT_NOT_NULL(keys);
struct key* result = NULL;
get_key(10, &result);
- TEST_ASSERT_TRUE(result != NULL);
+ TEST_ASSERT_NOT_NULL(result);
char data[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.
- TEST_ASSERT_TRUE(result == NULL);
+ TEST_ASSERT_NULL(result);
}
#include "sntptest.h"
#include "ntp_stdlib.h"
#include "sntp-opts.h"
-
#include "kod_management.h"
+#include "ntp_io.h"
#include "unity.h"
-void setUp(void)
-{
- kod_init_kod_db("/dev/null", TRUE);
-}
-void tearDown(void)
-{
+
+void
+setUp(void) {
+ kod_init_kod_db("/dev/null", TRUE);
}
-void test_SingleEntryHandling(void) {
- char HOST[] = "192.0.2.5";
- char REASON[] = "DENY";
+void
+test_SingleEntryHandling(void) {
+ const char HOST[] = "192.0.2.5";
+ const char REASON[] = "DENY";
add_entry(HOST, REASON);
TEST_ASSERT_EQUAL_STRING(REASON, result->type);
}
-void test_MultipleEntryHandling(void) {
- char HOST1[] = "192.0.2.3";
- char REASON1[] = "DENY";
- char HOST2[] = "192.0.5.5";
- char REASON2[] = "RATE";
+void
+test_MultipleEntryHandling(void) {
+ const char HOST1[] = "192.0.2.3";
+ const char REASON1[] = "DENY";
- char HOST3[] = "192.0.10.1";
- char REASON3[] = "DENY";
+ const char HOST2[] = "192.0.5.5";
+ const char REASON2[] = "RATE";
+
+ const char HOST3[] = "192.0.10.1";
+ const char REASON3[] = "DENY";
add_entry(HOST1, REASON1);
add_entry(HOST2, REASON2);
free(result);
}
-void test_NoMatchInSearch(void) {
- char HOST_ADD[] = "192.0.2.6";
- char HOST_NOTADD[] = "192.0.6.1";
- char REASON[] = "DENY";
+
+void
+test_NoMatchInSearch(void) {
+ const char HOST_ADD[] = "192.0.2.6";
+ const char HOST_NOTADD[] = "192.0.6.1";
+ const char REASON[] = "DENY";
add_entry(HOST_ADD, REASON);
TEST_ASSERT_TRUE(result == NULL);
}
-void test_AddDuplicate(void) {
- char HOST[] = "192.0.2.3";
- char REASON1[] = "RATE";
- char REASON2[] = "DENY";
+
+void
+test_AddDuplicate(void) {
+ const char HOST[] = "192.0.2.3";
+ const char REASON1[] = "RATE";
+ const char REASON2[] = "DENY";
add_entry(HOST, REASON1);
struct kod_entry* result1;
free(result2);
}
-void test_DeleteEntry(void) {
- char HOST1[] = "192.0.2.1";
- char HOST2[] = "192.0.2.2";
- char HOST3[] = "192.0.2.3";
- char REASON[] = "DENY";
+
+void
+test_DeleteEntry(void) {
+ const char HOST1[] = "192.0.2.1";
+ const char HOST2[] = "192.0.2.2";
+ const char HOST3[] = "192.0.2.3";
+ const char REASON[] = "DENY";
add_entry(HOST1, REASON);
add_entry(HOST2, REASON);
#include "config.h"
+
#include "ntp_types.h"
#include "ntp_stdlib.h" // For estrdup()
-
-
#include "fileHandlingTest.h"
-
#include "kod_management.h"
#include "unity.h"
extern struct kod_entry** kod_db;
extern char* kod_db_file;
-void setUp(void) {
- kod_db_cnt = 0;
- kod_db = NULL;
-}
-void tearDown(void) {
+void
+setUp(void) {
+ kod_db_cnt = 0;
+ kod_db = NULL;
}
-void test_ReadEmptyFile(void) {
+void
+test_ReadEmptyFile(void) {
kod_init_kod_db(CreatePath("kod-test-empty", INPUT_DIR), TRUE);
TEST_ASSERT_EQUAL(0, kod_db_cnt);
}
-void test_ReadCorrectFile(void) {
+
+void
+test_ReadCorrectFile(void) {
kod_init_kod_db(CreatePath("kod-test-correct", INPUT_DIR), TRUE);
TEST_ASSERT_EQUAL(2, kod_db_cnt);
TEST_ASSERT_EQUAL(0xfff, res->timestamp);
}
-void test_ReadFileWithBlankLines(void) {
+
+void
+test_ReadFileWithBlankLines(void) {
kod_init_kod_db(CreatePath("kod-test-blanks", INPUT_DIR), TRUE);
TEST_ASSERT_EQUAL(3, kod_db_cnt);
TEST_ASSERT_EQUAL(0xabcd, res->timestamp);
}
-void test_WriteEmptyFile(void) {
- //kod_db_file = estrdup(CreatePath("kod-output-blank", OUTPUT_DIR)); //causing issues on psp-at1, replaced
+
+void
+test_WriteEmptyFile(void) {
kod_db_file = estrdup("kod-output-blank");
- //printf("kod PATH: %s\n",kod_db_file);
write_kod_db();
// Open file and ensure that the filesize is 0 bytes.
- FILE * is;
- is = fopen(kod_db_file, "rb");//std::ios::binary);
- TEST_ASSERT_FALSE(is == NULL );//is.fail());
-
+ FILE * is = fopen(kod_db_file, "rb");
+ TEST_ASSERT_NOT_NULL(is);
+
TEST_ASSERT_EQUAL(0, GetFileSize(is));
fclose(is);
}
-void test_WriteFileWithSingleEntry(void) {
- //kod_db_file = estrdup(CreatePath("kod-output-single", OUTPUT_DIR)); //causing issues on psp-at1, replaced
+
+void
+test_WriteFileWithSingleEntry(void) {
kod_db_file = estrdup("kod-output-single");
- //printf("kod PATH: %s\n",kod_db_file);
add_entry("host1", "DENY");
// Here we must manipulate the timestamps, so they match the one in
// the expected file.
- //
+
kod_db[0]->timestamp = 1;
write_kod_db();
// Open file and compare sizes.
FILE * actual = fopen(kod_db_file, "rb");
FILE * expected = fopen(CreatePath("kod-expected-single", INPUT_DIR),"rb");
- TEST_ASSERT_TRUE(actual !=NULL);//TEST_ASSERT_TRUE(actual.good());
- TEST_ASSERT_TRUE(expected !=NULL);//TEST_ASSERT_TRUE(expected.good());
- TEST_ASSERT_EQUAL(GetFileSize(expected), GetFileSize(actual));
+ TEST_ASSERT_NOT_NULL(actual);
+ TEST_ASSERT_NOT_NULL(expected);
+ TEST_ASSERT_EQUAL(GetFileSize(expected), GetFileSize(actual));
+
TEST_ASSERT_TRUE(CompareFileContent(expected, actual));
}
-void test_WriteFileWithMultipleEntries(void) {
- //kod_db_file = estrdup(CreatePath("kod-output-multiple", OUTPUT_DIR)); //causing issues on psp-at1, replaced
+
+void
+test_WriteFileWithMultipleEntries(void) {
kod_db_file = estrdup("kod-output-multiple");
- //printf("kod PATH: %s\n",kod_db_file);
add_entry("example.com", "RATE");
add_entry("192.0.2.1", "DENY");
add_entry("192.0.2.5", "RSTR");
// Open file and compare sizes and content.
FILE * actual = fopen(kod_db_file, "rb");
FILE * expected = fopen(CreatePath("kod-expected-multiple", INPUT_DIR),"rb");
- TEST_ASSERT_TRUE(actual !=NULL);//TEST_ASSERT_TRUE(actual.good());
- TEST_ASSERT_TRUE(expected !=NULL);//TEST_ASSERT_TRUE(expected.good());
-
+ TEST_ASSERT_NOT_NULL(actual);
+ TEST_ASSERT_NOT_NULL(expected);
+
+
TEST_ASSERT_EQUAL(GetFileSize(expected), GetFileSize(actual));
TEST_ASSERT_TRUE(CompareFileContent(expected, actual));
}
-
#include "unity.h"
-int counter = 0;
-
-
-// old code from google test framework, moved to SetUp() for unity
-void setUp(void)
-{
+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;
- }
+int
+LfpEquality(const l_fp expected, const l_fp actual) {
+ if (L_ISEQU(&expected, &actual))
+ return TRUE;
+ else
+ return FALSE;
}
-void test_GenerateUnauthenticatedPacket(void) {
+
+void
+test_GenerateUnauthenticatedPacket(void) {
struct pkt testpkt;
struct timeval xmt;
TEST_ASSERT_TRUE(LfpEquality(expected_xmt, actual_xmt));
}
-void test_GenerateAuthenticatedPacket(void) {
+
+void
+test_GenerateAuthenticatedPacket(void) {
struct key testkey;
testkey.next = NULL;
testkey.key_id = 30;
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_TRUE(memcmp(expected_mac, (char*)&testpkt.exten[1], MAX_MD5_LEN -4) == 0);
+ TEST_ASSERT_EQUAL_MEMORY(expected_mac, (char*)&testpkt.exten[1], MAX_MD5_LEN -4);
}
-void test_OffsetCalculationPositiveOffset(void) {
+
+void
+test_OffsetCalculationPositiveOffset(void) {
struct pkt rpkt;
rpkt.precision = -16; // 0,000015259
double offset, precision, synch_distance;
offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &synch_distance);
- TEST_ASSERT_EQUAL_FLOAT(1.25, offset);
- TEST_ASSERT_EQUAL_FLOAT(1. / ULOGTOD(16), precision);
+ TEST_ASSERT_EQUAL_DOUBLE(1.25, offset);
+ TEST_ASSERT_EQUAL_DOUBLE(1. / ULOGTOD(16), precision);
// 1.1250150000000001 ?
- TEST_ASSERT_EQUAL_FLOAT(1.125015, synch_distance);
+ TEST_ASSERT_EQUAL_DOUBLE(1.125015, synch_distance);
}
-void test_OffsetCalculationNegativeOffset(void) {
+
+void
+test_OffsetCalculationNegativeOffset(void) {
struct pkt rpkt;
rpkt.precision = -1;
double offset, precision, synch_distance;
offset_calculation(&rpkt, LEN_PKT_NOMAC, &dst, &offset, &precision, &synch_distance);
- TEST_ASSERT_EQUAL_FLOAT(-1, offset);
- TEST_ASSERT_EQUAL_FLOAT(1. / ULOGTOD(1), precision);
- TEST_ASSERT_EQUAL_FLOAT(1.3333483333333334, synch_distance);
+ TEST_ASSERT_EQUAL_DOUBLE(-1, offset);
+ TEST_ASSERT_EQUAL_DOUBLE(1. / ULOGTOD(1), precision);
+ TEST_ASSERT_EQUAL_DOUBLE(1.3333483333333334, synch_distance);
}
-void test_HandleUnusableServer(void) {
+
+void
+test_HandleUnusableServer(void) {
struct pkt rpkt;
sockaddr_u host;
int rpktl;
TEST_ASSERT_EQUAL(-1, handle_pkt(rpktl, &rpkt, &host, ""));
}
-void test_HandleUnusablePacket(void) {
+
+void
+test_HandleUnusablePacket(void) {
struct pkt rpkt;
sockaddr_u host;
int rpktl;
TEST_ASSERT_EQUAL(1, handle_pkt(rpktl, &rpkt, &host, ""));
}
-void test_HandleServerAuthenticationFailure(void) {
+
+void
+test_HandleServerAuthenticationFailure(void) {
struct pkt rpkt;
sockaddr_u host;
int rpktl;
TEST_ASSERT_EQUAL(1, handle_pkt(rpktl, &rpkt, &host, ""));
}
-void test_HandleKodDemobilize(void) {
+
+void
+test_HandleKodDemobilize(void) {
const char * HOSTNAME = "192.0.2.1";
const char * REASON = "DENY";
struct pkt rpkt;
TEST_ASSERT_EQUAL(1, handle_pkt(rpktl, &rpkt, &host, HOSTNAME));
TEST_ASSERT_EQUAL(1, search_entry(HOSTNAME, &entry));
- TEST_ASSERT_TRUE(memcmp(REASON, entry->type, 4) == 0);
+ TEST_ASSERT_EQUAL_MEMORY(REASON, entry->type, 4);
}
-void test_HandleKodRate(void) {
+
+void
+test_HandleKodRate(void) {
struct pkt rpkt;
sockaddr_u host;
int rpktl;
TEST_ASSERT_EQUAL(1, handle_pkt(rpktl, &rpkt, &host, ""));
}
-void test_HandleCorrectPacket(void) {
+
+void
+test_HandleCorrectPacket(void) {
struct pkt rpkt;
sockaddr_u host;
int rpktl;
#include "ntp_stdlib.h"
#include "unity.h"
+
const char * Version = "stub unit test Version string";
// Hacks into the key database.
static sockaddr_u testsock;
bool restoreKeyDb;
-void PrepareAuthenticationTest(int key_id,
+
+void
+PrepareAuthenticationTest(int key_id,
int key_len,
const char* type,
const void* key_seq) {
char str[25];
- sprintf(str, "%d", key_id);
+ snprintf(str, 25, "%d", key_id);
ActivateOption("-a", str);
key_cnt = 1;
restoreKeyDb = true;
}
-void PrepareAuthenticationTestMD5(int key_id,
+
+void
+PrepareAuthenticationTestMD5(int key_id,
int key_len,
const void* key_seq) {
PrepareAuthenticationTest(key_id, key_len, "MD5", key_seq);
}
-void setUp(void) {
+
+void
+setUp(void) {
sntptest();
restoreKeyDb = false;
HTONL_FP(&tmp, &testpkt.org);
HTONL_FP(&tmp, &testspkt.xmt);
-
}
-void tearDown(void) {
+
+void
+tearDown(void) {
if (restoreKeyDb) {
key_cnt = 0;
}
sntptest_destroy(); //only on the final test!! if counter == 0 etc...
-
}
-void test_TooShortLength(void) {
+void
+test_TooShortLength(void) {
TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC - 1,
MODE_SERVER, &testspkt, "UnitTest"));
MODE_BROADCAST, &testspkt, "UnitTest"));
}
-void test_LengthNotMultipleOfFour(void) {
+
+void
+test_LengthNotMultipleOfFour(void) {
TEST_ASSERT_EQUAL(PACKET_UNUSEABLE,
process_pkt(&testpkt, &testsock, LEN_PKT_NOMAC + 6,
MODE_SERVER, &testspkt, "UnitTest"));
MODE_BROADCAST, &testspkt, "UnitTest"));
}
-void test_TooShortExtensionFieldLength(void) {
+
+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. */
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_UnauthenticatedPacketReject(void) {
+
+void
+test_UnauthenticatedPacketReject(void) {
//sntptest();
// Activate authentication option
ActivateOption("-a", "123");
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_CryptoNAKPacketReject(void) {
+
+void
+test_CryptoNAKPacketReject(void) {
// Activate authentication option
ActivateOption("-a", "123");
TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_AuthenticatedPacketInvalid(void) {
+
+void
+test_AuthenticatedPacketInvalid(void) {
// Activate authentication option
PrepareAuthenticationTestMD5(50, 9, "123456789");
TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_AuthenticatedPacketUnknownKey(void) {
+
+void
+test_AuthenticatedPacketUnknownKey(void) {
// Activate authentication option
PrepareAuthenticationTestMD5(30, 9, "123456789");
TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_ServerVersionTooOld(void) {
+
+void
+test_ServerVersionTooOld(void) {
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_ServerVersionTooNew(void) {
+
+void
+test_ServerVersionTooNew(void) {
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_NonWantedMode(void) {
+
+void
+test_NonWantedMode(void) {
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
MODE_SERVER, &testspkt, "UnitTest"));
}
+
/* Tests bug 1597 */
-void test_KoDRate(void) {
+void
+test_KoDRate(void) {
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.stratum = STRATUM_PKT_UNSPEC;
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_KoDDeny(void) {
+
+void
+test_KoDDeny(void) {
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.stratum = STRATUM_PKT_UNSPEC;
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_RejectUnsyncedServer(void) {
+
+void
+test_RejectUnsyncedServer(void) {
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC,
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_RejectWrongResponseServerMode(void) {
+
+void
+test_RejectWrongResponseServerMode(void) {
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
l_fp tmp;
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_AcceptNoSentPacketBroadcastMode(void) {
+
+void
+test_AcceptNoSentPacketBroadcastMode(void) {
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
testpkt.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
MODE_BROADCAST, NULL, "UnitTest"));
}
-void test_CorrectUnauthenticatedPacket(void) {
+
+void
+test_CorrectUnauthenticatedPacket(void) {
TEST_ASSERT_FALSE(ENABLED_OPT(AUTHENTICATION));
TEST_ASSERT_EQUAL(LEN_PKT_NOMAC,
MODE_SERVER, &testspkt, "UnitTest"));
}
-void test_CorrectAuthenticatedPacketMD5(void) {
+
+void
+test_CorrectAuthenticatedPacketMD5(void) {
PrepareAuthenticationTestMD5(10, 15, "123456789abcdef");
TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
}
-void test_CorrectAuthenticatedPacketSHA1(void) {
+
+void
+test_CorrectAuthenticatedPacketSHA1(void) {
PrepareAuthenticationTest(20, 15, "SHA1", "abcdefghijklmno");
TEST_ASSERT_TRUE(ENABLED_OPT(AUTHENTICATION));
progname = argv[0];
Unity.TestFile = "crypto.c";
UnityBegin("crypto.c");
- RUN_TEST(test_MakeMd5Mac, 12);
- RUN_TEST(test_MakeSHA1Mac, 34);
- RUN_TEST(test_VerifyCorrectMD5, 60);
- RUN_TEST(test_VerifySHA1, 79);
- RUN_TEST(test_VerifyFailure, 101);
- RUN_TEST(test_PacketSizeNotMultipleOfFourBytes, 121);
+ RUN_TEST(test_MakeMd5Mac, 13);
+ RUN_TEST(test_MakeSHA1Mac, 36);
+ RUN_TEST(test_VerifyCorrectMD5, 63);
+ RUN_TEST(test_VerifySHA1, 83);
+ RUN_TEST(test_VerifyFailure, 106);
+ RUN_TEST(test_PacketSizeNotMultipleOfFourBytes, 128);
return (UnityEnd());
}
progname = argv[0];
Unity.TestFile = "keyFile.c";
UnityBegin("keyFile.c");
- RUN_TEST(test_ReadEmptyKeyFile, 53);
- RUN_TEST(test_ReadASCIIKeys, 61);
- RUN_TEST(test_ReadHexKeys, 79);
- RUN_TEST(test_ReadKeyFileWithComments, 105);
- RUN_TEST(test_ReadKeyFileWithInvalidHex, 124);
+ RUN_TEST(test_ReadEmptyKeyFile, 55);
+ RUN_TEST(test_ReadASCIIKeys, 64);
+ RUN_TEST(test_ReadHexKeys, 84);
+ RUN_TEST(test_ReadKeyFileWithComments, 112);
+ RUN_TEST(test_ReadKeyFileWithInvalidHex, 133);
return (UnityEnd());
}
progname = argv[0];
Unity.TestFile = "kodDatabase.c";
UnityBegin("kodDatabase.c");
- RUN_TEST(test_SingleEntryHandling, 22);
- RUN_TEST(test_MultipleEntryHandling, 35);
- RUN_TEST(test_NoMatchInSearch, 66);
- RUN_TEST(test_AddDuplicate, 79);
- RUN_TEST(test_DeleteEntry, 104);
+ RUN_TEST(test_SingleEntryHandling, 21);
+ RUN_TEST(test_MultipleEntryHandling, 36);
+ RUN_TEST(test_NoMatchInSearch, 69);
+ RUN_TEST(test_AddDuplicate, 84);
+ RUN_TEST(test_DeleteEntry, 111);
return (UnityEnd());
}
progname = argv[0];
Unity.TestFile = "kodFile.c";
UnityBegin("kodFile.c");
- RUN_TEST(test_ReadEmptyFile, 29);
+ RUN_TEST(test_ReadEmptyFile, 27);
RUN_TEST(test_ReadCorrectFile, 35);
- RUN_TEST(test_ReadFileWithBlankLines, 53);
- RUN_TEST(test_WriteEmptyFile, 76);
- RUN_TEST(test_WriteFileWithSingleEntry, 92);
- RUN_TEST(test_WriteFileWithMultipleEntries, 116);
+ RUN_TEST(test_ReadFileWithBlankLines, 55);
+ RUN_TEST(test_WriteEmptyFile, 80);
+ RUN_TEST(test_WriteFileWithSingleEntry, 95);
+ RUN_TEST(test_WriteFileWithMultipleEntries, 120);
return (UnityEnd());
}
progname = argv[0];
Unity.TestFile = "packetHandling.c";
UnityBegin("packetHandling.c");
- RUN_TEST(test_GenerateUnauthenticatedPacket, 35);
- RUN_TEST(test_GenerateAuthenticatedPacket, 58);
- RUN_TEST(test_OffsetCalculationPositiveOffset, 97);
- RUN_TEST(test_OffsetCalculationNegativeOffset, 141);
- RUN_TEST(test_HandleUnusableServer, 184);
- RUN_TEST(test_HandleUnusablePacket, 195);
- RUN_TEST(test_HandleServerAuthenticationFailure, 206);
- RUN_TEST(test_HandleKodDemobilize, 217);
- RUN_TEST(test_HandleKodRate, 241);
- RUN_TEST(test_HandleCorrectPacket, 252);
+ RUN_TEST(test_GenerateUnauthenticatedPacket, 32);
+ RUN_TEST(test_GenerateAuthenticatedPacket, 57);
+ RUN_TEST(test_OffsetCalculationPositiveOffset, 98);
+ RUN_TEST(test_OffsetCalculationNegativeOffset, 144);
+ RUN_TEST(test_HandleUnusableServer, 189);
+ RUN_TEST(test_HandleUnusablePacket, 202);
+ RUN_TEST(test_HandleServerAuthenticationFailure, 215);
+ RUN_TEST(test_HandleKodDemobilize, 228);
+ RUN_TEST(test_HandleKodRate, 254);
+ RUN_TEST(test_HandleCorrectPacket, 267);
return (UnityEnd());
}
progname = argv[0];
Unity.TestFile = "packetProcessing.c";
UnityBegin("packetProcessing.c");
- RUN_TEST(test_TooShortLength, 83);
- RUN_TEST(test_LengthNotMultipleOfFour, 92);
- RUN_TEST(test_TooShortExtensionFieldLength, 101);
- RUN_TEST(test_UnauthenticatedPacketReject, 117);
- RUN_TEST(test_CryptoNAKPacketReject, 131);
- RUN_TEST(test_AuthenticatedPacketInvalid, 143);
- RUN_TEST(test_AuthenticatedPacketUnknownKey, 166);
- RUN_TEST(test_ServerVersionTooOld, 186);
- RUN_TEST(test_ServerVersionTooNew, 201);
- RUN_TEST(test_NonWantedMode, 216);
- RUN_TEST(test_KoDRate, 231);
- RUN_TEST(test_KoDDeny, 242);
- RUN_TEST(test_RejectUnsyncedServer, 253);
- RUN_TEST(test_RejectWrongResponseServerMode, 265);
- RUN_TEST(test_AcceptNoSentPacketBroadcastMode, 282);
- RUN_TEST(test_CorrectUnauthenticatedPacket, 294);
- RUN_TEST(test_CorrectAuthenticatedPacketMD5, 302);
- RUN_TEST(test_CorrectAuthenticatedPacketSHA1, 322);
+ RUN_TEST(test_TooShortLength, 91);
+ RUN_TEST(test_LengthNotMultipleOfFour, 102);
+ RUN_TEST(test_TooShortExtensionFieldLength, 113);
+ RUN_TEST(test_UnauthenticatedPacketReject, 131);
+ RUN_TEST(test_CryptoNAKPacketReject, 147);
+ RUN_TEST(test_AuthenticatedPacketInvalid, 161);
+ RUN_TEST(test_AuthenticatedPacketUnknownKey, 186);
+ RUN_TEST(test_ServerVersionTooOld, 208);
+ RUN_TEST(test_ServerVersionTooNew, 225);
+ RUN_TEST(test_NonWantedMode, 242);
+ RUN_TEST(test_KoDRate, 259);
+ RUN_TEST(test_KoDDeny, 272);
+ RUN_TEST(test_RejectUnsyncedServer, 285);
+ RUN_TEST(test_RejectWrongResponseServerMode, 299);
+ RUN_TEST(test_AcceptNoSentPacketBroadcastMode, 318);
+ RUN_TEST(test_CorrectUnauthenticatedPacket, 332);
+ RUN_TEST(test_CorrectAuthenticatedPacketMD5, 342);
+ RUN_TEST(test_CorrectAuthenticatedPacketSHA1, 364);
return (UnityEnd());
}
progname = argv[0];
Unity.TestFile = "utilities.c";
UnityBegin("utilities.c");
- RUN_TEST(test_IPv4Address, 66);
- RUN_TEST(test_IPv6Address, 76);
- RUN_TEST(test_SetLiVnMode1, 96);
- RUN_TEST(test_SetLiVnMode2, 109);
- RUN_TEST(test_PktOutput, 124);
- RUN_TEST(test_LfpOutputBinaryFormat, 144);
- RUN_TEST(test_LfpOutputDecimalFormat, 160);
+ RUN_TEST(test_IPv4Address, 74);
+ RUN_TEST(test_IPv6Address, 86);
+ RUN_TEST(test_SetLiVnMode1, 108);
+ RUN_TEST(test_SetLiVnMode2, 123);
+ RUN_TEST(test_PktOutput, 139);
+ RUN_TEST(test_LfpOutputBinaryFormat, 161);
+ RUN_TEST(test_LfpOutputDecimalFormat, 179);
return (UnityEnd());
}
void sntptest_destroy(void);
void ActivateOption(const char* option, const char* argument);
-void sntptest(void) {
+
+void
+sntptest(void) {
optionSaveState(&sntpOptions);
}
-void sntptest_destroy(void) {
+
+void
+sntptest_destroy(void) {
optionRestore(&sntpOptions);
}
-void ActivateOption(const char* option, const char* argument) {
+
+void
+ActivateOption(const char* option, const char* argument) {
const int ARGV_SIZE = 4;
#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";
+#include <math.h>
+const char * Version = "stub unit test Version string";
+
-sockaddr_u CreateSockaddr4(const char* address) {
+sockaddr_u
+CreateSockaddr4(const char* address) {
sockaddr_u s;
s.sa4.sin_family = AF_INET;
s.sa4.sin_addr.s_addr = inet_addr(address);
return s;
}
-struct addrinfo CreateAddrinfo( sockaddr_u* sock) {
+
+struct addrinfo
+CreateAddrinfo(sockaddr_u* sock) {
struct addrinfo a;
a.ai_family = sock->sa.sa_family;
a.ai_addrlen = SIZEOF_SOCKADDR(a.ai_family);
bool outputFileOpened;
FILE* outputFile;
-void InitDebugTest(const char * filename) {
+
+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);
+ TEST_ASSERT_NOT_NULL(outputFile);
outputFileOpened = true;
}
+
// Closes outputFile, and compare contents.
-void FinishDebugTest(const char * expected,
+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);
+ TEST_ASSERT_NOT_NULL(e);
+ TEST_ASSERT_NOT_NULL(a);
CompareFileContent(e, a);
}
* tests can be removed.
*/
-void test_IPv4Address(void) {
+void
+test_IPv4Address(void) {
const char* ADDR = "192.0.2.10";
sockaddr_u input = CreateSockaddr4(ADDR);
TEST_ASSERT_EQUAL_STRING(ADDR, addrinfo_to_str(&inputA));
}
-void test_IPv6Address(void) {
+
+void
+test_IPv6Address(void) {
const struct in6_addr address = {
0x20, 0x01, 0x0d, 0xb8,
0x85, 0xa3, 0x08, 0xd3,
TEST_ASSERT_EQUAL_STRING(expected, addrinfo_to_str(&inputA));
}
-void test_SetLiVnMode1(void) {
+
+void
+test_SetLiVnMode1(void) {
struct pkt expected;
expected.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOWARNING,
NTP_VERSION,
TEST_ASSERT_EQUAL(expected.li_vn_mode, actual.li_vn_mode);
}
-void test_SetLiVnMode2(void) {
+
+void
+test_SetLiVnMode2(void) {
struct pkt expected;
expected.li_vn_mode = PKT_LI_VN_MODE(LEAP_NOTINSYNC,
NTP_OLDVERSION,
/* Debug utilities tests */
-void test_PktOutput(void) {
- char * filename = "debug-output-pkt";//CreatePath("debug-output-pkt", OUTPUT_DIR);
+void
+test_PktOutput(void) {
+ char * filename = "debug-output-pkt";
InitDebugTest(filename);
struct pkt testpkt;
FinishDebugTest(CreatePath("debug-input-pkt", INPUT_DIR), filename);
}
-void test_LfpOutputBinaryFormat(void) {
+
+void
+test_LfpOutputBinaryFormat(void) {
char * filename = "debug-output-lfp-bin";//CreatePath("debug-output-lfp-bin", OUTPUT_DIR);
InitDebugTest(filename);
FinishDebugTest(CreatePath("debug-input-lfp-bin", INPUT_DIR), filename);
}
-void test_LfpOutputDecimalFormat(void) {
- char * filename = "debug-output-lfp-dec"; //CreatePath("debug-output-lfp-dec", OUTPUT_DIR);
+
+void
+test_LfpOutputDecimalFormat(void) {
+ char * filename = "debug-output-lfp-dec";
InitDebugTest(filename);
l_fp test;
FinishDebugTest(CreatePath("debug-input-lfp-dec", INPUT_DIR), filename);
}
-
#include "ntp_fp.h"
-int IsEqual(const l_fp expected, const l_fp actual);
-int IsEqual(const l_fp expected, const l_fp actual) {
+static const int32 HALF = -2147483647L - 1L;
+static const int32 HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005
+static const int32 HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005
+static const int32 QUARTER = 1073741824L;
+static const int32 QUARTER_PROMILLE_APPRX = 1073742L;
+
+int
+IsEqual(const l_fp expected, const l_fp actual) {
if (L_ISEQU(&expected, &actual)) {
return TRUE;
} else {
- //printf(" expected: ...");
- /*
- << " expected: " << lfptoa(&expected, FRACTION_PREC)
- << " (" << expected.l_ui << "." << expected.l_uf << ")"
- << " but was: " << lfptoa(&actual, FRACTION_PREC)
- << " (" << actual.l_ui << "." << actual.l_uf << ")";
- */
return FALSE;
}
-
}
-static const int32 HALF = -2147483647L - 1L;
-static const int32 HALF_PROMILLE_UP = 2147484; // slightly more than 0.0005
-static const int32 HALF_PROMILLE_DOWN = 2147483; // slightly less than 0.0005
-static const int32 QUARTER = 1073741824L;
-static const int32 QUARTER_PROMILLE_APPRX = 1073742L;
-
#endif
-
-
progname = argv[0];
Unity.TestFile = "timespecops.c";
UnityBegin("timespecops.c");
- RUN_TEST(test_Helpers1, 149);
- RUN_TEST(test_Normalise, 169);
- RUN_TEST(test_SignNoFrac, 183);
- RUN_TEST(test_SignWithFrac, 195);
- RUN_TEST(test_CmpFracEQ, 209);
- RUN_TEST(test_CmpFracGT, 222);
- RUN_TEST(test_CmpFracLT, 235);
- RUN_TEST(test_AddFullNorm, 252);
- RUN_TEST(test_AddFullOflow1, 266);
- RUN_TEST(test_AddNsecNorm, 280);
- RUN_TEST(test_AddNsecOflow1, 292);
- RUN_TEST(test_SubFullNorm, 308);
- RUN_TEST(test_SubFullOflow, 322);
- RUN_TEST(test_SubNsecNorm, 336);
- RUN_TEST(test_SubNsecOflow, 348);
- RUN_TEST(test_Neg, 364);
- RUN_TEST(test_AbsNoFrac, 381);
- RUN_TEST(test_AbsWithFrac, 392);
- RUN_TEST(test_Helpers2, 407);
- RUN_TEST(test_ToLFPbittest, 439);
- RUN_TEST(test_ToLFPrelPos, 452);
- RUN_TEST(test_ToLFPrelNeg, 464);
- RUN_TEST(test_ToLFPabs, 476);
- RUN_TEST(test_FromLFPbittest, 491);
- RUN_TEST(test_FromLFPrelPos, 510);
- RUN_TEST(test_FromLFPrelNeg, 523);
- RUN_TEST(test_LFProundtrip, 538);
- RUN_TEST(test_ToString, 557);
+ RUN_TEST(test_Helpers1, 153);
+ RUN_TEST(test_Normalise, 174);
+ RUN_TEST(test_SignNoFrac, 189);
+ RUN_TEST(test_SignWithFrac, 203);
+ RUN_TEST(test_CmpFracEQ, 218);
+ RUN_TEST(test_CmpFracGT, 233);
+ RUN_TEST(test_CmpFracLT, 248);
+ RUN_TEST(test_AddFullNorm, 266);
+ RUN_TEST(test_AddFullOflow1, 282);
+ RUN_TEST(test_AddNsecNorm, 298);
+ RUN_TEST(test_AddNsecOflow1, 312);
+ RUN_TEST(test_SubFullNorm, 329);
+ RUN_TEST(test_SubFullOflow, 345);
+ RUN_TEST(test_SubNsecNorm, 361);
+ RUN_TEST(test_SubNsecOflow, 375);
+ RUN_TEST(test_Neg, 393);
+ RUN_TEST(test_AbsNoFrac, 411);
+ RUN_TEST(test_AbsWithFrac, 424);
+ RUN_TEST(test_Helpers2, 440);
+ RUN_TEST(test_ToLFPbittest, 469);
+ RUN_TEST(test_ToLFPrelPos, 484);
+ RUN_TEST(test_ToLFPrelNeg, 498);
+ RUN_TEST(test_ToLFPabs, 512);
+ RUN_TEST(test_FromLFPbittest, 529);
+ RUN_TEST(test_FromLFPrelPos, 550);
+ RUN_TEST(test_FromLFPrelNeg, 565);
+ RUN_TEST(test_LFProundtrip, 581);
+ RUN_TEST(test_ToString, 601);
return (UnityEnd());
}
progname = argv[0];
Unity.TestFile = "timevalops.c";
UnityBegin("timevalops.c");
- RUN_TEST(test_Helpers1, 149);
- RUN_TEST(test_Normalise, 169);
- RUN_TEST(test_SignNoFrac, 183);
- RUN_TEST(test_SignWithFrac, 195);
- RUN_TEST(test_CmpFracEQ, 210);
- RUN_TEST(test_CmpFracGT, 224);
- RUN_TEST(test_CmpFracLT, 238);
- RUN_TEST(test_AddFullNorm, 256);
- RUN_TEST(test_AddFullOflow1, 270);
- RUN_TEST(test_AddUsecNorm, 284);
- RUN_TEST(test_AddUsecOflow1, 296);
- RUN_TEST(test_SubFullNorm, 312);
- RUN_TEST(test_SubFullOflow, 326);
- RUN_TEST(test_SubUsecNorm, 340);
- RUN_TEST(test_SubUsecOflow, 352);
- RUN_TEST(test_Neg, 368);
- RUN_TEST(test_AbsNoFrac, 385);
- RUN_TEST(test_AbsWithFrac, 396);
- RUN_TEST(test_Helpers2, 412);
- RUN_TEST(test_ToLFPbittest, 445);
- RUN_TEST(test_ToLFPrelPos, 460);
- RUN_TEST(test_ToLFPrelNeg, 474);
- RUN_TEST(test_ToLFPabs, 487);
- RUN_TEST(test_FromLFPbittest, 505);
- RUN_TEST(test_FromLFPrelPos, 523);
- RUN_TEST(test_FromLFPrelNeg, 536);
- RUN_TEST(test_LFProundtrip, 550);
- RUN_TEST(test_ToString, 569);
+ RUN_TEST(test_Helpers1, 157);
+ RUN_TEST(test_Normalise, 178);
+ RUN_TEST(test_SignNoFrac, 193);
+ RUN_TEST(test_SignWithFrac, 207);
+ RUN_TEST(test_CmpFracEQ, 223);
+ RUN_TEST(test_CmpFracGT, 239);
+ RUN_TEST(test_CmpFracLT, 255);
+ RUN_TEST(test_AddFullNorm, 274);
+ RUN_TEST(test_AddFullOflow1, 290);
+ RUN_TEST(test_AddUsecNorm, 306);
+ RUN_TEST(test_AddUsecOflow1, 320);
+ RUN_TEST(test_SubFullNorm, 337);
+ RUN_TEST(test_SubFullOflow, 353);
+ RUN_TEST(test_SubUsecNorm, 369);
+ RUN_TEST(test_SubUsecOflow, 383);
+ RUN_TEST(test_Neg, 400);
+ RUN_TEST(test_AbsNoFrac, 418);
+ RUN_TEST(test_AbsWithFrac, 431);
+ RUN_TEST(test_Helpers2, 448);
+ RUN_TEST(test_ToLFPbittest, 482);
+ RUN_TEST(test_ToLFPrelPos, 498);
+ RUN_TEST(test_ToLFPrelNeg, 514);
+ RUN_TEST(test_ToLFPabs, 529);
+ RUN_TEST(test_FromLFPbittest, 548);
+ RUN_TEST(test_FromLFPrelPos, 568);
+ RUN_TEST(test_FromLFPrelNeg, 583);
+ RUN_TEST(test_LFProundtrip, 599);
+ RUN_TEST(test_ToString, 619);
return (UnityEnd());
}
#include "ntp.h"
#include "ntp_stdlib.h"
-sockaddr_u CreateSockaddr4(const char* address, unsigned int port) {
+
+sockaddr_u
+CreateSockaddr4(const char* address, unsigned int port) {
sockaddr_u s;
s.sa4.sin_family = AF_INET;
s.sa4.sin_addr.s_addr = inet_addr(address);
return s;
}
-int IsEqual(const sockaddr_u expected, const sockaddr_u actual) {
+
+int
+IsEqual(const sockaddr_u expected, const sockaddr_u actual) {
struct in_addr in;
struct in6_addr in6;
#endif // TESTS_SOCKADDRTEST_H
-
-
-
#include "test-libntp.h"
-//const char *progname = "test-libntp";
-
-// current_time is needed by authkeys. Used only in to calculate lifetime.
-//u_long current_time = 4;
-
time_t nowtime = 0;
-time_t timefunc(time_t *ptr)
-{
+
+time_t
+timefunc(time_t *ptr) {
if (ptr)
*ptr = nowtime;
return nowtime;
}
-void settime(int y, int m, int d, int H, int M, int S)
-{
+
+void
+settime(int y, int m, int d, int H, int M, int S) {
time_t days = ntpcal_edate_to_eradays(y-1, m-1, d-1) + 1 - DAY_UNIX_STARTS;
time_t secs = ntpcal_etime_to_seconds(H, M, S);
nowtime = days * SECSPERDAY + secs;
}
-
-
#include "ntp_types.h"
#include "ntp_fp.h"
-
-#include <math.h>
#include "timespecops.h"
#include "unity.h"
-
+#include <math.h>
#include <string.h>
-//in unity_helper.h :
+
#define TEST_ASSERT_EQUAL_timespec(a, b) { \
TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec"); \
TEST_ASSERT_EQUAL_MESSAGE(a.tv_nsec, b.tv_nsec, "Field tv_nsec"); \
}
-//what about l_fp.l_ui ??? it's a union so it's either l_fp.l_ui or l_fp.l_i?
+
#define TEST_ASSERT_EQUAL_l_fp(a, b) { \
TEST_ASSERT_EQUAL_MESSAGE(a.l_i, b.l_i, "Field l_i"); \
TEST_ASSERT_EQUAL_UINT_MESSAGE(a.l_uf, b.l_uf, "Field l_uf"); \
}
-//timespec has time_t, long, and time_t is basically long uint, 4 or 8 bytes size, depending on 32/64bit
static u_int32 my_tick_to_tsf(u_int32 ticks);
static u_int32 my_tsf_to_tick(u_int32 tsf);
+
// that's it...
struct lfpfracdata {
long nsec;
//******************************************MY CUSTOM FUNCTIONS*******************************
-typedef int bool; //TRUE and FALSE are already defined somewhere, so I can't do typedef enum { FALSE, TRUE } boolean;
+typedef int bool;
+
+const bool
+timespec_isValid(struct timespec V) {
+ return V.tv_nsec >= 0 && V.tv_nsec < 1000000000;
+}
-const bool timespec_isValid(struct timespec V)
- { return V.tv_nsec >= 0 && V.tv_nsec < 1000000000; }
-struct timespec timespec_init(time_t hi, long lo){
+struct timespec
+timespec_init(time_t hi, long lo) {
struct timespec V;
V.tv_sec = hi;
V.tv_nsec = lo;
return V;
}
-//taken from lfpfunc.c -> maybe remove this from timevalops.c and lfpfunc. and put in c_timstructs.h ????!!!!!
-l_fp l_fp_init(int32 i, u_int32 f)
-{
+
+l_fp
+l_fp_init(int32 i, u_int32 f) {
l_fp temp;
temp.l_i = i;
temp.l_uf = f;
return temp;
}
-//also in timelalops.c!!!!!!
-bool AssertFpClose(const l_fp m,const l_fp n, const l_fp limit)
-{
+
+bool
+AssertFpClose(const l_fp m, const l_fp n, const l_fp limit) {
l_fp diff;
if (L_ISGEQ(&m, &n)) {
return TRUE;
}
else {
- printf("m_expr which is %s \nand\nn_expr which is %s\nare not close; diff=%susec\n",lfptoa(&m,10),lfptoa(&n,10),lfptoa(&diff,10));
+ printf("m_expr which is %s \nand\nn_expr which is %s\nare not close; diff=%susec\n", lfptoa(&m, 10), lfptoa(&n, 10), lfptoa(&diff, 10));
return FALSE;
}
}
-bool AssertTimespecClose(const struct timespec m,const struct timespec n, const struct timespec limit)
-{
+bool
+AssertTimespecClose(const struct timespec m, const struct timespec n, const struct timespec limit) {
struct timespec diff;
diff = abs_tspec(sub_tspec(m, n));
return TRUE;
else
{
- printf("m_expr which is %ld.%lu \nand\nn_expr which is %ld.%lu\nare not close; diff=%ld.%lunsec\n",m.tv_sec,m.tv_nsec,n.tv_sec,n.tv_nsec,diff.tv_sec,diff.tv_nsec);
+ printf("m_expr which is %ld.%lu \nand\nn_expr which is %ld.%lu\nare not close; diff=%ld.%lunsec\n", m.tv_sec, m.tv_nsec, n.tv_sec, n.tv_nsec, diff.tv_sec, diff.tv_nsec);
return FALSE;
}
}
};
-u_int32 my_tick_to_tsf(u_int32 ticks)
-{
+u_int32
+my_tick_to_tsf(u_int32 ticks) {
// convert nanoseconds to l_fp fractional units, using double
// precision float calculations or, if available, 64bit integer
// arithmetic. This should give the precise fraction, rounded to
// truncated nonsense, so don't use it out-of-bounds.
}
-u_int32 my_tsf_to_tick(u_int32 tsf)
-{
+
+u_int32
+my_tsf_to_tick(u_int32 tsf) {
// Inverse operation: converts fraction to microseconds.
#ifdef HAVE_U_INT64
return (u_int32)(( ((u_int64)(tsf)) * 1000000000 + 0x80000000) >> 32);
// test support stuff -- part 1
// ---------------------------------------------------------------------
-void test_Helpers1(void) {
+void
+test_Helpers1(void) {
struct timespec x;
for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) {
// test normalisation
//----------------------------------------------------------------------
-void test_Normalise(void) {
+void
+test_Normalise(void) {
long ns;
for ( ns = -2000000000; ns <= 2000000000; ns += 10000000) {
struct timespec x = timespec_init(0, ns);
// test classification
//----------------------------------------------------------------------
-void test_SignNoFrac(void) {
+void
+test_SignNoFrac(void) {
// sign test, no fraction
int i;
for (i = -4; i <= 4; ++i) {
}
}
-void test_SignWithFrac(void) {
+
+void
+test_SignWithFrac(void) {
// sign test, with fraction
int i;
for (i = -4; i <= 4; ++i) {
//----------------------------------------------------------------------
// test compare
//----------------------------------------------------------------------
-void test_CmpFracEQ(void) {
+void
+test_CmpFracEQ(void) {
// fractions are equal
- int i,j;
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init( i , 200);
}
}
-void test_CmpFracGT(void) {
+
+void
+test_CmpFracGT(void) {
// fraction a bigger fraction b
- int i,j;
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init(i, 999999800);
}
}
-void test_CmpFracLT(void) {
+
+void
+test_CmpFracLT(void) {
// fraction a less fraction b
- int i,j;
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init(i, 200);
// Test addition (sum)
//----------------------------------------------------------------------
-void test_AddFullNorm(void) {
- int i,j;
+void
+test_AddFullNorm(void) {
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init(i, 200);
}
}
-void test_AddFullOflow1(void) {
- int i,j;
+
+void
+test_AddFullOflow1(void) {
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init(i, 200);
}
}
-void test_AddNsecNorm(void) {
+
+void
+test_AddNsecNorm(void) {
int i;
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 200);
}
}
-void test_AddNsecOflow1(void) {
+
+void
+test_AddNsecOflow1(void) {
int i;
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 200);
// test subtraction (difference)
//----------------------------------------------------------------------
-void test_SubFullNorm(void) {
- int i,j;
+void
+test_SubFullNorm(void) {
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timespec a = timespec_init( i , 600);
}
}
-void test_SubFullOflow(void) {
- int i,j;
+
+void
+test_SubFullOflow(void) {
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
- struct timespec a = timespec_init( i , 100);
- struct timespec b = timespec_init( j , 999999900);
- struct timespec E = timespec_init(i-j-1, 200);
+ struct timespec a = timespec_init(i, 100);
+ struct timespec b = timespec_init(j, 999999900);
+ struct timespec E = timespec_init(i - j - 1, 200);
struct timespec c;
c = sub_tspec(a, b);
}
}
-void test_SubNsecNorm(void) {
+
+void
+test_SubNsecNorm(void) {
int i;
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 600);
}
}
-void test_SubNsecOflow(void) {
+
+void
+test_SubNsecOflow(void) {
int i;
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init( i , 100);
// test negation
//----------------------------------------------------------------------
-void test_Neg(void) {
+
+void
+test_Neg(void) {
int i;
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 100);
// test abs value
//----------------------------------------------------------------------
-void test_AbsNoFrac(void) {
+void
+test_AbsNoFrac(void) {
int i;
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i , 0);
}
}
-void test_AbsWithFrac(void) {
+
+void
+test_AbsWithFrac(void) {
int i;
for (i = -4; i <= 4; ++i) {
struct timespec a = timespec_init(i, 100);
// test support stuff -- part 2
// ---------------------------------------------------------------------
-void test_Helpers2(void) {
- struct timespec limit = timespec_init(0,2);
+void
+test_Helpers2(void) {
+ struct timespec limit = timespec_init(0, 2);
struct timespec x, y;
long i;
for (x.tv_nsec = 1;
x.tv_nsec < 1000000000;
x.tv_nsec += 499999999) {
- for (i = -4; i < 5; i++) {
+ for (i = -4; i < 5; ++i) {
y = x;
y.tv_nsec += i;
if (i >= -2 && i <= 2){
- TEST_ASSERT_TRUE(AssertTimespecClose(x,y,limit));//ASSERT_PRED_FORMAT2(isClose, x, y);
+ TEST_ASSERT_TRUE(AssertTimespecClose(x, y, limit));
}
else
{
- TEST_ASSERT_FALSE(AssertTimespecClose(x,y,limit));
+ TEST_ASSERT_FALSE(AssertTimespecClose(x, y, limit));
}
}
}
}
-// global predicate instances we're using here
-//static l_fp lfpClose = l_fp_init(0,1); //static AssertFpClose FpClose(0, 1);
-//static struct timespec limit = timespec_init(0,2); //static AssertTimespecClose TimespecClose(0, 2);
-
//----------------------------------------------------------------------
// conversion to l_fp
//----------------------------------------------------------------------
-void test_ToLFPbittest(void) {
- l_fp lfpClose = l_fp_init(0,1);
+void
+test_ToLFPbittest(void) {
+ l_fp lfpClose = l_fp_init(0, 1);
u_int32 i;
for (i = 0; i < 1000000000; i+=1000) {
struct timespec a = timespec_init(1, i);
l_fp r;
r = tspec_intv_to_lfp(a);
- TEST_ASSERT_TRUE(AssertFpClose(E,r,lfpClose));
+ TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
}
}
-void test_ToLFPrelPos(void) {
+
+void
+test_ToLFPrelPos(void) {
int i;
- for (i = 0; i < COUNTOF(fdata); i++) {
+ for (i = 0; i < COUNTOF(fdata); ++i) {
struct timespec a = timespec_init(1, fdata[i].nsec);
l_fp E = l_fp_init(1, fdata[i].frac);
l_fp r;
}
}
-void test_ToLFPrelNeg(void) {
+
+void
+test_ToLFPrelNeg(void) {
int i;
- for (i = 0; i < COUNTOF(fdata); i++) {
+ for (i = 0; i < COUNTOF(fdata); ++i) {
struct timespec a = timespec_init(-1, fdata[i].nsec);
l_fp E = l_fp_init(~0, fdata[i].frac);
l_fp r;
}
}
-void test_ToLFPabs(void) {
+
+void
+test_ToLFPabs(void) {
int i;
- for (i = 0; i < COUNTOF(fdata); i++) {
+ for (i = 0; i < COUNTOF(fdata); ++i) {
struct timespec a = timespec_init(1, fdata[i].nsec);
l_fp E = l_fp_init(1 + JAN_1970, fdata[i].frac);
l_fp r;
//----------------------------------------------------------------------
// conversion from l_fp
//----------------------------------------------------------------------
-void test_FromLFPbittest(void) {
- struct timespec limit = timespec_init(0,2);
+
+void
+test_FromLFPbittest(void) {
+ struct timespec limit = timespec_init(0, 2);
// Not *exactly* a bittest, because 2**32 tests would take a
// really long time even on very fast machines! So we do test
r = lfp_intv_to_tspec(a);
// The conversion might be off by one nanosecond when
// comparing to calculated value.
- TEST_ASSERT_TRUE(AssertTimespecClose(E,r,limit));
+ TEST_ASSERT_TRUE(AssertTimespecClose(E, r, limit));
}
}
-void test_FromLFPrelPos(void) {
- struct timespec limit = timespec_init(0,2);
+
+void
+test_FromLFPrelPos(void) {
+ struct timespec limit = timespec_init(0, 2);
int i;
- for (i = 0; i < COUNTOF(fdata); i++) {
+ for (i = 0; i < COUNTOF(fdata); ++i) {
l_fp a = l_fp_init(1, fdata[i].frac);
struct timespec E = timespec_init(1, fdata[i].nsec);
struct timespec r;
r = lfp_intv_to_tspec(a);
- TEST_ASSERT_TRUE(AssertTimespecClose(E,r,limit));
+ TEST_ASSERT_TRUE(AssertTimespecClose(E, r, limit));
}
}
-void test_FromLFPrelNeg(void) {
- struct timespec limit = timespec_init(0,2);
+
+void
+test_FromLFPrelNeg(void) {
+ struct timespec limit = timespec_init(0, 2);
int i;
- for (i = 0; i < COUNTOF(fdata); i++) {
+ for (i = 0; i < COUNTOF(fdata); ++i) {
l_fp a = l_fp_init(~0, fdata[i].frac);
struct timespec E = timespec_init(-1, fdata[i].nsec);
struct timespec r;
r = lfp_intv_to_tspec(a);
- TEST_ASSERT_TRUE(AssertTimespecClose(E,r,limit));
+ TEST_ASSERT_TRUE(AssertTimespecClose(E, r, limit));
}
}
// nsec -> frac -> nsec roundtrip, using a prime start and increment
-void test_LFProundtrip(void) {
+void
+test_LFProundtrip(void) {
int32_t t;
u_int32 i;
for (t = -1; t < 2; ++t)
- for (i = 4999; i < 1000000000; i+=10007) {
+ for (i = 4999; i < 1000000000; i += 10007) {
struct timespec E = timespec_init(t, i);
l_fp a;
struct timespec r;
// string formatting
//----------------------------------------------------------------------
-void test_ToString(void) {
+void
+test_ToString(void) {
static const struct {
time_t sec;
long nsec;
{-1,-1, "-1.000000001" },
};
int i;
- for (i = 0; i < COUNTOF(data); i++) {
+ for (i = 0; i < COUNTOF(data); ++i) {
struct timespec a = timespec_init(data[i].sec, data[i].nsec);
const char * E = data[i].repr;
const char * r = tspectoa(a);
#include "ntp_types.h"
#include "ntp_fp.h"
-#include <math.h>
#include "timevalops.h"
+#include <math.h>
#include "unity.h"
-//in unity_helper.h :
#define TEST_ASSERT_EQUAL_timeval(a, b) { \
TEST_ASSERT_EQUAL_MESSAGE(a.tv_sec, b.tv_sec, "Field tv_sec"); \
TEST_ASSERT_EQUAL_MESSAGE(a.tv_usec, b.tv_usec, "Field tv_usec"); \
}
-//timeval has time_t, long, and time_t is basically uint
static u_int32 my_tick_to_tsf(u_int32 ticks);
static u_int32 my_tsf_to_tick(u_int32 tsf);
+
// that's it...
typedef struct {
long usec;
//******************************************MY CUSTOM FUNCTIONS*******************************
-typedef int bool; //TRUE and FALSE are already defined somewhere, so I can't do typedef enum { FALSE, TRUE } boolean;
+typedef int bool;
+
-struct timeval timeval_init( time_t hi, long lo){
+struct timeval
+timeval_init( time_t hi, long lo){
struct timeval V;
V.tv_sec = hi;
V.tv_usec = lo;
return V;
}
-const bool timeval_isValid(struct timeval V)
- { return V.tv_usec >= 0 && V.tv_usec < 1000000; }
-//taken from lfpfunc.c -> maybe remove this from timevalops.c and lfpfunc. and put in c_timstructs.h ????!!!!!
-l_fp l_fp_init(int32 i, u_int32 f)
-{
+const bool
+timeval_isValid(struct timeval V) {
+ return V.tv_usec >= 0 && V.tv_usec < 1000000;
+}
+
+
+l_fp
+l_fp_init(int32 i, u_int32 f) {
l_fp temp;
temp.l_i = i;
temp.l_uf = f;
return temp;
}
-bool AssertTimevalClose(const struct timeval m, const struct timeval n, const struct timeval limit)
-{
+
+bool
+AssertTimevalClose(const struct timeval m, const struct timeval n, const struct timeval limit) {
struct timeval diff;
diff = abs_tval(sub_tval(m, n));
else
{
- printf("m_expr which is %ld.%lu \nand\nn_expr which is %ld.%lu\nare not close; diff=%ld.%luusec\n",m.tv_sec,m.tv_usec,n.tv_sec,n.tv_usec,diff.tv_sec,diff.tv_usec);
+ printf("m_expr which is %ld.%lu \nand\nn_expr which is %ld.%lu\nare not close; diff=%ld.%luusec\n", m.tv_sec, m.tv_usec, n.tv_sec, n.tv_usec, diff.tv_sec, diff.tv_usec);
//I don't have variables m_expr and n_expr in unity, those are command line arguments which only getst has!!!
return FALSE;
}
}
-bool AssertFpClose(const l_fp m,const l_fp n, const l_fp limit)
-{
+
+bool
+AssertFpClose(const l_fp m, const l_fp n, const l_fp limit) {
l_fp diff;
if (L_ISGEQ(&m, &n)) {
return TRUE;
}
else {
- printf("m_expr which is %s \nand\nn_expr which is %s\nare not close; diff=%susec\n",lfptoa(&m,10),lfptoa(&n,10),lfptoa(&diff,10));
- //printf("m_expr which is %d.%d \nand\nn_expr which is %d.%d\nare not close; diff=%d.%dusec\n",m.l_uf,m.Ul_i,n.l_uf,n.Ul_i,diff.l_uf,diff.Ul_i);
+ printf("m_expr which is %s \nand\nn_expr which is %s\nare not close; diff=%susec\n", lfptoa(&m, 10), lfptoa(&n, 10), lfptoa(&diff, 10));
+ //printf("m_expr which is %d.%d \nand\nn_expr which is %d.%d\nare not close; diff=%d.%dusec\n", m.l_uf, m.Ul_i, n.l_uf, n.Ul_i, diff.l_uf, diff.Ul_i);
return FALSE;
}
}
};
-u_int32 my_tick_to_tsf(u_int32 ticks)
-{
+u_int32
+my_tick_to_tsf(u_int32 ticks) {
// convert microseconds to l_fp fractional units, using double
// precision float calculations or, if available, 64bit integer
// arithmetic. This should give the precise fraction, rounded to
// truncated nonsense, so don't use it out-of-bounds.
}
-u_int32 my_tsf_to_tick(u_int32 tsf)
-{
+
+u_int32
+my_tsf_to_tick(u_int32 tsf) {
// Inverse operation: converts fraction to microseconds.
#ifdef HAVE_U_INT64
return (u_int32)( ((u_int64)(tsf) * 1000000 + 0x80000000) >> 32); //CHECK ME!!!
// test support stuff - part1
// ---------------------------------------------------------------------
-void test_Helpers1(void) {
+void
+test_Helpers1(void) {
struct timeval x;
for (x.tv_sec = -2; x.tv_sec < 3; x.tv_sec++) {
// test normalisation
//----------------------------------------------------------------------
-void test_Normalise(void) {
+void
+test_Normalise(void) {
long ns;
for (ns = -2000000000; ns <= 2000000000; ns += 10000000) {
struct timeval x = timeval_init(0, ns);
// test classification
//----------------------------------------------------------------------
-void test_SignNoFrac(void) {
+void
+test_SignNoFrac(void) {
int i;
// sign test, no fraction
for (i = -4; i <= 4; ++i) {
}
}
-void test_SignWithFrac(void) {
+
+void
+test_SignWithFrac(void) {
// sign test, with fraction
int i;
for (i = -4; i <= 4; ++i) {
//----------------------------------------------------------------------
// test compare
//----------------------------------------------------------------------
-void test_CmpFracEQ(void) {
- int i,j;
+void
+test_CmpFracEQ(void) {
+ int i, j;
// fractions are equal
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
}
}
-void test_CmpFracGT(void) {
+
+void
+test_CmpFracGT(void) {
// fraction a bigger fraction b
- int i,j;
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init( i , 999800);
}
}
-void test_CmpFracLT(void) {
+
+void
+test_CmpFracLT(void) {
// fraction a less fraction b
- int i,j;
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init(i, 200);
// Test addition (sum)
//----------------------------------------------------------------------
-void test_AddFullNorm(void) {
- int i,j;
+void
+test_AddFullNorm(void) {
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init(i, 200);
}
}
-void test_AddFullOflow1(void) {
- int i,j;
+
+void
+test_AddFullOflow1(void) {
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init(i, 200);
}
}
-void test_AddUsecNorm(void) {
+
+void
+test_AddUsecNorm(void) {
int i;
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 200);
}
}
-void test_AddUsecOflow1(void) {
+
+void
+test_AddUsecOflow1(void) {
int i;
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 200);
// test subtraction (difference)
//----------------------------------------------------------------------
-void test_SubFullNorm(void) {
- int i,j;
+void
+test_SubFullNorm(void) {
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init(i, 600);
}
}
-void test_SubFullOflow(void) {
- int i,j;
+
+void
+test_SubFullOflow(void) {
+ int i, j;
for (i = -4; i <= 4; ++i)
for (j = -4; j <= 4; ++j) {
struct timeval a = timeval_init(i, 100);
}
}
-void test_SubUsecNorm(void) {
+
+void
+test_SubUsecNorm(void) {
int i = -4;
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 600);
}
}
-void test_SubUsecOflow(void) {
+
+void
+test_SubUsecOflow(void) {
int i = -4;
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 100);
// test negation
//----------------------------------------------------------------------
-void test_Neg(void) {
+void
+test_Neg(void) {
int i = -4;
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 100);
// test abs value
//----------------------------------------------------------------------
-void test_AbsNoFrac(void) {
+void
+test_AbsNoFrac(void) {
int i = -4;
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 0);
}
}
-void test_AbsWithFrac(void) {
+
+void
+test_AbsWithFrac(void) {
int i = -4;
for (i = -4; i <= 4; ++i) {
struct timeval a = timeval_init(i, 100);
// ---------------------------------------------------------------------
-void test_Helpers2(void) {
+void
+test_Helpers2(void) {
struct timeval limit = timeval_init(0, 2);
struct timeval x, y;
for (x.tv_usec = 1;
x.tv_usec < 1000000;
x.tv_usec += 499999) {
- for (i = -4; i < 5; i++) {
+ for (i = -4; i < 5; ++i) {
y = x;
y.tv_usec += i;
if (i >= -2 && i <= 2){
- TEST_ASSERT_TRUE(AssertTimevalClose(x,y,limit));//ASSERT_PRED_FORMAT2(isClose, x, y);
+ TEST_ASSERT_TRUE(AssertTimevalClose(x, y, limit));//ASSERT_PRED_FORMAT2(isClose, x, y);
}
else {
- TEST_ASSERT_FALSE(AssertTimevalClose(x,y,limit));
+ TEST_ASSERT_FALSE(AssertTimevalClose(x, y, limit));
}
}
}
// and the global predicate instances we're using here
-//static l_fp lfpClose = l_fp_init(0,1); //static AssertFpClose FpClose(0, 1);
-//static struct timeval timevalClose = timeval_init(0,1); //static AssertTimevalClose TimevalClose(0, 1);
+//static l_fp lfpClose = l_fp_init(0, 1); //static AssertFpClose FpClose(0, 1);
+//static struct timeval timevalClose = timeval_init(0, 1); //static AssertTimevalClose TimevalClose(0, 1);
//----------------------------------------------------------------------
// conversion to l_fp
//----------------------------------------------------------------------
-void test_ToLFPbittest(void) {
- l_fp lfpClose = l_fp_init(0,1);
+void
+test_ToLFPbittest(void) {
+ l_fp lfpClose = l_fp_init(0, 1);
u_int32 i = 0;
- for (i = 0; i < 1000000; i++) {
+ for (i = 0; i < 1000000; ++i) {
struct timeval a = timeval_init(1, i);
- l_fp E = l_fp_init(1,my_tick_to_tsf(i));
+ l_fp E = l_fp_init(1, my_tick_to_tsf(i));
l_fp r;
r = tval_intv_to_lfp(a);
- TEST_ASSERT_TRUE(AssertFpClose(E,r,lfpClose)); //ASSERT_PRED_FORMAT2(FpClose, E, r);
+ TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose)); //ASSERT_PRED_FORMAT2(FpClose, E, r);
}
}
-void test_ToLFPrelPos(void) {
- l_fp lfpClose = l_fp_init(0,1);
+void
+test_ToLFPrelPos(void) {
+ l_fp lfpClose = l_fp_init(0, 1);
int i = 0;
- for (i = 0; i < COUNTOF(fdata); i++) {
+ for (i = 0; i < COUNTOF(fdata); ++i) {
struct timeval a = timeval_init(1, fdata[i].usec);
l_fp E = l_fp_init(1, fdata[i].frac);
l_fp r;
r = tval_intv_to_lfp(a);
- TEST_ASSERT_TRUE(AssertFpClose(E,r,lfpClose));
+ TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
}
}
-void test_ToLFPrelNeg(void) {
- l_fp lfpClose = l_fp_init(0,1);
+
+void
+test_ToLFPrelNeg(void) {
+ l_fp lfpClose = l_fp_init(0, 1);
int i = 0;
- for (i = 0; i < COUNTOF(fdata); i++) {
+ for (i = 0; i < COUNTOF(fdata); ++i) {
struct timeval a = timeval_init(-1, fdata[i].usec);
l_fp E = l_fp_init(~0, fdata[i].frac);
l_fp r;
r = tval_intv_to_lfp(a);
- TEST_ASSERT_TRUE(AssertFpClose(E,r,lfpClose));
+ TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
}
}
-void test_ToLFPabs(void) {
- l_fp lfpClose = l_fp_init(0,1);
+
+void
+test_ToLFPabs(void) {
+ l_fp lfpClose = l_fp_init(0, 1);
int i = 0;
- for (i = 0; i < COUNTOF(fdata); i++) {
+ for (i = 0; i < COUNTOF(fdata); ++i) {
struct timeval a = timeval_init(1, fdata[i].usec);
l_fp E = l_fp_init(1 + JAN_1970, fdata[i].frac);
l_fp r;
r = tval_stamp_to_lfp(a);
- TEST_ASSERT_TRUE(AssertFpClose(E,r,lfpClose));
+ TEST_ASSERT_TRUE(AssertFpClose(E, r, lfpClose));
}
}
// conversion from l_fp
//----------------------------------------------------------------------
-void test_FromLFPbittest(void) {
- struct timeval timevalClose = timeval_init(0,1);
+void
+test_FromLFPbittest(void) {
+ struct timeval timevalClose = timeval_init(0, 1);
// Not *exactly* a bittest, because 2**32 tests would take a
// really long time even on very fast machines! So we do test
// every 1000 fractional units.
r = lfp_intv_to_tval(a);
// The conversion might be off by one microsecond when
// comparing to calculated value.
- TEST_ASSERT_TRUE(AssertTimevalClose(E,r,timevalClose));
+ TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
}
}
-void test_FromLFPrelPos(void) {
- struct timeval timevalClose = timeval_init(0,1);
+
+void
+test_FromLFPrelPos(void) {
+ struct timeval timevalClose = timeval_init(0, 1);
int i = 0;
- for (i = 0; i < COUNTOF(fdata); i++) {
+ for (i = 0; i < COUNTOF(fdata); ++i) {
l_fp a = l_fp_init(1, fdata[i].frac);
struct timeval E = timeval_init(1, fdata[i].usec);
struct timeval r;
r = lfp_intv_to_tval(a);
- TEST_ASSERT_TRUE(AssertTimevalClose(E,r,timevalClose));
+ TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
}
}
-void test_FromLFPrelNeg(void) {
- struct timeval timevalClose = timeval_init(0,1);
+
+void
+test_FromLFPrelNeg(void) {
+ struct timeval timevalClose = timeval_init(0, 1);
int i = 0;
- for (i = 0; i < COUNTOF(fdata); i++) {
+ for (i = 0; i < COUNTOF(fdata); ++i) {
l_fp a = l_fp_init(~0, fdata[i].frac);
struct timeval E = timeval_init(-1, fdata[i].usec);
struct timeval r;
r = lfp_intv_to_tval(a);
- TEST_ASSERT_TRUE(AssertTimevalClose(E,r,timevalClose));
+ TEST_ASSERT_TRUE(AssertTimevalClose(E, r, timevalClose));
}
}
+
// usec -> frac -> usec roundtrip, using a prime start and increment
-void test_LFProundtrip(void) {
+void
+test_LFProundtrip(void) {
int32_t t = -1;
u_int32 i = 5;
for (t = -1; t < 2; ++t)
- for (i = 5; i < 1000000; i+=11) {
+ for (i = 5; i < 1000000; i += 11) {
struct timeval E = timeval_init(t, i);
l_fp a;
struct timeval r;
// string formatting
//----------------------------------------------------------------------
-void test_ToString(void) {
+void
+test_ToString(void) {
static const struct {
time_t sec;
long usec;