Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMem fixes #374

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ compile_commands.json

# NUNIT
*.VisualState.xml
TestResult.xml
TestResults.xml

# Build Results of an ATL Project
[Dd]ebugPS/
Expand Down
3 changes: 3 additions & 0 deletions Core/CLI/src/cli_load_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ bool CommandLineInterface::DoSave(std::vector<std::string>& argv, const std::str
if (thisAgent->SMem->connected() && (thisAgent->SMem->statistics->nodes->get_value() > 0))
{
result = thisAgent->SMem->export_smem(0, export_text, &(err));
if (!result) {
SetError(*err);
}
AddSaveText("# Semantic Memory\n");
if (!DoCLog(LOG_ADD, 0, &export_text, true)) return false;
} else {
Expand Down
56 changes: 12 additions & 44 deletions Core/CLI/src/cli_smem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ bool CommandLineInterface::DoSMem(const char pOp, const std::string* pArg1, cons
}
else if (pOp == 'i')
{
/* Don't think we need clear out anything else any more */

thisAgent->SMem->reinit();
if (thisAgent->SMem->connected()) {
thisAgent->SMem->reinit();
} else {
thisAgent->SMem->attach();
}

PrintCLIMessage("Semantic memory system re-initialized.");
if (thisAgent->SMem->settings->append_db->get_value() == on)
Expand Down Expand Up @@ -403,14 +405,13 @@ bool CommandLineInterface::DoSMem(const char pOp, const std::string* pArg1, cons
std::string* err = new std::string("");
uint64_t lti_id = NIL;

if (pArg2)
if (!thisAgent->SMem->connected())
{
thisAgent->SMem->attach();
if (!thisAgent->SMem->connected())
{
return SetError("Semantic memory database not connected.");
}
return SetError("Cannot export smem: smem database not connected.");
}

if (pArg2)
{
const char* pAttr_c_str = pArg2->c_str();
soar::Lexer lexer(thisAgent, pAttr_c_str);
if (!lexer.get_lexeme()) return SetError("LTI not found.");
Expand Down Expand Up @@ -456,41 +457,8 @@ bool CommandLineInterface::DoSMem(const char pOp, const std::string* pArg1, cons
return false;
}

PrintCLIMessage("Exported semantic memory to file.");
}
delete err;
return result;
}
else if (pOp == 'x')
{
std::string* err = new std::string("smem_export.soar");
uint64_t lti_id = NIL;

std::string export_text;
bool result = thisAgent->SMem->export_smem(0, export_text, &(err));

if (!result)
{
SetError(*err);
}
else
{
if (!DoCLog(LOG_NEW, err, 0, true))
{
return false;
}

if (!DoCLog(LOG_ADD, 0, &export_text, true))
{
return false;
}

if (!DoCLog(LOG_CLOSE, 0, 0, true))
{
return false;
}

PrintCLIMessage("Exported semantic memory to file.");
tempString << "Exported semantic memory to file '" << pArg1->c_str() << "'.";
PrintCLIMessage(&tempString);
}
delete err;
return result;
Expand Down
4 changes: 4 additions & 0 deletions Core/SoarKernel/src/semantic_memory/smem_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
bool SMem_Manager::export_smem(uint64_t lti_id, std::string& result_text, std::string** err_msg)
{
ltm_set store_set;
if (!connected()) {
(*err_msg)->append("Cannot export semantic memory if it is not connected.");
return false;
}

if (!lti_id)
{
Expand Down
10 changes: 10 additions & 0 deletions UnitTests/SoarTestAgents/testRegression370.soar
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# https://github.com/SoarGroup/Soar/issues/370
# Make sure that smem --init connects smem DB so that --clear doesn't raise an error.
smem --init
smem --clear

sp {pass
(state <S1>)
-->
(succeeded)
}
7 changes: 7 additions & 0 deletions UnitTests/SoarUnitTests/MiscTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ void MiscTests::testWrongAgentWmeFunctions()

}

void MiscTests::testRegression370()
{
source("testRegression370.soar");
agent->RunSelf(5000);
SoarHelper::init_check_to_find_refcount_leaks(agent);
}

void MiscTests::testRHSRand()
{
kernel->AddRhsFunction("failed", Handlers::MyRhsFunctionFailureHandler, 0) ;
Expand Down
2 changes: 2 additions & 0 deletions UnitTests/SoarUnitTests/MiscTests.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class MiscTests : public FunctionalTestHarness

TEST(testWrongAgentWmeFunctions, -1)
void testWrongAgentWmeFunctions();
TEST(testRegression370, -1)
void testRegression370();
TEST(testRHSRand, -1)
void testRHSRand();
TEST(testMultipleKernels, -1)
Expand Down