VirtualBox

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

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

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 KB
Line 
1/* $Id: tstR0ThreadPreemptionDriver.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT R0 Testcase - Thread Preemption, driver program.
4 */
5
6/*
7 * Copyright (C) 2009 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 "tstR0ThreadPreemption.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("tstR0ThreadPreemption", &hTest);
56 if (rc)
57 return rc;
58 RTTestBanner(hTest);
59
60 PSUPDRVSESSION pSession;
61 rc = SUPR3Init(&pSession);
62 if (RT_FAILURE(rc))
63 {
64 RTTestFailed(hTest, "SUPR3Init failed with rc=%Rrc\n", rc);
65 return RTTestSummaryAndDestroy(hTest);
66 }
67
68 char szPath[RTPATH_MAX];
69 rc = RTPathExecDir(szPath, sizeof(szPath));
70 if (RT_SUCCESS(rc))
71 rc = RTPathAppend(szPath, sizeof(szPath), "tstR0ThreadPreemption.r0");
72 if (RT_FAILURE(rc))
73 {
74 RTTestFailed(hTest, "Failed constructing .r0 filename (rc=%Rrc)", rc);
75 return RTTestSummaryAndDestroy(hTest);
76 }
77
78 void *pvImageBase;
79 rc = SUPR3LoadServiceModule(szPath, "tstR0ThreadPreemption",
80 "TSTR0ThreadPreemptionSrvReqHandler",
81 &pvImageBase);
82 if (RT_FAILURE(rc))
83 {
84 RTTestFailed(hTest, "SUPR3LoadServiceModule(%s,,,) failed with rc=%Rrc\n", szPath, rc);
85 return RTTestSummaryAndDestroy(hTest);
86 }
87
88 /* test request */
89 struct
90 {
91 SUPR0SERVICEREQHDR Hdr;
92 char szMsg[256];
93 } Req;
94
95 /*
96 * Sanity checks.
97 */
98 RTTestSub(hTest, "Sanity");
99 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
100 Req.Hdr.cbReq = sizeof(Req);
101 Req.szMsg[0] = '\0';
102 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
103 TSTR0THREADPREMEPTION_SANITY_OK, 0, &Req.Hdr), VINF_SUCCESS);
104 if (RT_FAILURE(rc))
105 return RTTestSummaryAndDestroy(hTest);
106 RTTESTI_CHECK_MSG(Req.szMsg[0] == '\0', ("%s", Req.szMsg));
107 if (Req.szMsg[0] != '\0')
108 return RTTestSummaryAndDestroy(hTest);
109
110 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
111 Req.Hdr.cbReq = sizeof(Req);
112 Req.szMsg[0] = '\0';
113 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
114 TSTR0THREADPREMEPTION_SANITY_FAILURE, 0, &Req.Hdr), VINF_SUCCESS);
115 if (RT_FAILURE(rc))
116 return RTTestSummaryAndDestroy(hTest);
117 RTTESTI_CHECK_MSG(!strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42") - 1), ("%s", Req.szMsg));
118 if (strncmp(Req.szMsg, "!42failure42", sizeof("!42failure42") - 1))
119 return RTTestSummaryAndDestroy(hTest);
120
121 /*
122 * Basic tests, bail out on failure.
123 */
124 RTTestSub(hTest, "Basics");
125 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
126 Req.Hdr.cbReq = sizeof(Req);
127 Req.szMsg[0] = '\0';
128 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
129 TSTR0THREADPREMEPTION_BASIC, 0, &Req.Hdr), VINF_SUCCESS);
130 if (RT_FAILURE(rc))
131 return RTTestSummaryAndDestroy(hTest);
132 if (Req.szMsg[0] == '!')
133 {
134 RTTestIFailed("%s", &Req.szMsg[1]);
135 return RTTestSummaryAndDestroy(hTest);
136 }
137 if (Req.szMsg[0])
138 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
139
140 /*
141 * Stay in ring-0 until preemption is pending.
142 */
143RTThreadSleep(250); /** @todo fix GIP initialization? */
144 RTTestSub(hTest, "Pending Preemption");
145 for (int i = 0; ; i++)
146 {
147 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
148 Req.Hdr.cbReq = sizeof(Req);
149 Req.szMsg[0] = '\0';
150 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
151 TSTR0THREADPREMEPTION_IS_PENDING, 0, &Req.Hdr), VINF_SUCCESS);
152 if ( strcmp(Req.szMsg, "cLoops=1\n")
153 || i >= 64)
154 {
155 if (Req.szMsg[0] == '!')
156 RTTestIFailed("%s", &Req.szMsg[1]);
157 else if (Req.szMsg[0])
158 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
159 break;
160 }
161 if ((i % 3) == 0)
162 RTThreadYield();
163 }
164
165 /*
166 * Test nested RTThreadPreemptDisable calls.
167 */
168 RTTestSub(hTest, "Nested");
169 Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
170 Req.Hdr.cbReq = sizeof(Req);
171 Req.szMsg[0] = '\0';
172 RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstR0ThreadPreemption", sizeof("tstR0ThreadPreemption") - 1,
173 TSTR0THREADPREMEPTION_NESTED, 0, &Req.Hdr), VINF_SUCCESS);
174 if (Req.szMsg[0] == '!')
175 RTTestIFailed("%s", &Req.szMsg[1]);
176 else if (Req.szMsg[0])
177 RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
178
179 /*
180 * Done.
181 */
182 return RTTestSummaryAndDestroy(hTest);
183#endif
184}
185
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