Commit c024f79f authored by Noah Orensa's avatar Noah Orensa
Browse files

add getter for worker id

parent 3b23f3f5
......@@ -18,6 +18,8 @@ using Status = dtest::Test::Status;
#define module(name) static auto __dtest_concat(__module_controller__uid_, __COUNTER__) = (*(new dtest::ModuleController(name)))
#define dtest_worker_id() dtest::Context::instance()->workerId()
////
#include <dtest_core/unit_test.h>
......
......@@ -226,6 +226,10 @@ public:
static inline Context * instance() {
return _currentCtx;
}
virtual uint32_t workerId() const {
return -1;
}
};
class DriverContext : public Context {
......@@ -390,6 +394,10 @@ public:
void wait(uint32_t n = -1u) override;
static Lazy<WorkerContext> instance;
uint32_t workerId() const override {
return _id;
}
};
class AssertionException : public SandboxException {
......
......@@ -85,6 +85,21 @@ dunit("distributed-unit-test", "worker-mem-leak")
assert(true);
});
dunit("unit-test", "worker-id")
.workers(4)
.driver([] {
uint32_t id;
for (auto i = 0; i < 4; ++i) {
dtest_recvMsg() >> id;
std::cout << id << '\n';
}
})
.worker([] {
uint32_t id = dtest_worker_id();
assert(id < 4);
dtest_sendMsg(id);
});
dunit("distributed-unit-test", "wait-notify")
.workers(4)
.driver([] {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment