summaryrefslogtreecommitdiffstats
path: root/coverity/do_coverity
blob: bb144d32517c0a9a7072dac6983139663d0cbb90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#! /bin/sh
#
#  This script automates running Coverity on RTEMS and submitting
#  the results.
#
#       + Instructions: http://scan.coverity.com/self-build/
#       + Results:      http://scan2.coverity.com:9104/
#
#  You have to have an account to view the results
# 
# NOTE:
#    + You have to be joel to run and submit official results.
#    + build.raw is very important if something goes wrong
# 

#
# TODO:
#   + parse arguments for some of the hard-coded items.
#   + better instructions on setup. Where to download, etc.
#

RTEMS_BIN=/opt/rtems-4.11/bin
COVERITY=${HOME}/prevent-linux-2.4.6
RTEMS_TARGET=sparc-rtems4.11
RTEMS_BSP=sis
#RTEMS_TARGET=i386-rtems4.11
#RTEMS_BSP=pc386

do_mail="yes"

#
#  Checks the status returned by executables and exits if it is non-zero.
#
check_fatal()
{
  if [ $1 -ne 0 ] ; then
    shift
    echo "ERROR: $*" >&2
    exit 1
  fi
}

type ${RTEMS_TARGET}-gcc
check_fatal $? "gcc not in path"

test -d ${COVERITY}
check_fatal $? "Coverity path not right"

test -d ${COVERITY}/bin
check_fatal $? "${COVERITY}/bin does not exist"

test ${LOGNAME} = "joel"
check_fatal $? "For now, Coverity must be run by joel"

# Prepend Coverity to our PATH
export PATH=${COVERITY}/bin:$PATH

# Configure Coverity for this target compiler
rm -rf ${COVERITY}/config/coverity_config.xml
rm -rf ${COVERITY}/config/gcc-config-? ${COVERITY}/config/g++-config-?

cov-configure -co ${RTEMS_BIN}/${RTEMS_TARGET}-gcc
check_fatal $? "could not coverity configure GCC"
cov-configure -co ${RTEMS_BIN}/${RTEMS_TARGET}-g++
check_fatal $? "could not coverity configure g++"

# Clean build directory and start over
rm     -rf  b-coverity-${RTEMS_TARGET}
check_fatal $? "Could not remove build directory"
mkdir  -p   b-coverity-${RTEMS_TARGET}/b-${RTEMS_TARGET}
check_fatal $? "Could not make build directory"
cd          b-coverity-${RTEMS_TARGET}/b-${RTEMS_TARGET}
check_fatal $? "Could not cd to build directory"

# Configure RTEMS
$r/configure --target=${RTEMS_TARGET} --enable-multilib \
  --disable-networking --disable-itron --disable-tests \
  --enable-rtemsbsp=${RTEMS_BSP} >c.log 2>&1
check_fatal $? "could not configure RTEMS"

# Build RTEMS
cov-build -e emit -o output make -C ${RTEMS_TARGET}/cpukit >b.log 2>&1
check_fatal $? "could not make RTEMS"

# Did we have problems loading the Coverity dynamic library?
grep -i "ERROR: ld.so:.*" b.log >/dev/null
if [ $? -ne 1 ] ; then
  check_fatal 1 "Looks like you have dynamic library issues with Coverity."
fi

# Did Coverity report something bad?
grep -i cata output/build.raw >/dev/null
if [ $? -ne 1 ] ; then
  check_fatal 1 "Catastrophic failures reported by coverity."
fi

# Did Coverity report that it had no results?
grep -i "No files were emitted" output/build.raw >/dev/null
if [ $? -ne 1 ] ; then
  check_fatal 1 "No output from Coverity.  Something went wrong."
fi

# Construct the README that is needed in project.tgz
cat <<EOF >README
Joel Sherrill
joel.sherrill@gmail.com
RTEMS
EOF

# Now create the tar file that Coverity wants
tar czvf project.tgz README emit output
check_fatal $? "could not make project.tgz"

# If running inside OAR and RTEMS lab, then you will be able to
# copy the results file to the ftp site and submit it to Coverity.
if [ ${do_mail} = "yes" ] ; then
  if [ -d /home/ftp/private/coverity ] ; then
    echo "Placing project.tgz on RTEMS ftp site."
    cp project.tgz /home/ftp/private/coverity/
    echo "Emailing analysis request to Coverity."
    do_mail_coverity
  else
    # There are unfortunately some by hand steps
    cat <<EOF
You do not have NFS access to the RTEMS.org ftp site. So you will have
to copy the project.tgz and email Coverity by hand.
  
(1) scp */project.tgz joel@www.rtems.org:/home/ftp/private/coverity/

(2) Send email to Coverity to request a run. (e.g. do_mail_coverity)
EOF
  fi
fi

# Ran completed OK
exit 0