Script "test-toolchain.sh"
#!/bin/sh

# ----------------------
# test-toolchain.sh
# version 1.5.7.12
# ----------------------

exit_code=0

echo "--------------------------------------------------"
gcc -v
echo "--------------------------------------------------"
echo ""

echo '++ 1. Testing if toolchain can build and run C programs, and that it produces uClibc binaries...'

echo '#include <stdio.h>' > ./helloworld.c
echo '' >> ./helloworld.c
echo 'int main(void) {' >> ./helloworld.c
echo '    printf("Hello, World!\n");' >> ./helloworld.c
echo '    return 0;' >> ./helloworld.c
echo '}' >> ./helloworld.c

gcc ./helloworld.c -o ./helloworld || echo "GCC error!"
[ -f ./helloworld ] && chmod +x ./helloworld
rm -f ./helloworld.c

lines_of_uClibc=0
[ -f ./helloworld ] && lines_of_uClibc=`objdump -T ./helloworld | grep uClibc | wc -l`
echo "--------------------"
success_c_flag=1
if [ $lines_of_uClibc -gt 0 ]; then
  hello_output=`./helloworld 2>&1 || echo "ERROR"`
  tail_c_test=`echo "${hello_output}" | tail -1`
  if [ "${tail_c_test}" = "ERROR" ]; then
    success_c_flag=-1
    printf "\033[1m%s\033[0m\n" `echo "${hello_output}" | head -1 | tr 'a-z' 'A-Z' | sed 's/ /_/g'`
  else
    success_c_flag=0
    echo "${hello_output}"
  fi
fi
if [ $success_c_flag -eq 0 ]; then
  echo "--------------------"
  echo ">> TEST #1 PASSED!" 
else
  exit_code=`expr $exit_code '+' 1`
  echo ">> TEST #1 FAILED!"
  echo "--------------------"
  if [ -f ./helloworld ] && [ $success_c_flag -ne -1 ]; then
    objdump -T ./helloworld
  fi
fi
rm -f ./helloworld

echo '++ 2. Testing if toolchain can build from C++ sources...'

echo '#include <iostream>' > ./hello.c++
echo '' >> ./hello.c++
echo 'int main(void)' >> ./hello.c++
echo '{' >> ./hello.c++
echo '    std::cout << "Hello, C++" << std::endl;' >> ./hello.c++
echo '    return 0;' >> ./hello.c++
echo '}' >> ./hello.c++

echo "--------------------"
cplusplus_success_flag=1
g++ ./hello.c++ -o ./helloc++ 1>/dev/null 2>&1 && cplusplus_success_flag=2
rm -f ./hello.c++

if [ $cplusplus_success_flag -eq 2 ]; then
  helloplus_output=`./helloc++ 2>&1 || echo "ERROR"`
  the_tail_plus=`echo "${helloplus_output}" | tail -1`
  if [ "${the_tail_plus}" = "ERROR" ]; then
    cplusplus_success_flag=-1
    printf "\033[1m%s\033[0m\n" `echo "${helloplus_output}" | head -1 | tr 'a-z' 'A-Z' | sed 's/ /_/g'`
  else
    cplusplus_success_flag=0
    echo "${helloplus_output}"
  fi
fi
if [ $cplusplus_success_flag -eq 0 ]; then
  echo "--------------------"
  echo ">> TEST #2 PASSED!"
else
  exit_code=`expr $exit_code '+' 2`
  echo ">> TEST #2 FAILED!"
  echo "--------------------"
fi
rm -f ./helloc++

exit $exit_code
Unless otherwise stated, the content of this page is licensed under GNU Free Documentation License.