Skip to content
Snippets Groups Projects
Commit 65a593bc authored by Florian Fischer's avatar Florian Fischer
Browse files

add concurrent BPS test

The test introduces multiple cycles of Semaphores and
a Fiber for each semaphore blocking and signaling the next.
Through work-stealing the fibers from a cycle should be spread
across different workers and thus test concurrent use of
BinaryPrivateSemaphores.

Cycle of length 3: Sem A -> Sem B -> Sem C -> Sem A -> ...
Algorithm:
	if isFirstInCycle
		signal next

	wait

	if not isFirstInCycle
		signal next
parent c58a9143
No related branches found
No related tags found
1 merge request!279add concurrent BPS test
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2021 Florian Fischer
#include "BinaryPrivateSemaphore.hpp"
#include "CountingPrivateSemaphore.hpp"
#include "Debug.hpp"
#include "emper-config.h"
#include "emper.hpp"
static BPS* sems;
static const unsigned CYCLE_LENGTH = 3;
static const unsigned CYCLE_COUNT = 100;
static const unsigned ITERATIONS = EMPER_LOG_LEVEL > Info ? 100 : 25000;
void emperTest() {
CPS cps;
const unsigned count = CYCLE_COUNT * CYCLE_LENGTH;
sems = new BPS[count];
for (unsigned i = 0; i < count; ++i) {
spawn(
[=] {
const unsigned cycleNum = i / CYCLE_LENGTH;
const unsigned cycleStart = CYCLE_LENGTH * cycleNum;
BPS& mySem = sems[i];
const unsigned next = cycleStart + ((i + 1) % CYCLE_LENGTH);
BPS& nextSem = sems[next];
for (unsigned it = 0; it < ITERATIONS; ++it) {
if (i == cycleStart) nextSem.signal();
mySem.wait();
mySem.reset();
if (i != cycleStart) nextSem.signal();
}
},
cps);
}
cps.wait();
delete[] sems;
}
...@@ -87,6 +87,13 @@ tests = [ ...@@ -87,6 +87,13 @@ tests = [
'dependencies': [liburcu_memb, liburcu_cds] 'dependencies': [liburcu_memb, liburcu_cds]
}, },
{
'source': files('BinaryPrivateSemaphoreTest.cpp'),
'name': 'BinaryPrivateSemaphoreTest',
'description': 'Concurrent test for BinrayPrivateSemaphores',
'test_runner': 'emper',
},
{ {
'source': files('SignalPrivateSemaphoreFromAnywhereTest.cpp'), 'source': files('SignalPrivateSemaphoreFromAnywhereTest.cpp'),
'name': 'SignalPrivateSemaphoreFromAnywhereTest', 'name': 'SignalPrivateSemaphoreFromAnywhereTest',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment