Skip to content

Commit

Permalink
* Fixed support for no_karl option in MADARA
Browse files Browse the repository at this point in the history
  * Should work with tools and tests. May not work with tutorials.
  * no_karl disables all support for karl evaluation
  * can aid with systems that can't work with RTTI support in C++
  • Loading branch information
jredmondson committed Mar 8, 2019
1 parent 005e34e commit 6f91034
Show file tree
Hide file tree
Showing 15 changed files with 96 additions and 288 deletions.
18 changes: 1 addition & 17 deletions Madara.mpc
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ project (Madara) : build_files, using_splice, splice_transport, using_ndds, mada
}
}

project (Madara_Version) : using_madara {
project (Madara_Version) : using_madara, no_karl {
exeout = $(MADARA_ROOT)/bin
exename = madara_version

Expand Down Expand Up @@ -224,19 +224,3 @@ project (Madara_Registry) : using_madara, no_karl {
tools/madara_registry.cpp
}
}


project (MPGen) : using_madara {
exeout = $(MADARA_ROOT)/bin
exename = mpgen

Documentation_Files {
}

Header_Files {
}

Source_Files {
tools/mpgen.cpp
}
}
4 changes: 2 additions & 2 deletions include/madara/knowledge/KnowledgeBaseImpl.inl
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,13 @@ inline VariableReferences KnowledgeBaseImpl::save_modifieds(void) const
return map_.save_modifieds();
}

#ifndef _MADARA_NO_KARL_

inline void KnowledgeBaseImpl::wait_for_change(void)
{
map_.wait_for_change();
}

#ifndef _MADARA_NO_KARL_

inline KnowledgeRecord KnowledgeBaseImpl::evaluate(
const std::string& expression, const EvalSettings& settings)
{
Expand Down
6 changes: 6 additions & 0 deletions include/madara/knowledge/ThreadSafeContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2191,9 +2191,15 @@ madara::knowledge::KnowledgeRecord ThreadSafeContext::evaluate_file(
" opening file %s\n",
checkpoint_settings.filename.c_str());

#ifndef _MADARA_NO_KARL_

CompiledExpression expression = compile(file_to_string(checkpoint_settings));

return evaluate(expression, update_settings);
#else // if KARL has been disabled
KnowledgeRecord result;
return result;
#endif
}

std::string ThreadSafeContext::file_to_string(
Expand Down
12 changes: 12 additions & 0 deletions include/madara/transport/QoSTransportSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,8 +844,14 @@ void madara::transport::QoSTransportSettings::load_text(
TransportSettings::load_text(filename, prefix);

knowledge::KnowledgeBase knowledge;


#ifndef _MADARA_NO_KARL_

knowledge.evaluate(madara::utility::file_to_string(filename));

#endif // end karl support

containers::Map trusted_peers(prefix + ".trusted_peers", knowledge);
containers::Map banned_peers(prefix + ".banned_peers", knowledge);

Expand Down Expand Up @@ -932,8 +938,14 @@ void madara::transport::QoSTransportSettings::save_text(

// then load the savings
knowledge::KnowledgeBase knowledge;

#ifndef _MADARA_NO_KARL_

knowledge.evaluate(madara::utility::file_to_string(filename));

#endif // end karl support


containers::Map trusted_peers(prefix + ".trusted_peers", knowledge);
containers::Map banned_peers(prefix + ".banned_peers", knowledge);

Expand Down
11 changes: 11 additions & 0 deletions include/madara/transport/TransportSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,14 @@ void madara::transport::TransportSettings::load_text(
const std::string& filename, const std::string& prefix)
{
knowledge::KnowledgeBase knowledge;

#ifndef _MADARA_NO_KARL_

knowledge.evaluate(madara::utility::file_to_string(filename));

#endif // end karl support


read_threads = (uint32_t)knowledge.get(prefix + ".read_threads").to_integer();
write_domain = knowledge.get(prefix + ".write_domain").to_string();
queue_length = (uint32_t)knowledge.get(prefix + ".queue_length").to_integer();
Expand Down Expand Up @@ -298,8 +304,13 @@ void madara::transport::TransportSettings::save_text(
knowledge::KnowledgeBase knowledge;

// load what exists at the file so we can append/overwrite it
#ifndef _MADARA_NO_KARL_

knowledge.evaluate(madara::utility::file_to_string(filename));

#endif // end karl support


containers::StringVector kb_hosts(
prefix + ".hosts", knowledge, (int)hosts.size());

Expand Down
8 changes: 8 additions & 0 deletions tests/test_basic_reasoning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,8 @@ void test_arrays(void)

knowledge::KnowledgeBase knowledge;

#ifndef _MADARA_NO_KARL_

madara::knowledge::KnowledgeRecord result =
knowledge.evaluate("my_array = [0, 1, 2]");

Expand All @@ -1554,6 +1556,8 @@ void test_arrays(void)
result.retrieve_index(0).to_integer() == 1 &&
result.retrieve_index(1).to_integer() == 6 &&
result.retrieve_index(2).to_integer() == 2);

#endif // end karl evaluation supported
}

#define MADARA_TEST_TRIOP(lhs, op, rhs, method, cmp, target) \
Expand Down Expand Up @@ -1629,11 +1633,15 @@ void test_reserved_words(void)
{
madara::knowledge::KnowledgeBase kb;

#ifndef _MADARA_NO_KARL_

kb.evaluate("var_inf = inf");
kb.evaluate("var_nan = nan");
kb.evaluate("var_true = true");
kb.evaluate("var_false = false");

assert(kb.get("var_nan") == NAN && kb.get("var_inf") == INFINITY &&
kb.get("var_true") == 1 && kb.get("var_false") == 0);

#endif // end karl evaluation support
}
4 changes: 4 additions & 0 deletions tests/test_checkpointing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,13 @@ void test_checkpoint_settings(void)
saver.set("int_array", integers);
saver.set("double_array", doubles);

#ifndef _MADARA_NO_KARL_

// set the system lamport clock to something arbitrary
saver.evaluate("#set_clock (2001)");

#endif // end karl support

settings.filename = "test_context_save_1.kb";
settings.clear_knowledge = true;

Expand Down
13 changes: 13 additions & 0 deletions tests/test_filters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ void test_fragments_to_files_filter(void)
}
void test_dynamic_predicate_filter(void)
{

#ifndef _MADARA_NO_KARL_

madara::knowledge::KnowledgeBase kb;
madara::knowledge::Variables vars(&kb.get_context());

Expand Down Expand Up @@ -250,10 +253,14 @@ void test_dynamic_predicate_filter(void)
}
++madara_fails;
}

#endif // end karl supported
}

void test_dynamic_prefix_filter(void)
{
#ifndef _MADARA_NO_KARL_

madara::knowledge::KnowledgeBase kb;
madara::knowledge::Variables vars(&kb.get_context());

Expand Down Expand Up @@ -289,10 +296,14 @@ void test_dynamic_prefix_filter(void)
std::cerr << "FAIL\n";
++madara_fails;
}

#endif // end karl evaluation support
}

void test_dynamic_prefix_int_convert(void)
{
#ifndef _MADARA_NO_KARL_

madara::knowledge::KnowledgeBase kb;
madara::knowledge::Variables vars(&kb.get_context());

Expand Down Expand Up @@ -339,6 +350,8 @@ void test_dynamic_prefix_int_convert(void)

++madara_fails;
}

#endif // end karl evaluation support
}

void test_prefix_int_convert(void)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_karl_exceptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace logger = madara::logger;

int madara_fails(0);

#ifndef _MADARA_NO_KARL_

void test_functions(void)
{
std::cerr << "#####################\n";
Expand Down Expand Up @@ -541,14 +543,19 @@ void test_unitialized(void)

}

#endif // end karl supported

int main(int, char**)
{
#ifndef _MADARA_NO_KARL_

test_functions();
test_nan();
test_min();
test_empty_assignment();
test_bad_operators();
test_unitialized();
#endif // end karl supported

if(madara_fails > 0)
{
Expand Down
8 changes: 1 addition & 7 deletions tests/test_reasoning_throughput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ madara::knowledge::KnowledgeRecord increment_var1(
return variables.evaluate(
increment_ce, madara::knowledge::KnowledgeUpdateSettings(false, false));
#else
return Integer(0);
return madara::knowledge::KnowledgeRecord();
#endif // _MADARA_NO_KARL_
}

Expand Down Expand Up @@ -1292,8 +1292,6 @@ uint64_t test_stl_inc_atomic(
uint64_t measured(0);
madara::utility::Timer<Clock> timer;

madara::knowledge::CompiledExpression ce;

std::atomic<long> counter;

timer.start();
Expand Down Expand Up @@ -1321,8 +1319,6 @@ uint64_t test_stl_inc_recursive(
uint64_t measured(0);
madara::utility::Timer<Clock> timer;

madara::knowledge::CompiledExpression ce;

long counter = 0;
std::recursive_mutex critical_section;

Expand Down Expand Up @@ -1353,8 +1349,6 @@ uint64_t test_stl_inc_mutex(
uint64_t measured(0);
madara::utility::Timer<Clock> timer;

madara::knowledge::CompiledExpression ce;

long counter = 0;
std::mutex critical_section;

Expand Down
4 changes: 4 additions & 0 deletions tests/transports/test_synchronization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,12 @@ int main(int argc, char ** argv)
// read madara initialization
if (madara_commands != "")
{
#ifndef _MADARA_NO_KARL_

kb.evaluate(madara_commands,
knowledge::EvalSettings(false, true));

#endif // end karl support
}

// begin thread creation
Expand Down
4 changes: 4 additions & 0 deletions tests/transports/test_synchronization_three_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,12 @@ int main(int argc, char ** argv)
// read madara initialization
if (madara_commands != "")
{
#ifndef _MADARA_NO_KARL_

kb.evaluate(madara_commands,
knowledge::EvalSettings(false, true));

#endif // end karl support
}

// begin thread creation
Expand Down
12 changes: 8 additions & 4 deletions tools/karl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,8 @@ void print_all_prefixes(knowledge::KnowledgeBase& context)
}
}

#ifndef _MADARA_NO_KARL_

class Evaluator : public threads::BaseThread
{
public:
Expand Down Expand Up @@ -1418,6 +1420,8 @@ class Evaluator : public threads::BaseThread
std::vector<knowledge::CompiledExpression>& expressions_;
};

#endif // end karl language enabled

int main(int argc, char** argv)
{
// load and incorporate the defaul karl config file arguments, but only once
Expand Down Expand Up @@ -1543,6 +1547,8 @@ int main(int argc, char** argv)
}
}

#ifndef _MADARA_NO_KARL_

// build the expressions to evaluate
std::vector<knowledge::CompiledExpression> expressions;

Expand Down Expand Up @@ -1656,15 +1662,13 @@ int main(int argc, char** argv)
" Evaluating expression %zu:\n", i);
}

#ifndef _MADARA_NO_KARL_
knowledge::KnowledgeRecord result =
kb.evaluate(expressions[i], knowledge::EvalSettings::SEND);

if(check_result && result.is_true())
{
break;
}
#endif // _MADARA_NO_KARL_
}
}

Expand Down Expand Up @@ -1696,15 +1700,13 @@ int main(int argc, char** argv)
" Evaluating expression %zu:\n", i);
}

#ifndef _MADARA_NO_KARL_
knowledge::KnowledgeRecord result =
kb.evaluate(expressions[i], madara::knowledge::EvalSettings::SEND);

if(check_result && result.is_true())
{
break;
}
#endif // _MADARA_NO_KARL_
}

} // if(after_wait)
Expand Down Expand Up @@ -1803,5 +1805,7 @@ int main(int argc, char** argv)
kb.save_context(save_checkpoint_settings);
}

#endif // _MADARA_NO_KARL_

return 0;
}

0 comments on commit 6f91034

Please sign in to comment.