VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTR0DbgKrnlInfoDriver.cpp@ 93943

Last change on this file since 93943 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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