e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync/* $Id$ */
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync/** @file
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * IPRT Testcase - RTProcCreate Profiling.
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync */
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync/*
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * Copyright (C) 2012 Oracle Corporation
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync *
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * available from http://www.virtualbox.org. This file is free software;
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * you can redistribute it and/or modify it under the terms of the GNU
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * General Public License (GPL) as published by the Free Software
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync *
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * The contents of this file may alternatively be used under the terms
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * of the Common Development and Distribution License Version 1.0
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * VirtualBox OSE distribution, in which case the provisions of the
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * CDDL are applicable instead of those of the GPL.
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync *
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * You may elect to license modified versions of this file under the
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * terms and conditions of either the GPL or the CDDL or both.
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync */
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync/*******************************************************************************
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync* Header Files *
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync*******************************************************************************/
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync#include <iprt/process.h>
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync#include <iprt/test.h>
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync#include <iprt/time.h>
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync#include <iprt/path.h>
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync#include <iprt/env.h>
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync#include <iprt/string.h>
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsyncint main(int argc, char **argv)
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync{
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync /* the child response. */
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync if (argc != 1)
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync return 0;
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync RTTEST hTest;
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync RTEXITCODE rcExit = RTTestInitAndCreate("tstRTProcCreatePrf", &hTest);
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync if (rcExit)
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync return rcExit;
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync RTTestBanner(hTest);
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync char szExecPath[RTPATH_MAX];
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync if (!RTProcGetExecutablePath(szExecPath, sizeof(szExecPath)))
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync RTStrCopy(szExecPath, sizeof(szExecPath), argv[0]);
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync const char *apszArgs[4] = { szExecPath, "child", "process", NULL };
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync uint64_t NsStart = RTTimeNanoTS();
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync uint32_t i;
809901544218a918753146ca0814fc66d5154464vboxsync#if defined(RT_OS_WINDOWS) || defined(RT_OS_OS2) || defined(RT_OS_DARWIN)
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync for (i = 0; i < 1000; i++)
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync#else
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync for (i = 0; i < 10000; i++)
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync#endif
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync {
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync RTPROCESS hProc;
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync RTTEST_CHECK_RC_BREAK(hTest, RTProcCreate(szExecPath, apszArgs, RTENV_DEFAULT, 0 /* fFlags*/, &hProc), VINF_SUCCESS);
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync RTPROCSTATUS ChildStatus;
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync RTTEST_CHECK_RC_BREAK(hTest, RTProcWait(hProc, RTPROCWAIT_FLAGS_BLOCK, &ChildStatus), VINF_SUCCESS);
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync RTTEST_CHECK_BREAK(hTest, ChildStatus.enmReason == RTPROCEXITREASON_NORMAL);
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync RTTEST_CHECK_BREAK(hTest, ChildStatus.iStatus == 0);
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync }
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync uint64_t cNsElapsed = RTTimeNanoTS() - NsStart;
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync if (i)
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync {
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync RTTestValue(hTest, "Time per process", cNsElapsed / i, RTTESTUNIT_NS);
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync }
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync /*
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync * Summary.
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync */
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync return RTTestSummaryAndDestroy(hTest);
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync}
e75babe1e6dafc9f3859ca5f34d571563e7618b2vboxsync