1 | /* $Id: tstRTR0DbgKrnlInfoDriver.cpp 51906 2014-07-07 16:28:37Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT R0 Testcase - Debug kernel information, driver program.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012 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 | #ifdef VBOX
|
---|
39 | # include <VBox/sup.h>
|
---|
40 | # include "tstRTR0DbgKrnlInfo.h"
|
---|
41 | #endif
|
---|
42 |
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Entry point.
|
---|
46 | */
|
---|
47 | extern "C" DECLEXPORT(int) TrustedMain(int argc, char **argv, char **envp)
|
---|
48 | {
|
---|
49 | #ifndef VBOX
|
---|
50 | RTPrintf("tstSup: SKIPPED\n");
|
---|
51 | return 0;
|
---|
52 | #else
|
---|
53 | /*
|
---|
54 | * Init.
|
---|
55 | */
|
---|
56 | RTTEST hTest;
|
---|
57 | int rc = RTTestInitAndCreate("tstRTR0DbgKrnlInfo", &hTest);
|
---|
58 | if (rc)
|
---|
59 | return rc;
|
---|
60 | RTTestBanner(hTest);
|
---|
61 |
|
---|
62 | uint8_t *pbPage = (uint8_t *)RTTestGuardedAllocTail(hTest, PAGE_SIZE);
|
---|
63 | if (!pbPage)
|
---|
64 | {
|
---|
65 | RTTestFailed(hTest, "RTTestGuardedAllocTail failed with rc=%Rrc\n", rc);
|
---|
66 | return RTTestSummaryAndDestroy(hTest);
|
---|
67 | }
|
---|
68 |
|
---|
69 | PSUPDRVSESSION pSession;
|
---|
70 | rc = SUPR3Init(&pSession);
|
---|
71 | if (RT_FAILURE(rc))
|
---|
72 | {
|
---|
73 | RTTestFailed(hTest, "SUPR3Init failed with rc=%Rrc\n", rc);
|
---|
74 | return RTTestSummaryAndDestroy(hTest);
|
---|
75 | }
|
---|
76 |
|
---|
77 | char szPath[RTPATH_MAX];
|
---|
78 | rc = RTPathExecDir(szPath, sizeof(szPath));
|
---|
79 | if (RT_SUCCESS(rc))
|
---|
80 | rc = RTPathAppend(szPath, sizeof(szPath), "tstRTR0DbgKrnlInfo.r0");
|
---|
81 | if (RT_FAILURE(rc))
|
---|
82 | {
|
---|
83 | RTTestFailed(hTest, "Failed constructing .r0 filename (rc=%Rrc)", rc);
|
---|
84 | return RTTestSummaryAndDestroy(hTest);
|
---|
85 | }
|
---|
86 |
|
---|
87 | void *pvImageBase;
|
---|
88 | rc = SUPR3LoadServiceModule(szPath, "tstRTR0DbgKrnlInfo",
|
---|
89 | "TSTR0DbgKrnlInfoSrvReqHandler",
|
---|
90 | &pvImageBase);
|
---|
91 | if (RT_FAILURE(rc))
|
---|
92 | {
|
---|
93 | RTTestFailed(hTest, "SUPR3LoadServiceModule(%s,,,) failed with rc=%Rrc\n", szPath, rc);
|
---|
94 | return RTTestSummaryAndDestroy(hTest);
|
---|
95 | }
|
---|
96 |
|
---|
97 | /* test request */
|
---|
98 | struct
|
---|
99 | {
|
---|
100 | SUPR0SERVICEREQHDR Hdr;
|
---|
101 | char szMsg[256];
|
---|
102 | } Req;
|
---|
103 |
|
---|
104 | /*
|
---|
105 | * Sanity checks.
|
---|
106 | */
|
---|
107 | RTTestSub(hTest, "Sanity");
|
---|
108 | Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
|
---|
109 | Req.Hdr.cbReq = sizeof(Req);
|
---|
110 | Req.szMsg[0] = '\0';
|
---|
111 | RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0DbgKrnlInfo", sizeof("tstRTR0DbgKrnlInfo") - 1,
|
---|
112 | TSTRTR0DBGKRNLINFO_SANITY_OK, 0, &Req.Hdr), VINF_SUCCESS);
|
---|
113 | if (RT_FAILURE(rc))
|
---|
114 | return RTTestSummaryAndDestroy(hTest);
|
---|
115 | RTTESTI_CHECK_MSG(Req.szMsg[0] == '\0', ("%s", Req.szMsg));
|
---|
116 | if (Req.szMsg[0] != '\0')
|
---|
117 | return RTTestSummaryAndDestroy(hTest);
|
---|
118 |
|
---|
119 | Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
|
---|
120 | Req.Hdr.cbReq = sizeof(Req);
|
---|
121 | Req.szMsg[0] = '\0';
|
---|
122 | RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0DbgKrnlInfo", sizeof("tstRTR0DbgKrnlInfo") - 1,
|
---|
123 | TSTRTR0DBGKRNLINFO_SANITY_FAILURE, 0, &Req.Hdr), VINF_SUCCESS);
|
---|
124 | if (RT_FAILURE(rc))
|
---|
125 | return RTTestSummaryAndDestroy(hTest);
|
---|
126 | RTTESTI_CHECK_MSG(!strncmp(Req.szMsg, RT_STR_TUPLE("!42failure42")), ("%s", Req.szMsg));
|
---|
127 | if (strncmp(Req.szMsg, RT_STR_TUPLE("!42failure42")))
|
---|
128 | return RTTestSummaryAndDestroy(hTest);
|
---|
129 |
|
---|
130 | /*
|
---|
131 | * Basic tests, bail out on failure.
|
---|
132 | */
|
---|
133 | RTTestSub(hTest, "Basics");
|
---|
134 | Req.Hdr.u32Magic = SUPR0SERVICEREQHDR_MAGIC;
|
---|
135 | Req.Hdr.cbReq = sizeof(Req);
|
---|
136 | Req.szMsg[0] = '\0';
|
---|
137 | RTTESTI_CHECK_RC(rc = SUPR3CallR0Service("tstRTR0DbgKrnlInfo", sizeof("tstRTR0DbgKrnlInfo") - 1,
|
---|
138 | TSTRTR0DBGKRNLINFO_BASIC, 0, &Req.Hdr), VINF_SUCCESS);
|
---|
139 | if (RT_FAILURE(rc))
|
---|
140 | return RTTestSummaryAndDestroy(hTest);
|
---|
141 | if (Req.szMsg[0] == '!')
|
---|
142 | {
|
---|
143 | RTTestIFailed("%s", &Req.szMsg[1]);
|
---|
144 | return RTTestSummaryAndDestroy(hTest);
|
---|
145 | }
|
---|
146 | if (Req.szMsg[0])
|
---|
147 | RTTestIPrintf(RTTESTLVL_ALWAYS, "%s", Req.szMsg);
|
---|
148 |
|
---|
149 | /*
|
---|
150 | * Done.
|
---|
151 | */
|
---|
152 | return RTTestSummaryAndDestroy(hTest);
|
---|
153 | #endif
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 | #if !defined(VBOX_WITH_HARDENING) || !defined(RT_OS_WINDOWS)
|
---|
158 | /**
|
---|
159 | * Main entry point.
|
---|
160 | */
|
---|
161 | int main(int argc, char **argv, char **envp)
|
---|
162 | {
|
---|
163 | return TrustedMain(argc, argv, envp);
|
---|
164 | }
|
---|
165 | #endif
|
---|
166 |
|
---|