1 | /* $Id: bs3-cmn-TestFailed.c 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * BS3Kit - Bs3TestFailed, Bs3TestFailedF, Bs3TestFailedV.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2007-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include "bs3kit-template-header.h"
|
---|
42 | #include "bs3-cmn-test.h"
|
---|
43 | #include <iprt/asm-amd64-x86.h>
|
---|
44 |
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * @callback_method_impl{FNBS3STRFORMATOUTPUT,
|
---|
48 | * Used by Bs3TestFailedV and Bs3TestSkippedV.}
|
---|
49 | */
|
---|
50 | BS3_DECL_CALLBACK(size_t) bs3TestFailedStrOutput(char ch, void BS3_FAR *pvUser)
|
---|
51 | {
|
---|
52 | PBS3TESTFAILEDBUF pBuf = (PBS3TESTFAILEDBUF)pvUser;
|
---|
53 |
|
---|
54 | /*
|
---|
55 | * VMMDev first. We postpone newline processing here so we can strip one
|
---|
56 | * trailing newline.
|
---|
57 | */
|
---|
58 | if (g_fbBs3VMMDevTesting)
|
---|
59 | {
|
---|
60 | if (pBuf->fNewLine && ch != '\0')
|
---|
61 | ASMOutU8(VMMDEV_TESTING_IOPORT_DATA, '\n');
|
---|
62 | pBuf->fNewLine = ch == '\n';
|
---|
63 | if (ch != '\n')
|
---|
64 | ASMOutU8(VMMDEV_TESTING_IOPORT_DATA, ch);
|
---|
65 | }
|
---|
66 |
|
---|
67 | /*
|
---|
68 | * Console next.
|
---|
69 | */
|
---|
70 | if (ch != '\0')
|
---|
71 | {
|
---|
72 | BS3_ASSERT(pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf));
|
---|
73 | pBuf->achBuf[pBuf->cchBuf++] = ch;
|
---|
74 |
|
---|
75 | /* Whether to flush the buffer. We do line flushing here to avoid
|
---|
76 | dropping too much info when the formatter crashes on bad input. */
|
---|
77 | if ( pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf)
|
---|
78 | && ch != '\n')
|
---|
79 | {
|
---|
80 | pBuf->fNewLine = false;
|
---|
81 | return 1;
|
---|
82 | }
|
---|
83 | pBuf->fNewLine = '\n';
|
---|
84 | }
|
---|
85 | /* Try fit missing newline into the buffer. */
|
---|
86 | else if (!pBuf->fNewLine && pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf))
|
---|
87 | {
|
---|
88 | pBuf->fNewLine = true;
|
---|
89 | pBuf->achBuf[pBuf->cchBuf++] = '\n';
|
---|
90 | }
|
---|
91 |
|
---|
92 | BS3_ASSERT(pBuf->cchBuf <= RT_ELEMENTS(pBuf->achBuf));
|
---|
93 | Bs3PrintStrN(&pBuf->achBuf[0], pBuf->cchBuf);
|
---|
94 | pBuf->cchBuf = 0;
|
---|
95 |
|
---|
96 | /* In case we failed to add trailing new line, print one separately. */
|
---|
97 | if (!pBuf->fNewLine)
|
---|
98 | Bs3PrintChr('\n');
|
---|
99 |
|
---|
100 | return ch != '\0';
|
---|
101 | }
|
---|
102 |
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Equivalent to RTTestIFailedV.
|
---|
106 | */
|
---|
107 | #undef Bs3TestFailedV
|
---|
108 | BS3_CMN_DEF(bool, Bs3TestFailedV,(const char *pszFormat, va_list BS3_FAR va))
|
---|
109 | {
|
---|
110 | BS3TESTFAILEDBUF Buf;
|
---|
111 |
|
---|
112 | if (!++g_cusBs3TestErrors)
|
---|
113 | g_cusBs3TestErrors++;
|
---|
114 |
|
---|
115 | if (g_fbBs3VMMDevTesting)
|
---|
116 | #if ARCH_BITS == 16
|
---|
117 | ASMOutU16(VMMDEV_TESTING_IOPORT_CMD, (uint16_t)VMMDEV_TESTING_CMD_FAILED);
|
---|
118 | #else
|
---|
119 | ASMOutU32(VMMDEV_TESTING_IOPORT_CMD, VMMDEV_TESTING_CMD_FAILED);
|
---|
120 | #endif
|
---|
121 |
|
---|
122 | Buf.fNewLine = false;
|
---|
123 | Buf.cchBuf = 0;
|
---|
124 | Bs3StrFormatV(pszFormat, va, bs3TestFailedStrOutput, &Buf);
|
---|
125 | return false;
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | /**
|
---|
130 | * Equivalent to RTTestIFailedF.
|
---|
131 | */
|
---|
132 | #undef Bs3TestFailedF
|
---|
133 | BS3_CMN_DEF(bool, Bs3TestFailedF,(const char *pszFormat, ...))
|
---|
134 | {
|
---|
135 | va_list va;
|
---|
136 | va_start(va, pszFormat);
|
---|
137 | BS3_CMN_NM(Bs3TestFailedV)(pszFormat, va);
|
---|
138 | va_end(va);
|
---|
139 | return false;
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | /**
|
---|
144 | * Equivalent to RTTestIFailed.
|
---|
145 | */
|
---|
146 | #undef Bs3TestFailed
|
---|
147 | BS3_CMN_DEF(bool, Bs3TestFailed,(const char *pszMessage))
|
---|
148 | {
|
---|
149 | return BS3_CMN_NM(Bs3TestFailedF)("%s", pszMessage);
|
---|
150 | }
|
---|
151 |
|
---|