]> git.saurik.com Git - apple/xnu.git/blobdiff - tests/ntp_adjtime_29192647.c
xnu-7195.101.1.tar.gz
[apple/xnu.git] / tests / ntp_adjtime_29192647.c
index 28663859ed5da585a503923df992d66c7de2a4e5..c29db4bfe16671bebad1c7065b6f06155a98319a 100644 (file)
 #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);
@@ -54,7 +54,9 @@ T_DECL(settimeofday_29192647,
        }
 }
 
-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;
@@ -63,13 +65,13 @@ static void get_abs_to_us_scale_factor(uint64_t* numer, uint64_t* denom){
 
        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);
@@ -81,10 +83,11 @@ static void get_abs_to_us_scale_factor(uint64_t* numer, uint64_t* denom){
        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);
 
@@ -97,8 +100,8 @@ static void get_abs_to_us_scale_factor(uint64_t* numer, uint64_t* denom){
 #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;
@@ -113,17 +116,16 @@ T_DECL(adjtime_29192647,
 #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.");
        }
 
@@ -134,7 +136,7 @@ T_DECL(adjtime_29192647,
 
        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;
@@ -147,21 +149,21 @@ T_DECL(adjtime_29192647,
         * 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;
@@ -178,7 +180,6 @@ T_DECL(adjtime_29192647,
        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)*/
@@ -186,8 +187,8 @@ T_DECL(adjtime_29192647,
 #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;
@@ -202,18 +203,17 @@ T_DECL(ntp_adjtime_29192647,
        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.");
        }
 
@@ -229,10 +229,10 @@ T_DECL(ntp_adjtime_29192647,
 
        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);
 
@@ -246,13 +246,13 @@ T_DECL(ntp_adjtime_29192647,
 
        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;
@@ -261,14 +261,14 @@ T_DECL(ntp_adjtime_29192647,
        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;
 
@@ -283,8 +283,8 @@ T_DECL(ntp_adjtime_29192647,
        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);
@@ -300,28 +300,28 @@ T_DECL(ntp_adjtime_29192647,
        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);
 
@@ -336,7 +336,7 @@ T_DECL(ntp_adjtime_29192647,
 
        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;
@@ -356,16 +356,13 @@ T_DECL(ntp_adjtime_29192647,
        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);
-
 }
-
-