VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTCoreDump.cpp@ 36549

Last change on this file since 36549 was 32350, checked in by vboxsync, 14 years ago

Runtime/r3/coredumper: name flags similar to planned CFGM keys.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1/* $Id: tstRTCoreDump.cpp 32350 2010-09-09 12:29:57Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Core Dumper.
4 */
5
6/*
7 * Copyright (C) 2010 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/types.h>
31#include <iprt/err.h>
32#include <iprt/initterm.h>
33#include <iprt/thread.h>
34#include <iprt/stream.h>
35#include <iprt/coredumper.h>
36
37
38/*******************************************************************************
39* Globals *
40*******************************************************************************/
41static unsigned volatile g_cErrors = 0;
42
43static DECLCALLBACK(int) SleepyThread(RTTHREAD Thread, void *pvUser)
44{
45 NOREF(pvUser);
46 RTThreadSleep(90000000);
47 return VINF_SUCCESS;
48}
49
50int main()
51{
52 RTR3Init();
53 RTPrintf("tstRTCoreDump: TESTING...\n");
54
55 /*
56 * Setup core dumping.
57 */
58 int rc = RTCoreDumperSetup(NULL, RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP | RTCOREDUMPER_FLAGS_LIVE_CORE);
59 if (RT_SUCCESS(rc))
60 {
61 /*
62 * Spawn a few threads.
63 */
64 RTTHREAD ahThreads[5];
65 unsigned i = 0;
66 for (; i < RT_ELEMENTS(ahThreads); i++)
67 {
68 rc = RTThreadCreate(&ahThreads[i], SleepyThread, &ahThreads[i], 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "TEST1");
69 if (RT_FAILURE(rc))
70 {
71 RTPrintf("tstRTCoreDump: FAILURE(%d) - %d RTThreadCreate failed, rc=%Rrc\n", __LINE__, i, rc);
72 g_cErrors++;
73 ahThreads[i] = NIL_RTTHREAD;
74 break;
75 }
76 }
77 RTPrintf("Spawned %d threads.\n", i);
78
79 /*
80 * Write the core to disk.
81 */
82 rc = RTCoreDumperTakeDump(NULL, false /* fLiveCore*/);
83 if (RT_FAILURE(rc))
84 {
85 g_cErrors++;
86 RTPrintf("RTCoreDumperTakeDump failed. rc=%Rrc\n", rc);
87 }
88 RTCoreDumperDisable();
89 }
90 else
91 {
92 g_cErrors++;
93 RTPrintf("RTCoreDumperSetup failed. rc=%Rrc\n", rc);
94 }
95
96 /*
97 * Summary.
98 */
99 if (!g_cErrors)
100 RTPrintf("tstRTCoreDump: SUCCESS\n");
101 else
102 RTPrintf("tstRTCoreDump: FAILURE - %d errors\n", g_cErrors);
103
104 return !!g_cErrors;
105}
106
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