c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync/* $Id$ */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync/** @file
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * IPRT Testcase - Core Dumper.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync/*
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync * Copyright (C) 2010-2011 Oracle Corporation
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync *
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * available from http://www.virtualbox.org. This file is free software;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * you can redistribute it and/or modify it under the terms of the GNU
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * General Public License (GPL) as published by the Free Software
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync *
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * The contents of this file may alternatively be used under the terms
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * of the Common Development and Distribution License Version 1.0
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * VirtualBox OSE distribution, in which case the provisions of the
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * CDDL are applicable instead of those of the GPL.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync *
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * You may elect to license modified versions of this file under the
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * terms and conditions of either the GPL or the CDDL or both.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync */
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync/*******************************************************************************
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync* Header Files *
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync*******************************************************************************/
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync#include <iprt/coredumper.h>
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync#include <iprt/test.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#include <iprt/err.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#include <iprt/initterm.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync#include <iprt/thread.h>
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync/*******************************************************************************
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync* Globals *
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync*******************************************************************************/
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsyncstatic DECLCALLBACK(int) SleepyThread(RTTHREAD hThread, void *pvUser)
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync{
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync NOREF(pvUser);
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTThreadUserWait(hThread, 90000000);
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync return VINF_SUCCESS;
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync}
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsyncint main()
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync{
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTTEST hTest;
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTEXITCODE rcExit = RTTestInitAndCreate("tstRTCoreDump", &hTest);
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync if (rcExit != RTEXITCODE_SUCCESS)
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync return rcExit;
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTTestBanner(hTest);
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync /*
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * Setup core dumping.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync */
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync int rc;
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTTESTI_CHECK_RC(rc = RTCoreDumperSetup(NULL, RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP | RTCOREDUMPER_FLAGS_LIVE_CORE),
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync VINF_SUCCESS);
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync if (RT_SUCCESS(rc))
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync {
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync /*
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * Spawn a few threads.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync */
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync RTTHREAD ahThreads[5];
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync unsigned i;
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync for (i = 0; i < RT_ELEMENTS(ahThreads); i++)
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync {
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTTESTI_CHECK_RC_BREAK(RTThreadCreate(&ahThreads[i], SleepyThread, &ahThreads[i], 0, RTTHREADTYPE_DEFAULT,
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTTHREADFLAGS_WAITABLE, "TEST1"),
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync VINF_SUCCESS);
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync }
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTTestIPrintf(RTTESTLVL_ALWAYS, "Spawned %d threads.\n", i);
807512a9a87993f7c56ea2e58e81fb866f578164vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync /*
5330cda3253fc3d94ed03a7609774e8c85a4c56dvboxsync * Write the core to disk.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync */
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTTESTI_CHECK_RC(RTCoreDumperTakeDump(NULL, true /* fLiveCore*/), VINF_SUCCESS);
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync /*
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync * Clean up.
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync */
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTTESTI_CHECK_RC(RTCoreDumperDisable(), VINF_SUCCESS);
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync while (i-- > 0)
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync {
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTTESTI_CHECK_RC(RTThreadUserSignal(ahThreads[i]), VINF_SUCCESS);
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync RTTESTI_CHECK_RC(RTThreadWait(ahThreads[i], 60*1000, NULL), VINF_SUCCESS);
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync }
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync }
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync /*
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync * Summary.
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync */
0e3021c718d32b7803f6481d16cb5c847138cb5evboxsync return RTTestSummaryAndDestroy(hTest);
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync}
c74a793852e1fd8994bf9bd2495e1b731ed4ac09vboxsync