-
Notifications
You must be signed in to change notification settings - Fork 3
/
checkCoreGen.sh
executable file
·182 lines (140 loc) · 5.41 KB
/
checkCoreGen.sh
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
#
#------------------------------
#
# Import settings
#
# Git branch
. ./settings.sh
# WriteLog() function
. ./timestampLogger.sh
#
#------------------------------
#
# Constants
#
LOG_DIR=.
LONG_DATE=$(date "+%Y-%m-%d_%H-%M-%S")
CRASH_TEST_LOG_FILE=${LOG_DIR}/Core-gen-test-${LONG_DATE}.log
CPP_SOURCE_NAME=mycrash.cpp
CPP_BIN_NAME=mycrash
ECL_SOURCE_NAME=ecl/mycrash.ecl
#
#-----------------------------------------
#
# Functions
CreateMyCrashCpp()
{
WriteLog "Create $CPP_SOURCE_NAME source file..." "${CRASH_TEST_LOG_FILE}"
echo '#include "stdio.h"' > $CPP_SOURCE_NAME
echo 'int main(int argc, char* argv[])' >> $CPP_SOURCE_NAME
echo '{' >> $CPP_SOURCE_NAME
echo ' int *p;' >> $CPP_SOURCE_NAME
echo ' *p = 0;' >> $CPP_SOURCE_NAME
echo ' return 0;' >> $CPP_SOURCE_NAME
echo '}' >> $CPP_SOURCE_NAME
WriteLog "Done." "${CRASH_TEST_LOG_FILE}"
}
CreateMyCrashEcl()
{
WriteLog "Create $ECL_SOURCE_NAME source file..." "${CRASH_TEST_LOG_FILE}"
[[ ! -d ecl ]] && mkdir ecl
echo 'boolean seg() := beginc++ #option action' > $ECL_SOURCE_NAME
echo ' #include <csignal>' >> $ECL_SOURCE_NAME
echo ' #include <csignal>' >> $ECL_SOURCE_NAME
echo ' #body' >> $ECL_SOURCE_NAME
echo ' raise(SIGABRT);' >> $ECL_SOURCE_NAME
echo ' return false;' >> $ECL_SOURCE_NAME
echo 'endc++;' >> $ECL_SOURCE_NAME
echo 'output(seg());' >> $ECL_SOURCE_NAME
WriteLog "Done." "${CRASH_TEST_LOG_FILE}"
}
BuildMyCrashBin()
{
WriteLog "Build $CPP_BIN_NAME ..." "${CRASH_TEST_LOG_FILE}"
res=$( c++ $CPP_SOURCE_NAME -o $CPP_BIN_NAME 2>&1)
if [[ $? -ne 0 ]]
then
WriteLog "Build $CPP_BIN_NAME resturns with ${res}!" "${CRASH_TEST_LOG_FILE}"
else
WriteLog "Build $CPP_BIN_NAME test finished!" "${CRASH_TEST_LOG_FILE}"
fi
}
#
#-----------------------------------------
#
# Main start
WriteLog "Core generation test started." "${CRASH_TEST_LOG_FILE}"
#
WriteLog "Current core generation is: $(cat /proc/sys/kernel/core_pattern)" "${CRASH_TEST_LOG_FILE}"
# would cause all future core dumps to be generated in same directory as the binary
# and be named core_[program].[pid]
WriteLog "Forceing standard core to be generated in same directory" "${CRASH_TEST_LOG_FILE}"
res=$(echo 'core_%e.%p' | sudo tee /proc/sys/kernel/core_pattern)
WriteLog "res:${res}" "${CRASH_TEST_LOG_FILE}"
res=$(sudo service abrtd reload)
WriteLog "res:${res}" "${CRASH_TEST_LOG_FILE}"
if [ "$1." == "." ]
then
if [ ! -f $CPP_BIN_NAME ]
then
WriteLog "There is not $CPP_BIN_NAME binary file." "${CRASH_TEST_LOG_FILE}"
if [ ! -f $CPP_SOURCE_NAME ]
then
WriteLog "There is not $CPP_SOURCE_NAME source file." "${CRASH_TEST_LOG_FILE}"
CreateMyCrashCpp
fi
BuildMyCrashBin
fi
if [ -f $CPP_BIN_NAME ]
then
chmod +x ./$CPP_BIN_NAME
WriteLog "Execute ${CPP_BIN_NAME} to create core dump!" "${CRASH_TEST_LOG_FILE}"
res=$( ./${CPP_BIN_NAME} 2>&1 )
WriteLog "res: $?." "${CRASH_TEST_LOG_FILE}"
cores=( $( find . -maxdepth 1 -name 'core*' -type f ) )
if [ ${#cores[@]} -ne 0 ]
then
WriteLog "There is/are ${#cores[@]} core file(s) '${cores[*]}'" "${CRASH_TEST_LOG_FILE}"
WriteLog "Core generation is OK!" "${CRASH_TEST_LOG_FILE}"
WriteLog "Clean up." "${CRASH_TEST_LOG_FILE}"
rm -f ${cores[*]}
rm -f ${CPP_SOURCE_NAME}
else
WriteLog "Core generation disabled!" "${CRASH_TEST_LOG_FILE}"
fi
fi
else
if [ ! -f $ECL_SOURCE_NAME ]
then
WriteLog "There is not $ECL_SOURCE_NAME source file." "${CRASH_TEST_LOG_FILE}"
CreateMyCrashEcl
fi
WriteLog "Execute ${ECL_SOURCE_NAME} on hthor to create core dump!" "${CRASH_TEST_LOG_FILE}"
res=$( ecl run -t hthor ./${ECL_SOURCE_NAME} 2>&1 )
WriteLog "res: $?." "${CRASH_TEST_LOG_FILE}"
WriteLog "Execute ${ECL_SOURCE_NAME} on thor to create core dump!" "${CRASH_TEST_LOG_FILE}"
res=$( ecl run -t thor ./${ECL_SOURCE_NAME} 2>&1 )
WriteLog "res: $?." "${CRASH_TEST_LOG_FILE}"
# Somehow this execution on Roxie takes ages to finish. Should investigate.
#WriteLog "Execute ${ECL_SOURCE_NAME} on roxie to create core dump!" "${CRASH_TEST_LOG_FILE}"
#res=$( ecl run -t roxie ./${ECL_SOURCE_NAME} 2>&1 )
#WriteLog "res: $?." "${CRASH_TEST_LOG_FILE}"
cores=( $( find /var/lib/HPCCSystems/ -name 'core_*' -type f ) )
if [ ${#cores[@]} -ne 0 ]
then
WriteLog "There is/are ${#cores[@]} core file(s) '${cores[*]}'" "${CRASH_TEST_LOG_FILE}"
if [ ${#cores[@]} -eq 2 ]
then
WriteLog "Core generation is OK!" "${CRASH_TEST_LOG_FILE}"
else
WriteLog "Core generation failed on some platform(s)!" "${CRASH_TEST_LOG_FILE}"
fi
WriteLog "Clean up." "${CRASH_TEST_LOG_FILE}"
${SUDO} rm -f ${cores[*]}
rm eclcc.log
else
WriteLog "Core generation disabled!" "${CRASH_TEST_LOG_FILE}"
fi
fi
WriteLog "End." "${CRASH_TEST_LOG_FILE}"