VirtualBox

Changeset 18848 in vbox for trunk/src/VBox/VMM/testcase


Ignore:
Timestamp:
Apr 8, 2009 4:28:35 PM (16 years ago)
Author:
vboxsync
Message:

tstVMMR0CallHost-1: Converted to RTTest, use guarded memory for the stack, emulate kernel stack switching on darwin by using alloca().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/testcase/tstVMMR0CallHost-1.cpp

    r14831 r18848  
    2727#include <iprt/stream.h>
    2828#include <iprt/alloca.h>
     29#include <iprt/test.h>
    2930#include <VBox/err.h>
    3031
     
    3435#include "VMMInternal.h"
    3536
     37
     38/*******************************************************************************
     39*   Defined Constants And Macros                                               *
     40*******************************************************************************/
     41#ifdef RT_OS_DARWIN
     42# define VMM_R0_SWITCH_STACK
     43#endif
    3644
    3745
     
    4351/** The number of jumps we've done. */
    4452static unsigned volatile    g_cJmps;
    45 /** The saved stack. */
    46 static uint8_t              g_Stack[8192];
    4753
    4854
     
    6369        return -1;
    6470    }
     71    NOREF(iMinusOne);
    6572    return i;
    6673}
     
    6976DECLCALLBACK(int) tst2(intptr_t i, intptr_t i2)
    7077{
    71     if (i < 0 || i > 8192)
    72     {
    73         RTPrintf("tstVMMR0CallHost-1: FAILURE - i=%d is out of range [0..8192]\n", i);
    74         return 1;
    75     }
    76     if (i2 != 0)
    77     {
    78         RTPrintf("tstVMMR0CallHost-1: FAILURE - i2=%d is out of range [0]\n", i2);
    79         return 1;
    80     }
     78    RTTESTI_CHECK_MSG_RET(i >= 0 && i <= 8192, ("i=%d is out of range [0..8192]\n", i),      1);
     79    RTTESTI_CHECK_MSG_RET(i2 == 0,             ("i2=%d is out of range [0]\n", i2),          1);
    8180    int iExpect = (i % 7) == 0 ? i + 10000 : i;
    8281    int rc = foo(i, 0, -1);
    83     if (rc != iExpect)
    84     {
    85         RTPrintf("tstVMMR0CallHost-1: FAILURE - i=%d rc=%d expected=%d\n", i, rc, iExpect);
    86         return 1;
    87     }
     82    RTTESTI_CHECK_MSG_RET(rc == iExpect,       ("i=%d rc=%d expected=%d\n", i, rc, iExpect), 1);
    8883    return 0;
    8984}
    9085
    91 int tst(int iFrom, int iTo, int iInc)
     86
     87void tst(int iFrom, int iTo, int iInc)
    9288{
     89#ifdef VMM_R0_SWITCH_STACK
     90    int const cIterations = iFrom > iTo ? iFrom - iTo : iTo - iFrom;
     91    void   *pvPrev = alloca(1);
     92#endif
     93
    9394    g_cJmps = 0;
    94     for (int i = iFrom; i != iTo; i += iInc)
     95    for (int i = iFrom, iItr = 0; i != iTo; i += iInc, iItr++)
    9596    {
    9697        int rc = vmmR0CallHostSetJmp(&g_Jmp, (PFNVMMR0SETJMP)tst2, (PVM)i, 0);
    97         if (rc != 0 && rc != 42)
     98        RTTESTI_CHECK_MSG_RETV(rc == 0 || rc == 42, ("i=%d rc=%d setjmp\n", i, rc));
     99
     100#ifdef VMM_R0_SWITCH_STACK
     101        /* Make the stack pointer slide for the second half of the calls. */
     102        if (iItr >= cIterations / 2)
    98103        {
    99             RTPrintf("tstVMMR0CallHost-1: FAILURE - i=%d rc=%d setjmp\n", i, rc);
    100             return 1;
     104            /* Note! gcc does funny rounding up of alloca(). */
     105            void  *pv2 = alloca((i % 63) | 1);
     106            size_t cb2 = (uintptr_t)pvPrev - (uintptr_t)pv2;
     107            RTTESTI_CHECK_MSG(cb2 >= 16 && cb2 <= 128, ("cb2=%zu pv2=%p pvPrev=%p iAlloca=%d\n", cb2, pv2, pvPrev, iItr));
     108            memset(pv2, 0xff, cb2);
     109            memset(pvPrev, 0xee, 1);
     110            pvPrev = pv2;
    101111        }
     112#endif
    102113    }
    103     if (!g_cJmps)
    104     {
    105         RTPrintf("tstVMMR0CallHost-1: FAILURE - no jumps!\n");
    106         return 1;
    107     }
    108     return 0;
     114    RTTESTI_CHECK_MSG_RETV(g_cJmps, ("No jumps!"));
    109115}
    110116
     
    115121     * Init.
    116122     */
    117     RTR3Init();
    118     g_Jmp.pvSavedStack = (RTR0PTR)&g_Stack[0];
     123    RTTEST hTest;
     124    int rc;
     125    if (    RT_FAILURE(rc = RTR3Init())
     126        ||  RT_FAILURE(rc = RTTestCreate("tstVMMR0CallHost-1", &hTest)))
     127    {
     128        RTStrmPrintf(g_pStdErr, "tstVMMR0CallHost-1: Fatal error during init: %Rrc\n", rc);
     129        return 1;
     130    }
     131    RTTestBanner(hTest);
     132
     133    g_Jmp.pvSavedStack = (RTR0PTR)RTTestGuardedAllocTail(hTest, 8192);
    119134
    120135    /*
    121      * Try about 1000 long jumps with increasing stack size..
     136     * Run two test with about 1000 long jumps each.
    122137     */
    123     RTPrintf("tstVMMR0CallHost-1: Testing 1\n");
    124     int rc = tst(0, 7000, 1);
    125     if (!rc)
    126     {
    127         RTPrintf("tstVMMR0CallHost-1: Testing 2\n");
    128         rc = tst(7599, 0, -1);
    129     }
     138    RTTestSub(hTest, "Increasing stack usage");
     139    tst(0, 7000, 1);
     140    RTTestSub(hTest, "Decreasing stack usage");
     141    tst(7599, 0, -1);
    130142
    131     if (!rc)
    132         RTPrintf("tstVMMR0CallHost-1: SUCCESS\n");
    133     else
    134         RTPrintf("tstVMMR0CallHost-1: FAILED\n");
    135     return !!rc;
     143    return RTTestSummaryAndDestroy(hTest);
    136144}
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette