VirtualBox

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

Last change on this file since 85546 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 3.5 KB
Line 
1/* $Id: tstRTCoreDump.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * IPRT Testcase - Core Dumper.
4 */
5
6/*
7 * Copyright (C) 2010-2020 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/coredumper.h>
32
33#include <iprt/test.h>
34#include <iprt/errcore.h>
35#include <iprt/initterm.h>
36#include <iprt/thread.h>
37
38
39/*********************************************************************************************************************************
40* Globals *
41*********************************************************************************************************************************/
42static DECLCALLBACK(int) SleepyThread(RTTHREAD hThread, void *pvUser)
43{
44 NOREF(pvUser);
45 RTThreadUserWait(hThread, 90000000);
46 return VINF_SUCCESS;
47}
48
49int main()
50{
51 RTTEST hTest;
52 RTEXITCODE rcExit = RTTestInitAndCreate("tstRTCoreDump", &hTest);
53 if (rcExit != RTEXITCODE_SUCCESS)
54 return rcExit;
55 RTTestBanner(hTest);
56
57 /*
58 * Setup core dumping.
59 */
60 int rc;
61 RTTESTI_CHECK_RC(rc = RTCoreDumperSetup(NULL, RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP | RTCOREDUMPER_FLAGS_LIVE_CORE),
62 VINF_SUCCESS);
63 if (RT_SUCCESS(rc))
64 {
65 /*
66 * Spawn a few threads.
67 */
68 RTTHREAD ahThreads[5];
69 unsigned i;
70 for (i = 0; i < RT_ELEMENTS(ahThreads); i++)
71 {
72 RTTESTI_CHECK_RC_BREAK(RTThreadCreate(&ahThreads[i], SleepyThread, &ahThreads[i], 0, RTTHREADTYPE_DEFAULT,
73 RTTHREADFLAGS_WAITABLE, "TEST1"),
74 VINF_SUCCESS);
75 }
76 RTTestIPrintf(RTTESTLVL_ALWAYS, "Spawned %d threads.\n", i);
77
78 /*
79 * Write the core to disk.
80 */
81 RTTESTI_CHECK_RC(RTCoreDumperTakeDump(NULL, true /* fLiveCore*/), VINF_SUCCESS);
82
83 /*
84 * Clean up.
85 */
86 RTTESTI_CHECK_RC(RTCoreDumperDisable(), VINF_SUCCESS);
87 while (i-- > 0)
88 {
89 RTTESTI_CHECK_RC(RTThreadUserSignal(ahThreads[i]), VINF_SUCCESS);
90 RTTESTI_CHECK_RC(RTThreadWait(ahThreads[i], 60*1000, NULL), VINF_SUCCESS);
91 }
92 }
93
94 /*
95 * Summary.
96 */
97 return RTTestSummaryAndDestroy(hTest);
98}
99
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