Commit 5ad9992c by Tobias Fuchs

dataflow_cpp: added explicit exception handling, improved unit tests

parent 81ce63c8
...@@ -36,6 +36,9 @@ ...@@ -36,6 +36,9 @@
#include <embb/dataflow/dataflow.h> #include <embb/dataflow/dataflow.h>
#define NUM_SLICES 8
#define TEST_COUNT 12
typedef embb::dataflow::Network<8> MyNetwork; typedef embb::dataflow::Network<8> MyNetwork;
typedef MyNetwork::ConstantSource< int > MyConstantSource; typedef MyNetwork::ConstantSource< int > MyConstantSource;
typedef MyNetwork::Source< int > MySource; typedef MyNetwork::Source< int > MySource;
...@@ -49,8 +52,6 @@ typedef MyNetwork::Sink< int > MySink; ...@@ -49,8 +52,6 @@ typedef MyNetwork::Sink< int > MySink;
typedef MyNetwork::Switch< int > MySwitch; typedef MyNetwork::Switch< int > MySwitch;
typedef MyNetwork::Select< int > MySelect; typedef MyNetwork::Select< int > MySelect;
#define TEST_COUNT 12
embb::base::Atomic<int> source_counter; embb::base::Atomic<int> source_counter;
int source_array[TEST_COUNT]; int source_array[TEST_COUNT];
...@@ -148,13 +149,16 @@ SimpleTest::SimpleTest() { ...@@ -148,13 +149,16 @@ SimpleTest::SimpleTest() {
void SimpleTest::TestBasic() { void SimpleTest::TestBasic() {
// All available cores // All available cores
embb::base::CoreSet core_set(true); embb::base::CoreSet core_set(true);
int num_cores = core_set.Count();
embb::tasks::Node::Initialize( embb::tasks::Node::Initialize(
MTAPI_DOMAIN_ID, MTAPI_DOMAIN_ID,
MTAPI_NODE_ID, MTAPI_NODE_ID,
core_set, core_set,
1024, // max tasks (default: 1024) 1024, // max tasks (default: 1024)
128, // max groups (default: 128) 128, // max groups (default: 128)
128, // max queues (default: 16) // Currently needs to be initialized
// with (max_queues + 1), see defect embb449
num_cores + 1, // max queues (default: 16)
1024, // queue capacity (default: 1024) 1024, // queue capacity (default: 1024)
4 // num priorities (default: 4) 4 // num priorities (default: 4)
); );
...@@ -204,7 +208,12 @@ void SimpleTest::TestBasic() { ...@@ -204,7 +208,12 @@ void SimpleTest::TestBasic() {
network.AddSource(constant); network.AddSource(constant);
network.AddSource(source); network.AddSource(source);
network(); try {
network();
} catch (embb::base::ErrorException & e) {
std::cout << e.What() << std::endl;
break;
}
PT_EXPECT(asink.Check()); PT_EXPECT(asink.Check());
} }
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#include <embb/base/exceptions.h> #include <embb/base/exceptions.h>
#include <embb/tasks/tasks.h> #include <embb/tasks/tasks.h>
#include <iostream>
namespace embb { namespace embb {
namespace tasks { namespace tasks {
...@@ -54,12 +56,17 @@ Queue::Queue(mtapi_uint_t priority, bool ordered) { ...@@ -54,12 +56,17 @@ Queue::Queue(mtapi_uint_t priority, bool ordered) {
mtapi_job_hndl_t job = mtapi_job_get(TASKS_CPP_JOB, domain_id, &status); mtapi_job_hndl_t job = mtapi_job_get(TASKS_CPP_JOB, domain_id, &status);
assert(MTAPI_SUCCESS == status); assert(MTAPI_SUCCESS == status);
handle_ = mtapi_queue_create(MTAPI_QUEUE_ID_NONE, job, &attr, &status); handle_ = mtapi_queue_create(MTAPI_QUEUE_ID_NONE, job, &attr, &status);
// Handle MTAPI error status in appropriate exceptions
if (status == MTAPI_SUCCESS) { if (status == MTAPI_SUCCESS) {
return; return;
} else if (status == MTAPI_ERR_QUEUE_LIMIT) { } else if (status == MTAPI_ERR_QUEUE_LIMIT) {
EMBB_THROW(embb::base::ErrorException, EMBB_THROW(embb::base::ErrorException,
"mtapi::Queue could not be constructed, " "mtapi::Queue could not be constructed, "
"maximum number of queues exceeded"); "maximum number of queues exceeded");
} else if (status == MTAPI_ERR_JOB_INVALID) {
EMBB_THROW(embb::base::ErrorException,
"mtapi::Queue could not be constructed, "
"invalid job");
} else { } else {
EMBB_THROW(embb::base::ErrorException, EMBB_THROW(embb::base::ErrorException,
"mtapi::Queue could not be constructed"); "mtapi::Queue could not be constructed");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment