OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [cxx/] [ustl/] [current/] [tests/] [stdtest.h] - Blame information for rev 819

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
// This file is part of the ustl library, an STL implementation.
2
//
3
// Copyright (C) 2005 by Mike Sharov <msharov@users.sourceforge.net>
4
// This file is free software, distributed under the MIT License.
5
//
6
// \file stdtest.h
7
// \brief Standard BVT harness.
8
//
9
#ifndef CYGONCE_STDTEST_H
10
#define CYGONCE_STDTEST_H
11
 
12
#include <ustl.h>
13
#include <signal.h>
14
#include <cyg/infra/testcase.h>
15
using namespace ustl;
16
 
17
typedef void (*stdtestfunc_t)(void);
18
 
19
#ifdef CYGVAR_USTL_CIN_COUT_CERR
20
/// Called when a signal is received.
21
static void OnSignal (int sig)
22
{
23
    cout.flush();
24
#ifdef HAVE_STRSIGNAL
25
    cerr.format ("Fatal error: %s received.\n", strsignal(sig));
26
#else
27
    cerr.format ("Fatal error: system signal %d received.\n", sig);
28
#endif
29
    cerr.flush();
30
    CYG_TEST_FAIL("Test failed");
31
    exit (sig);
32
}
33
 
34
/// Installs OnSignal as handler for signals.
35
static void InstallCleanupHandlers (void)
36
{
37
    static const uint8_t c_Signals[] = {
38
    SIGINT, SIGQUIT, SIGILL,  SIGTRAP, SIGABRT,
39
    SIGIOT, SIGBUS,  SIGFPE,  SIGSEGV, SIGTERM};
40
    for (uoff_t i = 0; i < VectorSize(c_Signals); ++i)
41
    {
42
        signal (c_Signals[i], OnSignal);
43
    }
44
}
45
 
46
/// executes the test function
47
#ifndef __EXCEPTIONS
48
// if eCos is compiled without exceptions support then we implement and install
49
// our own low level exception handler
50
void app_exception_handler(const ustl::exception& ex)
51
{
52
    ustl::diag_print_exception(ex);
53
    CYG_TEST_FAIL("Test failed because of an uSTL exception");
54
}
55
 
56
int StdTestHarness (stdtestfunc_t testFunction)
57
{
58
    InstallCleanupHandlers();
59
    ustl::set_app_exception_handler(app_exception_handler);
60
    (*testFunction)();
61
    cout << endl;
62
    cout.flush(); // if there is anything left to print then print it now
63
    return (EXIT_SUCCESS);
64
}
65
#else
66
// if eCos is compiled with exceptions support the we use the default 
67
// StdTestHarness implementation from uSTL library
68
int StdTestHarness (stdtestfunc_t testFunction)
69
{
70
    InstallCleanupHandlers();
71
    int rv = EXIT_FAILURE;
72
    try {
73
    (*testFunction)();
74
    rv = EXIT_SUCCESS;
75
    } catch (ustl::exception& e) {
76
    cout.flush();
77
    cerr << "Error: " << e << endl;
78
    } catch (...) {
79
    cout.flush();
80
    cerr << "Unexpected error." << endl;
81
    }
82
    cout << endl;
83
    cout.flush(); // if there is anything left to print then print it now
84
    return (rv);
85
}
86
#endif
87
 
88
 
89
#define StdBvtMain(function) int main(int argc, char *argv[])                    \
90
{                                                                                \
91
    CYG_TEST_INIT();                                                             \
92
    CYG_TEST_INFO("Starting tests from uSTL testcase " #function);               \
93
    StdTestHarness(&function);                                                   \
94
    CYG_TEST_PASS_FINISH(#function " finished successfully");                    \
95
    return EXIT_SUCCESS;                                                         \
96
}
97
#else
98
#define StdBvtMain(function) int main(int argc, char *argv[])                    \
99
{                                                                                \
100
    CYG_TEST_INIT();                                                             \
101
    CYG_TEST_NA("cin, cout & cerr support disabled");                            \
102
}
103
#endif
104
 
105
//---------------------------------------------------------------------------
106
#endif // CYGONCE_STDTEST_H

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.