VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstLog.cpp@ 86669

Last change on this file since 86669 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 6.0 KB
Line 
1/* $Id: tstLog.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Log Groups.
4 */
5
6/*
7 * Copyright (C) 2006-2020 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*********************************************************************************************************************************
29* Header Files *
30*********************************************************************************************************************************/
31#include <iprt/log.h>
32#include <iprt/string.h>
33#include <iprt/test.h>
34#ifdef VBOX
35# include <VBox/log.h>
36#endif
37
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}
63
64int main()
65{
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);
76
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]);
82
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]);
91
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);
96
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);
101
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);
106
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);
111
112 RTLogFlush(NULL);
113#endif
114
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;
148}
149
Note: See TracBrowser for help on using the repository browser.

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