VirtualBox

source: vbox/trunk/src/VBox/Debugger/testcase/tstDBGCParser.cpp@ 31637

Last change on this file since 31637 was 31530, checked in by vboxsync, 14 years ago

Debugger: Updated the file headers.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 6.8 KB
Line 
1/* $Id: tstDBGCParser.cpp 31530 2010-08-10 12:24:45Z vboxsync $ */
2/** @file
3 * DBGC Testcase - Command Parser.
4 */
5
6/*
7 * Copyright (C) 2006-2010 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
18/*******************************************************************************
19* Header Files *
20*******************************************************************************/
21#include <VBox/dbg.h>
22#include "../DBGCInternal.h"
23
24#include <iprt/stream.h>
25#include <iprt/string.h>
26#include <iprt/initterm.h>
27
28
29/*******************************************************************************
30* Internal Functions *
31*******************************************************************************/
32static DECLCALLBACK(bool) tstDBGCBackInput(PDBGCBACK pBack, uint32_t cMillies);
33static DECLCALLBACK(int) tstDBGCBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead);
34static DECLCALLBACK(int) tstDBGCBackWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten);
35static DECLCALLBACK(void) tstDBGCBackSetReady(PDBGCBACK pBack, bool fReady);
36
37
38/*******************************************************************************
39* Global Variables *
40*******************************************************************************/
41/** Global error counter. */
42static unsigned g_cErrors = 0;
43/** The DBGC backend structure for use in this testcase. */
44static DBGCBACK g_tstBack =
45{
46 tstDBGCBackInput,
47 tstDBGCBackRead,
48 tstDBGCBackWrite,
49 tstDBGCBackSetReady
50};
51/** For keeping track of output prefixing. */
52static bool g_fPendingPrefix = true;
53/** Pointer to the current input position. */
54const char *g_pszInput = NULL;
55
56/**
57 * Checks if there is input.
58 *
59 * @returns true if there is input ready.
60 * @returns false if there not input ready.
61 * @param pBack Pointer to the backend structure supplied by
62 * the backend. The backend can use this to find
63 * it's instance data.
64 * @param cMillies Number of milliseconds to wait on input data.
65 */
66static DECLCALLBACK(bool) tstDBGCBackInput(PDBGCBACK pBack, uint32_t cMillies)
67{
68 return g_pszInput != NULL
69 && *g_pszInput != '\0';
70}
71
72
73/**
74 * Read input.
75 *
76 * @returns VBox status code.
77 * @param pBack Pointer to the backend structure supplied by
78 * the backend. The backend can use this to find
79 * it's instance data.
80 * @param pvBuf Where to put the bytes we read.
81 * @param cbBuf Maximum nymber of bytes to read.
82 * @param pcbRead Where to store the number of bytes actually read.
83 * If NULL the entire buffer must be filled for a
84 * successful return.
85 */
86static DECLCALLBACK(int) tstDBGCBackRead(PDBGCBACK pBack, void *pvBuf, size_t cbBuf, size_t *pcbRead)
87{
88 if (g_pszInput && *g_pszInput)
89 {
90 size_t cb = strlen(g_pszInput);
91 if (cb > cbBuf)
92 cb = cbBuf;
93 *pcbRead = cb;
94 memcpy(pvBuf, g_pszInput, cb);
95 g_pszInput += cb;
96 }
97 else
98 *pcbRead = 0;
99 return VINF_SUCCESS;
100}
101
102
103/**
104 * Write (output).
105 *
106 * @returns VBox status code.
107 * @param pBack Pointer to the backend structure supplied by
108 * the backend. The backend can use this to find
109 * it's instance data.
110 * @param pvBuf What to write.
111 * @param cbBuf Number of bytes to write.
112 * @param pcbWritten Where to store the number of bytes actually written.
113 * If NULL the entire buffer must be successfully written.
114 */
115static DECLCALLBACK(int) tstDBGCBackWrite(PDBGCBACK pBack, const void *pvBuf, size_t cbBuf, size_t *pcbWritten)
116{
117 const char *pch = (const char *)pvBuf;
118 if (pcbWritten)
119 *pcbWritten = cbBuf;
120 while (cbBuf-- > 0)
121 {
122 if (g_fPendingPrefix)
123 {
124 RTPrintf("tstDBGCParser: OUTPUT: ");
125 g_fPendingPrefix = false;
126 }
127 if (*pch == '\n')
128 g_fPendingPrefix = true;
129 RTPrintf("%c", *pch);
130 pch++;
131 }
132 return VINF_SUCCESS;
133}
134
135
136/**
137 * Ready / busy notification.
138 *
139 * @param pBack Pointer to the backend structure supplied by
140 * the backend. The backend can use this to find
141 * it's instance data.
142 * @param fReady Whether it's ready (true) or busy (false).
143 */
144static DECLCALLBACK(void) tstDBGCBackSetReady(PDBGCBACK pBack, bool fReady)
145{
146}
147
148
149/**
150 * Completes the output, making sure that we're in
151 * the 1 position of a new line.
152 */
153static void tstCompleteOutput(void)
154{
155 if (!g_fPendingPrefix)
156 RTPrintf("\n");
157 g_fPendingPrefix = true;
158}
159
160
161/**
162 * Tries one command string.
163 * @param pDbgc Pointer to the debugger instance.
164 * @param pszCmds The command to test.
165 * @param rcCmd The expected result.
166 */
167static void tstTry(PDBGC pDbgc, const char *pszCmds, int rcCmd)
168{
169 g_pszInput = pszCmds;
170 if (strchr(pszCmds, '\0')[-1] == '\n')
171 RTPrintf("tstDBGCParser: RUNNING: %s", pszCmds);
172 else
173 RTPrintf("tstDBGCParser: RUNNING: %s\n", pszCmds);
174
175 pDbgc->rcCmd = VERR_INTERNAL_ERROR;
176 dbgcProcessInput(pDbgc, true /* fNoExecute */);
177 tstCompleteOutput();
178
179 if (pDbgc->rcCmd != rcCmd)
180 {
181 RTPrintf("tstDBGCParser: rcCmd=%Rrc expected =%Rrc\n", pDbgc->rcCmd, rcCmd);
182 g_cErrors++;
183 }
184}
185
186
187int main()
188{
189 /*
190 * Init.
191 */
192 RTR3Init();
193 RTPrintf("tstDBGCParser: TESTING...\n");
194
195 /*
196 * Create a DBGC instance.
197 */
198 PDBGC pDbgc;
199 int rc = dbgcCreate(&pDbgc, &g_tstBack, 0);
200 if (RT_SUCCESS(rc))
201 {
202 rc = dbgcProcessInput(pDbgc, true /* fNoExecute */);
203 tstCompleteOutput();
204 if (RT_SUCCESS(rc))
205 {
206 tstTry(pDbgc, "stop\n", VINF_SUCCESS);
207 tstTry(pDbgc, "format \n", VERR_PARSE_TOO_FEW_ARGUMENTS);
208 tstTry(pDbgc, "format 0 1 23 4\n", VERR_PARSE_TOO_MANY_ARGUMENTS);
209 tstTry(pDbgc, "sa 3 23 4 'q' \"21123123\" 'b' \n", VINF_SUCCESS);
210 }
211
212 dbgcDestroy(pDbgc);
213 }
214
215 /*
216 * Summary
217 */
218 if (!g_cErrors)
219 RTPrintf("tstDBGCParser: SUCCESS\n");
220 else
221 RTPrintf("tstDBGCParser: FAILURE - %d errors\n", g_cErrors);
222 return g_cErrors != 0;
223}
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