VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTR0CommonDriver.h@ 32648

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

IPRT: linux kernel timer changes, testcase. hrtimers are not working reliably yet.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.7 KB
Line 
1/* $Id: tstRTR0CommonDriver.h 32648 2010-09-20 16:17:03Z vboxsync $ */
2/** @file
3 * IPRT R0 Testcase - Common header for the testcase drivers.
4 */
5
6/*
7 * Copyright (C) 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 * 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#ifndef ___testcase_tstRTR0CommonDriver_h
29#define ___testcase_tstRTR0CommonDriver_h
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <iprt/ctype.h>
36#include <iprt/string.h>
37#include <VBox/sup.h>
38#include "tstRTR0CommonReq.h"
39
40
41/*******************************************************************************
42* Global Variables *
43*******************************************************************************/
44/** The test handle. */
45RTTEST g_hTest;
46/** The test & service name. */
47char g_szSrvName[64];
48/** The length of the service name. */
49uint32_t g_cchSrvName;
50/** The base address of the service module. */
51void *g_pvImageBase;
52
53
54/**
55 * Initializes the test driver.
56 *
57 * This means creating a test instance (RTTEST), initializing the support
58 * library, and loading the service module.
59 *
60 * @returns RTEXITCODE_SUCCESS on success, appropriate exit code on failure.
61 * @param pszTestServiceName The name of the test and service. This
62 * will be used when creating the test
63 * instance as well as when talking with the
64 * kernel side of the test.
65 *
66 * The ring-0 module name will be derived from
67 * this + '.r0'.
68 *
69 * The service request handler function name
70 * will be derived by upper casing the first
71 * chars and appending 'SrvReqHandler'.
72 *
73 */
74RTEXITCODE RTR3TestR0CommonDriverInit(const char *pszTestServiceName)
75{
76 /*
77 * Init the test.
78 */
79 RTEXITCODE rcExit = RTTestInitAndCreate(pszTestServiceName, &g_hTest);
80 if (rcExit != RTEXITCODE_SUCCESS)
81 return rcExit;
82 RTTestBanner(g_hTest);
83
84 /*
85 * Init the globals.
86 */
87 g_cchSrvName = strlen(pszTestServiceName);
88 int rc = RTStrCopy(g_szSrvName, sizeof(g_szSrvName), pszTestServiceName);
89 if (rc != VINF_SUCCESS)
90 {
91 RTTestFailed(g_hTest, "The test name is too long! (%zu bytes)", g_cchSrvName);
92 return RTTestSummaryAndDestroy(g_hTest);
93 }
94
95 /*
96 * Initialize the support driver session.
97 */
98 PSUPDRVSESSION pSession;
99 rc = SUPR3Init(&pSession);
100 if (RT_FAILURE(rc))
101 {
102 RTTestFailed(g_hTest, "SUPR3Init failed with rc=%Rrc\n", rc);
103 return RTTestSummaryAndDestroy(g_hTest);
104 }
105
106 char szPath[RTPATH_MAX + sizeof(".r0")];
107 rc = RTPathExecDir(szPath, RTPATH_MAX);
108 if (RT_SUCCESS(rc))
109 rc = RTPathAppend(szPath, RTPATH_MAX, pszTestServiceName);
110 if (RT_SUCCESS(rc))
111 strcat(szPath, ".r0");
112 if (RT_FAILURE(rc))
113 {
114 RTTestFailed(g_hTest, "Failed constructing .r0 filename (rc=%Rrc)", rc);
115 return RTTestSummaryAndDestroy(g_hTest);
116 }
117
118 char szSrvReqHandler[sizeof(g_szSrvName) + sizeof("SrvReqHandler")];
119 strcpy(szSrvReqHandler, pszTestServiceName);
120 strcat(szSrvReqHandler, "SrvReqHandler");
121 for (size_t off = 0; RT_C_IS_LOWER(szSrvReqHandler[off]); off++)
122 szSrvReqHandler[off] = RT_C_TO_UPPER(szSrvReqHandler[off]);
123
124 rc = SUPR3LoadServiceModule(szPath, pszTestServiceName, szSrvReqHandler, &g_pvImageBase);
125 if (RT_FAILURE(rc))
126 {
127 RTTestFailed(g_hTest, "SUPR3LoadServiceModule(%s,%s,%s,) failed with rc=%Rrc\n",
128 szPath, pszTestServiceName, szSrvReqHandler, rc);
129 return RTTestSummaryAndDestroy(g_hTest);
130 }
131
132 /*
133 * Do the sanity checks.
134 */
135 RTTestSub(g_hTest, "Sanity");
136 RTTSTR0REQ Req;
137 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
138 Req.Hdr.cbReq = sizeof(Req);
139 memset(Req.szMsg, 0xef, sizeof(Req.szMsg));
140 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service(g_szSrvName, g_cchSrvName, RTTSTR0REQ_SANITY_OK, 0, &Req.Hdr), VINF_SUCCESS);
141 if (RT_FAILURE(rc))
142 return RTTestSummaryAndDestroy(g_hTest);
143 RTTESTI_CHECK_MSG(Req.szMsg[0] == '\0', ("%s", Req.szMsg));
144 if (Req.szMsg[0] != '\0')
145 return RTTestSummaryAndDestroy(g_hTest);
146
147
148 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
149 Req.Hdr.cbReq = sizeof(Req);
150 Req.szMsg[0] = '\0';
151 memset(Req.szMsg, 0xfe, sizeof(Req.szMsg));
152 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service(g_szSrvName, g_cchSrvName, RTTSTR0REQ_SANITY_FAILURE, 0, &Req.Hdr), VINF_SUCCESS);
153 if (RT_FAILURE(rc))
154 return RTTestSummaryAndDestroy(g_hTest);
155 rc = !strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42"));
156 if (rc)
157 {
158 RTTestFailed(g_hTest, "the negative sanity check failed");
159 return RTTestSummaryAndDestroy(g_hTest);
160 }
161 RTTestSubDone(g_hTest);
162
163 return RTEXITCODE_SUCCESS;
164}
165
166
167/**
168 * Performs a common test.
169 *
170 * @returns true on success, false on failure.
171 * @param uOperation The operation to perform.
172 * @param pszTest The sub-test name.
173 */
174bool RTR3TestR0SimpleTest(uint32_t uOperation, const char *pszTest)
175{
176 RTTestSub(g_hTest, pszTest);
177
178 /*
179 * Issue the request.
180 */
181 RTTSTR0REQ Req;
182 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
183 Req.Hdr.cbReq = sizeof(Req);
184 RT_ZERO(Req.szMsg);
185
186 int rc = SUPR3CallR0Service(g_szSrvName, g_cchSrvName, uOperation, 0, &Req.Hdr);
187 if (RT_FAILURE(rc))
188 {
189 RTTestFailed(g_hTest, "SUPR3CallR0Service failed with rc=%Rrc", rc);
190 return false;
191 }
192
193 /*
194 * Process the message strings.
195 *
196 * We can have multiple failures and info messages packed into szMsg. They
197 * are separated by a double newline. The kind of message is indicated by
198 * the first character, '!' means error and '?' means info message.
199 */
200 bool fRc = true;
201 if (Req.szMsg[0])
202 {
203 Req.szMsg[sizeof(Req.szMsg) - 1] = '\0'; /* paranoia */
204
205 char *pszNext = &Req.szMsg[0];
206 do
207 {
208 char *pszCur = pszNext;
209 do
210 pszNext = strpbrk(pszNext + 1, "!?");
211 while (pszNext && (pszNext[-1] != '\n' || pszNext[-2] != '\n'));
212
213 char *pszEnd = pszNext ? pszNext - 1 : strchr(pszCur, '\0');
214 while ( (uintptr_t)pszEnd > (uintptr_t)pszCur
215 && pszEnd[-1] == '\n')
216 *--pszEnd = '\0';
217
218 if (*pszCur == '!')
219 {
220 RTTestFailed(g_hTest, "%s", pszCur + 1);
221 fRc = false;
222 }
223 else
224 RTTestPrintfNl(g_hTest, RTTESTLVL_ALWAYS, "%s", pszCur + 1);
225 } while (pszNext);
226 }
227
228 return fRc;
229}
230
231#endif
232
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