1.Test Cases

All these test cases can be found at gsoc-lib/TestCases/ folder at source code

1.1 Conversion from UTC to GPS

struct time_struct t1,t2,gps1,gps2;
t1.timestamp.Uf_i.Xf_ui = 1379977315;
t1.timestamp.f_uf = 0;
t1.timescale = 131329; //2013d

t2.timestamp.Uf_i.Xf_ui = 1379977313;
t2.timestamp.f_uf = 0;
t2.timescale = 131328; //2006a

convert_to_gps(&t1,&gps1);
convert_to_gps(&t2,&gps2);

printf("utc(2013d): %lld,%lld\n",t1.timestamp.Uf_i.Xf_ui,t1.timestamp.f_uf);
printf("gps1      : %lld,%lld\n",gps1.timestamp.Uf_i.Xf_ui,gps1.timestamp.f_uf);
printf("utc(2006d): %lld,%lld\n",t2.timestamp.Uf_i.Xf_ui,t2.timestamp.f_uf);
printf("gps2      : %lld,%lld\n",gps2.timestamp.Uf_i.Xf_ui,gps2.timestamp.f_uf);

The excution result is as below:
[root@limifly-vpc TestCase]# gcc test1.c /root/gsoc-lib/libtimestamp.so -o test1
[root@limifly-vpc TestCase]# ./test1
utc(2013d): 1379977315,0
gps1      : 1379977290,0
utc(2006d): 1379977313,0
gps2      : 1379977290,0

1.2 Conversion from GPS to UTC

struct time_struct t1,t2,gps;
gps.timestamp.Uf_i.Xf_ui = 1379977290;
gps.timestamp.f_uf = 0;
gps.timescale = 65536;

convert_from_gps(&gps,&t1,131328); //2006a
convert_from_gps(&gps,&t2,131329); //2013d

printf("gps       : %lld,%lld\n",gps.timestamp.Uf_i.Xf_ui,gps.timestamp.f_uf);
printf("utc(2006a): %lld,%lld\n",t1.timestamp.Uf_i.Xf_ui,t1.timestamp.f_uf);
printf("utc(2013d): %lld,%lld\n",t2.timestamp.Uf_i.Xf_ui,t2.timestamp.f_uf);

The excution result is as below:
[root@limifly-vpc TestCase]# gcc test2.c /root/gsoc-lib/libtimestamp.so -o test2
[root@limifly-vpc TestCase]# ./test2
gps       : 1379977290,0
utc(2006a): 1379977313,0
utc(2013d): 1379977315,0

1.3 Conversion from IERS-A to GPS

struct time_struct t1,t2,t3,gps1,gps2,gps3;
t1.timescale = 196609; //iers bulletina-xxv-027
t1.timestamp.Uf_i.Xf_ui = 1341100800;
t1.timestamp.f_uf = 0;
convert_to_gps(&t1,&gps1);
printf("IERS-A xxv-027 : %lld,%lld\n",t1.timestamp.Uf_i.Xf_ui,t1.timestamp.f_uf);
printf("gps1           : %lld,%lld\n",gps1.timestamp.Uf_i.Xf_ui,gps1.timestamp.f_uf);


t2.timescale = 196610; //iers bulletina-xxvi-035
t2.timestamp.Uf_i.Xf_ui = 1377475200;
t2.timestamp.f_uf = 0;
convert_to_gps(&t2,&gps2);
printf("IERS-A xxvi-035: %lld,%lld\n",t2.timestamp.Uf_i.Xf_ui,t2.timestamp.f_uf);
printf("gps2           : %lld,%lld\n",gps2.timestamp.Uf_i.Xf_ui,gps2.timestamp.f_uf);

t3.timescale = 196610; //iers bulletina-xxvi-035
t3.timestamp.Uf_i.Xf_ui = 1377518400;
t3.timestamp.f_uf = 0;
convert_to_gps(&t3,&gps3);
printf("IERS-A xxvi-035: %lld,%lld\n",t3.timestamp.Uf_i.Xf_ui,t3.timestamp.f_uf);
printf("gps3           : %lld,%lld\n",gps3.timestamp.Uf_i.Xf_ui,gps3.timestamp.f_uf);

The excution result is as below:
[root@limifly-vpc TestCase]# gcc test3.c /root/gsoc-lib/libtimestamp.so -o test3
[root@limifly-vpc TestCase]# ./test3
IERS-A xxv-027 : 1341100800,0
gps1           : 1341100775,586777000
IERS-A xxvi-035: 1377475200,0
gps2           : 1377475174,960010000
IERS-A xxvi-035: 1377518400,0
gps3           : 1377518374,960244500

1.4 Conversion from GPS to IERS-A

struct time_struct t1,t2,gps1,gps2;
gps1.timescale = 65536;
gps1.timestamp.Uf_i.Xf_ui = 1341187175;
gps1.timestamp.f_uf = 413415000;
convert_from_gps(&gps1,&t1,196609); //iers bulletina-xxv-027
printf("gps1           : %lld,%lld\n",gps1.timestamp.Uf_i.Xf_ui,gps1.timestamp.f_uf);
printf("IERS-A xxv-027 : %lld,%lld\n",t1.timestamp.Uf_i.Xf_ui,t1.timestamp.f_uf);

gps2.timescale = 65536; //iers bulletina-xxvi-035
gps2.timestamp.Uf_i.Xf_ui = 1341014399;//1341057599;
gps2.timestamp.f_uf = 413146000;
convert_from_gps(&gps2,&t2,196609); //iers bulletina-xxv-027
printf("gps2 (leap_sec): %lld,%lld\n",gps2.timestamp.Uf_i.Xf_ui,gps2.timestamp.f_uf);
printf("IERS-A xxv-027 : %lld,%lld\n",t2.timestamp.Uf_i.Xf_ui,t2.timestamp.f_uf);

The excution result is as below:
[root@limifly-vpc TestCase]# gcc test4.c /root/gsoc-lib/libtimestamp.so -o test4
[root@limifly-vpc TestCase]# ./test4
gps1           : 1341187175,413415000
IERS-A xxv-027 : 1341187200,0
gps2 (leap_sec): 1341014399,413146000
IERS-A xxv-027 : 1341014423,999722225

1.5 Comparison between timestamps

struct time_struct t1,t2,t3;
int i;
my_gettimeofday(&t1);
convert_to_gps(&t1,&t2);
convert_from_gps(&t2,&t3,131328);

printf("utc(2013d) : %lld,%lld\n",t1.timestamp.Uf_i.Xf_ui,t1.timestamp.f_uf);
printf("gps tick   : %lld,%lld\n",t2.timestamp.Uf_i.Xf_ui,t2.timestamp.f_uf);
printf("utc(2006a) : %lld,%lld\n",t3.timestamp.Uf_i.Xf_ui,t3.timestamp.f_uf);
printf("Compare1   : %d\n",compare_timestamp(&t2,&t1));

struct time_struct t4,t5,t6,t7;
t4.timescale = 65536;
t4.timestamp.Uf_i.Xf_ui = 1379983024;
t4.timestamp.f_uf = 0;
t5.timescale = 65536;
t5.timestamp.Uf_i.Xf_ui = 1379983023;
t5.timestamp.f_uf = 0;
t6.timescale = 65536;
t6.timestamp.Uf_i.Xf_ui = 1379983025;
t6.timestamp.f_uf = 0;
t7.timescale = 65536;
t7.timestamp.Uf_i.Xf_ui = 1379983024;
t7.timestamp.f_uf = 0;
printf("Compare2   : %d\n",compare_timestamp(&t4,&t5));
printf("Compare3   : %d\n",compare_timestamp(&t4,&t6));
printf("Compare4   : %d\n",compare_timestamp(&t4,&t7));

The excution result is as below:
[root@limifly-vpc TestCase]# gcc test5.c /root/gsoc-lib/libtimestamp.so -o test5
[root@limifly-vpc TestCase]# ./test5
utc(2013d) : 1379983288,855395839
gps tick   : 1379983263,855395839
utc(2006a) : 1379983286,855395839
Compare1   : 0
Compare2   : 1
Compare3   : -1
Compare4   : 0

1.6 Add/Subtract/Get offset

struct time_struct t1,t2,t3;
struct f_fp offset;

t1.timescale = 65536;
t1.timestamp.Uf_i.Xf_ui = 1379983024;
t1.timestamp.f_uf = 0;

t2.timescale = 65536;
t2.timestamp.Uf_i.Xf_ui = 1379983029;
t2.timestamp.f_uf = 0;

offset = get_offset(&t2,&t1);

printf("offset     : %lld,%lld\n",offset.Uf_i.Xf_ui,offset.f_uf);

struct time_struct t4 = add(&t1,&offset);
struct time_struct t5 = subtract(&t2,&offset);

printf("add result : %lld,%lld\n",t4.timestamp.Uf_i.Xf_ui,t4.timestamp.f_uf);
printf("sub result : %lld,%lld\n",t5.timestamp.Uf_i.Xf_ui,t5.timestamp.f_uf);

The excution result is as below:
[root@limifly-vpc TestCase]# gcc test6.c /root/gsoc-lib/libtimestamp.so -o test6
[root@limifly-vpc TestCase]# ./test6
offset     : 5,0
add result : 1379983029,0
sub result : 1379983024,0

1.7 discontinuity counter

struct time_struct t1,t2,t3;
my_gettimeofday(&t1);
printf("discontinuity count: %d\n",t1.discon_count);

struct timeval temp1;

gettimeofday(&temp1,NULL);
settimeofday(&temp1,NULL);
printf("call settimeofday()\n");
my_gettimeofday(&t2);
printf("discontinuity count: %d\n",t2.discon_count);

struct timespec temp2;
clock_gettime(CLOCK_REALTIME, &temp2);
clock_settime(CLOCK_REALTIME, &temp2);
printf("call clock_settime()\n");
my_gettimeofday(&t3);
printf("discontinuity count: %d\n",t3.discon_count);

The excution result is as below (!!Remember that compiling this test case need "-lrt" option):
[root@limifly-vpc TestCase]# gcc test7.c /root/gsoc-lib/libtimestamp.so -o test7 -lrt
[root@limifly-vpc TestCase]# ./test7
discontinuity count: 1
call settimeofday()
discontinuity count: 2
call clock_settime()
discontinuity count: 3

1.8 discontinuity counter

struct time_struct t1,t2,t3;
my_gettimeofday(&t1);
printf("exp_error(first time): %d\n",t1.exp_error);

my_gettimeofday(&t2);
printf("exp_error(second time): %d\n",t2.exp_error);

int i,j,k;
for (i=0;i<1000000;i++) {
    for (j=0;j<5000;j++) {
        k = 0;
    }
}

my_gettimeofday(&t3);
printf("exp_error(third time): %d\n",t3.exp_error);

The excution result is as below :
[root@limifly-vpc TestCase]# gcc test8.c /root/gsoc-lib/libtimestamp.so -o test8
[root@limifly-vpc TestCase]# ./test8
exp_error(first time): 10245 (From chenli: this value will be -1 if it is the first time calling "my_gettimeofday()" since system start up)
exp_error(second time): 10245
exp_error(third time): 10255

-- ChenLi - 23 Sep 2013
Topic revision: r3 - 08 Feb 2014, HarlanStenn
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Network Time Foundation Community Wiki? Send feedback