VirtualBox

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

Last change on this file since 21551 was 21551, checked in by vboxsync, 15 years ago

tstR0ThreadPreemption: Some adjustments to new RTThreadPreemptIsEnabled behavior.

  • 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 21551 2009-07-13 16:40:43Z 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#include <iprt/thread.h>
43#ifdef VBOX
44# include <VBox/sup.h>
45# include "tstR0ThreadPreemption.h"
46#endif
47
48
49int main(int argc, char **argv)
50{
51#ifndef VBOX
52 RTPrintf("tstSup: SKIPPED\n");
53 return 0;
54#else
55 /*
56 * Init.
57 */
58 RTTEST hTest;
59 int rc = RTTestInitAndCreate("tstR0ThreadPreemption", &hTest);
60 if (rc)
61 return rc;
62 RTTestBanner(hTest);
63
64 PSUPDRVSESSION pSession;
65 rc = SUPR3Init(&pSession);
66 if (RT_FAILURE(rc))
67 {
68 RTTestFailed(hTest, "SUPR3Init failed with rc=%Rrc\n", rc);
69 return RTTestSummaryAndDestroy(hTest);
70 }
71
72 char szPath[RTPATH_MAX];
73 rc = RTPathExecDir(szPath, sizeof(szPath));
74 if (RT_SUCCESS(rc))
75 rc = RTPathAppend(szPath, sizeof(szPath), "tstR0ThreadPreemption.r0");
76 if (RT_FAILURE(rc))
77 {
78 RTTestFailed(hTest, "Failed constructing .r0 filename (rc=%Rrc)", rc);
79 return RTTestSummaryAndDestroy(hTest);
80 }
81
82 void *pvImageBase;
83 rc = SUPR3LoadServiceModule(szPath, "tstR0ThreadPreemption",
84 "TSTR0ThreadPreemptionSrvReqHandler",
85 &pvImageBase);
86 if (RT_FAILURE(rc))
87 {
88 RTTestFailed(hTest, "SUPR3LoadServiceModule(%s,,,) failed with rc=%Rrc\n", szPath, rc);
89 return RTTestSummaryAndDestroy(hTest);
90 }
91
92 /* test request */
93 struct
94 {
95 SUPR0SERVICEREQHDR Hdr;
96 char szMsg[256];
97 } Req;
98
99 /*
100 * Sanity checks.
101 */
102 RTTestSub(hTest, "Sanity");
103 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
104 Req.Hdr.cbReq = sizeof(Req);
105 Req.szMsg[0] = '\0';
106 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
107 TSTR0THREADPREMEPTION_SANITY_OK, 0, &Req.Hdr), VINF_SUCCESS);
108 if (RT_FAILURE(rc))
109 return RTTestSummaryAndDestroy(hTest);
110 RTTESTI_CHECK_MSG(Req.szMsg[0] == '\0', ("%s", Req.szMsg));
111 if (Req.szMsg[0] != '\0')
112 return RTTestSummaryAndDestroy(hTest);
113
114 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
115 Req.Hdr.cbReq = sizeof(Req);
116 Req.szMsg[0] = '\0';
117 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
118 TSTR0THREADPREMEPTION_SANITY_FAILURE, 0, &Req.Hdr), VINF_SUCCESS);
119 if (RT_FAILURE(rc))
120 return RTTestSummaryAndDestroy(hTest);
121 RTTESTI_CHECK_MSG(!strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42") - 1), ("%s", Req.szMsg));
122 if (strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42") - 1))
123 return RTTestSummaryAndDestroy(hTest);
124
125 /*
126 * Basic tests, bail out on failure.
127 */
128 RTTestSub(hTest, "Basics");
129 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
130 Req.Hdr.cbReq = sizeof(Req);
131 Req.szMsg[0] = '\0';
132 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
133 TSTR0THREADPREMEPTION_BASIC, 0, &Req.Hdr), VINF_SUCCESS);
134 if (RT_FAILURE(rc))
135 return RTTestSummaryAndDestroy(hTest);
136 if (Req.szMsg[0] == '!')
137 {
138 RTTestIFailed("%s", &Req.szMsg[1]);
139 return RTTestSummaryAndDestroy(hTest);
140 }
141 if (Req.szMsg[0])
142 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
143
144 /*
145 * Stay in ring-0 until preemption is pending.
146 */
147RTThreadSleep(250); /** @todo fix GIP initialization? */
148 RTTestSub(hTest, "Pending Preemption");
149 for (int i = 0; ; i++)
150 {
151 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
152 Req.Hdr.cbReq = sizeof(Req);
153 Req.szMsg[0] = '\0';
154 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
155 TSTR0THREADPREMEPTION_IS_PENDING, 0, &Req.Hdr), VINF_SUCCESS);
156 if ( strcmp(Req.szMsg, "cLoops=1\n")
157 || i >= 64)
158 {
159 if (Req.szMsg[0] == '!')
160 RTTestIFailed("%s", &Req.szMsg[1]);
161 else if (Req.szMsg[0])
162 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
163 break;
164 }
165 if ((i % 3) == 0)
166 RTThreadYield();
167 }
168
169 /*
170 * Test nested RTThreadPreemptDisable calls.
171 */
172 RTTestSub(hTest, "Nested");
173 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
174 Req.Hdr.cbReq = sizeof(Req);
175 Req.szMsg[0] = '\0';
176 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
177 TSTR0THREADPREMEPTION_NESTED, 0, &Req.Hdr), VINF_SUCCESS);
178 if (Req.szMsg[0] == '!')
179 RTTestIFailed("%s", &Req.szMsg[1]);
180 else if (Req.szMsg[0])
181 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
182
183 /*
184 * Done.
185 */
186 return RTTestSummaryAndDestroy(hTest);
187#endif
188}
189
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