libreoffice-online/loolwsd/test/UnitPrefork.cpp

71 lines
1.6 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <dlfcn.h>
#include <ftw.h>
#include <cassert>
2016-04-07 14:15:18 -05:00
#include <iostream>
#include "Util.hpp"
#include "Unit.hpp"
2016-04-07 14:15:18 -05:00
#include <Poco/Timestamp.h>
using Poco::Timestamp;
2016-04-09 12:26:33 -05:00
// Inside the WSD process
class UnitPrefork : public UnitWSD
{
int _numStarted;
const int _numToPrefork;
2016-04-07 14:15:18 -05:00
Timestamp _startTime;
public:
UnitPrefork()
: _numStarted(0),
_numToPrefork(20)
{
2016-04-09 12:26:33 -05:00
setHasKitHooks();
}
virtual void preSpawnCount(int &numPrefork) override
{
numPrefork = _numToPrefork;
}
virtual void newChild() override
{
_numStarted++;
if (_numStarted >= _numToPrefork + 1)
2016-04-07 14:15:18 -05:00
{
exitTest(TestResult::TEST_OK);
2016-04-07 14:15:18 -05:00
Poco::Timestamp::TimeDiff elapsed = _startTime.elapsed();
std::cout << "Launched " << _numStarted << " in "
<< (1.0 * elapsed)/Poco::Timestamp::resolution() << std::endl;
}
}
};
2016-04-09 12:26:33 -05:00
// Inside the forkit & kit processes
class UnitKitPrefork : public UnitKit
{
public:
UnitKitPrefork() {}
};
UnitBase *unit_create_wsd(void)
{
return new UnitPrefork();
}
2016-04-09 12:26:33 -05:00
UnitBase *unit_create_kit(void)
{
return new UnitKitPrefork();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */