VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstR0ThreadPreemptionDriver.cpp@ 19935

Last change on this file since 19935 was 19935, checked in by vboxsync, 16 years ago

tstR0ThreadPreemption: Test nesting and fix enum.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1/* $Id: tstR0ThreadPreemptionDriver.cpp 19935 2009-05-23 01:50:33Z vboxsync $ */
2/** @file
3 * IPRT R0 Testcase - Thread Preemption, driver program.
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
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 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31/*******************************************************************************
32* Header Files *
33*******************************************************************************/
34#include <iprt/initterm.h>
35
36#include <iprt/err.h>
37#include <iprt/path.h>
38#include <iprt/param.h>
39#include <iprt/stream.h>
40#include <iprt/string.h>
41#include <iprt/test.h>
42#ifdef VBOX
43# include <VBox/sup.h>
44# include "tstR0ThreadPreemption.h"
45#endif
46
47
48int main(int argc, char **argv)
49{
50#ifndef VBOX
51 RTPrintf("tstSup: SKIPPED\n");
52 return 0;
53#else
54 /*
55 * Init.
56 */
57 int rc = RTR3InitAndSUPLib();
58 if (RT_FAILURE(rc))
59 {
60 RTPrintf("tstR0ThreadPreemption: fatal error: RTR3InitAndSUPLib failed with rc=%Rrc\n", rc);
61 return 1;
62 }
63
64 RTTEST hTest;
65 rc = RTTestCreate("tstR0ThreadPreemption", &hTest);
66 if (RT_FAILURE(rc))
67 {
68 RTPrintf("tstR0ThreadPreemption: fatal error: RTTestCreate failed with rc=%Rrc\n", rc);
69 return 1;
70 }
71 RTTestBanner(hTest);
72
73 PSUPDRVSESSION pSession;
74 rc = SUPR3Init(&pSession);
75 if (RT_FAILURE(rc))
76 {
77 RTTestFailed(hTest, "SUPR3Init failed with rc=%Rrc\n", rc);
78 return RTTestSummaryAndDestroy(hTest);
79 }
80
81 char szPath[RTPATH_MAX];
82 rc = RTPathExecDir(szPath, sizeof(szPath));
83 if (RT_SUCCESS(rc))
84 rc = RTPathAppend(szPath, sizeof(szPath), "tstR0ThreadPreemption.r0");
85 if (RT_FAILURE(rc))
86 {
87 RTTestFailed(hTest, "Failed constructing .r0 filename (rc=%Rrc)", rc);
88 return RTTestSummaryAndDestroy(hTest);
89 }
90
91 void *pvImageBase;
92 rc = SUPR3LoadServiceModule(szPath, "tstR0ThreadPreemption",
93 "TSTR0ThreadPreemptionSrvReqHandler",
94 &pvImageBase);
95 if (RT_FAILURE(rc))
96 {
97 RTTestFailed(hTest, "SUPR3LoadServiceModule(%s,,,) failed with rc=%Rrc\n", szPath, rc);
98 return RTTestSummaryAndDestroy(hTest);
99 }
100
101 /* test request */
102 struct
103 {
104 SUPR0SERVICEREQHDR Hdr;
105 char szMsg[256];
106 } Req;
107
108 /*
109 * Sanity checks.
110 */
111 RTTestSub(hTest, "Sanity");
112 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
113 Req.Hdr.cbReq = sizeof(Req);
114 Req.szMsg[0] = '\0';
115 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
116 TSTR0THREADPREMEPTION_SANITY_OK, 0, &Req.Hdr), VINF_SUCCESS);
117 if (RT_FAILURE(rc))
118 return RTTestSummaryAndDestroy(hTest);
119 RTTESTI_CHECK_MSG(Req.szMsg[0] == '\0', ("%s", Req.szMsg));
120 if (Req.szMsg[0] != '\0')
121 return RTTestSummaryAndDestroy(hTest);
122
123 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
124 Req.Hdr.cbReq = sizeof(Req);
125 Req.szMsg[0] = '\0';
126 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
127 TSTR0THREADPREMEPTION_SANITY_FAILURE, 0, &Req.Hdr), VINF_SUCCESS);
128 if (RT_FAILURE(rc))
129 return RTTestSummaryAndDestroy(hTest);
130 RTTESTI_CHECK_MSG(!strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42") - 1), ("%s", Req.szMsg));
131 if (strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42") - 1))
132 return RTTestSummaryAndDestroy(hTest);
133
134 /*
135 * Basic tests, bail out on failure.
136 */
137 RTTestSub(hTest, "Basics");
138 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
139 Req.Hdr.cbReq = sizeof(Req);
140 Req.szMsg[0] = '\0';
141 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
142 TSTR0THREADPREMEPTION_BASIC, 0, &Req.Hdr), VINF_SUCCESS);
143 if (RT_FAILURE(rc))
144 return RTTestSummaryAndDestroy(hTest);
145 RTTESTI_CHECK_MSG(Req.szMsg[0] == '\0', ("%s", Req.szMsg));
146 if (Req.szMsg[0] == '!')
147 return RTTestSummaryAndDestroy(hTest);
148 if (Req.szMsg[0])
149 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
150
151 /*
152 * Stay in ring-0 until preemption is pending.
153 */
154 RTTestSub(hTest, "Pending Preemption");
155 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
156 Req.Hdr.cbReq = sizeof(Req);
157 Req.szMsg[0] = '\0';
158 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
159 TSTR0THREADPREMEPTION_IS_PENDING, 0, &Req.Hdr), VINF_SUCCESS);
160 RTTESTI_CHECK_MSG(Req.szMsg[0] != '!', ("%s", Req.szMsg));
161 if (Req.szMsg[0])
162 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
163
164 /*
165 * Stay in ring-0 until preemption is pending.
166 */
167 RTTestSub(hTest, "Nested");
168 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
169 Req.Hdr.cbReq = sizeof(Req);
170 Req.szMsg[0] = '\0';
171 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
172 TSTR0THREADPREMEPTION_NESTED, 0, &Req.Hdr), VINF_SUCCESS);
173 RTTESTI_CHECK_MSG(Req.szMsg[0] != '!', ("%s", Req.szMsg));
174 if (Req.szMsg[0])
175 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
176
177
178
179 /*
180 * Done.
181 */
182 return RTTestSummaryAndDestroy(hTest);
183#endif
184}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette