1#!/usr/bin/env bash
2
3# Script to do performance testing.
4
5# Invocation
6# check_performance SRC_DIR BUILD_DIR
7
8# 1: variables
9#
10SRC_DIR=$1
11BUILD_DIR=$2
12
13# Now that we've successfully translated the numerical option into
14# a symbolic one, we can safely ignore it.
15shift
16
17# This has been true all along.  Found out about it the hard way...
18case $BASH_VERSION in
19    1*)
20	echo 'You need bash 2.x to run check_performance.  Exiting.';
21	exit 1 ;;
22    *)   ;;
23esac
24
25flags_script=$BUILD_DIR/scripts/testsuite_flags
26INCLUDES=`$flags_script --build-includes`
27PCH_FLAGS=`$flags_script --cxxpchflags`
28FLAGS=`$flags_script --cxxflags`
29THREAD_FLAG='-pthread'
30COMPILER=`$flags_script --build-cxx`
31SH_FLAG="-Wl,--rpath -Wl,$BUILD_DIR/../../gcc \
32         -Wl,--rpath -Wl,$BUILD_DIR/src/.libs"
33ST_FLAG="-static"
34LINK=$SH_FLAG
35CXX="$COMPILER $INCLUDES $FLAGS -std=gnu++0x $CXXFLAGS $LINK"
36LIBS="./libtestc++.a"
37TESTS_FILE="testsuite_files_performance"
38
39echo CXX is $CXX
40
41for NAME in `cat $TESTS_FILE`
42do
43  RUN=true
44  TESTNAME=$SRC_DIR/testsuite/$NAME
45  FILE_NAME="`basename $NAME`"
46  FILE_NAME="`echo $FILE_NAME | sed 's/.cc//g'`"
47  ORIG_CXX="$CXX"
48  CXX="$CXX `sed -n 's/.* STD=/-std=/p' $TESTNAME`"
49
50  # TEST_S == single thread
51  # TEST_B == do both single and multi-thread
52  # TEST_T == multi-thread
53  for CYCLE in `sed -n 's,.*\(TEST_[SB][0-9]*\)$,\1,p' $TESTNAME`
54  do
55    RUN=false
56    echo $NAME $CYCLE
57    EXE_NAME="`echo $FILE_NAME-$CYCLE.exe`"
58    $CXX -DNOTHREAD -D$CYCLE $TESTNAME $LIBS -o $EXE_NAME
59    if [ -f $EXE_NAME ]; then
60      ./$EXE_NAME
61    else
62      echo "compile error:"
63      echo "$CXX -DNOTHREAD -D$CYCLE $TESTNAME $LIBS -o $EXE_NAME"
64    fi
65  done
66
67  for CYCLE in `sed -n 's,.*\(TEST_[TB][0-9]*\)$,\1,p' $TESTNAME`
68  do
69    RUN=false
70    echo $NAME $CYCLE thread
71    EXE_NAME="`echo $FILE_NAME-$CYCLE.exe`"
72    $CXX $THREAD_FLAG -D$CYCLE $TESTNAME $LIBS -o $EXE_NAME
73    if [ -f $EXE_NAME ]; then
74      ./$EXE_NAME
75    else
76      echo "compile error:"
77      echo "$CXX $THREAD_FLAG -D$CYCLE $TESTNAME $LIBS -o $EXE_NAME"
78    fi
79  done
80
81  if $RUN; then
82    echo $NAME
83    EXE_NAME="`echo $FILE_NAME.exe`"
84    $CXX $TESTNAME $LIBS -o $EXE_NAME
85    if [ -f $EXE_NAME ]; then
86      ./$EXE_NAME >& tmp.$FILE_NAME
87    else
88      echo "compile error:"
89      echo "$CXX $TESTNAME $LIBS -o $EXE_NAME"
90    fi
91    if [ -s tmp.$FILE_NAME ]; then
92	mv tmp.$FILE_NAME $FILE_NAME.xml
93    fi
94  fi
95  CXX="$ORIG_CXX"
96done
97
98exit 0
99