Home | History | Annotate | Download | only in Unit
      1 //===-- absvsi2_test.c - Test __absvsi2 -----------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file tests __absvsi2 for the compiler_rt library.
     11 //
     12 //===----------------------------------------------------------------------===//
     13 
     14 #include "int_lib.h"
     15 #include <stdio.h>
     16 #include <stdlib.h>
     17 
     18 // Returns: absolute value
     19 
     20 // Effects: aborts if abs(x) < 0
     21 
     22 si_int __absvsi2(si_int a);
     23 
     24 int test__absvsi2(si_int a)
     25 {
     26     si_int x = __absvsi2(a);
     27     si_int expected = a;
     28     if (expected < 0)
     29         expected = -expected;
     30     if (x != expected || expected < 0)
     31         printf("error in __absvsi2(0x%X) = %d, expected positive %d\n",
     32                a, x, expected);
     33     return x != expected;
     34 }
     35 
     36 int main()
     37 {
     38 //     if (test__absvsi2(0x80000000))  // should abort
     39 //         return 1;
     40     if (test__absvsi2(0x00000000))
     41         return 1;
     42     if (test__absvsi2(0x00000001))
     43         return 1;
     44     if (test__absvsi2(0x00000002))
     45         return 1;
     46     if (test__absvsi2(0x7FFFFFFE))
     47         return 1;
     48     if (test__absvsi2(0x7FFFFFFF))
     49         return 1;
     50     if (test__absvsi2(0x80000001))
     51         return 1;
     52     if (test__absvsi2(0x80000002))
     53         return 1;
     54     if (test__absvsi2(0xFFFFFFFE))
     55         return 1;
     56     if (test__absvsi2(0xFFFFFFFF))
     57         return 1;
     58 
     59     int i;
     60     for (i = 0; i < 10000; ++i)
     61         if (test__absvsi2(rand()))
     62             return 1;
     63 
     64     return 0;
     65 }
     66