Kaydet (Commit) b8c87dee authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Show backtraces for core files from CppunitTests, too

Change-Id: Idff2831913b6fb6e5b522ae36fffeb345e3a1140
üst b524fb86
......@@ -28,39 +28,34 @@
# instead of those above.
#
# we expect our work directory to be where soffice had been started
# $(1) should be the path to the executable
EXECUTABLE=${1}
COREDIR=${2}
OFFICEFILE=${1}
WORKDIR=${2}
if test -n "`which gdb`"
if test -n "$(which gdb)"
then
if test `ls "${WORKDIR}"/core* 2>/dev/null | wc -l` -eq 1
if test "$(ls "$COREDIR"/core* 2>/dev/null | wc -l)" -eq 1
then
COREFILE=`ls "${WORKDIR}"/core*`
COREFILE=$(ls "$COREDIR"/core*)
echo
echo "It seems like soffice.bin crashed during the test excution!"
echo "Found a core dump at ${COREFILE}"
echo "Stacktrace:"
echo "It looks like ${EXECUTABLE} generated a core file at ${COREFILE}"
echo "Backtraces:"
GDBCOMMANDFILE=`mktemp`
echo "thread apply all bt" > ${GDBCOMMANDFILE}
gdb -x $GDBCOMMANDFILE --batch ${OFFICEFILE}.bin ${COREFILE}
rm ${GDBCOMMANDFILE}
echo "thread apply all backtrace" > "$GDBCOMMANDFILE"
gdb -x "$GDBCOMMANDFILE" --batch "$EXECUTABLE" "$COREFILE"
rm "$GDBCOMMANDFILE"
echo
exit 1
exit 0
else
echo
echo "No core dump at ${WORKDIR}, to create core dumps (and stack traces)"
echo "for crashed soffice instances, enable core dumps with:"
echo "No core file identified in directory ${COREDIR}"
echo "To show backtraces for crashes during test execution,"
echo "enable core files with:"
echo
echo " ulimit -c unlimited"
echo
exit 0
exit 1
fi
else
echo "You need gdb in your path to generate stacktraces."
exit 0
echo "You need gdb in your path to show backtraces"
exit 1
fi
# vim: set et sw=4 sts=4:
......@@ -83,6 +83,9 @@ $(call gb_CppunitTest_get_target,%) :| $(gb_CppunitTest_CPPTESTDEPS)
$(call gb_Output_announce,$*,$(true),CUT,2)
$(call gb_Helper_abbreviate_dirs,\
mkdir -p $(dir $@) && \
$(if $(gb_CppunitTest__interactive),, \
$(if $(value gb_CppunitTest_postprocess), \
rm -fr $@.core && mkdir $@.core && cd $@.core &&)) \
($(gb_CppunitTest_CPPTESTPRECOMMAND) \
$(if $(G_SLICE),G_SLICE=$(G_SLICE)) \
$(if $(GLIBCXX_FORCE_NEW),GLIBCXX_FORCE_NEW=$(GLIBCXX_FORCE_NEW)) \
......@@ -92,7 +95,12 @@ $(call gb_CppunitTest_get_target,%) :| $(gb_CppunitTest_CPPTESTDEPS)
$(ICECREAM_RUN) $(gb_CppunitTest_GDBTRACE) $(gb_CppunitTest_VALGRINDTOOL) $(gb_CppunitTest_CPPTESTCOMMAND) \
$(call gb_LinkTarget_get_target,CppunitTest/$(call gb_CppunitTest_get_libfilename,$*)) \
$(call gb_CppunitTest__make_args) \
$(if $(gb_CppunitTest__interactive),,> $@.log 2>&1 || (cat $@.log && $(UNIT_FAILED_MSG) && false))))
$(if $(gb_CppunitTest__interactive),, \
> $@.log 2>&1 \
|| (cat $@.log && $(UNIT_FAILED_MSG) \
$(if $(value gb_CppunitTest_postprocess), \
&& $(call gb_CppunitTest_postprocess,$(gb_CppunitTest_CPPTESTCOMMAND),$@.core)) \
&& false))))
define gb_CppunitTest_CppunitTest
$(call gb_CppunitTest__CppunitTest_impl,$(1),$(call gb_CppunitTest__get_linktargetname,$(1)))
......
......@@ -303,8 +303,7 @@ define gb_UnoApiHeadersTarget__command
RESPONSEFILE=$(call var2file,$(shell $(gb_MKTEMP)),100,\
$(UNOAPI_DEPS)) && \
$(gb_UnoApiHeadersTarget_CPPUMAKERCOMMAND) \
-Gc $(4) -BUCR \
-O$(3) $(call gb_UnoApiTarget_get_target,$(2)) \
-Gc $(4) -O$(3) $(call gb_UnoApiTarget_get_target,$(2)) \
@$${RESPONSEFILE} && \
rm -f $${RESPONSEFILE} && \
touch $(1)
......
......@@ -333,6 +333,10 @@ $(call gb_LinkTarget_get_target,$(2)) : RPATH :=
endef
define gb_CppunitTest_postprocess
$(SRCDIR)/solenv/bin/gdb-core-bt.sh $(1) $(2)
endef
# JunitTest class
ifneq ($(OOO_TEST_SOFFICE),)
......@@ -350,7 +354,7 @@ $(call gb_JunitTest_get_target,$(1)) : DEFS := \
-Dorg.openoffice.test.arg.env=$(gb_Helper_LIBRARY_PATH_VAR)"$$$${$(gb_Helper_LIBRARY_PATH_VAR)+=$$$$$(gb_Helper_LIBRARY_PATH_VAR)}" \
-Dorg.openoffice.test.arg.user=$(call gb_Helper_make_url,$(call gb_JunitTest_get_userdir,$(1))) \
-Dorg.openoffice.test.arg.workdir=$(call gb_JunitTest_get_userdir,$(1)) \
-Dorg.openoffice.test.arg.postprocesscommand=$(GBUILDDIR)/platform/unxgcc_gdbforjunit.sh \
-Dorg.openoffice.test.arg.postprocesscommand=$(SRCDIR)/solenv/bin/gdb-core-bt.sh \
-Dorg.openoffice.test.arg.soffice="$(gb_JunitTest_SOFFICEARG)" \
endef
......
......@@ -329,6 +329,10 @@ $(call gb_LinkTarget_get_target,$(2)) : RPATH :=
endef
define gb_CppunitTest_postprocess
$(SRCDIR)/solenv/bin/gdb-core-bt.sh $(1) $(2)
endef
# JunitTest class
ifneq ($(OOO_TEST_SOFFICE),)
......@@ -346,7 +350,7 @@ $(call gb_JunitTest_get_target,$(1)) : DEFS := \
-Dorg.openoffice.test.arg.env=$(gb_Helper_LIBRARY_PATH_VAR)"$$$${$(gb_Helper_LIBRARY_PATH_VAR)+=$$$$$(gb_Helper_LIBRARY_PATH_VAR)}" \
-Dorg.openoffice.test.arg.user=$(call gb_Helper_make_url,$(call gb_JunitTest_get_userdir,$(1))) \
-Dorg.openoffice.test.arg.workdir=$(call gb_JunitTest_get_userdir,$(1)) \
-Dorg.openoffice.test.arg.postprocesscommand=$(GBUILDDIR)/platform/unxgcc_gdbforjunit.sh \
-Dorg.openoffice.test.arg.postprocesscommand=$(SRCDIR)/solenv/bin/gdb-core-bt.sh \
-Dorg.openoffice.test.arg.soffice="$(gb_JunitTest_SOFFICEARG)" \
endef
......
......@@ -43,11 +43,6 @@ import static org.junit.Assert.*;
public final class OfficeConnection {
private final class PostprocessFailedException extends java.lang.RuntimeException {
PostprocessFailedException() {
super("This likely means that soffice crashed during the test.");
}
};
/** Start up an OOo instance.
*/
public void setUp() throws Exception {
......@@ -108,6 +103,7 @@ public final class OfficeConnection {
public void tearDown()
throws InterruptedException, com.sun.star.uno.Exception
{
boolean cleanTermination = false;
try {
boolean desktopTerminated = true;
if (process != null) {
......@@ -148,38 +144,45 @@ public final class OfficeConnection {
if (process != null) {
code = process.waitFor();
}
boolean outTerminated = outForward == null || outForward.terminated();
boolean errTerminated = errForward == null || errForward.terminated();
boolean outTerminated = outForward == null
|| outForward.terminated();
boolean errTerminated = errForward == null
|| errForward.terminated();
assertEquals(0, code);
cleanTermination = true;
assertTrue(outTerminated);
assertTrue(errTerminated);
} finally {
try {
String sofficeArg = Argument.get("soffice");
String workdir = Argument.get("workdir");
String postprocesscommand = Argument.get("postprocesscommand");
if(sofficeArg.startsWith("path:") && workdir != null && postprocesscommand != null) {
ProcessBuilder pb = new ProcessBuilder(
postprocesscommand,
sofficeArg.substring("path:".length()),
workdir);
Process postprocess = pb.start();
Forward ppoutForward = new Forward(postprocess.getInputStream(), System.out);
ppoutForward.start();
Forward pperrForward = new Forward(postprocess.getErrorStream(), System.err);
pperrForward.start();
postprocess.waitFor();
if(postprocess.exitValue() != 0)
if (!cleanTermination) {
try {
String sofficeArg = Argument.get("soffice");
String workdir = Argument.get("workdir");
String postprocesscommand = Argument.get(
"postprocesscommand");
if (sofficeArg.startsWith("path:") && workdir != null
&& postprocesscommand != null)
{
// no ugly long java stacktrace needed here
PostprocessFailedException e = new PostprocessFailedException();
StackTraceElement[] newStackTrace = new StackTraceElement[0];
e.setStackTrace(newStackTrace);
throw e;
ProcessBuilder pb = new ProcessBuilder(
postprocesscommand,
sofficeArg.substring("path:".length()) + ".bin",
workdir);
Process postprocess = pb.start();
Forward ppoutForward = new Forward(
postprocess.getInputStream(), System.out);
ppoutForward.start();
Forward pperrForward = new Forward(
postprocess.getErrorStream(), System.err);
pperrForward.start();
int code = postprocess.waitFor();
if (code != 0) {
throw new PostprocessFailedException(code);
}
}
}
catch (IOException e) {
throw new PostprocessFailedException(e);
}
}
catch(IOException e) {}
}
}
......@@ -262,6 +265,18 @@ public final class OfficeConnection {
private boolean done = false;
}
private static final class PostprocessFailedException
extends RuntimeException
{
PostprocessFailedException(int exitCode) {
super("postprocessing failed with exit code " + exitCode);
}
PostprocessFailedException(IOException cause) {
super("postprocessing failed with IOException " + cause, cause);
}
};
private String description;
private Process process = null;
private Forward outForward = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment