Skip to content
Snippets Groups Projects
Commit 2272a5e4 authored by Florian Schmaus's avatar Florian Schmaus
Browse files

Merge branch 'alarm-test' into 'master'

[test] add AlarmActorTest

See merge request i4/manycore/emper!24
parents 118a4dcb cbe2a880
No related branches found
No related tags found
No related merge requests found
// SPDX-License-Identifier: LGPL-3.0-or-later
// Copyright © 2020 Florian Fischer
#include <cstdlib> // for exit, EXIT_FAILURE, EXIT_SUC...
#include <iostream> // for operator<<, basic_ostream
#include "Actor.hpp" // for Actor
#include "BinaryPrivateSemaphore.hpp" // for BPS
#include "CountingPrivateSemaphore.hpp" // for CPS
#include "Fiber.hpp" // for Fiber
#include "Runtime.hpp" // for Runtime
#include "emper.hpp" // for spawn
class AlarmActor : public Actor<BPS*> {
protected:
void receive(BPS* sem) override { sem->signal(); }
public:
AlarmActor(Runtime& runtime) : Actor(runtime) {}
void stop() { Actor::stop(); }
};
auto main(int argc, char* argv[]) -> int {
unsigned int sleeper_count = 10;
unsigned int sleeps = 1000;
if (argc > 3) {
std::cerr << "Usage: " << argv[0] << " [fiber count] [block count]" << std::endl;
exit(EXIT_FAILURE);
}
const int DECIMAL = 10;
if (argc > 1) {
sleeper_count = strtol(argv[1], nullptr, DECIMAL);
}
if (argc > 2) {
sleeps = strtol(argv[2], nullptr, DECIMAL);
}
Runtime runtime;
AlarmActor alarmActor(runtime);
alarmActor.start();
Fiber* fiber = Fiber::from([&] {
CPS cps;
for (unsigned int i = 0; i < sleeper_count; ++i) {
spawn(
[&alarmActor, &sleeps] {
for (unsigned int i = 1; i <= sleeps; ++i) {
BPS sem;
alarmActor.tell(&sem);
sem.wait();
}
},
cps);
}
// Wait for the sleeping fibers to finish
cps.wait();
// Wait for the actor to become idle.
bool actorIdle = alarmActor.waitUntilIdle(60 * 1000);
if (!actorIdle) {
std::cerr << "FAILURE: Actor did not went idle";
exit(EXIT_FAILURE);
}
alarmActor.stop();
exit(EXIT_SUCCESS);
});
runtime.schedule(*fiber);
runtime.waitUntilFinished();
return EXIT_FAILURE;
}
......@@ -29,6 +29,11 @@ tests = {
'description': 'Simple Actor Test',
},
'AlarmActorTest.cpp':
{
'description': 'Use an Actor to unblock fibers using BPS',
},
'SimpleLawsTest.cpp':
{
'description': 'Simple LAWS scheduling strategy test',
......
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