1#!/bin/sh
2
3DFSAN_DIR=$(dirname "$0")/../
4DFSAN_CUSTOM_TESTS=${DFSAN_DIR}/../../test/dfsan/custom.cpp
5DFSAN_CUSTOM_WRAPPERS=${DFSAN_DIR}/dfsan_custom.cpp
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
20# Ignore __sanitizer_cov_trace* because they are implemented elsewhere.
21trap on_exit EXIT
22grep -E "^fun:.*=custom" ${DFSAN_ABI_LIST} \
23  | grep -v "dfsan_get_label\|dfsan_get_origin\|__sanitizer_cov_trace" \
24  | sed "s/^fun:\(.*\)=custom.*/\1/" | sort > $DIFF_A
25grep -E "__dfsw.*\(" ${DFSAN_CUSTOM_WRAPPERS} \
26  | grep -v "__sanitizer_cov_trace" \
27  | sed "s/.*__dfsw_\(.*\)(.*/\1/" | sort | uniq > $DIFF_B
28diff -u $DIFF_A $DIFF_B > ${DIFFOUT}
29if [ $? -ne 0 ]
30then
31  echo -n "The following differences between the ABI list and ">> ${ERRORLOG}
32  echo "the implemented custom wrappers have been found:" >> ${ERRORLOG}
33  cat ${DIFFOUT} >> ${ERRORLOG}
34fi
35
36grep -E __dfsw_ ${DFSAN_CUSTOM_WRAPPERS} \
37  | grep -v "__sanitizer_cov_trace" \
38  | sed "s/.*__dfsw_\([^(]*\).*/\1/" | sort | uniq > $DIFF_A
39grep -E "^[[:space:]]*test_.*\(\);" ${DFSAN_CUSTOM_TESTS} \
40  | sed "s/.*test_\(.*\)();/\1/" | sort > $DIFF_B
41diff -u $DIFF_A $DIFF_B > ${DIFFOUT}
42if [ $? -ne 0 ]
43then
44  echo -n "The following differences between the implemented " >> ${ERRORLOG}
45  echo "custom wrappers and the tests have been found:" >> ${ERRORLOG}
46  cat ${DIFFOUT} >> ${ERRORLOG}
47fi
48
49if [ -s ${ERRORLOG} ]
50then
51  cat ${ERRORLOG}
52  exit 1
53fi
54
55