testBacktrace.cpp

Go to the documentation of this file.
00001 /*
00002 // $Id: //open/dev/fennel/common/testBacktrace.cpp#6 $
00003 // Fennel is a library of data storage and processing components.
00004 // Copyright (C) 2005-2009 The Eigenbase Project
00005 // Copyright (C) 2005-2009 SQLstream, Inc.
00006 // Copyright (C) 2005-2009 LucidEra, Inc.
00007 // Portions Copyright (C) 1999-2009 John V. Sichi
00008 //
00009 // This program is free software; you can redistribute it and/or modify it
00010 // under the terms of the GNU General Public License as published by the Free
00011 // Software Foundation; either version 2 of the License, or (at your option)
00012 // any later version approved by The Eigenbase Project.
00013 //
00014 // This program is distributed in the hope that it will be useful,
00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 // GNU General Public License for more details.
00018 //
00019 // You should have received a copy of the GNU General Public License
00020 // along with this program; if not, write to the Free Software
00021 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 // a primitive, manual, stand-alone test of Backtrace
00025 
00026 #include "fennel/common/CommonPreamble.h"
00027 #include "fennel/common/Backtrace.h"
00028 #include "fennel/common/ConfigMap.h"
00029 #include <ostream>
00030 #include <cassert>
00031 #include <stdexcept>
00032 
00033 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/common/testBacktrace.cpp#6 $");
00034 
00035 class foo {
00036     void g(int);
00037     void h(int);
00038     void k(int);
00039 public:
00040     foo() {}
00041     ~foo() {}
00042     void f(int);
00043 };
00044 
00045 void foo::f(int n)
00046 {
00047     g(n);
00048 }
00049 
00050 void foo::g(int n)
00051 {
00052     h(n);
00053     k(n);
00054 }
00055 
00056 void foo::h(int n)
00057 {
00058     std::cerr << "\ntesting Backtrace(" << n << ")\n";
00059     Backtrace bt(n);
00060     std::cerr << bt;
00061 }
00062 
00063 void foo::k(int n)
00064 {
00065     void *addrs[32];
00066     assert(n < 32);
00067     std::cerr << "\ntesting Backtrace(" << n << ", addrs)\n";
00068     Backtrace bt(n, addrs);
00069     std::cerr << bt;
00070 }
00071 
00072 FENNEL_END_CPPFILE("$Id");
00073 
00074 // testBacktrace tests Backtrace()
00075 // testBacktrace a tests AutoBacktrace of assert()
00076 // testBacktrace e tests AutoBacktrace of an uncaught exception
00077 // testBacktrace s tests AutoBacktrace of a SIGSEGV
00078 int main(int argc, char **argv)
00079 {
00080     if (argc == 1) {
00081         fennel::foo o;
00082         o.f(16);
00083         o.f(2);
00084     } else {
00085         fennel::AutoBacktrace::install();
00086         switch (argv[1][0]) {
00087         case 'a':
00088             assert(false);
00089             std::cerr << "not reached\n";
00090             break;
00091         case 'p':
00092             permAssert(false);
00093             std::cerr << "not reached\n";
00094             break;
00095         case 'e':
00096             std::cerr << "throw new std::runtime_error(\"testing AutoBacktrace\")\n";
00097             throw new std::runtime_error("testing AutoBacktrace");
00098             std::cerr << "not reached\n";
00099             break;
00100         case 's':
00101             {
00102                 fennel::ConfigMap configMap;
00103                 configMap.readParams(*(std::istream *) NULL);
00104             }
00105             break;
00106         default:
00107             ;
00108         }
00109     }
00110     exit(0);
00111 }
00112 
00113 // End testBacktrace.cpp

Generated on Mon Jun 22 04:00:18 2009 for Fennel by  doxygen 1.5.1