VirtualBox

Changeset 79521 in vbox for trunk/src


Ignore:
Timestamp:
Jul 4, 2019 9:25:05 AM (6 years ago)
Author:
vboxsync
Message:

VBox/log.h: Kicked out most event group (base classes are still there) and made tstLog check the ordering of the enum and string array. E:\vbox\svn\trunk\include\VBox\log.h E:\vbox\svn\trunk\src\VBox\Devices\Network\lwip-new\vbox\include\lwip-log.h E:\vbox\svn\trunk\src\VBox\Runtime\

Location:
trunk/src/VBox/Runtime/testcase
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r77684 r79521  
    503503tstRTLockValidator_SOURCES = tstRTLockValidator.cpp
    504504
    505 tstLog_TEMPLATE = VBOXR3TSTEXE
    506 tstLog_SOURCES = tstLog.cpp
     505tstLog_TEMPLATE      = VBOXR3TSTEXE
     506tstLog_SOURCES       = tstLog.cpp
     507tstLog_INCS          = $(tstLog_0_OUTDIR)
     508tstLog_INTERMEDIATES = $(tstLog_0_OUTDIR)/tstLogGroups.h
     509tstLog_CLEANS        = $(tstLog_0_OUTDIR)/tstLogGroups.h
     510$$(tstLog_0_OUTDIR)/tstLogGroups.h: $(PATH_ROOT)/include/VBox/log.h
     511        $(call MSG_GENERATE,,$@,$<)
     512        $(QUIET)$(RM) -f -- "$@"
     513        $(QUIET)$(SED) -n -e 's/^ *LOG_GROUP_\([A-Z0-9_]*\),.*$(DOLLAR)/{ LOG_GROUP_\1, "\1" },/p' --output "$@" "$<"
    507514
    508515tstRTMemEf_TEMPLATE = VBOXR3TSTEXE
  • trunk/src/VBox/Runtime/testcase/tstLog.cpp

    r76553 r79521  
    11/* $Id$ */
    22/** @file
    3  * IPRT Testcase - Log Formatting.
     3 * IPRT Testcase - Log Groups.
    44 */
    55
     
    3030*********************************************************************************************************************************/
    3131#include <iprt/log.h>
    32 #include <iprt/initterm.h>
    33 #include <iprt/errcore.h>
     32#include <iprt/string.h>
     33#include <iprt/test.h>
     34#ifdef VBOX
     35# include <VBox/log.h>
     36#endif
    3437
    35 #include <stdio.h>
     38
     39/** Differs from normal strcmp in that '_' is considered smaller than
     40 * alphanumerical characters. */
     41static int CompareLogGroups(const char *psz1, const char *psz2)
     42{
     43    for (;;)
     44    {
     45        char ch1 = *psz1++;
     46        char ch2 = *psz2++;
     47        if (ch1 != ch2)
     48        {
     49            if (ch1 == 0)
     50                return -1;
     51            if (ch2 == 0)
     52                return 1;
     53            if (ch1 == '_')
     54                ch1 = 1;
     55            if (ch2 == '_')
     56                ch2 = 1;
     57            return ch1 < ch2 ? -1 : 1;
     58        }
     59        if (ch1 == 0)
     60            return 0;
     61    }
     62}
    3663
    3764int main()
    3865{
    39     RTR3InitExeNoArguments(0);
    40     printf("tstLog: Requires manual inspection of the log output!\n");
    41     RTLogPrintf("%%Rrc %d: %Rrc\n", VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER);
    42     RTLogPrintf("%%Rrs %d: %Rrs\n", VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER);
    43     RTLogPrintf("%%Rrf %d: %Rrf\n", VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER);
    44     RTLogPrintf("%%Rra %d: %Rra\n", VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER);
     66    RTTEST hTest;
     67    RTEXITCODE rcExit = RTTestInitAndCreate("tstLog", &hTest);
     68    if (rcExit == RTEXITCODE_SUCCESS)
     69    {
     70#if 0   /* Old tests: */
     71        printf("tstLog: Requires manual inspection of the log output!\n");
     72        RTLogPrintf("%%Rrc %d: %Rrc\n", VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER);
     73        RTLogPrintf("%%Rrs %d: %Rrs\n", VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER);
     74        RTLogPrintf("%%Rrf %d: %Rrf\n", VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER);
     75        RTLogPrintf("%%Rra %d: %Rra\n", VERR_INVALID_PARAMETER, VERR_INVALID_PARAMETER);
    4576
    46     static uint8_t au8Hex[256];
    47     for (unsigned iHex = 0; iHex < sizeof(au8Hex); iHex++)
    48         au8Hex[iHex] = (uint8_t)iHex;
    49     RTLogPrintf("%%Rhxs   : %Rhxs\n", &au8Hex[0]);
    50     RTLogPrintf("%%.32Rhxs: %.32Rhxs\n", &au8Hex[0]);
     77        static uint8_t au8Hex[256];
     78        for (unsigned iHex = 0; iHex < sizeof(au8Hex); iHex++)
     79            au8Hex[iHex] = (uint8_t)iHex;
     80        RTLogPrintf("%%Rhxs   : %Rhxs\n", &au8Hex[0]);
     81        RTLogPrintf("%%.32Rhxs: %.32Rhxs\n", &au8Hex[0]);
    5182
    52     RTLogPrintf("%%Rhxd   :\n%Rhxd\n", &au8Hex[0]);
    53     RTLogPrintf("%%.64Rhxd:\n%.64Rhxd\n", &au8Hex[0]);
    54     RTLogPrintf("%%.*Rhxd:\n%.*Rhxd\n", 64, &au8Hex[0]);
    55     RTLogPrintf("%%32.256Rhxd : \n%32.256Rhxd\n", &au8Hex[0]);
    56     RTLogPrintf("%%32.*Rhxd : \n%32.*Rhxd\n", 256, &au8Hex[0]);
    57     RTLogPrintf("%%7.32Rhxd : \n%7.32Rhxd\n", &au8Hex[0]);
    58     RTLogPrintf("%%7.*Rhxd : \n%7.*Rhxd\n", 32, &au8Hex[0]);
    59     RTLogPrintf("%%*.*Rhxd : \n%*.*Rhxd\n", 7, 32, &au8Hex[0]);
     83        RTLogPrintf("%%Rhxd   :\n%Rhxd\n", &au8Hex[0]);
     84        RTLogPrintf("%%.64Rhxd:\n%.64Rhxd\n", &au8Hex[0]);
     85        RTLogPrintf("%%.*Rhxd:\n%.*Rhxd\n", 64, &au8Hex[0]);
     86        RTLogPrintf("%%32.256Rhxd : \n%32.256Rhxd\n", &au8Hex[0]);
     87        RTLogPrintf("%%32.*Rhxd : \n%32.*Rhxd\n", 256, &au8Hex[0]);
     88        RTLogPrintf("%%7.32Rhxd : \n%7.32Rhxd\n", &au8Hex[0]);
     89        RTLogPrintf("%%7.*Rhxd : \n%7.*Rhxd\n", 32, &au8Hex[0]);
     90        RTLogPrintf("%%*.*Rhxd : \n%*.*Rhxd\n", 7, 32, &au8Hex[0]);
    6091
    61     RTLogPrintf("%%RGp: %RGp\n", (RTGCPHYS)0x87654321);
    62     RTLogPrintf("%%RGv: %RGv\n", (RTGCPTR)0x87654321);
    63     RTLogPrintf("%%RHp: %RHp\n", (RTGCPHYS)0x87654321);
    64     RTLogPrintf("%%RHv: %RHv\n", (RTGCPTR)0x87654321);
     92        RTLogPrintf("%%RGp: %RGp\n", (RTGCPHYS)0x87654321);
     93        RTLogPrintf("%%RGv: %RGv\n", (RTGCPTR)0x87654321);
     94        RTLogPrintf("%%RHp: %RHp\n", (RTGCPHYS)0x87654321);
     95        RTLogPrintf("%%RHv: %RHv\n", (RTGCPTR)0x87654321);
    6596
    66     RTLogPrintf("%%RI8 : %RI8\n", (uint8_t)88);
    67     RTLogPrintf("%%RI16: %RI16\n", (uint16_t)16016);
    68     RTLogPrintf("%%RI32: %RI32\n", _1G);
    69     RTLogPrintf("%%RI64: %RI64\n", _1E);
     97        RTLogPrintf("%%RI8 : %RI8\n", (uint8_t)88);
     98        RTLogPrintf("%%RI16: %RI16\n", (uint16_t)16016);
     99        RTLogPrintf("%%RI32: %RI32\n", _1G);
     100        RTLogPrintf("%%RI64: %RI64\n", _1E);
    70101
    71     RTLogPrintf("%%RU8 : %RU8\n", (uint8_t)88);
    72     RTLogPrintf("%%RU16: %RU16\n", (uint16_t)16016);
    73     RTLogPrintf("%%RU32: %RU32\n", _2G32);
    74     RTLogPrintf("%%RU64: %RU64\n", _2E);
     102        RTLogPrintf("%%RU8 : %RU8\n", (uint8_t)88);
     103        RTLogPrintf("%%RU16: %RU16\n", (uint16_t)16016);
     104        RTLogPrintf("%%RU32: %RU32\n", _2G32);
     105        RTLogPrintf("%%RU64: %RU64\n", _2E);
    75106
    76     RTLogPrintf("%%RX8 : %RX8 %#RX8\n",   (uint8_t)88, (uint8_t)88);
    77     RTLogPrintf("%%RX16: %RX16 %#RX16\n", (uint16_t)16016, (uint16_t)16016);
    78     RTLogPrintf("%%RX32: %RX32 %#RX32\n", _2G32, _2G32);
    79     RTLogPrintf("%%RX64: %RX64 %#RX64\n", _2E, _2E);
     107        RTLogPrintf("%%RX8 : %RX8 %#RX8\n",   (uint8_t)88, (uint8_t)88);
     108        RTLogPrintf("%%RX16: %RX16 %#RX16\n", (uint16_t)16016, (uint16_t)16016);
     109        RTLogPrintf("%%RX32: %RX32 %#RX32\n", _2G32, _2G32);
     110        RTLogPrintf("%%RX64: %RX64 %#RX64\n", _2E, _2E);
    80111
    81     RTLogFlush(NULL);
     112        RTLogFlush(NULL);
     113#endif
    82114
    83     return 0;
     115        /*
     116         * Check the groups.
     117         */
     118#ifdef VBOX
     119        static const char                                               *s_apszGroups[] = VBOX_LOGGROUP_NAMES;
     120        static const struct { uint16_t idGroup; const char *pszGroup;  } s_aGroupEnumValues[] =
     121        {
     122# include "tstLogGroups.h"
     123        };
     124
     125        for (size_t iVal = 0, iGrp = RTLOGGROUP_FIRST_USER + 1; iVal < RT_ELEMENTS(s_aGroupEnumValues); iVal++, iGrp++)
     126        {
     127            if (iGrp >= RT_ELEMENTS(s_apszGroups))
     128            {
     129                RTTestIFailed("iGrp=%zu >= RT_ELEMENTS(s_apszGroups)=%zu\n", iGrp, RT_ELEMENTS(s_apszGroups));
     130                break;
     131            }
     132            if (strcmp(s_apszGroups[iGrp], s_aGroupEnumValues[iVal].pszGroup))
     133                RTTestIFailed("iGrp=%zu mismatch: %s vs %s\n", iGrp, s_apszGroups[iGrp], s_aGroupEnumValues[iVal].pszGroup);
     134            if (   iVal > 0
     135                && CompareLogGroups(s_aGroupEnumValues[iVal].pszGroup, s_aGroupEnumValues[iVal - 1].pszGroup) <= 0)
     136                RTTestIFailed("iGrp=%zu wrong order: %s, prev %s\n",
     137                              iGrp, s_aGroupEnumValues[iVal].pszGroup, s_aGroupEnumValues[iVal - 1].pszGroup);
     138            if (   iVal > 0
     139                && s_aGroupEnumValues[iVal - 1].idGroup + 1 != s_aGroupEnumValues[iVal].idGroup)
     140                RTTestIFailed("Enum values jumped - bad log.h sed: %u -> %u; %s and %s\n",
     141                              s_aGroupEnumValues[iVal - 1].idGroup, s_aGroupEnumValues[iVal].idGroup,
     142                              s_aGroupEnumValues[iVal - 1].pszGroup, s_aGroupEnumValues[iVal].pszGroup);
     143        }
     144#endif
     145        rcExit = RTTestSummaryAndDestroy(hTest);
     146    }
     147    return rcExit;
    84148}
    85149
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