Exemplo n.º 1
0
//----------------------------------------------------------------------
// test absolute value
//----------------------------------------------------------------------
void
test_Absolute(void)
{
	size_t idx = 0;

	for (idx = 0; idx < addsub_cnt; ++idx) {
		l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
		l_fp op2 = l_fp_abs(op1);

		TEST_ASSERT_TRUE(l_fp_signum(op2) >= 0);

		if (l_fp_signum(op1) >= 0)
			op1 = l_fp_subtract(op1, op2);
		else
			op1 = l_fp_add(op1, op2);

		l_fp zero = l_fp_init(0, 0);

		TEST_ASSERT_EQUAL_l_fp(zero, op1);
	}

	// There is one special case we have to check: the minimum
	// value cannot be negated, or, to be more precise, the
	// negation reproduces the original pattern.
	l_fp minVal = l_fp_init(0x80000000, 0x00000000);
	l_fp minAbs = l_fp_abs(minVal);
	TEST_ASSERT_EQUAL(-1, l_fp_signum(minVal));

	TEST_ASSERT_EQUAL_l_fp(minVal, minAbs);

	return;
}
Exemplo n.º 2
0
void test_ToLFPrelNeg() {
	l_fp lfpClose =  l_fp_init(0,1);
	int i = 0;
	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)); //ASSERT_PRED_FORMAT2(FpClose,E, r);
	}
}
Exemplo n.º 3
0
void test_ToLFPbittest() {
	l_fp lfpClose =  l_fp_init(0,1);	

	u_int32 i = 0;
	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 r;

		r = tval_intv_to_lfp(a);
		TEST_ASSERT_TRUE(AssertFpClose(E,r,lfpClose));	//ASSERT_PRED_FORMAT2(FpClose, E, r);
	}
}
Exemplo n.º 4
0
void
test_ToLFPabs(void) {
	l_fp lfpClose =  l_fp_init(0, 1);

	int i = 0;
	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));
	}
}
Exemplo n.º 5
0
void
test_SubtractionRL(void)
{
	size_t idx = 0;

	for (idx = 0; idx < addsub_cnt; ++idx) {
		l_fp e_res = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
		l_fp op2 = l_fp_init(addsub_tab[idx][1].h, addsub_tab[idx][1].l);
		l_fp op1 = l_fp_init(addsub_tab[idx][2].h, addsub_tab[idx][2].l);
		l_fp res = l_fp_subtract(op1, op2);

		TEST_ASSERT_EQUAL_l_fp(e_res, res);
	}
	return;
}
Exemplo n.º 6
0
void
test_Negation(void)
{
	size_t idx = 0;

	for (idx = 0; idx < addsub_cnt; ++idx) {
		l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
		l_fp op2 = l_fp_negate(op1);
		l_fp sum = l_fp_add(op1, op2);

		l_fp zero = l_fp_init(0, 0);

		TEST_ASSERT_EQUAL_l_fp(zero, sum);
	}
	return;
}
Exemplo n.º 7
0
void
test_ToLFPrelNeg(void)
{
	l_fp lfpClose =  l_fp_init(0, 1);
	int i = 0;

	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));
	}

	return;
}
Exemplo n.º 8
0
//----------------------------------------------------------------------
// test the compare stuff
//
// This uses the local compare and checks if the operations using the
// macros in 'ntp_fp.h' produce mathing results.
// ----------------------------------------------------------------------
void
test_SignedRelOps(void)
{
	const lfp_hl * tv = (&addsub_tab[0][0]);
	size_t lc ;

	for (lc = addsub_tot - 1; lc; --lc, ++tv) {
		l_fp op1 = l_fp_init(tv[0].h, tv[0].l);
		l_fp op2 = l_fp_init(tv[1].h, tv[1].l);
		int cmp = l_fp_scmp(op1, op2);

		switch (cmp) {
		case -1:
			//printf("op1:%d %d, op2:%d %d\n",op1.l_uf,op1.l_ui,op2.l_uf,op2.l_ui);
			l_fp_swap(&op1, &op2);
			//printf("op1:%d %d, op2:%d %d\n",op1.l_uf,op1.l_ui,op2.l_uf,op2.l_ui);
		case 1:
			TEST_ASSERT_TRUE (l_isgt(op1, op2));
			TEST_ASSERT_FALSE(l_isgt(op2, op1));

			TEST_ASSERT_TRUE (l_isgeq(op1, op2));
			TEST_ASSERT_FALSE(l_isgeq(op2, op1));

			TEST_ASSERT_FALSE(l_isequ(op1, op2));
			TEST_ASSERT_FALSE(l_isequ(op2, op1));
			break;
		case 0:
			TEST_ASSERT_FALSE(l_isgt(op1, op2));
			TEST_ASSERT_FALSE(l_isgt(op2, op1));

			TEST_ASSERT_TRUE (l_isgeq(op1, op2));
			TEST_ASSERT_TRUE (l_isgeq(op2, op1));

			TEST_ASSERT_TRUE (l_isequ(op1, op2));
			TEST_ASSERT_TRUE (l_isequ(op2, op1));
			break;
		default:
			TEST_FAIL_MESSAGE("unexpected UCMP result: ");
		}
	}

	return;
}
Exemplo n.º 9
0
void test_FromLFPrelNeg() {
	struct timeval timevalClose = timeval_init(0,1);
	int i = 0;
	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)); //ASSERT_PRED_FORMAT2(TimevalClose, E, r);
	}
}
Exemplo n.º 10
0
void
test_FromLFPrelPos(void) {
	struct timeval timevalClose = timeval_init(0, 1);
	int i = 0;	
	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));
	}
}
Exemplo n.º 11
0
void test_FromLFPbittest() {
	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.
	u_int32 tsf = 0;
	for (tsf = 0; tsf < ~((u_int32)(1000)); tsf += 1000) {
		struct timeval E = timeval_init(1, my_tsf_to_tick(tsf));
		l_fp a = l_fp_init(1, tsf);
		struct timeval r;

		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)); //ASSERT_PRED_FORMAT2(TimevalClose, E, r);
	}
}
Exemplo n.º 12
0
//----------------------------------------------------------------------
// fp -> double -> fp rountrip test
//----------------------------------------------------------------------
void
test_FDF_RoundTrip(void)
{
	size_t idx = 0;

	// since a l_fp has 64 bits in it's mantissa and a double has
	// only 54 bits available (including the hidden '1') we have to
	// make a few concessions on the roundtrip precision. The 'eps()'
	// function makes an educated guess about the avilable precision
	// and checks the difference in the two 'l_fp' values against
	// that limit.

	for (idx = 0; idx < addsub_cnt; ++idx) {
		l_fp op1 = l_fp_init(addsub_tab[idx][0].h, addsub_tab[idx][0].l);
		double op2 = l_fp_convert_to_double(op1);
		l_fp op3 = l_fp_init_from_double(op2); 

		l_fp temp = l_fp_subtract(op1, op3);
		double d = l_fp_convert_to_double(temp);
		TEST_ASSERT_DOUBLE_WITHIN(eps(op2), 0.0, fabs(d));
	}

	return;
}