2016-04-15 09:01:02 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
2023-11-09 12:23:00 -06:00
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2016-04-15 09:01:02 -05:00
|
|
|
* 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/.
|
|
|
|
*/
|
|
|
|
|
2020-04-18 03:39:50 -05:00
|
|
|
#pragma once
|
2016-04-15 09:01:02 -05:00
|
|
|
|
2021-01-19 20:40:54 -06:00
|
|
|
#include <chrono>
|
2017-01-06 09:54:19 -06:00
|
|
|
#include <iostream>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
2016-04-28 21:01:05 -05:00
|
|
|
#include <Poco/DirectoryIterator.h>
|
2017-01-06 09:54:19 -06:00
|
|
|
#include <Poco/FileStream.h>
|
|
|
|
#include <Poco/StreamCopier.h>
|
2016-04-28 21:01:05 -05:00
|
|
|
|
2017-01-06 09:54:19 -06:00
|
|
|
#include <Common.hpp>
|
2023-04-25 06:53:56 -05:00
|
|
|
#include "Util.hpp"
|
2024-01-05 01:16:13 -06:00
|
|
|
#include "lokassert.hpp"
|
2017-09-19 15:16:44 -05:00
|
|
|
#include "test.hpp"
|
2024-01-05 01:16:13 -06:00
|
|
|
#include "testlog.hpp"
|
2016-04-28 21:01:05 -05:00
|
|
|
|
2021-11-18 06:08:14 -06:00
|
|
|
static int countCoolKitProcesses(const int expected,
|
2021-01-19 20:40:54 -06:00
|
|
|
std::chrono::milliseconds timeoutMs
|
|
|
|
= std::chrono::milliseconds(COMMAND_TIMEOUT_MS * 8))
|
2016-04-28 21:01:05 -05:00
|
|
|
{
|
2021-11-18 06:08:14 -06:00
|
|
|
const auto testname = "countCoolKitProcesses ";
|
|
|
|
TST_LOG_BEGIN("Waiting until coolkit processes are exactly " << expected << ". Coolkits: ");
|
2016-10-17 13:44:28 -05:00
|
|
|
|
2023-04-25 06:53:56 -05:00
|
|
|
Util::Stopwatch stopwatch;
|
|
|
|
|
2016-11-11 21:23:05 -06:00
|
|
|
// This does not need to depend on any constant from Common.hpp.
|
|
|
|
// The shorter the better (the quicker the test runs).
|
2021-01-19 20:40:54 -06:00
|
|
|
constexpr int sleepMs = 10;
|
2016-10-17 13:44:28 -05:00
|
|
|
|
2020-07-22 11:01:02 -05:00
|
|
|
// This has to cause waiting for at least COMMAND_TIMEOUT_MS. Tolerate more for safety.
|
2021-01-19 20:40:54 -06:00
|
|
|
const std::size_t repeat = (timeoutMs.count() / sleepMs);
|
2021-11-18 06:08:14 -06:00
|
|
|
int count = getCoolKitProcessCount();
|
2020-11-15 11:03:45 -06:00
|
|
|
for (std::size_t i = 0; i < repeat; ++i)
|
2016-04-28 21:01:05 -05:00
|
|
|
{
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG_APPEND(count << ' ');
|
2016-04-28 21:01:05 -05:00
|
|
|
if (count == expected)
|
|
|
|
{
|
2016-10-08 20:40:52 -05:00
|
|
|
break;
|
2016-04-28 21:01:05 -05:00
|
|
|
}
|
|
|
|
|
2021-11-15 10:07:24 -06:00
|
|
|
// Give polls in the cool processes time to time out etc
|
2017-01-06 09:54:19 -06:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(sleepMs));
|
2016-04-28 21:01:05 -05:00
|
|
|
|
2021-11-18 06:08:14 -06:00
|
|
|
const int newCount = getCoolKitProcessCount();
|
2017-01-29 13:04:54 -06:00
|
|
|
if (count != newCount)
|
|
|
|
{
|
|
|
|
// Allow more time until the number settles.
|
|
|
|
i = 0;
|
|
|
|
count = newCount;
|
|
|
|
}
|
2016-04-28 21:01:05 -05:00
|
|
|
}
|
|
|
|
|
2018-01-22 08:11:43 -06:00
|
|
|
TST_LOG_END;
|
2016-04-29 16:16:53 -05:00
|
|
|
if (expected != count)
|
|
|
|
{
|
2019-10-12 12:51:56 -05:00
|
|
|
TST_LOG_BEGIN("Found " << count << " LoKit processes but was expecting " << expected << ": [");
|
2021-03-26 11:57:08 -05:00
|
|
|
for (pid_t i : getKitPids())
|
2019-10-12 12:51:56 -05:00
|
|
|
{
|
|
|
|
TST_LOG_APPEND(i << ' ');
|
|
|
|
}
|
|
|
|
TST_LOG_APPEND(']');
|
|
|
|
TST_LOG_END;
|
|
|
|
|
2016-04-29 16:16:53 -05:00
|
|
|
}
|
|
|
|
|
2021-03-26 11:57:08 -05:00
|
|
|
std::set<pid_t> pids = getKitPids();
|
2019-05-03 07:51:49 -05:00
|
|
|
std::ostringstream oss;
|
2022-02-25 06:50:21 -06:00
|
|
|
oss << "Test kit pids are [";
|
2021-03-26 11:57:08 -05:00
|
|
|
for (pid_t i : pids)
|
2020-05-24 08:10:18 -05:00
|
|
|
oss << i << ' ';
|
2023-04-25 06:53:56 -05:00
|
|
|
oss << "] after waiting for " << stopwatch.elapsed();
|
2019-05-03 07:51:49 -05:00
|
|
|
TST_LOG(oss.str());
|
|
|
|
|
2016-04-28 21:01:05 -05:00
|
|
|
return count;
|
|
|
|
}
|
2016-04-15 09:01:02 -05:00
|
|
|
|
2017-01-06 09:54:19 -06:00
|
|
|
// FIXME: we probably should make this extern
|
|
|
|
// and reuse it. As it stands now, it is per
|
|
|
|
// translation unit, which isn't desirable if
|
|
|
|
// (in the non-ideal event that) it's not 1,
|
2021-11-18 06:08:14 -06:00
|
|
|
// it will cause testNoExtraCoolKitsLeft to
|
2017-01-06 09:54:19 -06:00
|
|
|
// wait unnecessarily and fail.
|
2021-11-18 06:08:14 -06:00
|
|
|
static int InitialCoolKitCount = 1;
|
2017-01-08 20:11:50 -06:00
|
|
|
static std::chrono::steady_clock::time_point TestStartTime;
|
2017-01-06 09:54:19 -06:00
|
|
|
|
2021-11-18 06:08:14 -06:00
|
|
|
static void testCountHowManyCoolkits()
|
2017-01-06 09:54:19 -06:00
|
|
|
{
|
2021-11-18 06:08:14 -06:00
|
|
|
const char testname[] = "countHowManyCoolkits ";
|
2017-04-09 17:25:31 -05:00
|
|
|
TestStartTime = std::chrono::steady_clock::now();
|
|
|
|
|
2021-11-18 06:08:14 -06:00
|
|
|
InitialCoolKitCount = countCoolKitProcesses(InitialCoolKitCount);
|
|
|
|
TST_LOG("Initial coolkit count is " << InitialCoolKitCount);
|
|
|
|
LOK_ASSERT(InitialCoolKitCount > 0);
|
2017-01-08 20:11:50 -06:00
|
|
|
|
|
|
|
TestStartTime = std::chrono::steady_clock::now();
|
2017-01-06 09:54:19 -06:00
|
|
|
}
|
|
|
|
|
2021-11-18 06:08:14 -06:00
|
|
|
static void testNoExtraCoolKitsLeft()
|
2017-01-06 09:54:19 -06:00
|
|
|
{
|
2021-11-18 06:08:14 -06:00
|
|
|
const char testname[] = "noExtraCoolKitsLeft ";
|
|
|
|
const int countNow = countCoolKitProcesses(InitialCoolKitCount);
|
|
|
|
LOK_ASSERT_EQUAL(InitialCoolKitCount, countNow);
|
2017-01-08 20:11:50 -06:00
|
|
|
|
|
|
|
const auto duration = (std::chrono::steady_clock::now() - TestStartTime);
|
2020-12-06 21:45:46 -06:00
|
|
|
const auto durationMs = std::chrono::duration_cast<std::chrono::milliseconds>(duration);
|
2017-01-08 20:11:50 -06:00
|
|
|
|
2020-12-06 21:45:46 -06:00
|
|
|
TST_LOG(" (" << durationMs << ')');
|
2017-01-06 09:54:19 -06:00
|
|
|
}
|
|
|
|
|
2016-04-15 09:01:02 -05:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|