Ignore:
Timestamp:
Nov 16, 2010, 11:38:57 PM (15 years ago)
Author:
dmik
Message:

testapp: Improved SEH/except test case.

Location:
trunk/testapp/exceptions/seh
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/testapp/exceptions/seh/Makefile

    r21449 r21476  
    33include $(ODIN)/testapp/common.mak
    44
    5 all: except.exe finally.exe # except.s
     5all: except.exe finally.exe longjmp.exe # except.s
     6
     7except.exe_ARGS.1 = 1
     8except.exe_ARGS.2 = 2
     9except.exe_ARGS.3 = 3
     10except.exe_ARGS.4 = 4
    611
    712finally.exe_ARGS.1 = 1
     
    914finally.exe_ARGS.3 = 3
    1015
    11 run: run-except.exe $(call run-with-args,finally.exe,1 2 3,all)
     16longjmp.exe_ARGS.1 = 1
     17longjmp.exe_ARGS.2 = 2
     18
     19run: \
     20     $(call run-with-args,except.exe,1 2 3 4,all) \
     21     $(call run-with-args,finally.exe,1 2 3,all) \
     22     $(call run-with-args,longjmp.exe,1 2,all)
    1223
    1324CLEAN += *.s
  • trunk/testapp/exceptions/seh/except.c

    r21449 r21476  
    88
    99int _main();
     10int _argc;
     11char **_argv;
    1012
    1113int WIN32API WinMain(HANDLE hInstance,
     
    1416                     int    nCmdShow)
    1517{
    16     return _main();
     18    return _main(_argc, _argv);
    1719}
    1820
    19 int main()
     21int main(int argc, char **argv)
    2022{
     23    _argc = argc;
     24    _argv = argv;
    2125    EnableSEH();
    2226    RegisterLxExe(WinMain, NULL);
     
    2731#endif
    2832
    29 int exc_filter(DWORD code, DWORD filtercode, PEXCEPTION_RECORD pRec)
     33int testCode = 0;
     34
     35int tries = 3;
     36
     37int exc_filter(DWORD code, DWORD filtercode, PEXCEPTION_POINTERS pPtrs)
    3038{
     39    PEXCEPTION_RECORD pRec = pPtrs->ExceptionRecord;
     40
    3141    printf("Filter: code %08lx, filtercode %08lx\n", code, filtercode);
    3242    printf("ExceptionCode %p\n", pRec->ExceptionCode);
     
    3444    printf("NumberParameters %d\n", pRec->NumberParameters);
    3545
    36 //  if (code == filtercode)
     46    if (code == filtercode)
     47    {
     48        if (testCode == 4 && tries)
     49        {
     50            --tries;
     51            return EXCEPTION_CONTINUE_EXECUTION;
     52        }
     53
    3754        return EXCEPTION_EXECUTE_HANDLER;
    38 //  return EXCEPTION_CONTINUE_SEARCH;
    39 //  return EXCEPTION_CONTINUE_EXECUTION;
     55    }
     56
     57    return EXCEPTION_CONTINUE_SEARCH;
    4058}
    4159
     
    5472}
    5573
    56 int _main()
     74int _main(int argc, char **argv)
    5775{
     76    testCode = argc > 1 ? atoi(argv[1]) : 0;
     77
     78    switch (testCode)
     79    {
     80        case 1:
     81            printf("Target: Throw EXCEPTION_ACCESS_VIOLATION from inner __try\n"
     82                   "and catch it in inner __except.\n\n");
     83            break;
     84        case 2:
     85            printf("Target: Throw EXCEPTION_INT_DIVIDE_BY_ZERO from inner __try\n"
     86                   "and catch it in outer __except.\n\n");
     87            break;
     88        case 3:
     89            printf("Target: Throw EXCEPTION_INT_DIVIDE_BY_ZERO from outer __try\n"
     90                   "and catch it in outer __except.\n\n");
     91            break;
     92        case 4:
     93            printf("Target: Throw EXCEPTION_INT_DIVIDE_BY_ZERO from outer __try,\n"
     94                   "fix it in the handler and continue execution.\n\n");
     95            break;
     96        default:
     97            printf("Invalid test code %d\n", testCode);
     98            return 1;
     99    }
     100
    58101    __try
    59102    {
    60 #if 0
    61         throw_EXCEPTION_INT_DIVIDE_BY_ZERO();
    62         printf("FAILED: No outer exception!\n");
    63         return 1;
    64 #endif
     103        if (testCode == 3 || testCode == 4)
     104        {
     105            throw_EXCEPTION_INT_DIVIDE_BY_ZERO();
     106
     107            printf("FAILED: No outer exception!\n");
     108            return 1;
     109        }
     110
    65111        __try
    66112        {
    67 #if 1
    68             throw_EXCEPTION_ACCESS_VIOLATION();
    69 #else
    70             throw_EXCEPTION_INT_DIVIDE_BY_ZERO();
    71 #endif
     113            if (testCode == 1)
     114                throw_EXCEPTION_ACCESS_VIOLATION();
     115            else if (testCode == 2)
     116                throw_EXCEPTION_INT_DIVIDE_BY_ZERO();
     117
    72118            printf("FAILED: No inner exception!\n");
    73119            return 1;
    74120        }
    75121        __except(exc_filter(GetExceptionCode(),
    76                  EXCEPTION_ACCESS_VIOLATION,
    77                  _exception_info()->ExceptionRecord))
     122                            EXCEPTION_ACCESS_VIOLATION,
     123                            exception_info()))
    78124        {
    79125            // handle exception
     
    82128    }
    83129    __except(exc_filter(GetExceptionCode(),
    84              EXCEPTION_INT_DIVIDE_BY_ZERO,
    85              _exception_info()->ExceptionRecord))
     130                        EXCEPTION_INT_DIVIDE_BY_ZERO,
     131                        exception_info()))
    86132    {
     133        if (testCode == 4 && tries)
     134        {
     135            printf("FAILED: Outer exception (tries = %d)!\n", tries);
     136            return 1;
     137        }
     138
    87139        // handle exception
    88140        printf("Outer exception handled.\n");
Note: See TracChangeset for help on using the changeset viewer.