Skip to content
Snippets Groups Projects
Commit 61d17e0c authored by Thomas Moulard's avatar Thomas Moulard
Browse files

Add tracer test.

parent e933e50d
No related branches found
No related tags found
No related merge requests found
// -*- mode: c++ -*-
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
// JRL, CNRS/AIST.
//
// This file is part of dynamic-graph.
// dynamic-graph is free software: you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation, either version 3 of
// the License, or (at your option) any later version.
//
// dynamic-graph is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Lesser Public License for more details. You should have
// received a copy of the GNU Lesser General Public License along with
// dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
#ifndef DYNAMIC_GRAPH_SHELL_PROCEDURE_H
# define DYNAMIC_GRAPH_SHELL_PROCEDURE_H
# incxlude <string>
# include <map>
# include <sstream>
# include <list>
# include <vector>
# include <dynamic-graph/exception-factory.h>
# include <dynamic-graph/interpreter.h>
# include <dynamic-graph/config-shell-procedure.hh>
/// \ingroup dgraph
///
/// \brief This plugin exposes shell commands relative to the script
/// language constructs such as procedures and for loops.
///
/// For more information, load the plugin and type help in a shell.
class DG_SHELLPROCEDURE_DLLAPI ShellProcedure
{
public:
/// \brief Symbolizes a function call in the dynamic-graph language.
struct Instruction
{
/// \brief Command name.
std::string cmd;
/// \brief Arguments lists.
std::vector<std::string> args;
std::vector<int> params;
};
/// \brief Symbolizes a procedure in the dynamic-graph language.
struct Procedure
{
/// \brief Store the procedure body.
std::list<Instruction> instructions;
/// \brief Store the procedure arguments.
std::vector<std::string> params;
/// \brief Reset the procedure.
void clear ()
{
instructions.clear ();
params.clear ();
}
};
/// \brief Map procedure name to their body.
typedef std::map<std::string, Procedure> ProcedureList;
public:
std::string procName;
ProcedureList procedureList;
Procedure currentProc;
public:
void cmdStartProcedure (const std::string& cmd,
std::istringstream& args,
std::ostream& os);
void cmdContinueProcedure (const std::string& cmd,
std::istringstream& args,
std::ostream& os);
void cmdEndProcedure (const std::string& cmd,
std::istringstream& args,
std::ostream& os);
void cmdProcedure (const std::string& procname,
const std::string& cmd,
std::istringstream& args,
std::ostream& os);
static void cmdFor (const std::string& cmd,
std::istringstream& args,
std::ostream& os);
};
#endif //! DYNAMIC_GRAPH_SHELL_PROCEDURE_H
thomas@cleo.16209:1293725997
\ No newline at end of file
import shell-functions
import "shell-functions"
# DO NOT MOVE THIS LINE: comments are not implemented before.
# Copyright 2010, Thomas Moulard, JRL, CNRS/AIST.
......@@ -20,4 +20,4 @@ import shell-functions
# This file should ALWAYS be imported as it provides core features
# such as comments.
import shell-procedure
import "shell-procedure"
import shell.dg
import "shell.dg"
# Copyright 2010, Thomas Moulard, JRL, CNRS/AIST.
# .
# This file is part of dynamic-graph.
......@@ -19,5 +19,5 @@ import shell.dg
# The tracer can be used to log signal values without
# intefering with the real-time properties of dynamic-graph.
import tracer-real-time
import tracer
import "tracer-real-time"
import "tracer"
......@@ -62,4 +62,6 @@ DYNAMIC_GRAPH_TEST(custom-entity)
DYNAMIC_GRAPH_TEST(factory)
DYNAMIC_GRAPH_TEST(pool)
DYNAMIC_GRAPH_TEST(signal-time-dependent)
DYNAMIC_GRAPH_TEST(interpreter)
\ No newline at end of file
DYNAMIC_GRAPH_TEST(interpreter)
DYNAMIC_GRAPH_TEST(interpreter-tracer)
import "tracer"
new Tracer tracer
tracer.open /tmp debug.dat
tracer.add tracer.triger
tracer.start
tracer.stop
tracer.clear
tracer.record
tracer.close
// Copyright 2010 Thomas Moulard.
//
// This file is part of dynamic-graph.
// dynamic-graph is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// dynamic-graph is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
#include <sstream>
#include <dynamic-graph/exception-factory.h>
#include <dynamic-graph/interpreter.h>
#include <dynamic-graph/plugin-loader.h>
#define BOOST_TEST_MODULE tracer
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
#include "interpreter.h"
using boost::test_tools::output_test_stream;
// Check that plug-in loading/unloading is working.
BOOST_AUTO_TEST_CASE (cmd_tracer)
{
dynamicgraph::PluginLoader pl;
dynamicgraph::Interpreter shell (&pl);
// Push paths.
{
RUN_COMMAND ("pushImportPaths", TESTS_DATADIR);
BOOST_CHECK (output.is_empty ());
}
{
RUN_COMMAND ("pushImportPaths", TESTS_PLUGINDIR);
BOOST_CHECK (output.is_empty ());
}
// Import tracer.dg
{
RUN_COMMAND ("import", "interpreter-tracer.dg");
BOOST_CHECK (output.is_empty ());
}
}
......@@ -23,6 +23,8 @@
#include <boost/test/unit_test.hpp>
#include <boost/test/output_test_stream.hpp>
#include "interpreter.h"
using boost::test_tools::output_test_stream;
// This unit test checks the dynamic-graph interpreter
......@@ -31,23 +33,6 @@ using boost::test_tools::output_test_stream;
// It may be split in several tests in the future if this
// becomes too big.
#define RUN_COMMAND(CMD, ARGS) \
output_test_stream output; \
std::stringstream ss; \
std::string cmd = CMD; \
ss << ARGS; \
std::istringstream args (ss.str ()); \
shell.cmd (cmd, args, output)
#define RUN_COMMAND_NOARG(CMD) \
output_test_stream output; \
std::stringstream ss; \
std::string cmd = CMD; \
std::istringstream args (ss.str ()); \
shell.cmd (cmd, args, output)
// Simple test to check the shell default constructor.
BOOST_AUTO_TEST_CASE (constructor)
{
......
// Copyright 2010 Thomas Moulard.
//
// This file is part of dynamic-graph.
// dynamic-graph is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// dynamic-graph is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with dynamic-graph. If not, see <http://www.gnu.org/licenses/>.
#ifndef DYNAMIC_GRAPH_TESTS_INTERPRETER_H
# define DYNAMIC_GRAPH_TESTS_INTERPRETER_H
# define RUN_COMMAND(CMD, ARGS) \
output_test_stream output; \
std::stringstream ss; \
std::string cmd = CMD; \
ss << ARGS; \
std::istringstream args (ss.str ()); \
shell.cmd (cmd, args, output)
# define RUN_COMMAND_NOARG(CMD) \
output_test_stream output; \
std::stringstream ss; \
std::string cmd = CMD; \
std::istringstream args (ss.str ()); \
shell.cmd (cmd, args, output)
#endif //! DYNAMIC_GRAPH_TESTS_INTERPRETER_H
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