- Timestamp:
- Jul 4, 2019 9:25:05 AM (6 years ago)
- Location:
- trunk/src/VBox/Runtime/testcase
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/testcase/Makefile.kmk
r77684 r79521 503 503 tstRTLockValidator_SOURCES = tstRTLockValidator.cpp 504 504 505 tstLog_TEMPLATE = VBOXR3TSTEXE 506 tstLog_SOURCES = tstLog.cpp 505 tstLog_TEMPLATE = VBOXR3TSTEXE 506 tstLog_SOURCES = tstLog.cpp 507 tstLog_INCS = $(tstLog_0_OUTDIR) 508 tstLog_INTERMEDIATES = $(tstLog_0_OUTDIR)/tstLogGroups.h 509 tstLog_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 "$@" "$<" 507 514 508 515 tstRTMemEf_TEMPLATE = VBOXR3TSTEXE -
trunk/src/VBox/Runtime/testcase/tstLog.cpp
r76553 r79521 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT Testcase - Log Formatting.3 * IPRT Testcase - Log Groups. 4 4 */ 5 5 … … 30 30 *********************************************************************************************************************************/ 31 31 #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 34 37 35 #include <stdio.h> 38 39 /** Differs from normal strcmp in that '_' is considered smaller than 40 * alphanumerical characters. */ 41 static 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 } 36 63 37 64 int main() 38 65 { 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); 45 76 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]); 51 82 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]); 60 91 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); 65 96 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); 70 101 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); 75 106 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); 80 111 81 RTLogFlush(NULL); 112 RTLogFlush(NULL); 113 #endif 82 114 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; 84 148 } 85 149
Note:
See TracChangeset
for help on using the changeset viewer.