VirtualBox

Changeset 46632 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Jun 18, 2013 4:58:49 PM (12 years ago)
Author:
vboxsync
Message:

tstMp-1.cpp: Converted it to iprt/test.h.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/tstMp-1.cpp

    r46144 r46632  
    3131#include <iprt/cpuset.h>
    3232#include <iprt/err.h>
    33 #include <iprt/initterm.h>
    34 #include <iprt/stream.h>
    3533#include <iprt/string.h>
    36 
    37 
    38 /*******************************************************************************
    39 *   Global Variables                                                           *
    40 *******************************************************************************/
    41 static unsigned g_cErrors = 0;
     34#include <iprt/test.h>
     35
    4236
    4337
    4438int main()
    4539{
    46     RTR3InitExeNoArguments(0);
    47     RTPrintf("tstMp-1: TESTING...\n");
     40    RTTEST hTest;
     41    RTEXITCODE rcExit = RTTestInitAndCreate("tstRTMp-1", &hTest);
     42    if (rcExit != RTEXITCODE_SUCCESS)
     43        return rcExit;
     44    RTTestBanner(hTest);
    4845
    4946    /*
     
    5249    RTCPUID cCpus = RTMpGetCount();
    5350    if (cCpus > 0)
    54         RTPrintf("tstMp-1: RTMpGetCount -> %d\n", (int)cCpus);
    55     else
    56     {
    57         RTPrintf("tstMp-1: FAILURE: RTMpGetCount -> %d\n", (int)cCpus);
    58         g_cErrors++;
     51        RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetCount -> %u\n", cCpus);
     52    else
     53    {
     54        RTTestIFailed("RTMpGetCount returned zero");
    5955        cCpus = 1;
    6056    }
     
    6258    RTCPUID cCoreCpus = RTMpGetCoreCount();
    6359    if (cCoreCpus > 0)
    64         RTPrintf("tstMp-1: RTMpGetCoreCount -> %d\n", (int)cCoreCpus);
    65     else
    66     {
    67         RTPrintf("tstMp-1: FAILURE: RTMpGetCoreCount -> %d\n", (int)cCoreCpus);
    68         g_cErrors++;
     60        RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetCoreCount -> %d\n", (int)cCoreCpus);
     61    else
     62    {
     63        RTTestIFailed("RTMpGetCoreCount returned zero");
    6964        cCoreCpus = 1;
    7065    }
     66    RTTESTI_CHECK(cCoreCpus <= cCpus);
    7167
    7268    RTCPUSET Set;
    7369    PRTCPUSET pSet = RTMpGetSet(&Set);
     70    RTTESTI_CHECK(pSet == &Set);
    7471    if (pSet == &Set)
    7572    {
    76         if ((RTCPUID)RTCpuSetCount(&Set) != cCpus)
    77         {
    78             RTPrintf("tstMp-1: FAILURE: RTMpGetSet returned a set with a different cpu count; %d, expected %d\n",
    79                      RTCpuSetCount(&Set), cCpus);
    80             g_cErrors++;
    81         }
    82         RTPrintf("tstMp-1: Possible CPU mask:\n");
     73        RTTESTI_CHECK((RTCPUID)RTCpuSetCount(&Set) == cCpus);
     74
     75        RTTestIPrintf(RTTESTLVL_ALWAYS, "Possible CPU mask:\n");
    8376        for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
    8477        {
     
    8679            if (RTCpuSetIsMemberByIndex(&Set, iCpu))
    8780            {
    88                 RTPrintf("tstMp-1: %2d - id %d: %u/%u MHz", iCpu, (int)idCpu,
    89                          RTMpGetCurFrequency(idCpu), RTMpGetMaxFrequency(idCpu));
     81                RTTestIPrintf(RTTESTLVL_ALWAYS, "%2d - id %d: %u/%u MHz", iCpu, (int)idCpu,
     82                              RTMpGetCurFrequency(idCpu), RTMpGetMaxFrequency(idCpu));
    9083                if (RTMpIsCpuPresent(idCpu))
    91                     RTPrintf(RTMpIsCpuOnline(idCpu) ? " online\n" : " offline\n");
     84                    RTTestIPrintf(RTTESTLVL_ALWAYS, RTMpIsCpuOnline(idCpu) ? " online\n" : " offline\n");
    9285                else
    9386                {
    9487                    if (!RTMpIsCpuOnline(idCpu))
    95                         RTPrintf(" absent\n");
     88                        RTTestIPrintf(RTTESTLVL_ALWAYS, " absent\n");
    9689                    else
    9790                    {
    98                         RTPrintf(" online but absent!\n");
    99                         RTPrintf("tstMp-1: FAILURE: Cpu with index %d is report as !RTIsCpuPresent while RTIsCpuOnline returns true!\n", iCpu);
    100                         g_cErrors++;
     91                        RTTestIPrintf(RTTESTLVL_ALWAYS, " online but absent!\n");
     92                        RTTestIFailed("Cpu with index %d is report as !RTIsCpuPresent while RTIsCpuOnline returns true!\n", iCpu);
    10193                    }
    10294                }
    10395                if (!RTMpIsCpuPossible(idCpu))
    104                 {
    105                     RTPrintf("tstMp-1: FAILURE: Cpu with index %d is returned by RTCpuSet but not RTMpIsCpuPossible!\n", iCpu);
    106                     g_cErrors++;
    107                 }
     96                    RTTestIFailed("Cpu with index %d is returned by RTCpuSet but not RTMpIsCpuPossible!\n", iCpu);
    10897            }
    10998            else if (RTMpIsCpuPossible(idCpu))
    110             {
    111                 RTPrintf("tstMp-1: FAILURE: Cpu with index %d is returned by RTMpIsCpuPossible but not RTCpuSet!\n", iCpu);
    112                 g_cErrors++;
    113             }
     99                RTTestIFailed("Cpu with index %d is returned by RTMpIsCpuPossible but not RTCpuSet!\n", iCpu);
    114100            else if (RTMpGetCurFrequency(idCpu) != 0)
    115             {
    116                 RTPrintf("tstMp-1: FAILURE: RTMpGetCurFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu);
    117                 g_cErrors++;
    118             }
     101                RTTestIFailed("RTMpGetCurFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu);
    119102            else if (RTMpGetMaxFrequency(idCpu) != 0)
    120             {
    121                 RTPrintf("tstMp-1: FAILURE: RTMpGetMaxFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu);
    122                 g_cErrors++;
    123             }
     103                RTTestIFailed("RTMpGetMaxFrequency(%d[idx=%d]) didn't return 0 as it should\n", (int)idCpu, iCpu);
    124104        }
    125105    }
    126106    else
    127107    {
    128         RTPrintf("tstMp-1: FAILURE: RTMpGetSet -> %p, expected %p\n", pSet, &Set);
    129         g_cErrors++;
    130108        RTCpuSetEmpty(&Set);
    131109        RTCpuSetAdd(&Set, RTMpCpuIdFromSetIndex(0));
     
    139117    {
    140118        if (cCpusOnline <= cCpus)
    141             RTPrintf("tstMp-1: RTMpGetOnlineCount -> %d\n", (int)cCpusOnline);
     119            RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetOnlineCount -> %d\n", (int)cCpusOnline);
    142120        else
    143121        {
    144             RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineCount -> %d, expected <= %d\n", (int)cCpusOnline, (int)cCpus);
    145             g_cErrors++;
     122            RTTestIFailed("RTMpGetOnlineCount -> %d, expected <= %d\n", (int)cCpusOnline, (int)cCpus);
    146123            cCpusOnline = cCpus;
    147124        }
     
    149126    else
    150127    {
    151         RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineCount -> %d\n", (int)cCpusOnline);
    152         g_cErrors++;
     128        RTTestIFailed("RTMpGetOnlineCount -> %d\n", (int)cCpusOnline);
    153129        cCpusOnline = 1;
    154130    }
     
    159135    {
    160136        if (RTCpuSetCount(&SetOnline) <= 0)
    161         {
    162             RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet returned an empty set!\n");
    163             g_cErrors++;
    164         }
     137            RTTestIFailed("RTMpGetOnlineSet returned an empty set!\n");
    165138        else if ((RTCPUID)RTCpuSetCount(&SetOnline) > cCpus)
    166         {
    167             RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet returned a too high value; %d, expected <= %d\n",
    168                      RTCpuSetCount(&SetOnline), cCpus);
    169             g_cErrors++;
    170         }
    171         RTPrintf("tstMp-1: Online CPU mask:\n");
     139            RTTestIFailed("RTMpGetOnlineSet returned a too high value; %d, expected <= %d\n",
     140                          RTCpuSetCount(&SetOnline), cCpus);
     141        RTTestIPrintf(RTTESTLVL_ALWAYS, "Online CPU mask:\n");
    172142        for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
    173143            if (RTCpuSetIsMemberByIndex(&SetOnline, iCpu))
    174144            {
    175145                RTCPUID idCpu = RTMpCpuIdFromSetIndex(iCpu);
    176                 RTPrintf("tstMp-1: %2d - id %d: %u/%u MHz %s\n", iCpu, (int)idCpu, RTMpGetCurFrequency(idCpu),
    177                          RTMpGetMaxFrequency(idCpu), RTMpIsCpuOnline(idCpu) ? "online" : "offline");
     146                RTTestIPrintf(RTTESTLVL_ALWAYS, "%2d - id %d: %u/%u MHz %s\n", iCpu, (int)idCpu, RTMpGetCurFrequency(idCpu),
     147                              RTMpGetMaxFrequency(idCpu), RTMpIsCpuOnline(idCpu) ? "online" : "offline");
    178148                if (!RTCpuSetIsMemberByIndex(&Set, iCpu))
    179                 {
    180                     RTPrintf("tstMp-1: FAILURE: online cpu with index %2d is not a member of the possible cpu set!\n", iCpu);
    181                     g_cErrors++;
    182                 }
     149                    RTTestIFailed("online cpu with index %2d is not a member of the possible cpu set!\n", iCpu);
    183150            }
    184151
     
    186153    }
    187154    else
    188     {
    189         RTPrintf("tstMp-1: FAILURE: RTMpGetOnlineSet -> %p, expected %p\n", pSet, &Set);
    190         g_cErrors++;
    191     }
     155        RTTestIFailed("RTMpGetOnlineSet -> %p, expected %p\n", pSet, &Set);
    192156
    193157    /*
     
    199163        if (    cCpusPresent <= cCpus
    200164            &&  cCpusPresent >= cCpusOnline)
    201             RTPrintf("tstMp-1: RTMpGetPresentCount -> %d\n", (int)cCpusPresent);
     165            RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetPresentCount -> %d\n", (int)cCpusPresent);
    202166        else
    203         {
    204             RTPrintf("tstMp-1: FAILURE: RTMpGetPresentCount -> %d, expected <= %d and >= %d\n", (int)cCpusPresent, (int)cCpus, (int)cCpusOnline);
    205             g_cErrors++;
    206         }
    207     }
    208     else
    209     {
    210         RTPrintf("tstMp-1: FAILURE: RTMpGetPresentCount -> %d\n", (int)cCpusPresent);
    211         g_cErrors++;
     167            RTTestIFailed("RTMpGetPresentCount -> %d, expected <= %d and >= %d\n",
     168                          (int)cCpusPresent, (int)cCpus, (int)cCpusOnline);
     169    }
     170    else
     171    {
     172        RTTestIFailed("RTMpGetPresentCount -> %d\n", (int)cCpusPresent);
    212173        cCpusPresent = 1;
    213174    }
     
    218179    {
    219180        if (RTCpuSetCount(&SetPresent) <= 0)
    220         {
    221             RTPrintf("tstMp-1: FAILURE: RTMpGetPresentSet returned an empty set!\n");
    222             g_cErrors++;
    223         }
     181            RTTestIFailed("RTMpGetPresentSet returned an empty set!\n");
    224182        else if ((RTCPUID)RTCpuSetCount(&SetPresent) != cCpusPresent)
    225         {
    226             RTPrintf("tstMp-1: FAILURE: RTMpGetPresentSet returned a bad value; %d, expected = %d\n",
    227                      RTCpuSetCount(&SetPresent), cCpusPresent);
    228             g_cErrors++;
    229         }
    230         RTPrintf("tstMp-1: Present CPU mask:\n");
     183            RTTestIFailed("RTMpGetPresentSet returned a bad value; %d, expected = %d\n",
     184                          RTCpuSetCount(&SetPresent), cCpusPresent);
     185        RTTestIPrintf(RTTESTLVL_ALWAYS, "Present CPU mask:\n");
    231186        for (int iCpu = 0; iCpu < RTCPUSET_MAX_CPUS; iCpu++)
    232187            if (RTCpuSetIsMemberByIndex(&SetPresent, iCpu))
    233188            {
    234189                RTCPUID idCpu = RTMpCpuIdFromSetIndex(iCpu);
    235                 RTPrintf("tstMp-1: %2d - id %d: %u/%u MHz %s\n", iCpu, (int)idCpu, RTMpGetCurFrequency(idCpu),
    236                          RTMpGetMaxFrequency(idCpu), RTMpIsCpuPresent(idCpu) ? "present" : "absent");
     190                RTTestIPrintf(RTTESTLVL_ALWAYS, "%2d - id %d: %u/%u MHz %s\n", iCpu, (int)idCpu, RTMpGetCurFrequency(idCpu),
     191                              RTMpGetMaxFrequency(idCpu), RTMpIsCpuPresent(idCpu) ? "present" : "absent");
    237192                if (!RTCpuSetIsMemberByIndex(&Set, iCpu))
    238                 {
    239                     RTPrintf("tstMp-1: FAILURE: online cpu with index %2d is not a member of the possible cpu set!\n", iCpu);
    240                     g_cErrors++;
    241                 }
     193                    RTTestIFailed("online cpu with index %2d is not a member of the possible cpu set!\n", iCpu);
    242194            }
    243195
     
    245197    }
    246198    else
    247     {
    248         RTPrintf("tstMp-1: FAILURE: RTMpGetPresentSet -> %p, expected %p\n", pSet, &Set);
    249         g_cErrors++;
    250     }
     199        RTTestIFailed("RTMpGetPresentSet -> %p, expected %p\n", pSet, &Set);
    251200
    252201
     
    264213    if (RT_SUCCESS(rc))
    265214    {
    266         RTPrintf("tstMp-1: RTMpGetDescription -> '%s'\n", szBuf);
     215        RTTestIPrintf(RTTESTLVL_ALWAYS, "RTMpGetDescription -> '%s'\n", szBuf);
    267216
    268217        size_t cch = strlen(szBuf);
    269218        rc = RTMpGetDescription(idCpuOnline, &szBuf[0], cch);
    270219        if (rc != VERR_BUFFER_OVERFLOW)
    271         {
    272             RTPrintf("tstMp-1: FAILURE: RTMpGetDescription -> %Rrc, expected VERR_BUFFER_OVERFLOW\n", rc);
    273             g_cErrors++;
    274         }
     220            RTTestIFailed("RTMpGetDescription -> %Rrc, expected VERR_BUFFER_OVERFLOW\n", rc);
     221
    275222        rc = RTMpGetDescription(idCpuOnline, &szBuf[0], cch + 1);
    276223        if (RT_FAILURE(rc))
    277         {
    278             RTPrintf("tstMp-1: FAILURE: RTMpGetDescription -> %Rrc, expected VINF_SUCCESS\n", rc);
    279             g_cErrors++;
    280         }
    281     }
    282     else
    283     {
    284         RTPrintf("tstMp-1: FAILURE: RTMpGetDescription -> %Rrc\n", rc);
    285         g_cErrors++;
    286     }
    287 
    288 
    289     if (!g_cErrors)
    290         RTPrintf("tstMp-1: SUCCESS\n", g_cErrors);
    291     else
    292         RTPrintf("tstMp-1: FAILURE - %d errors\n", g_cErrors);
    293     return !!g_cErrors;
     224            RTTestIFailed("RTMpGetDescription -> %Rrc, expected VINF_SUCCESS\n", rc);
     225    }
     226    else
     227        RTTestIFailed("RTMpGetDescription -> %Rrc\n", rc);
     228
     229    return RTTestSummaryAndDestroy(hTest);
    294230}
    295231
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