VirtualBox

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

Last change on this file since 55384 was 54389, checked in by vboxsync, 10 years ago

Runtime/testcase: very basic ring-0 thread creation.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Id: tstRTR0Thread.cpp 54389 2015-02-23 17:00:56Z vboxsync $ */
2/** @file
3 * IPRT R0 Testcase - Kernel thread.
4 */
5
6/*
7 * Copyright (C) 2015 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/thread.h>
31
32#include <iprt/asm-amd64-x86.h>
33#include <iprt/err.h>
34#include <VBox/sup.h>
35#include "tstRTR0Thread.h"
36#include "tstRTR0Common.h"
37
38#define TSTRTR0THREADDATA_MAGIC 0xcececece
39
40/**
41 * State structure for tstRTR0ThreadCallback().
42 */
43typedef struct TSTRTR0THREADDATA
44{
45 /** The magic value. */
46 uint32_t uMagic;
47 /** Sample counter. */
48 uint32_t volatile cCounter;
49 /** The thread handle. */
50 RTTHREAD hThread;
51} TSTRTR0THREADDATA;
52/** Pointer to state structure for tstRTR0ThreadCallback(). */
53typedef TSTRTR0THREADDATA *PTSTRTR0THREADDATA;
54
55
56static DECLCALLBACK(int) tstRTR0ThreadCallback(RTTHREAD hThread, void *pvUser)
57{
58 PTSTRTR0THREADDATA pData = (PTSTRTR0THREADDATA)pvUser;
59 if (RT_LIKELY(pData))
60 {
61 if (pData->uMagic == TSTRTR0THREADDATA_MAGIC)
62 pData->uMagic = ~pData->uMagic;
63 if (pData->cCounter == 127)
64 pData->cCounter = 196;
65 }
66 RTThreadUserSignal(RTThreadSelf());
67 return VINF_SUCCESS;
68}
69
70
71/**
72 * Service request callback function.
73 *
74 * @returns VBox status code.
75 * @param pSession The caller's session.
76 * @param u64Arg 64-bit integer argument.
77 * @param pReqHdr The request header. Input / Output. Optional.
78 */
79DECLEXPORT(int) TSTRTR0ThreadSrvReqHandler(PSUPDRVSESSION pSession, uint32_t uOperation,
80 uint64_t u64Arg, PSUPR0SERVICEREQHDR pReqHdr)
81{
82 RTR0TESTR0_SRV_REQ_PROLOG_RET(pReqHdr);
83
84 /*
85 * The big switch.
86 */
87 switch (uOperation)
88 {
89 RTR0TESTR0_IMPLEMENT_SANITY_CASES();
90 RTR0TESTR0_IMPLEMENT_DEFAULT_CASE(uOperation);
91
92 case TSTRTR0THREAD_BASIC:
93 {
94 TSTRTR0THREADDATA Data;
95 RT_ZERO(Data);
96 Data.uMagic = TSTRTR0THREADDATA_MAGIC;
97 Data.cCounter = 127;
98
99 /* Create the kernel thread. */
100 RTR0TESTR0_CHECK_RC_BREAK(RTThreadCreate(&Data.hThread, tstRTR0ThreadCallback, &Data, 0 /* cbStack */,
101 RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "tstRTR0Thr"), VINF_SUCCESS);
102
103 /* Wait for thread to signal. */
104 RTR0TESTR0_CHECK_RC(RTThreadUserWait(Data.hThread, 500 /* ms */), VINF_SUCCESS);
105
106 /* Reset the semaphore. */
107 RTR0TESTR0_CHECK_RC(RTThreadUserReset(Data.hThread), VINF_SUCCESS);
108
109 /* Check if the thread has modified data as expected. */
110 RTR0TESTR0_CHECK_MSG_BREAK(Data.cCounter = 196 && Data.uMagic == ~TSTRTR0THREADDATA_MAGIC,
111 ("Thread didn't modify data as expected.\n"));
112 break;
113 }
114 }
115
116 RTR0TESTR0_SRV_REQ_EPILOG(pReqHdr);
117 /* The error indicator is the '!' in the message buffer. */
118 return VINF_SUCCESS;
119}
120
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