Skip to content

Instantly share code, notes, and snippets.

@draganglumac
Created May 15, 2015 13:31
Show Gist options
  • Select an option

  • Save draganglumac/a182a0972256d8b5472a to your computer and use it in GitHub Desktop.

Select an option

Save draganglumac/a182a0972256d8b5472a to your computer and use it in GitHub Desktop.
Ideas for conditional flag when running jnxlibc tests
#!/bin/bash
OS=`uname`
if [ "$OS" == "Darwin" ]; then
echo "Building with Clang"
COMPILER=clang
else
echo "Building with GCC"
COMPILER=gcc
fi
function echo_red()
{
tput setaf 1
echo $1
tput sgr0
}
function echo_green()
{
tput setaf 2
echo $1
tput sgr0
}
function test_against_file()
{
file=$1
echo "Compiling $file"
str="$COMPILER $file ../../src/**/*.c -I../../src/alg -I../../src/bug -I../../src/io -I../../src/ipc -I../../src/dat -I../../src/net -I../../src/sig -I../../src/sys -I../../src/thr -o ${file:0:${#file}-2} -pthread -w -rdynamic"
if [ "${LOG_LEVEL}" != "" ]; then
str="${str} -D${LOG_LEVEL}"
fi
`$str`
out=$?
if [ ! $out -eq 0 ]; then
echo_red "Test failed"
exit 1
else
ls -la
test_binary="$PWD/${file:0:${#file}-2}"
echo $test_binary
$test_binary
if [ $? -eq 0 ]; then
echo_green "Test passed"
else
echo_red "Test failed"
fi
rm $current
fi
}
function run_full_suite()
{
filelist=`ls *.c`
for file in $filelist; do
if [ "$file" == "run_tests" ]
then
continue
fi
current=${file:0:${#file}-2}
if [ -e $current ]
then
rm $current
fi
echo "Running next test for --> ${file}"
test_against_file $file
done;
}
function run_single_test()
{
filelist=`ls *.c`
for file in $filelist; do
if [ "$file" == "$1" ]; then
echo "found match"
current=${file:0:${#file}-2}
if [ -e $current ]
then
rm $current
fi
test_against_file $file
fi
done
}
case "$#" in
0)
export LOG_LEVEL=""
run_full_suite
;;
2)
export LOG_LEVEL="$2"
run_single_test $1
;;
1)
if [[ $1 =~ ^.*\.c$ ]]; then
export LOG_LEVEL=""
run_single_test $1
else
export LOG_LEVEL="$1"
run_full_suite
fi
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment