VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/bootsectors/bs3kit/bs3-cmn-TestFailed.c@ 83878

Last change on this file since 83878 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 Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Id: bs3-cmn-TestFailed.c 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * BS3Kit - Bs3TestFailed, Bs3TestFailedF, Bs3TestFailedV.
4 */
5
6/*
7 * Copyright (C) 2007-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 "bs3kit-template-header.h"
32#include "bs3-cmn-test.h"
33#include <iprt/asm-amd64-x86.h>
34
35
36/**
37 * @callback_method_impl{FNBS3STRFORMATOUTPUT,
38 * Used by Bs3TestFailedV and Bs3TestSkippedV.}
39 */
40BS3_DECL_CALLBACK(size_t) bs3TestFailedStrOutput(char ch, void BS3_FAR *pvUser)
41{
42 PBS3TESTFAILEDBUF pBuf = (PBS3TESTFAILEDBUF)pvUser;
43
44 /*
45 * VMMDev first. We postpone newline processing here so we can strip one
46 * trailing newline.
47 */
48 if (g_fbBs3VMMDevTesting)
49 {
50 if (pBuf->fNewLine && ch != '\0')
51 ASMOutU8(VMMDEV_TESTING_IOPORT_DATA, '\n');
52 pBuf->fNewLine = ch == '\n';
53 if (ch != '\n')
54 ASMOutU8(VMMDEV_TESTING_IOPORT_DATA, ch);
55 }
56
57 /*
58 * Console next.
59 */
60 if (ch != '\0')
61 {
62 BS3_ASSERT(pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf));
63 pBuf->achBuf[pBuf->cchBuf++] = ch;
64
65 /* Whether to flush the buffer. We do line flushing here to avoid
66 dropping too much info when the formatter crashes on bad input. */
67 if ( pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf)
68 && ch != '\n')
69 {
70 pBuf->fNewLine = false;
71 return 1;
72 }
73 pBuf->fNewLine = '\n';
74 }
75 /* Try fit missing newline into the buffer. */
76 else if (!pBuf->fNewLine && pBuf->cchBuf < RT_ELEMENTS(pBuf->achBuf))
77 {
78 pBuf->fNewLine = true;
79 pBuf->achBuf[pBuf->cchBuf++] = '\n';
80 }
81
82 BS3_ASSERT(pBuf->cchBuf <= RT_ELEMENTS(pBuf->achBuf));
83 Bs3PrintStrN(&pBuf->achBuf[0], pBuf->cchBuf);
84 pBuf->cchBuf = 0;
85
86 /* In case we failed to add trailing new line, print one separately. */
87 if (!pBuf->fNewLine)
88 Bs3PrintChr('\n');
89
90 return ch != '\0';
91}
92
93
94/**
95 * Equivalent to RTTestIFailedV.
96 */
97#undef Bs3TestFailedV
98BS3_CMN_DEF(bool, Bs3TestFailedV,(const char *pszFormat, va_list BS3_FAR va))
99{
100 BS3TESTFAILEDBUF Buf;
101
102 if (!++g_cusBs3TestErrors)
103 g_cusBs3TestErrors++;
104
105 if (g_fbBs3VMMDevTesting)
106#if ARCH_BITS == 16
107 ASMOutU16(VMMDEV_TESTING_IOPORT_CMD, (uint16_t)VMMDEV_TESTING_CMD_FAILED);
108#else
109 ASMOutU32(VMMDEV_TESTING_IOPORT_CMD, VMMDEV_TESTING_CMD_FAILED);
110#endif
111
112 Buf.fNewLine = false;
113 Buf.cchBuf = 0;
114 Bs3StrFormatV(pszFormat, va, bs3TestFailedStrOutput, &Buf);
115 return false;
116}
117
118
119/**
120 * Equivalent to RTTestIFailedF.
121 */
122#undef Bs3TestFailedF
123BS3_CMN_DEF(bool, Bs3TestFailedF,(const char *pszFormat, ...))
124{
125 va_list va;
126 va_start(va, pszFormat);
127 BS3_CMN_NM(Bs3TestFailedV)(pszFormat, va);
128 va_end(va);
129 return false;
130}
131
132
133/**
134 * Equivalent to RTTestIFailed.
135 */
136#undef Bs3TestFailed
137BS3_CMN_DEF(bool, Bs3TestFailed,(const char *pszMessage))
138{
139 return BS3_CMN_NM(Bs3TestFailedF)("%s", pszMessage);
140}
141
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