#define ERROR 2 /*2 us of error tolerance*/
T_DECL(settimeofday_29192647,
- "Verify that the syscall settimeofday is effective",
- T_META_ASROOT(true), T_META_CHECK_LEAKS(NO), T_META_LTEPHASE(LTE_POSTINIT))
+ "Verify that the syscall settimeofday is effective",
+ T_META_ASROOT(true), T_META_CHECK_LEAKS(NO), T_META_LTEPHASE(LTE_POSTINIT))
{
struct timeval time;
long new_time;
- if (geteuid() != 0){
- T_SKIP("settimeofday_29192647 test requires root privileges to run.");
- }
+ if (geteuid() != 0) {
+ T_SKIP("settimeofday_29192647 test requires root privileges to run.");
+ }
T_QUIET;
T_ASSERT_POSIX_ZERO(gettimeofday(&time, NULL), NULL);
}
}
-static void get_abs_to_us_scale_factor(uint64_t* numer, uint64_t* denom){
+static void
+get_abs_to_us_scale_factor(uint64_t* numer, uint64_t* denom)
+{
struct timespec time;
uint64_t old_abstime, new_abstime;
uint64_t old_time_usec, new_time_usec;
T_QUIET; T_ASSERT_EQ(mach_get_times(&old_abstime, NULL, &time), KERN_SUCCESS, NULL);
- old_time_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec/1000;
+ old_time_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec / 1000;
sleep(1);
T_QUIET; T_ASSERT_EQ(mach_get_times(&new_abstime, NULL, &time), KERN_SUCCESS, NULL);
- new_time_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec/1000;
+ new_time_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec / 1000;
/* this is conversion factors from abs to nanos */
T_ASSERT_EQ(mach_timebase_info(&timebaseInfo), KERN_SUCCESS, NULL);
time_conv1 *= timebaseInfo.numer;
time_conv1 /= timebaseInfo.denom * 1000;
- if (time_conv1 > new_time_usec)
+ if (time_conv1 > new_time_usec) {
diff = time_conv1 - new_time_usec;
- else
+ } else {
diff = new_time_usec - time_conv1;
+ }
T_EXPECT_LE_ULLONG(diff, (unsigned long long)ERROR, "Check scale factor time base (%u/%u) delta read usec %llu delta converted %llu delta abs %llu", timebaseInfo.numer, timebaseInfo.denom, time_conv1, new_time_usec, new_abstime);
#define ADJTIME_OFFSET_PER_SEC 500
T_DECL(adjtime_29192647,
- "Verify that the syscall adjtime is effective",
- T_META_CHECK_LEAKS(NO), T_META_LTEPHASE(LTE_POSTINIT), T_META_ASROOT(true))
+ "Verify that the syscall adjtime is effective",
+ T_META_CHECK_LEAKS(NO), T_META_LTEPHASE(LTE_POSTINIT), T_META_ASROOT(true))
{
struct timespec time;
struct timeval adj;
#endif
if (geteuid() != 0) {
- T_SKIP("adjtime_29192647 test requires root privileges to run.");
- }
+ T_SKIP("adjtime_29192647 test requires root privileges to run.");
+ }
lterdos_env = getenv("LTERDOS");
- if (lterdos_env != NULL){
+ if (lterdos_env != NULL) {
if (!(strcmp(lterdos_env, "YES") == 0)) {
- T_SKIP("adjtime_29192647 test requires LTE to run.");
+ T_SKIP("adjtime_29192647 test requires LTE to run.");
}
- }
- else {
+ } else {
T_SKIP("adjtime_29192647 test requires LTE to run.");
}
T_QUIET; T_ASSERT_EQ(mach_get_times(&old_abstime, NULL, &time), KERN_SUCCESS, NULL);
- old_time_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec/1000;
+ old_time_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec / 1000;
adj.tv_sec = 0;
adj.tv_usec = ADJSTMENT;
* until the last second is slewed the final < 500 usecs.
*/
T_WITH_ERRNO;
- T_ASSERT_POSIX_ZERO(adjtime(&adj, NULL),NULL);
+ T_ASSERT_POSIX_ZERO(adjtime(&adj, NULL), NULL);
/*
* Wait that the full adjustment is applied.
* Note, add 2 more secs for take into account division error
* and that the last block of adj is fully elapsed.
*/
- sleep_time = (ADJSTMENT)/(ADJTIME_OFFSET_PER_SEC)+2;
+ sleep_time = (ADJSTMENT) / (ADJTIME_OFFSET_PER_SEC)+2;
T_LOG("Waiting for %u sec\n", sleep_time);
sleep(sleep_time);
T_QUIET; T_ASSERT_EQ(mach_get_times(&new_abstime, NULL, &time), KERN_SUCCESS, NULL);
- new_time_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec/1000;
+ new_time_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec / 1000;
us_delta = new_time_usec - old_time_usec;
us_delta -= ADJSTMENT;
T_EXPECT_LE_LONG(diff, (long) ERROR, "Check abs time vs calendar time");
T_EXPECT_GE_LONG(diff, (long) -ERROR, "Check abs time vs calendar time");
-
}
#define FREQ_PPM 222 /*222 PPM(us/s)*/
#define OFFSET_US 123 /*123us*/
T_DECL(ntp_adjtime_29192647,
- "Verify that the syscall ntp_adjtime is effective",
- T_META_CHECK_LEAKS(NO), T_META_LTEPHASE(LTE_POSTINIT), T_META_ASROOT(true))
+ "Verify that the syscall ntp_adjtime is effective",
+ T_META_CHECK_LEAKS(NO), T_META_LTEPHASE(LTE_POSTINIT), T_META_ASROOT(true))
{
struct timespec time;
struct timex ntptime;
T_SKIP("ntp_adjtime_29192647 test requires LTE to run.");
#endif
- if (geteuid() != 0){
- T_SKIP("ntp_adjtime_29192647 test requires root privileges to run.");
- }
+ if (geteuid() != 0) {
+ T_SKIP("ntp_adjtime_29192647 test requires root privileges to run.");
+ }
lterdos_env = getenv("LTERDOS");
- if (lterdos_env != NULL){
+ if (lterdos_env != NULL) {
if (!(strcmp(lterdos_env, "YES") == 0)) {
- T_SKIP("adjtime_29192647 test requires LTE to run.");
+ T_SKIP("adjtime_29192647 test requires LTE to run.");
}
- }
- else {
+ } else {
T_SKIP("adjtime_29192647 test requires LTE to run.");
}
ntptime.modes = MOD_STATUS;
ntptime.status = TIME_OK;
- /* ntp input freq is in ppm (us/s) * 2^16, max freq is 500 ppm */
- freq = (FREQ_PPM) * 65536;
+ /* ntp input freq is in ppm (us/s) * 2^16, max freq is 500 ppm */
+ freq = (FREQ_PPM) * 65536;
ntptime.modes |= MOD_FREQUENCY;
- ntptime.freq = freq;
+ ntptime.freq = freq;
T_LOG("Attemping to change calendar frequency of %d ppm", FREQ_PPM);
T_QUIET; T_ASSERT_EQ(mach_get_times(&abstime1, NULL, &time), KERN_SUCCESS, NULL);
- time1_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec/1000;
+ time1_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec / 1000;
sleep(1);
T_QUIET; T_ASSERT_EQ(mach_get_times(&abstime2, NULL, &time), KERN_SUCCESS, NULL);
- time2_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec/1000;
+ time2_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec / 1000;
abs_delta = abstime2 - abstime1;
us_delta = time2_usec - time1_usec;
time_conv *= num;
time_conv /= den;
- app = time_conv/USEC_PER_SEC; //sec elapsed
+ app = time_conv / USEC_PER_SEC; //sec elapsed
time_delta = time_conv;
time_delta += app * (FREQ_PPM);
- app = time_conv%USEC_PER_SEC;
+ app = time_conv % USEC_PER_SEC;
- time_delta += (app*(FREQ_PPM))/USEC_PER_SEC;
+ time_delta += (app * (FREQ_PPM)) / USEC_PER_SEC;
diff = (long) us_delta - (long) time_delta;
freq = 0;
ntptime.modes = MOD_STATUS;
ntptime.status = TIME_OK;
- ntptime.modes |= MOD_FREQUENCY;
- ntptime.freq = freq;
+ ntptime.modes |= MOD_FREQUENCY;
+ ntptime.freq = freq;
T_WITH_ERRNO;
T_ASSERT_EQ(ntp_adjtime(&ntptime), TIME_OK, NULL);
memset(&ntptime, 0, sizeof(ntptime));
ntptime.modes |= MOD_STATUS;
ntptime.status = TIME_OK;
- ntptime.status |= STA_PLL|STA_FREQHOLD;
+ ntptime.status |= STA_PLL | STA_FREQHOLD;
/* ntp input phase can be both ns or us (MOD_MICRO), max offset is 500 ms */
- ntptime.offset = OFFSET_US;
- ntptime.modes |= MOD_OFFSET|MOD_MICRO;
+ ntptime.offset = OFFSET_US;
+ ntptime.modes |= MOD_OFFSET | MOD_MICRO;
/*
* The system will slew each sec of:
* slew = ntp.offset >> (SHIFT_PLL + time_constant);
* ntp.offset -= slew;
*/
- offset= (OFFSET_US) * 1000;
+ offset = (OFFSET_US) * 1000;
sleep_time = 2;
- while((offset>>SHIFT_PLL)>0){
+ while ((offset >> SHIFT_PLL) > 0) {
offset -= offset >> SHIFT_PLL;
sleep_time++;
}
T_QUIET; T_ASSERT_EQ(mach_get_times(&abstime1, NULL, &time), KERN_SUCCESS, NULL);
- time1_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec/1000;
+ time1_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec / 1000;
T_LOG("Attemping to change calendar phase of %d us", OFFSET_US);
T_QUIET; T_ASSERT_EQ(mach_get_times(&abstime2, NULL, &time), KERN_SUCCESS, NULL);
- time2_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec/1000;
+ time2_usec = (uint64_t)time.tv_sec * USEC_PER_SEC + (uint64_t)time.tv_nsec / 1000;
abs_delta = abstime2 - abstime1;
us_delta = time2_usec - time1_usec;
memset(&ntptime, 0, sizeof(ntptime));
ntptime.modes = MOD_STATUS;
ntptime.status = TIME_OK;
- ntptime.modes |= MOD_FREQUENCY;
- ntptime.freq = 0;
+ ntptime.modes |= MOD_FREQUENCY;
+ ntptime.freq = 0;
ntptime.status |= STA_PLL;
- ntptime.offset = 0;
+ ntptime.offset = 0;
ntptime.modes |= MOD_OFFSET;
T_WITH_ERRNO;
T_ASSERT_EQ(ntp_adjtime(&ntptime), TIME_OK, NULL);
-
}
-
-