xref: /aosp_15_r20/external/compiler-rt/test/builtins/Unit/test (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot#!/usr/bin/env bash
2*7c3d14c8STreehugger Robot
3*7c3d14c8STreehugger RobotARCHS='<host>'
4*7c3d14c8STreehugger RobotREMOTE=0
5*7c3d14c8STreehugger Robotif test `uname` = "Darwin"; then
6*7c3d14c8STreehugger Robot  if test "$1" = "armv6"; then
7*7c3d14c8STreehugger Robot    ARCHS="armv6"
8*7c3d14c8STreehugger Robot    LIBS="-lSystem"
9*7c3d14c8STreehugger Robot    REMOTE=1
10*7c3d14c8STreehugger Robot    mkdir -p remote
11*7c3d14c8STreehugger Robot  else
12*7c3d14c8STreehugger Robot    ARCHS="i386 x86_64 ppc"
13*7c3d14c8STreehugger Robot    LIBS="-lSystem"
14*7c3d14c8STreehugger Robot  fi
15*7c3d14c8STreehugger Robotelse
16*7c3d14c8STreehugger Robot  LIBS="-lc -lm"
17*7c3d14c8STreehugger Robotfi
18*7c3d14c8STreehugger Robot
19*7c3d14c8STreehugger Robotfor ARCH in $ARCHS; do
20*7c3d14c8STreehugger Robot  CFLAGS="-Os -nodefaultlibs -I../../lib"
21*7c3d14c8STreehugger Robot  if test "$ARCH" != '<host>'; then
22*7c3d14c8STreehugger Robot    CFLAGS="-arch $ARCH $CFLAGS"
23*7c3d14c8STreehugger Robot  fi
24*7c3d14c8STreehugger Robot  for FILE in $(ls *.c); do
25*7c3d14c8STreehugger Robot    # Use -nodefaultlibs to avoid using libgcc.a
26*7c3d14c8STreehugger Robot    # Use -lSystem to link with libSystem.dylb.
27*7c3d14c8STreehugger Robot    # Note -lSystem is *after* libcompiler_rt.Optimized.a so that linker will
28*7c3d14c8STreehugger Robot    # prefer our implementation over the ones in libSystem.dylib
29*7c3d14c8STreehugger Robot    EXTRA=
30*7c3d14c8STreehugger Robot    if test $FILE = gcc_personality_test.c
31*7c3d14c8STreehugger Robot    then
32*7c3d14c8STreehugger Robot      # the gcc_personality_test.c requires a helper C++ program
33*7c3d14c8STreehugger Robot      EXTRA="-fexceptions gcc_personality_test_helper.cxx -lstdc++ /usr/lib/libgcc_s.1.dylib"
34*7c3d14c8STreehugger Robot      # the libgcc_s.1.dylib use at the end is a hack until libSystem contains _Unwind_Resume
35*7c3d14c8STreehugger Robot    fi
36*7c3d14c8STreehugger Robot    if test $FILE = trampoline_setup_test.c
37*7c3d14c8STreehugger Robot    then
38*7c3d14c8STreehugger Robot      # this test requires an extra compiler option
39*7c3d14c8STreehugger Robot      EXTRA="-fnested-functions"
40*7c3d14c8STreehugger Robot    fi
41*7c3d14c8STreehugger Robot    if test "$REMOTE" = "1"
42*7c3d14c8STreehugger Robot    then
43*7c3d14c8STreehugger Robot      if gcc $CFLAGS $FILE ../../darwin_fat/Release/libcompiler_rt.a $LIBS $EXTRA -o ./remote/$FILE.exe
44*7c3d14c8STreehugger Robot      then
45*7c3d14c8STreehugger Robot        echo "Built $FILE.exe for $ARCH"
46*7c3d14c8STreehugger Robot      else
47*7c3d14c8STreehugger Robot        echo "$FILE failed to compile"
48*7c3d14c8STreehugger Robot      fi
49*7c3d14c8STreehugger Robot    else
50*7c3d14c8STreehugger Robot      if gcc $CFLAGS $FILE ../../darwin_fat/Release/libcompiler_rt.a $LIBS $EXTRA
51*7c3d14c8STreehugger Robot      then
52*7c3d14c8STreehugger Robot        echo "Testing $FILE for $ARCH"
53*7c3d14c8STreehugger Robot        if ./a.out
54*7c3d14c8STreehugger Robot        then
55*7c3d14c8STreehugger Robot          rm ./a.out
56*7c3d14c8STreehugger Robot        else
57*7c3d14c8STreehugger Robot          echo "fail"
58*7c3d14c8STreehugger Robot          exit 1
59*7c3d14c8STreehugger Robot        fi
60*7c3d14c8STreehugger Robot      else
61*7c3d14c8STreehugger Robot        echo "$FILE failed to compile"
62*7c3d14c8STreehugger Robot        exit 1
63*7c3d14c8STreehugger Robot      fi
64*7c3d14c8STreehugger Robot    fi
65*7c3d14c8STreehugger Robot  done
66*7c3d14c8STreehugger Robotdone
67*7c3d14c8STreehugger Robotecho "pass"
68*7c3d14c8STreehugger Robotexit
69