adding an event handler testing program to help to ROOT people to find a bug in their event handler

This commit is contained in:
nemu 2010-10-08 10:57:14 +00:00
parent c3d9a11f63
commit 04aae790ca
7 changed files with 560 additions and 0 deletions

View File

@ -0,0 +1,92 @@
#---------------------------------------------------
# Makefile
#
# Author: Andreas Suter
# e-mail: andreas.suter@psi.ch
#
# $Id$
#
#---------------------------------------------------
#---------------------------------------------------
# get compilation and library flags from root-config
ROOTCFLAGS = $(shell $(ROOTSYS)/bin/root-config --cflags)
ROOTLIBS = $(shell $(ROOTSYS)/bin/root-config --libs)
ROOTGLIBS = $(shell $(ROOTSYS)/bin/root-config --glibs)
#---------------------------------------------------
# depending on the architecture, choose the compiler,
# linker, and the flags to use
#
OSTYPE = $(shell uname)
ifeq ($(OSTYPE),Linux)
OS = LINUX
endif
ifeq ($(OSTYPE),Linux-gnu)
OS = LINUX
endif
ifeq ($(OSTYPE),darwin)
OS = DARWIN
endif
# -- Linux
ifeq ($(OS),LINUX)
CXX = g++
CXXFLAGS = -g -Wall -Wno-trigraphs -fPIC
INCLUDES = -I./
LD = g++
LDFLAGS = -g
SOFLAGS = -O -shared
endif
# -- Darwin
ifeq ($(OS),DARWIN)
CXX = g++
CXXFLAGS = -g -Wall -Wno-trigraphs -fPIC
INCLUDES = -I../include
LD = g++
LDFLAGS = -g
SOFLAGS = -dynamic
endif
# the output from the root-config script:
CXXFLAGS += $(ROOTCFLAGS)
LDFLAGS +=
# the ROOT libraries (G = graphic)
LIBS = $(ROOTLIBS) -lXMLParser
GLIBS = $(ROOTGLIBS) -lXMLParser
EXEC = eventHandlerTest
# some definitions: headers (used to generate *Dict* stuff), sources, objects,...
OBJS =
OBJS += $(EXEC).o
OBJS += PEventHandlerTest.o PEventHandlerTestDict.o
# make the executable:
#
all: $(EXEC)
$(EXEC): $(OBJS)
@echo "---> Building $(EXEC) ..."
$(LD) $(OBJS) -o $(EXEC) $(GLIBS)
@echo "done"
# clean up: remove all object file (and core files)
# semicolon needed to tell make there is no source
# for this target!
#
clean:; @rm -f $(OBJS) *Dict* core*
@echo "---> removing $(OBJS)"
#
$(OBJS): %.o: %.cpp
$(CXX) $(INCLUDES) $(CXXFLAGS) -c $<
PEventHandlerTestDict.cpp: ./PEventHandlerTest.h ./PEventHandlerTestLinkDef.h
@echo "Generating dictionary $@..."
rootcint -v -f $@ -c -p $^

View File

@ -0,0 +1,154 @@
/***************************************************************************
PEventHandlerTest.cpp
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2010 by Andreas Suter *
* andreas.suter@psi.ch *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <TRandom.h>
#include <TAxis.h>
#include "PEventHandlerTest.h"
ClassImpQ(PEventHandlerTest)
PEventHandlerTest::PEventHandlerTest()
{
fSwitched = false;
fMainCanvas = new TCanvas("fMainCanvas", "Event Handler Test", 10, 10, 600, 400);
fMainCanvas->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "PEventHandlerTest",
this, "HandleCmdKey(Int_t,Int_t,Int_t,TObject*)");
fMultiGraph1 = new TMultiGraph();
fMultiGraph2 = 0;
// feed to random graphs
TGraph *graph;
TRandom rand;
for (UInt_t i=0; i<3; i++) {
graph = new TGraph(100);
for (UInt_t j=0; j<100; j++) {
graph->SetPoint(j, 0.01*(Double_t)j, 0.0001*(Double_t)i*(Double_t)(j*j)+0.01*(Double_t)j+0.1*rand.Rndm());
}
graph->SetMarkerStyle(20+i);
graph->SetMarkerColor(1+i);
fGraph.push_back(graph);
}
fMultiGraph1->Add(new TGraph(*(fGraph[0])), "p");
fMultiGraph1->Add(new TGraph(*(fGraph[1])), "p");
fMultiGraph1->Draw("a");
fMainCanvas->Show();
}
PEventHandlerTest::~PEventHandlerTest()
{
for (UInt_t i=0; i<fGraph.size(); i++) {
delete fGraph[i];
}
fGraph.clear();
if (fMultiGraph1) {
delete fMultiGraph1;
fMultiGraph1 = 0;
}
if (fMultiGraph2) {
delete fMultiGraph2;
fMultiGraph2 = 0;
}
if (fMainCanvas) {
delete fMainCanvas;
fMainCanvas = 0;
}
}
void PEventHandlerTest::Done(Int_t status)
{
Emit("Done(Int_t)", status);
}
void PEventHandlerTest::HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected)
{
if (event != kKeyPress)
return;
if (x == 'q') { // quit
Done(0);
} else if (x == 's') { // switch
fSwitched = !fSwitched;
SwitchGraph();
}
}
void PEventHandlerTest::LastCanvasClosed()
{
if (gROOT->GetListOfCanvases()->IsEmpty()) {
Done(0);
}
}
void PEventHandlerTest::SwitchGraph()
{
Double_t xmin, xmax;
if (fSwitched) {
xmin = fMultiGraph1->GetXaxis()->GetBinCenter(fMultiGraph1->GetXaxis()->GetFirst());
xmax = fMultiGraph1->GetXaxis()->GetBinCenter(fMultiGraph1->GetXaxis()->GetLast());
delete fMultiGraph1;
fMultiGraph1 = 0;
fMultiGraph2 = new TMultiGraph();
fMultiGraph2->Add(new TGraph(*(fGraph[0])), "p");
fMultiGraph2->Add(new TGraph(*(fGraph[2])), "p");
fMultiGraph2->Draw("a");
fMultiGraph2->GetXaxis()->SetRangeUser(xmin, xmax);
fMultiGraph2->Draw("a");
} else {
xmin = fMultiGraph2->GetXaxis()->GetBinCenter(fMultiGraph2->GetXaxis()->GetFirst());
xmax = fMultiGraph2->GetXaxis()->GetBinCenter(fMultiGraph2->GetXaxis()->GetLast());
delete fMultiGraph2;
fMultiGraph2 = 0;
fMultiGraph1 = new TMultiGraph();
fMultiGraph1->Add(new TGraph(*(fGraph[0])), "p");
fMultiGraph1->Add(new TGraph(*(fGraph[1])), "p");
fMultiGraph1->Draw("a");
fMultiGraph1->GetXaxis()->SetRangeUser(xmin, xmax);
fMultiGraph1->Draw("a");
}
fMainCanvas->Update();
}

View File

@ -0,0 +1,67 @@
/***************************************************************************
PEventHandlerTest.cpp
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2010 by Andreas Suter *
* andreas.suter@psi.ch *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef _PEVENTHANDLERTEST_H_
#define _PEVENTHANDLERTEST_H_
#include <vector>
using namespace std;
#include <TROOT.h>
#include <TObject.h>
#include <TQObject.h>
#include <TCanvas.h>
#include <TMultiGraph.h>
#include <TGraph.h>
class PEventHandlerTest : public TObject, public TQObject
{
public:
PEventHandlerTest();
virtual ~PEventHandlerTest();
virtual void Done(Int_t status=0); // *SIGNAL*
virtual void HandleCmdKey(Int_t event, Int_t x, Int_t y, TObject *selected); // SLOT
virtual void LastCanvasClosed(); // SLOT
private:
TCanvas *fMainCanvas; ///< main canvas
TMultiGraph *fMultiGraph1;
TMultiGraph *fMultiGraph2;
Bool_t fSwitched;
vector<TGraph*> fGraph;
virtual void SwitchGraph();
ClassDef(PEventHandlerTest, 1)
};
#endif //_PEVENTHANDLERTEST_H_

View File

@ -0,0 +1,41 @@
/***************************************************************************
PEventHandlerTestLinkDef.h
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2010 by Andreas Suter *
* andreas.suter@psi.ch *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class PEventHandlerTest+;
#endif

View File

@ -0,0 +1,70 @@
[nemu@pc8372 eventHandler]$ ./eventHandlerTest
*** Break *** segmentation violation
===========================================================
There was a crash (#7 0x00d6569d in SigHandler () from /apps/cern/root/lib/libCore.so).
This is the entire stack trace of all threads:
===========================================================
#0 0x004b4410 in __kernel_vsyscall ()
#1 0x03f8c353 in __waitpid_nocancel () from /lib/libc.so.6
#2 0x03f33bbf in do_system () from /lib/libc.so.6
#3 0x062031ad in system () from /lib/libpthread.so.0
#4 0x00d60e1d in TUnixSystem::Exec () from /apps/cern/root/lib/libCore.so
#5 0x00d6805d in TUnixSystem::StackTrace ()
from /apps/cern/root/lib/libCore.so
#6 0x00d655ce in TUnixSystem::DispatchSignals ()
from /apps/cern/root/lib/libCore.so
#7 0x00d6569d in SigHandler () from /apps/cern/root/lib/libCore.so
#8 0x00d5e6c4 in sighandler () from /apps/cern/root/lib/libCore.so
#9 <signal handler called>
#10 0x08914070 in ?? ()
#11 0x003ed6fb in TCanvas::EnterLeave () from /apps/cern/root/lib/libGpad.so
#12 0x003f1ed7 in TCanvas::HandleInput () from /apps/cern/root/lib/libGpad.so
#13 0x01522c04 in TRootCanvas::HandleContainerMotion ()
from /apps/cern/root/lib/libGui.so
#14 0x0152a0aa in TRootContainer::HandleMotion ()
from /apps/cern/root/lib/libGui.so
#15 0x014525be in TGFrame::HandleEvent () from /apps/cern/root/lib/libGui.so
#16 0x0141633d in TGClient::HandleEvent () from /apps/cern/root/lib/libGui.so
#17 0x0141668e in TGClient::ProcessOneEvent ()
from /apps/cern/root/lib/libGui.so
#18 0x014166fd in TGClient::HandleInput () from /apps/cern/root/lib/libGui.so
#19 0x01416730 in TGInputHandler::Notify () from /apps/cern/root/lib/libGui.so
#20 0x00d64edd in TUnixSystem::DispatchOneEvent ()
from /apps/cern/root/lib/libCore.so
#21 0x00cd56b1 in TSystem::InnerLoop () from /apps/cern/root/lib/libCore.so
#22 0x00cd9381 in TSystem::Run () from /apps/cern/root/lib/libCore.so
#23 0x00c73308 in TApplication::Run () from /apps/cern/root/lib/libCore.so
#24 0x08051de9 in main (argc=0, argv=0x1c35) at eventHandlerTest.cpp:52
===========================================================
The lines below might hint at the cause of the crash.
If they do not help you then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
===========================================================
#10 0x08914070 in ?? ()
#11 0x003ed6fb in TCanvas::EnterLeave () from /apps/cern/root/lib/libGpad.so
#12 0x003f1ed7 in TCanvas::HandleInput () from /apps/cern/root/lib/libGpad.so
#13 0x01522c04 in TRootCanvas::HandleContainerMotion ()
from /apps/cern/root/lib/libGui.so
#14 0x0152a0aa in TRootContainer::HandleMotion ()
from /apps/cern/root/lib/libGui.so
#15 0x014525be in TGFrame::HandleEvent () from /apps/cern/root/lib/libGui.so
#16 0x0141633d in TGClient::HandleEvent () from /apps/cern/root/lib/libGui.so
#17 0x0141668e in TGClient::ProcessOneEvent ()
from /apps/cern/root/lib/libGui.so
#18 0x014166fd in TGClient::HandleInput () from /apps/cern/root/lib/libGui.so
#19 0x01416730 in TGInputHandler::Notify () from /apps/cern/root/lib/libGui.so
#20 0x00d64edd in TUnixSystem::DispatchOneEvent ()
from /apps/cern/root/lib/libCore.so
#21 0x00cd56b1 in TSystem::InnerLoop () from /apps/cern/root/lib/libCore.so
#22 0x00cd9381 in TSystem::Run () from /apps/cern/root/lib/libCore.so
#23 0x00c73308 in TApplication::Run () from /apps/cern/root/lib/libCore.so
#24 0x08051de9 in main (argc=0, argv=0x1c35) at eventHandlerTest.cpp:52
===========================================================

View File

@ -0,0 +1,75 @@
==30642== Memcheck, a memory error detector.
==30642== Copyright (C) 2002-2006, and GNU GPL'd, by Julian Seward et al.
==30642== Using LibVEX rev 1658, a library for dynamic binary translation.
==30642== Copyright (C) 2004-2006, and GNU GPL'd, by OpenWorks LLP.
==30642== Using valgrind-3.2.1, a dynamic binary instrumentation framework.
==30642== Copyright (C) 2000-2006, and GNU GPL'd, by Julian Seward et al.
==30642== For more details, rerun with: -v
==30642==
==30642== My PID = 30642, parent PID = 19037. Prog and args are:
==30642== ./eventHandlerTest
==30642==
==30642== Syscall param writev(vector[...]) points to uninitialised byte(s)
==30642== at 0xC188B8: writev (in /lib/libc-2.5.so)
==30642== by 0xD30A2D: (within /usr/lib/libX11.so.6.2.0)
==30642== by 0xD3081E: _X11TransWritev (in /usr/lib/libX11.so.6.2.0)
==30642== by 0xD36508: _XSend (in /usr/lib/libX11.so.6.2.0)
==30642== by 0xD2742A: XQueryExtension (in /usr/lib/libX11.so.6.2.0)
==30642== by 0xD1BD4A: XInitExtension (in /usr/lib/libX11.so.6.2.0)
==30642== by 0x238C3F: XFixesFindDisplay (in /usr/lib/libXfixes.so.3.1.0)
==30642== by 0x23769E: XFixesSetCursorName (in /usr/lib/libXfixes.so.3.1.0)
==30642== by 0x22D8E6: XcursorImagesLoadCursor (in /usr/lib/libXcursor.so.1.0.2)
==30642== by 0x230F79: XcursorTryShapeCursor (in /usr/lib/libXcursor.so.1.0.2)
==30642== by 0xD0FCE1: XCreateGlyphCursor (in /usr/lib/libX11.so.6.2.0)
==30642== by 0xD1016C: XCreateFontCursor (in /usr/lib/libX11.so.6.2.0)
==30642== Address 0x7674690 is 256 bytes inside a block of size 16,384 alloc'd
==30642== at 0x40046FF: calloc (vg_replace_malloc.c:279)
==30642== by 0xD214A6: XOpenDisplay (in /usr/lib/libX11.so.6.2.0)
==30642== by 0x76A52DD: TGX11::OpenDisplay(char const*) (in /apps/cern/root-5.27.04/lib/libGX11.so)
==30642== by 0x608CED8: TGClient::TGClient(char const*) (in /apps/cern/root-5.27.04/lib/libGui.so)
==30642== by 0x6186B83: TRootApplication::TRootApplication(char const*, int*, char**) (in /apps/cern/root-5.27.04/lib/libGui.so)
==30642== by 0x61A9094: TRootGuiFactory::CreateApplicationImp(char const*, int*, char**) (in /apps/cern/root-5.27.04/lib/libGui.so)
==30642== by 0x4151C8E: TApplication::InitializeGraphics() (in /apps/cern/root-5.27.04/lib/libCore.so)
==30642== by 0x4154065: TApplication::TApplication(char const*, int*, char**, void*, int) (in /apps/cern/root-5.27.04/lib/libCore.so)
==30642== by 0x8051D74: main (eventHandlerTest.cpp:41)
==30642==
==30642== Invalid read of size 4
==30642== at 0x57356DD: TCanvas::EnterLeave(TPad*, TObject*) (in /apps/cern/root-5.27.04/lib/libGpad.so)
==30642== by 0x5739ED6: TCanvas::HandleInput(EEventType, int, int) (in /apps/cern/root-5.27.04/lib/libGpad.so)
==30642== by 0x6199C03: TRootCanvas::HandleContainerMotion(Event_t*) (in /apps/cern/root-5.27.04/lib/libGui.so)
==30642== by 0x61A10A9: TRootContainer::HandleMotion(Event_t*) (in /apps/cern/root-5.27.04/lib/libGui.so)
==30642== by 0x60C95BD: TGFrame::HandleEvent(Event_t*) (in /apps/cern/root-5.27.04/lib/libGui.so)
==30642== by 0x608D33C: TGClient::HandleEvent(Event_t*) (in /apps/cern/root-5.27.04/lib/libGui.so)
==30642== by 0x608D68D: TGClient::ProcessOneEvent() (in /apps/cern/root-5.27.04/lib/libGui.so)
==30642== by 0x608D6FC: TGClient::HandleInput() (in /apps/cern/root-5.27.04/lib/libGui.so)
==30642== by 0x608D72F: TGInputHandler::Notify() (in /apps/cern/root-5.27.04/lib/libGui.so)
==30642== by 0x4242EDC: TUnixSystem::DispatchOneEvent(bool) (in /apps/cern/root-5.27.04/lib/libCore.so)
==30642== by 0x41B36B0: TSystem::InnerLoop() (in /apps/cern/root-5.27.04/lib/libCore.so)
==30642== by 0x41B7380: TSystem::Run() (in /apps/cern/root-5.27.04/lib/libCore.so)
==30642== Address 0x6EF0BF0 is 0 bytes inside a block of size 100 free'd
==30642== at 0x4004CF1: operator delete(void*) (vg_replace_malloc.c:244)
==30642== by 0x41A38C3: TStorage::ObjectDealloc(void*) (in /apps/cern/root-5.27.04/lib/libCore.so)
==30642== by 0x4182296: TObject::operator delete(void*) (in /apps/cern/root-5.27.04/lib/libCore.so)
==30642== by 0x516E46A: TGraph::~TGraph() (in /apps/cern/root-5.27.04/lib/libHist.so)
==30642== by 0x41E8279: TCollection::GarbageCollect(TObject*) (in /apps/cern/root-5.27.04/lib/libCore.so)
==30642== by 0x41EF1A6: TList::Delete(char const*) (in /apps/cern/root-5.27.04/lib/libCore.so)
==30642== by 0x51E7D67: TMultiGraph::~TMultiGraph() (in /apps/cern/root-5.27.04/lib/libHist.so)
==30642== by 0x805249C: PEventHandlerTest::SwitchGraph() (PEventHandlerTest.cpp:129)
==30642== by 0x8052267: PEventHandlerTest::HandleCmdKey(int, int, int, TObject*) (PEventHandlerTest.cpp:108)
==30642== by 0x8056979: G__PEventHandlerTestDict_274_0_3(G__value*, char const*, G__param*, int) (PEventHandlerTestDict.cpp:286)
==30642== by 0x4833B9E: Cint::G__CallFunc::Execute(void*) (in /apps/cern/root-5.27.04/lib/libCint.so)
==30642== by 0x41FDD0A: TCint::CallFunc_Exec(void*, void*) const (in /apps/cern/root-5.27.04/lib/libCore.so)
==30642==
==30642== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 87 from 2)
==30642== malloc/free: in use at exit: 3,484,199 bytes in 72,209 blocks.
==30642== malloc/free: 204,308 allocs, 132,099 frees, 15,526,505 bytes allocated.
==30642== For counts of detected errors, rerun with: -v
==30642== searching for pointers to 72,209 not-freed blocks.
==30642== checked 8,510,996 bytes.
==30642==
==30642== LEAK SUMMARY:
==30642== definitely lost: 2,426 bytes in 41 blocks.
==30642== possibly lost: 164,286 bytes in 3,612 blocks.
==30642== still reachable: 3,317,487 bytes in 68,556 blocks.
==30642== suppressed: 0 bytes in 0 blocks.
==30642== Use --leak-check=full to see details of leaked memory.

View File

@ -0,0 +1,61 @@
/***************************************************************************
eventHandlerTest.cpp
Author: Andreas Suter
e-mail: andreas.suter@psi.ch
$Id$
***************************************************************************/
/***************************************************************************
* Copyright (C) 2010 by Andreas Suter *
* andreas.suter@psi.ch *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <iostream>
using namespace std;
#include "TApplication.h"
#include "PEventHandlerTest.h"
int main(int argc, char *argv[])
{
TApplication app("App", &argc, argv);
PEventHandlerTest *eht = new PEventHandlerTest();
if (eht == 0) {
cerr << endl << "**ERROR** couldn't invoke eht ..." << endl;
return 0;
}
TQObject::Connect("TCanvas", "Closed()", "PEventHandlerTest", eht, "LastCanvasClosed()");
eht->Connect("Done(Int_t)", "TApplication", &app, "Terminate(Int_t)");
app.Run(true);
// clean up
if (eht) {
delete eht;
eht = 0;
}
return 1;
}