1#!/bin/sh
2
3DFSAN_DIR=$(dirname "$0")/../
4DFSAN_CUSTOM_TESTS=${DFSAN_DIR}/../../test/dfsan/custom.cc
5DFSAN_CUSTOM_WRAPPERS=${DFSAN_DIR}/dfsan_custom.cc
6DFSAN_ABI_LIST=${DFSAN_DIR}/done_abilist.txt
7
8DIFFOUT=$(mktemp -q /tmp/tmp.XXXXXXXXXX)
9ERRORLOG=$(mktemp -q /tmp/tmp.XXXXXXXXXX)
10DIFF_A=$(mktemp -q /tmp/tmp.XXXXXXXXXX)
11DIFF_B=$(mktemp -q /tmp/tmp.XXXXXXXXXX)
12
13on_exit() {
14  rm -f ${DIFFOUT} 2> /dev/null
15  rm -f ${ERRORLOG} 2> /dev/null
16  rm -f ${DIFF_A} 2> /dev/null
17  rm -f ${DIFF_B} 2> /dev/null
18}
19
20trap on_exit EXIT
21grep -E "^fun:.*=custom" ${DFSAN_ABI_LIST} | grep -v "dfsan_get_label" \
22  | sed "s/^fun:\(.*\)=custom.*/\1/" | sort > $DIFF_A
23grep -E "__dfsw.*\(" ${DFSAN_CUSTOM_WRAPPERS} \
24  | sed "s/.*__dfsw_\(.*\)(.*/\1/" | sort > $DIFF_B
25diff -u $DIFF_A $DIFF_B > ${DIFFOUT}
26if [ $? -ne 0 ]
27then
28  echo -n "The following differences between the ABI list and ">> ${ERRORLOG}
29  echo "the implemented custom wrappers have been found:" >> ${ERRORLOG}
30  cat ${DIFFOUT} >> ${ERRORLOG}
31fi
32
33grep -E __dfsw_ ${DFSAN_CUSTOM_WRAPPERS} \
34  | sed "s/.*__dfsw_\([^(]*\).*/\1/" | sort > $DIFF_A
35grep -E "^[[:space:]]*test_.*\(\);" ${DFSAN_CUSTOM_TESTS} \
36  | sed "s/.*test_\(.*\)();/\1/" | sort > $DIFF_B
37diff -u $DIFF_A $DIFF_B > ${DIFFOUT}
38if [ $? -ne 0 ]
39then
40  echo -n "The following differences between the implemented " >> ${ERRORLOG}
41  echo "custom wrappers and the tests have been found:" >> ${ERRORLOG}
42  cat ${DIFFOUT} >> ${ERRORLOG}
43fi
44
45if [ -s ${ERRORLOG} ]
46then
47  cat ${ERRORLOG}
48  exit 1
49fi
50
51