1 /* Copyright 2013-2015 IBM Corp. 2 * 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 12 * implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include <stdint.h> 18 #include <stdlib.h> 19 #include <stdio.h> 20 #include <assert.h> 21 22 #define __TEST__ 23 #include <timebase.h> 24 25 unsigned long tb_hz = 512000000; 26 main(void)27int main(void) 28 { 29 /* This is a fairly solid assumption that the math we're doing 30 * is based on tb_hz of exactly 512mhz. 31 * If we do start doing the math on different tb_hz, you probably 32 * want to go and audit every bit of code that touches tb to 33 * count/delay things. 34 */ 35 assert(tb_hz == 512000000); 36 assert(secs_to_tb(1) == tb_hz); 37 assert(secs_to_tb(2) == 1024000000); 38 assert(secs_to_tb(10) == 5120000000); 39 assert(tb_to_secs(512000000) == 1); 40 assert(tb_to_secs(5120000000) == 10); 41 assert(tb_to_secs(1024000000) == 2); 42 43 assert(msecs_to_tb(1) == 512000); 44 assert(msecs_to_tb(100) == 51200000); 45 assert(msecs_to_tb(5) == 2560000); 46 assert(tb_to_msecs(512000) == 1); 47 48 assert(usecs_to_tb(5) == 2560); 49 assert(tb_to_usecs(2560) == 5); 50 assert(usecs_to_tb(5)*1000 == msecs_to_tb(5)); 51 assert(tb_to_usecs(512000) == 1000); 52 53 assert(tb_compare(msecs_to_tb(5), usecs_to_tb(5)) == TB_AAFTERB); 54 assert(tb_compare(msecs_to_tb(5), usecs_to_tb(50000)) == TB_ABEFOREB); 55 assert(tb_compare(msecs_to_tb(5), usecs_to_tb(5)*1000) == TB_AEQUALB); 56 57 return 0; 58 } 59