VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTProcWait.cpp@ 4071

Last change on this file since 4071 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.1 KB
Line 
1/* $Id: tstRTProcWait.cpp 4071 2007-08-07 17:07:59Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime Testcase - RTProcWait.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#include <iprt/runtime.h>
23#include <iprt/process.h>
24#include <iprt/thread.h>
25#include <iprt/stream.h>
26#include <iprt/semaphore.h>
27#include <iprt/err.h>
28#include <iprt/string.h>
29
30
31
32
33typedef struct SpawnerArgs
34{
35 RTPROCESS Process;
36 const char *pszExe;
37} SPAWNERARGS, *PSPAWNERARGS;
38
39
40DECLCALLBACK(int) SpawnerThread(RTTHREAD Thread, void *pvUser)
41{
42 PSPAWNERARGS pArgs = (PSPAWNERARGS)pvUser;
43 pArgs->Process = NIL_RTPROCESS;
44 const char *apszArgs[3] = { pArgs->pszExe, "child", NULL };
45 return RTProcCreate(apszArgs[0], apszArgs, NULL, 0, &pArgs->Process);
46}
47
48
49int main(int argc, char **argv)
50{
51 RTR3Init();
52 if (argc == 2 && !strcmp(argv[1], "child"))
53 return 42;
54
55 RTPrintf("tstRTWait: spawning a child in a separate thread and waits for it in the main thread...\n");
56 RTTHREAD Thread;
57 SPAWNERARGS Args = { NIL_RTPROCESS, argv[0] };
58 int rc = RTThreadCreate(&Thread, SpawnerThread, &Args, 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "SPAWNER");
59 if (RT_SUCCESS(rc))
60 {
61 /* Wait for it to complete. */
62 int rc2;
63 int rc = RTThreadWait(Thread, RT_INDEFINITE_WAIT, &rc2);
64 if (RT_SUCCESS(rc))
65 rc = rc2;
66 if (RT_SUCCESS(rc))
67 {
68 /* wait for the process to complete */
69 RTPROCSTATUS Status;
70 rc = RTProcWait(Args.Process, 0, &Status);
71 if (RT_SUCCESS(rc))
72 {
73 if ( Status.enmReason == RTPROCEXITREASON_NORMAL
74 && Status.iStatus == 42)
75 RTPrintf("tstRTWait: Success!\n");
76 else
77 {
78 rc = VERR_GENERAL_FAILURE;
79 if (Status.enmReason != RTPROCEXITREASON_NORMAL)
80 RTPrintf("tstRTWait: Expected exit reason RTPROCEXITREASON_NORMAL, got %d.\n", Status.enmReason);
81 else
82 RTPrintf("tstRTWait: Expected exit status 42, got %d.\n", Status.iStatus);
83 }
84 }
85 else
86 RTPrintf("tstRTWait: RTProcWait failed with rc=%Vrc!\n", rc);
87 }
88 else
89 RTPrintf("tstRTWait: RTThreadWait or SpawnerThread failed with rc=%Vrc!\n", rc);
90 }
91 else
92 RTPrintf("tstRTWait: RTThreadCreate failed with rc=%Vrc!\n", rc);
93
94 return RT_SUCCESS(rc) ? 0 : 1;
95}
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