VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTR0Thread.cpp@ 107044

Last change on this file since 107044 was 106924, checked in by vboxsync, 3 weeks ago

IPRT/testcase: Made the R0 modules build on win.arm64. jiraref:VBP-1449

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1/* $Id: tstRTR0Thread.cpp 106924 2024-11-11 11:57:12Z vboxsync $ */
2/** @file
3 * IPRT R0 Testcase - Kernel thread.
4 */
5
6/*
7 * Copyright (C) 2015-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#include <iprt/thread.h>
42
43#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
44# include <iprt/asm-amd64-x86.h>
45#elif defined(RT_ARCH_ARM64)
46# include <iprt/asm-arm.h>
47#endif
48#include <iprt/errcore.h>
49#include <VBox/sup.h>
50#include "tstRTR0Thread.h"
51#include "tstRTR0Common.h"
52
53#define TSTRTR0THREADDATA_MAGIC 0xcececece
54
55/**
56 * State structure for tstRTR0ThreadCallback().
57 */
58typedef struct TSTRTR0THREADDATA
59{
60 /** The magic value. */
61 uint32_t uMagic;
62 /** Sample counter. */
63 uint32_t volatile cCounter;
64 /** The thread handle. */
65 RTTHREAD hThread;
66} TSTRTR0THREADDATA;
67/** Pointer to state structure for tstRTR0ThreadCallback(). */
68typedef TSTRTR0THREADDATA *PTSTRTR0THREADDATA;
69
70
71static DECLCALLBACK(int) tstRTR0ThreadCallback(RTTHREAD hThread, void *pvUser)
72{
73 PTSTRTR0THREADDATA pData = (PTSTRTR0THREADDATA)pvUser;
74 RT_NOREF1(hThread);
75 if (RT_LIKELY(pData))
76 {
77 if (pData->uMagic == TSTRTR0THREADDATA_MAGIC)
78 pData->uMagic = ~pData->uMagic;
79 if (pData->cCounter == 127)
80 pData->cCounter = 196;
81 }
82 RTThreadUserSignal(RTThreadSelf());
83 return VINF_SUCCESS;
84}
85
86
87/**
88 * Service request callback function.
89 *
90 * @returns VBox status code.
91 * @param pSession The caller's session.
92 * @param u64Arg 64-bit integer argument.
93 * @param pReqHdr The request header. Input / Output. Optional.
94 */
95DECLEXPORT(int) TSTRTR0ThreadSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation,
96 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr)
97{
98 RTR0TESTR0_SRV_REQ_PROLOG_RET(pReqHdr);
99 RT_NOREF2(pSession, u64Arg);
100
101 /*
102 * The big switch.
103 */
104 switch (uOperation)
105 {
106 RTR0TESTR0_IMPLEMENT_SANITY_CASES();
107 RTR0TESTR0_IMPLEMENT_DEFAULT_CASE(uOperation);
108
109 case TSTRTR0THREAD_BASIC:
110 {
111 TSTRTR0THREADDATA Data;
112 RT_ZERO(Data);
113 Data.uMagic = TSTRTR0THREADDATA_MAGIC;
114 Data.cCounter = 127;
115
116 /* Create the kernel thread. */
117 RTR0TESTR0_CHECK_RC_BREAK(RTThreadCreate(&Data.hThread, tstRTR0ThreadCallback, &Data, 0 /* cbStack */,
118 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "tstRTR0Thr"), VINF_SUCCESS);
119
120 /* Wait for thread to signal. */
121 RTR0TESTR0_CHECK_RC(RTThreadUserWait(Data.hThread, 500 /* ms */), VINF_SUCCESS);
122
123 /* Reset the semaphore. */
124 RTR0TESTR0_CHECK_RC(RTThreadUserReset(Data.hThread), VINF_SUCCESS);
125
126 /* Check if the thread has modified data as expected. */
127 RTR0TESTR0_CHECK_MSG_BREAK(Data.cCounter = 196 && Data.uMagic == ~TSTRTR0THREADDATA_MAGIC,
128 ("Thread didn't modify data as expected.\n"));
129 break;
130 }
131 }
132
133 RTR0TESTR0_SRV_REQ_EPILOG(pReqHdr);
134 /* The error indicator is the '!' in the message buffer. */
135 return VINF_SUCCESS;
136}
137
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