summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2014-06-03 16:16:41 +0000
committerrandomdan <randomdan@localhost>2014-06-03 16:16:41 +0000
commit1028d3af2736520f7cc39e0ff8a83ee693c13e34 (patch)
treed746f2923aadc840bde85c9f9bbd6d456796ce88
parentSplit out ICE support from project jam file, add support for slicer (diff)
downloadslicer-1028d3af2736520f7cc39e0ff8a83ee693c13e34.tar.bz2
slicer-1028d3af2736520f7cc39e0ff8a83ee693c13e34.tar.xz
slicer-1028d3af2736520f7cc39e0ff8a83ee693c13e34.zip
Update tests to perform an end-to-end (albeit non-validating) slice, slicer, compile, link, load and run
-rw-r--r--slicer/slicer/parser.cpp15
-rw-r--r--slicer/slicer/parser.h4
-rw-r--r--slicer/test/Jamfile.jam58
-rw-r--r--slicer/test/do-slicer.cpp52
-rw-r--r--slicer/test/helpers.cpp32
-rw-r--r--slicer/test/helpers.h18
-rw-r--r--slicer/test/run-slicer.cpp34
-rw-r--r--slicer/test/types.ice4
8 files changed, 203 insertions, 14 deletions
diff --git a/slicer/slicer/parser.cpp b/slicer/slicer/parser.cpp
index a67f483..fd1d9b1 100644
--- a/slicer/slicer/parser.cpp
+++ b/slicer/slicer/parser.cpp
@@ -5,6 +5,9 @@
#include <boost/algorithm/string/predicate.hpp>
#include <Slice/CPlusPlusUtil.h>
#include <boost/shared_ptr.hpp>
+#include <boost/filesystem/convenience.hpp>
+
+namespace fs = boost::filesystem;
namespace Slicer {
Slicer::Slicer(FILE * c) :
@@ -12,16 +15,20 @@ namespace Slicer {
{
}
- void
- Slicer::leadIn()
+ bool
+ Slicer::visitUnitStart(const Slice::UnitPtr & u)
{
+ fs::path topLevelFile(u->topLevelFile());
+
fprintf(cpp, "// Begin Slicer code\n\n");
+ fprintf(cpp, "#include <%s>\n\n", fs::change_extension(topLevelFile.filename(), ".h").string().c_str());
fprintf(cpp, "#include <slicer/modelParts.h>\n\n");
fprintf(cpp, "namespace Slicer {\n");
+ return true;
}
void
- Slicer::leadOut()
+ Slicer::visitUnitEnd(const Slice::UnitPtr&)
{
fprintf(cpp, "}\n\n");
fprintf(cpp, "// End Slicer code\n\n");
@@ -258,9 +265,7 @@ namespace Slicer {
}
Slicer s(cppfile.get());
- s.leadIn();
u->visit(&s, false);
- s.leadOut();
u->destroy();
}
diff --git a/slicer/slicer/parser.h b/slicer/slicer/parser.h
index c660cc6..90aa05a 100644
--- a/slicer/slicer/parser.h
+++ b/slicer/slicer/parser.h
@@ -14,9 +14,9 @@ namespace Slicer {
static void Apply(const boost::filesystem::path & ice, const boost::filesystem::path & cpp);
- void leadIn();
+ virtual bool visitUnitStart(const Slice::UnitPtr&) override;
- void leadOut();
+ virtual void visitUnitEnd(const Slice::UnitPtr&) override;
virtual bool visitModuleStart(const Slice::ModulePtr & m) override;
diff --git a/slicer/test/Jamfile.jam b/slicer/test/Jamfile.jam
index b4e05b3..88c981f 100644
--- a/slicer/test/Jamfile.jam
+++ b/slicer/test/Jamfile.jam
@@ -1,3 +1,59 @@
import testing ;
-run do-slicer.cpp ../slicer//slicer : : types.ice ;
+lib dl ;
+lib pthread ;
+lib Ice ;
+lib IceUtil ;
+lib boost_system ;
+lib boost_filesystem ;
+lib slicer-test : : <name>slicertypes <search>bin/slicer ;
+
+lib types :
+ types.ice
+ :
+ <library>pthread
+ <library>Ice
+ <library>IceUtil
+ ;
+
+lib common :
+ helpers.cpp
+ ../../libmisc/misc.cpp
+ :
+ <library>dl
+ <library>boost_system
+ <library>boost_filesystem
+ : :
+ <library>boost_filesystem
+ <library>boost_system
+ ;
+
+unit-test do-slicer :
+ types
+ common
+ do-slicer.cpp
+ :
+ <library>dl
+ <include>..
+ <library>pthread
+ <library>Ice
+ <library>IceUtil
+ <library>../slicer//slicer
+ <implicit-dependency>types
+ ;
+
+unit-test run-slicer :
+ run-slicer.cpp
+ types
+ common
+ :
+ <implicit-dependency>types
+ <dependency>do-slicer
+ <library>slicer-test
+ <include>..
+ <library>pthread
+ <library>Ice
+ <library>IceUtil
+ <library>../slicer//slicer
+ <library>../xml//slicer-xml
+;
diff --git a/slicer/test/do-slicer.cpp b/slicer/test/do-slicer.cpp
index 8b03a7d..30c5cfb 100644
--- a/slicer/test/do-slicer.cpp
+++ b/slicer/test/do-slicer.cpp
@@ -1,12 +1,60 @@
#include <slicer/parser.h>
#include <boost/filesystem/convenience.hpp>
#include <boost/filesystem/operations.hpp>
+#include <boost/format.hpp>
+#include <boost/function.hpp>
+#include "../../libmisc/misc.h"
+#include <types.h>
+#include "helpers.h"
+
+namespace fs = boost::filesystem;
int
main(int, char ** argv)
{
- const boost::filesystem::path slice = argv[1];
- Slicer::Slicer::Apply(slice, "/dev/null");
+ const fs::path me = argv[0];
+ const fs::path base = "types";
+ const fs::path bjamout = me.parent_path();
+ const fs::path root = me.parent_path().parent_path().parent_path().parent_path();
+ fprintf(stderr, "root -- %s\n", root.string().c_str());
+ const fs::path slice = fs::change_extension(root / base, ".ice");
+ fprintf(stderr, "slice - %s\n", slice.string().c_str());
+
+ // Tmp
+ const fs::path tmp = root / "bin" / "slicer";
+ fprintf(stderr, "tmp --- %s\n", tmp.string().c_str());
+ fs::create_directory(tmp);
+
+ // Slicer
+ const fs::path cpp = fs::change_extension(tmp / base, ".cpp");
+ fprintf(stderr, "cpp --- %s\n", cpp.string().c_str());
+ fs::remove(cpp);
+ Slicer::Slicer::Apply(slice, cpp);
+
+ // Compile
+ const fs::path obj = fs::change_extension(tmp / base, ".o");
+ fprintf(stderr, "obj --- %s\n", obj.string().c_str());
+ system(stringbf(
+ "g++ -Os -fPIC -c -std=c++0x -I tmp -I /usr/include/Ice -I /usr/include/IceUtil -I %s -I %s %s -o %s",
+ bjamout,
+ root / "..",
+ cpp, obj));
+
+ // Link
+ const fs::path so = fs::change_extension(tmp / ("libslicer" + slice.filename().string()), ".so");
+ fprintf(stderr, "so ---- %s\n", so.string().c_str());
+ system(stringbf(
+ "g++ -shared -lIce -lIceUtil %s/lib%s.so %s -o %s",
+ bjamout, base,
+ obj, so));
+
+ // Load
+ fprintf(stderr, "load -- %s\n", so.string().c_str());
+ auto handle = loadlib(so);
+
+ // Unload
+ fprintf(stderr, "unload %p\n", handle);
+ closelib(handle);
return 0;
}
diff --git a/slicer/test/helpers.cpp b/slicer/test/helpers.cpp
new file mode 100644
index 0000000..5527f5a
--- /dev/null
+++ b/slicer/test/helpers.cpp
@@ -0,0 +1,32 @@
+#include "helpers.h"
+#include <stdexcept>
+#include <stdlib.h>
+#include <dlfcn.h>
+
+void
+system(const std::string & cmd)
+{
+ if (system(cmd.c_str())) {
+ fprintf(stderr, "Failed to execute:\n\t%s\n", cmd.c_str());
+ throw std::runtime_error(cmd);
+ }
+}
+
+void *
+loadlib(const boost::filesystem::path & so)
+{
+ auto handle = dlopen(so.string().c_str(), RTLD_NOW | RTLD_GLOBAL);
+ if (!handle) {
+ throw std::runtime_error(dlerror());
+ }
+ return handle;
+}
+
+void
+closelib(void * handle)
+{
+ if (dlclose(handle)) {
+ throw std::runtime_error(dlerror());
+ }
+}
+
diff --git a/slicer/test/helpers.h b/slicer/test/helpers.h
new file mode 100644
index 0000000..f8f7a7d
--- /dev/null
+++ b/slicer/test/helpers.h
@@ -0,0 +1,18 @@
+#ifndef SLICER_TEST_HELPERS_H
+#define SLICER_TEST_HELPERS_H
+
+#include <string>
+#include <boost/filesystem/path.hpp>
+
+// These are just thin wrappers that throw exceptions
+void
+system(const std::string &);
+
+void *
+loadlib(const boost::filesystem::path &);
+
+void
+closelib(void *);
+
+#endif
+
diff --git a/slicer/test/run-slicer.cpp b/slicer/test/run-slicer.cpp
new file mode 100644
index 0000000..6a73736
--- /dev/null
+++ b/slicer/test/run-slicer.cpp
@@ -0,0 +1,34 @@
+#include <slicer/parser.h>
+#include <slicer/slicer.h>
+#include <xml/serializer.h>
+#include <boost/filesystem/convenience.hpp>
+#include <boost/filesystem/operations.hpp>
+#include <boost/format.hpp>
+#include <boost/function.hpp>
+#include <types.h>
+
+namespace fs = boost::filesystem;
+
+int
+main(int, char ** argv)
+{
+ const fs::path me = argv[0];
+ const fs::path base = "types";
+ const fs::path bjamout = me.parent_path();
+ const fs::path root = me.parent_path().parent_path().parent_path().parent_path();
+ fprintf(stderr, "root -- %s\n", root.string().c_str());
+ const fs::path slice = fs::change_extension(root / base, ".ice");
+ fprintf(stderr, "slice - %s\n", slice.string().c_str());
+
+ // Tmp
+ const fs::path tmp = root / "bin" / "slicer";
+ fprintf(stderr, "tmp --- %s\n", tmp.string().c_str());
+ fs::create_directory(tmp);
+
+ // Execute
+ TestModule::BuiltInsPtr p(new TestModule::BuiltIns());
+ Slicer::Serialize<Slicer::Xml>(p, tmp / "out.xml");
+
+ return 0;
+}
+
diff --git a/slicer/test/types.ice b/slicer/test/types.ice
index fdacb2d..0fef708 100644
--- a/slicer/test/types.ice
+++ b/slicer/test/types.ice
@@ -17,10 +17,6 @@ module TestModule {
int a;
int b;
};
- class Optionals {
- optional(1) int simple;
- optional(2) StructType str;
- };
sequence<ClassType> Classes;
sequence<StructType> Structs;
dictionary<int, ClassType> ClassMap;