summaryrefslogtreecommitdiff
path: root/src/VBox/Runtime/testcase
diff options
context:
space:
mode:
authorFelix Geyer <debfx-pkg@fobos.de>2010-10-12 15:58:30 +0200
committerFelix Geyer <debfx-pkg@fobos.de>2010-10-12 15:58:30 +0200
commit7f230f4ac2a1b544b47ded0584c22822b9bd65d7 (patch)
treeee5808929787047784013befd706131196a30d1d /src/VBox/Runtime/testcase
parentadf97a4e6386ea334ce8d77f0cde3b92454b9fa5 (diff)
downloadvirtualbox-7f230f4ac2a1b544b47ded0584c22822b9bd65d7.tar.gz
Imported Upstream version 3.2.10-dfsgupstream/3.2.10-dfsg
Diffstat (limited to 'src/VBox/Runtime/testcase')
-rw-r--r--src/VBox/Runtime/testcase/Makefile.kmk5
-rw-r--r--src/VBox/Runtime/testcase/tstInlineAsm.cpp22
-rw-r--r--src/VBox/Runtime/testcase/tstRTCoreDump.cpp106
-rw-r--r--src/VBox/Runtime/testcase/tstRTCoreDump.h144
4 files changed, 273 insertions, 4 deletions
diff --git a/src/VBox/Runtime/testcase/Makefile.kmk b/src/VBox/Runtime/testcase/Makefile.kmk
index 9b3af1b92..53038d468 100644
--- a/src/VBox/Runtime/testcase/Makefile.kmk
+++ b/src/VBox/Runtime/testcase/Makefile.kmk
@@ -124,6 +124,8 @@ PROGRAMS.linux += \
tstRTBitOperationsPIC3 \
tstInlineAsmPIC \
tstInlineAsmPIC3
+PROGRAMS.solaris += \
+ tstRTCoreDump
PROGRAMS.l4 += \
tstIoCtl
PROGRAMS.darwin += \
@@ -488,6 +490,9 @@ tstRTUuid_SOURCES = tstRTUuid.cpp
tstUtf8_SOURCES = tstUtf8.cpp
+tstRTCoreDump_TEMPLACE = VBOXR3TSTEXE
+tstRTCoreDump_SOURCES = tstRTCoreDump.cpp
+
#
# odds and ends
#
diff --git a/src/VBox/Runtime/testcase/tstInlineAsm.cpp b/src/VBox/Runtime/testcase/tstInlineAsm.cpp
index 552655fa0..c7e296145 100644
--- a/src/VBox/Runtime/testcase/tstInlineAsm.cpp
+++ b/src/VBox/Runtime/testcase/tstInlineAsm.cpp
@@ -29,7 +29,17 @@
*******************************************************************************/
#include <iprt/asm.h>
#include <iprt/asm-math.h>
-#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
+
+/* See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44018. Only gcc version 4.4
+ * is affected. No harm for the VBox code: If the cpuid code compiles, it works
+ * fine. */
+#if defined(__GNUC__) && defined(RT_ARCH_X86) && defined(__PIC__)
+# if __GNUC__ == 4 && __GNUC_MINOR__ == 4
+# define GCC44_32BIT_PIC
+# endif
+#endif
+
+#if !defined(GCC44_32BIT_PIC) && (defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86))
# include <iprt/asm-amd64-x86.h>
#else
# include <iprt/time.h>
@@ -68,7 +78,7 @@
} while (0)
-#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
+#if !defined(GCC44_32BIT_PIC) && (defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86))
const char *getCacheAss(unsigned u)
{
@@ -119,6 +129,7 @@ const char *getL2CacheAss(unsigned u)
*/
void tstASMCpuId(void)
{
+#if 0
unsigned iBit;
struct
{
@@ -161,6 +172,8 @@ void tstASMCpuId(void)
"Function eax ebx ecx edx\n");
for (unsigned iStd = 0; iStd <= cFunctions + 3; iStd++)
{
+ if (iStd == 4)
+ continue; /* Leaf 04 output depends on the initial value of ECX */
ASMCpuId(iStd, &s.uEAX, &s.uEBX, &s.uECX, &s.uEDX);
RTPrintf("%08x %08x %08x %08x %08x%s\n",
iStd, s.uEAX, s.uEBX, s.uECX, s.uEDX, iStd <= cFunctions ? "" : "*");
@@ -435,6 +448,7 @@ void tstASMCpuId(void)
s.uEAX & 0xff, s.uEAX & 0xff,
s.uEBX, s.uEBX);
}
+#endif
}
#endif /* AMD64 || X86 */
@@ -1186,7 +1200,7 @@ void tstASMBench(void)
RTPrintf("tstInlineASM: Benchmarking:\n");
-#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
+#if !defined(GCC44_32BIT_PIC) && (defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86))
# define BENCH(op, str) \
do { \
RTThreadYield(); \
@@ -1281,7 +1295,7 @@ int main(int argc, char *argv[])
/*
* Execute the tests.
*/
-#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
+#if !defined(GCC44_32BIT_PIC) && (defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86))
tstASMCpuId();
#endif
tstASMAtomicXchgU8();
diff --git a/src/VBox/Runtime/testcase/tstRTCoreDump.cpp b/src/VBox/Runtime/testcase/tstRTCoreDump.cpp
new file mode 100644
index 000000000..d4942358b
--- /dev/null
+++ b/src/VBox/Runtime/testcase/tstRTCoreDump.cpp
@@ -0,0 +1,106 @@
+/* $Id: tstRTCoreDump.cpp $ */
+/** @file
+ * IPRT Testcase - Core Dumper.
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+/*******************************************************************************
+* Header Files *
+*******************************************************************************/
+#include <iprt/types.h>
+#include <iprt/err.h>
+#include <iprt/initterm.h>
+#include <iprt/thread.h>
+#include <iprt/stream.h>
+#include <iprt/coredumper.h>
+
+
+/*******************************************************************************
+* Globals *
+*******************************************************************************/
+static unsigned volatile g_cErrors = 0;
+
+static DECLCALLBACK(int) SleepyThread(RTTHREAD Thread, void *pvUser)
+{
+ NOREF(pvUser);
+ RTThreadSleep(90000000);
+ return VINF_SUCCESS;
+}
+
+int main()
+{
+ RTR3Init();
+ RTPrintf("tstRTCoreDump: TESTING...\n");
+
+ /*
+ * Setup core dumping.
+ */
+ int rc = RTCoreDumperSetup(NULL, RTCOREDUMPER_FLAGS_REPLACE_SYSTEM_DUMP | RTCOREDUMPER_FLAGS_LIVE_CORE);
+ if (RT_SUCCESS(rc))
+ {
+ /*
+ * Spawn a few threads.
+ */
+ RTTHREAD ahThreads[5];
+ unsigned i = 0;
+ for (; i < RT_ELEMENTS(ahThreads); i++)
+ {
+ rc = RTThreadCreate(&ahThreads[i], SleepyThread, &ahThreads[i], 0, RTTHREADTYPE_DEFAULT, RTTHREADFLAGS_WAITABLE, "TEST1");
+ if (RT_FAILURE(rc))
+ {
+ RTPrintf("tstRTCoreDump: FAILURE(%d) - %d RTThreadCreate failed, rc=%Rrc\n", __LINE__, i, rc);
+ g_cErrors++;
+ ahThreads[i] = NIL_RTTHREAD;
+ break;
+ }
+ }
+ RTPrintf("Spawned %d threads.\n", i);
+
+ /*
+ * Write the core to disk.
+ */
+ rc = RTCoreDumperTakeDump(NULL, false /* fLiveCore*/);
+ if (RT_FAILURE(rc))
+ {
+ g_cErrors++;
+ RTPrintf("RTCoreDumperTakeDump failed. rc=%Rrc\n", rc);
+ }
+ RTCoreDumperDisable();
+ }
+ else
+ {
+ g_cErrors++;
+ RTPrintf("RTCoreDumperSetup failed. rc=%Rrc\n", rc);
+ }
+
+ /*
+ * Summary.
+ */
+ if (!g_cErrors)
+ RTPrintf("tstRTCoreDump: SUCCESS\n");
+ else
+ RTPrintf("tstRTCoreDump: FAILURE - %d errors\n", g_cErrors);
+
+ return !!g_cErrors;
+}
+
diff --git a/src/VBox/Runtime/testcase/tstRTCoreDump.h b/src/VBox/Runtime/testcase/tstRTCoreDump.h
new file mode 100644
index 000000000..524db6628
--- /dev/null
+++ b/src/VBox/Runtime/testcase/tstRTCoreDump.h
@@ -0,0 +1,144 @@
+/* $Id: tstRTCoreDump.h $ */
+/** @file
+ * IPRT Testcase - Core dump, header.
+ */
+
+/*
+ * Copyright (C) 2010 Oracle Corporation
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * The contents of this file may alternatively be used under the terms
+ * of the Common Development and Distribution License Version 1.0
+ * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
+ * VirtualBox OSE distribution, in which case the provisions of the
+ * CDDL are applicable instead of those of the GPL.
+ *
+ * You may elect to license modified versions of this file under the
+ * terms and conditions of either the GPL or the CDDL or both.
+ */
+
+#include <iprt/process.h>
+#include <iprt/file.h>
+
+#ifdef RT_OS_SOLARIS
+# if defined(RT_ARCH_X86) && _FILE_OFFSET_BITS==64
+/*
+ * Solaris' procfs cannot be used with large file environment in 32-bit.
+ */
+# undef _FILE_OFFSET_BITS
+# define _FILE_OFFSET_BITS 32
+# include <procfs.h>
+# include <sys/procfs.h>
+# include <sys/old_procfs.h>
+# undef _FILE_OFFSET_BITS
+# define _FILE_OFFSET_BITS 64
+#else
+# include <procfs.h>
+# include <sys/procfs.h>
+# include <sys/old_procfs.h>
+#endif
+# include <limits.h>
+# include <thread.h>
+# include <sys/auxv.h>
+# include <sys/lwp.h>
+# include <sys/zone.h>
+# include <sys/utsname.h>
+
+#ifdef RT_ARCH_AMD64
+# define _ELF64
+# undef _ELF32_COMPAT
+#endif
+# include <sys/machelf.h>
+# include <sys/corectl.h>
+#endif
+
+/**
+ * ELF NOTE header.
+ */
+typedef struct ELFNOTEHDR
+{
+ Nhdr Hdr; /* Header of NOTE section */
+ char achName[8]; /* Name of NOTE section */
+} ELFNOTEHDR;
+typedef ELFNOTEHDR *PELFNOTEHDR;
+
+#ifdef RT_OS_SOLARIS
+typedef struct VBOXSOLMAPINFO
+{
+ prmap_t pMap; /* Proc description of this mapping */
+ int fError; /* Any error reading this mapping (errno) */
+ struct VBOXSOLMAPINFO *pNext; /* Pointer to the next mapping */
+} VBOXSOLMAPINFO;
+typedef VBOXSOLMAPINFO *PVBOXSOLMAPINFO;
+
+typedef struct VBOXSOLTHREADINFO
+{
+ lwpsinfo_t Info; /* Proc description of this thread */
+ lwpstatus_t *pStatus; /* Proc description of this thread's status (can be NULL, zombie lwp) */
+ struct VBOXSOLTHREADINFO *pNext; /* Pointer to the next thread */
+} VBOXSOLTHREADINFO;
+typedef VBOXSOLTHREADINFO *PVBOXSOLTHREADINFO;
+#endif
+
+typedef int (*PFNCOREREADER)(RTFILE hFile, void *pv, size_t cb);
+typedef int (*PFNCOREWRITER)(RTFILE hFile, const void *pcv, size_t cb);
+
+typedef struct VBOXPROCESS
+{
+ RTPROCESS Process; /* The pid of the process */
+ char szExecPath[PATH_MAX]; /* Path of the executable */
+ char *pszExecName; /* Name of the executable file */
+#ifdef RT_OS_SOLARIS
+ psinfo_t ProcInfo; /* Process info. */
+ prpsinfo_t ProcInfoOld; /* Process info. Older version (for GDB compat.) */
+ pstatus_t ProcStatus; /* Process status info. */
+ thread_t hCurThread; /* The current thread */
+ ucontext_t *pCurThreadCtx; /* Context info. of current thread before starting to dump */
+ RTFILE hAs; /* proc/<pid/as file handle */
+ auxv_t *pAuxVecs; /* Aux vector of process */
+ int cAuxVecs; /* Number of aux vector entries */
+ PVBOXSOLMAPINFO pMapInfoHead; /* Pointer to the head of list of mappings */
+ uint32_t cMappings; /* Number of mappings (count of pMapInfoHead list) */
+ PVBOXSOLTHREADINFO pThreadInfoHead; /* Pointer to the head of list of threads */
+ uint64_t cThreads; /* Number of threads (count of pThreadInfoHead list) */
+ char szPlatform[SYS_NMLN]; /* Platform name */
+ char szZoneName[ZONENAME_MAX]; /* Zone name */
+ struct utsname UtsName; /* UTS name */
+ void *pvCred; /* Process credential info. */
+ size_t cbCred; /* Size of process credential info. */
+ void *pvLdt; /* Process LDT info. */
+ size_t cbLdt; /* Size of the LDT info. */
+ prpriv_t *pPriv; /* Process privilege info. */
+ size_t cbPriv; /* Size of process privilege info. */
+ const priv_impl_info_t *pcPrivImpl; /* Process privilege implementation info. (opaque handle) */
+ core_content_t CoreContent; /* What information goes in the core */
+#else
+# error Port Me!
+#endif
+
+} VBOXPROCESS;
+typedef VBOXPROCESS *PVBOXPROCESS;
+
+typedef struct VBOXCORE
+{
+ char szCorePath[PATH_MAX]; /* Path of the core file */
+ VBOXPROCESS VBoxProc; /* Current process information */
+ void *pvCore; /* Pointer to memory area during dumping */
+ size_t cbCore; /* Size of memory area during dumping */
+ void *pvFree; /* Pointer to base of free range in preallocated memory area */
+ bool fIsValid; /* Whether core information has been fully collected */
+ PFNCOREREADER pfnReader; /* Reader function */
+ PFNCOREWRITER pfnWriter; /* Writer function */
+ RTFILE hCoreFile; /* Core file (used only while writing the core) */
+ RTFOFF offWrite; /* Segment/section offset (used only while writing the core) */
+} VBOXCORE;
+typedef VBOXCORE *PVBOXCORE;
+
+typedef int (*PFNCOREACCUMULATOR)(PVBOXCORE pVBoxCOre);