VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTR0MemUserKernelDriver.cpp@ 45733

Last change on this file since 45733 was 44529, checked in by vboxsync, 12 years ago

header (C) fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1/* $Id: tstRTR0MemUserKernelDriver.cpp 44529 2013-02-04 15:54:15Z vboxsync $ */
2/** @file
3 * IPRT R0 Testcase - Thread Preemption, driver program.
4 */
5
6/*
7 * Copyright (C) 2009-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* Header Files *
29*******************************************************************************/
30#include <iprt/initterm.h>
31
32#include <iprt/err.h>
33#include <iprt/path.h>
34#include <iprt/param.h>
35#include <iprt/stream.h>
36#include <iprt/string.h>
37#include <iprt/test.h>
38#include <iprt/thread.h>
39#ifdef VBOX
40# include <VBox/sup.h>
41# include "tstRTR0MemUserKernel.h"
42#endif
43
44
45int main(int argc, char **argv)
46{
47#ifndef VBOX
48 RTPrintf("tstSup: SKIPPED\n");
49 return 0;
50#else
51 /*
52 * Init.
53 */
54 RTTEST hTest;
55 int rc = RTTestInitAndCreate("tstRTR0MemUserKernel", &hTest);
56 if (rc)
57 return rc;
58 RTTestBanner(hTest);
59
60 uint8_t *pbPage = (uint8_t *)RTTestGuardedAllocTail(hTest, PAGE_SIZE);
61 if (!pbPage)
62 {
63 RTTestFailed(hTest, "RTTestGuardedAllocTail failed with rc=%Rrc\n", rc);
64 return RTTestSummaryAndDestroy(hTest);
65 }
66
67 PSUPDRVSESSION pSession;
68 rc = SUPR3Init(&pSession);
69 if (RT_FAILURE(rc))
70 {
71 RTTestFailed(hTest, "SUPR3Init failed with rc=%Rrc\n", rc);
72 return RTTestSummaryAndDestroy(hTest);
73 }
74
75 char szPath[RTPATH_MAX];
76 rc = RTPathExecDir(szPath, sizeof(szPath));
77 if (RT_SUCCESS(rc))
78 rc = RTPathAppend(szPath, sizeof(szPath), "tstRTR0MemUserKernel.r0");
79 if (RT_FAILURE(rc))
80 {
81 RTTestFailed(hTest, "Failed constructing .r0 filename (rc=%Rrc)", rc);
82 return RTTestSummaryAndDestroy(hTest);
83 }
84
85 void *pvImageBase;
86 rc = SUPR3LoadServiceModule(szPath, "tstRTR0MemUserKernel",
87 "TSTRTR0MemUserKernelSrvReqHandler",
88 &pvImageBase);
89 if (RT_FAILURE(rc))
90 {
91 RTTestFailed(hTest, "SUPR3LoadServiceModule(%s,,,) failed with rc=%Rrc\n", szPath, rc);
92 return RTTestSummaryAndDestroy(hTest);
93 }
94
95 /* test request */
96 struct
97 {
98 SUPR0SERVICEREQHDR Hdr;
99 char szMsg[256];
100 } Req;
101
102 /*
103 * Sanity checks.
104 */
105 RTTestSub(hTest, "Sanity");
106 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
107 Req.Hdr.cbReq = sizeof(Req);
108 Req.szMsg[0] = '\0';
109 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1,
110 TSTRTR0MEMUSERKERNEL_SANITY_OK, 0, &Req.Hdr), VINF_SUCCESS);
111 if (RT_FAILURE(rc))
112 return RTTestSummaryAndDestroy(hTest);
113 RTTESTI_CHECK_MSG(Req.szMsg[0] == '\0', ("%s", Req.szMsg));
114 if (Req.szMsg[0] != '\0')
115 return RTTestSummaryAndDestroy(hTest);
116
117 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
118 Req.Hdr.cbReq = sizeof(Req);
119 Req.szMsg[0] = '\0';
120 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1,
121 TSTRTR0MEMUSERKERNEL_SANITY_FAILURE, 0, &Req.Hdr), VINF_SUCCESS);
122 if (RT_FAILURE(rc))
123 return RTTestSummaryAndDestroy(hTest);
124 RTTESTI_CHECK_MSG(!strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42") - 1), ("%s", Req.szMsg));
125 if (strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42") - 1))
126 return RTTestSummaryAndDestroy(hTest);
127
128 /*
129 * Basic tests, bail out on failure.
130 */
131 RTTestSub(hTest, "Basics");
132 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
133 Req.Hdr.cbReq = sizeof(Req);
134 Req.szMsg[0] = '\0';
135 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1,
136 TSTRTR0MEMUSERKERNEL_BASIC, (uintptr_t)pbPage, &Req.Hdr), VINF_SUCCESS);
137 if (RT_FAILURE(rc))
138 return RTTestSummaryAndDestroy(hTest);
139 if (Req.szMsg[0] == '!')
140 {
141 RTTestIFailed("%s", &Req.szMsg[1]);
142 return RTTestSummaryAndDestroy(hTest);
143 }
144 if (Req.szMsg[0])
145 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
146
147 /*
148 * Good buffer, bail out on failure.
149 */
150 RTTestSub(hTest, "Good buffer");
151 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
152 Req.Hdr.cbReq = sizeof(Req);
153 Req.szMsg[0] = '\0';
154 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1,
155 TSTRTR0MEMUSERKERNEL_GOOD, (uintptr_t)pbPage, &Req.Hdr), VINF_SUCCESS);
156 if (RT_FAILURE(rc))
157 return RTTestSummaryAndDestroy(hTest);
158 if (Req.szMsg[0] == '!')
159 {
160 RTTestIFailed("%s", &Req.szMsg[1]);
161 return RTTestSummaryAndDestroy(hTest);
162 }
163 if (Req.szMsg[0])
164 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
165
166 /*
167 * Bad buffer, bail out on failure.
168 */
169 RTTestSub(hTest, "Bad buffer");
170 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
171 Req.Hdr.cbReq = sizeof(Req);
172 Req.szMsg[0] = '\0';
173 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1,
174 TSTRTR0MEMUSERKERNEL_BAD, (uintptr_t)pbPage + PAGE_SIZE, &Req.Hdr), VINF_SUCCESS);
175 if (RT_FAILURE(rc))
176 return RTTestSummaryAndDestroy(hTest);
177 if (Req.szMsg[0] == '!')
178 {
179 RTTestIFailed("%s", &Req.szMsg[1]);
180 return RTTestSummaryAndDestroy(hTest);
181 }
182 if (Req.szMsg[0])
183 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
184
185 /*
186 * Bad buffer, bail out on failure.
187 */
188 RTTestSub(hTest, "Kernel buffer");
189 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
190 Req.Hdr.cbReq = sizeof(Req);
191 Req.szMsg[0] = '\0';
192 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0MemUserKernel", sizeof("tstRTR0MemUserKernel") - 1,
193 TSTRTR0MEMUSERKERNEL_INVALID_ADDRESS, (uintptr_t)pvImageBase, &Req.Hdr), VINF_SUCCESS);
194 if (RT_FAILURE(rc))
195 return RTTestSummaryAndDestroy(hTest);
196 if (Req.szMsg[0] == '!')
197 {
198 RTTestIFailed("%s", &Req.szMsg[1]);
199 return RTTestSummaryAndDestroy(hTest);
200 }
201 if (Req.szMsg[0])
202 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
203
204 /*
205 * Done.
206 */
207 return RTTestSummaryAndDestroy(hTest);
208#endif
209}
210
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