aboutsummaryrefslogtreecommitdiffstats
path: root/bruiser
diff options
context:
space:
mode:
Diffstat (limited to 'bruiser')
-rw-r--r--bruiser/bruiser-extra.h3
-rw-r--r--bruiser/bruiser.cpp67
-rw-r--r--bruiser/bruiser.h6
-rw-r--r--bruiser/lua-scripts/mutation-example.lua9
4 files changed, 75 insertions, 10 deletions
diff --git a/bruiser/bruiser-extra.h b/bruiser/bruiser-extra.h
index 73ffe3c..a4389f0 100644
--- a/bruiser/bruiser-extra.h
+++ b/bruiser/bruiser-extra.h
@@ -98,7 +98,6 @@ std::vector<std::string> LUA_FUNCS =
"version()",
"clear()",
"m0()",
- "runlua",
"Funcs()",
"Vars()",
"Arrays()",
@@ -111,6 +110,8 @@ std::vector<std::string> LUA_FUNCS =
"showsource",
"readxmlfile",
"extractmutagen",
+ "strainrecognition()",
+ "setmakepath",
"_G",
"_VERSION",
"assert",
diff --git a/bruiser/bruiser.cpp b/bruiser/bruiser.cpp
index 7030377..f9e317d 100644
--- a/bruiser/bruiser.cpp
+++ b/bruiser/bruiser.cpp
@@ -35,6 +35,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*
#include <unistd.h>
#include <sys/time.h>
#include <sys/wait.h>
+#include <thread>
/*LLVM headers*/
#include "clang/AST/AST.h"
#include "clang/AST/ASTConsumer.h"
@@ -82,6 +83,7 @@ namespace
std::vector<std::string> PATH;
std::vector<std::string> SOURCE_FILES;
+ std::string MAKEPATH;
};
struct ShellCache
@@ -1092,22 +1094,49 @@ class LuaWrapper
int BruiserLuaRunMake(lua_State* __ls)
{
- unsigned int result = 0U;
unsigned int args = 0U;
if ((args = lua_gettop(__ls)) != 1U)
{
PRINT_WITH_COLOR_LB(RED, "function was not called by one argument. Run help().");
- return 0;
+ lua_pushnumber(__ls, 1);
+ return 1;
+ }
+
+ std::string makearg = lua_tostring(__ls , 1);
+
+ if (ShellGlobalInstance.MAKEPATH == "")
+ {
+ PRINT_WITH_COLOR_LB(RED, "MAKEPATH is not set. set it using setmakepath or type help.");
+ lua_pushnumber(__ls, 1);
+ return 1;
}
- const char *makepath;
- makepath = lua_tostring(__ls, 1);
+ pid_t pid = fork();
- result = dostring(__ls, makepath, "make");
+ if (pid < 0)
+ {
+ PRINT_WITH_COLOR_LB(RED, "could not fork...");
+ lua_pushnumber(__ls, EXIT_FAILURE);
+ }
+
+ if (pid == 0)
+ {
+ std::cout << BLUE << "MAKEPATH: " << ShellGlobalInstance.MAKEPATH << NORMAL << "\n";
+ std::cout << BLUE << "Running: " << "make -C " << ShellGlobalInstance.MAKEPATH << " " << makearg << NORMAL << "\n";
+ int retval = execl("/usr/bin/make", "make", "-C", ShellGlobalInstance.MAKEPATH.c_str(), makearg.c_str(), NULL);
+ lua_pushnumber(__ls, retval);
+ exit(EXIT_SUCCESS);
+ }
+
+ if (pid > 0)
+ {
+ int status;
+ pid_t returned;
+ returned = waitpid(pid, &status, 0);
+ lua_pushnumber(__ls, returned);
+ }
- lua_pushnumber(__ls, result);
- free((char*)makepath);
return 1;
}
@@ -1220,6 +1249,28 @@ class LuaWrapper
return 1;
}
+ int BruiserLuaStrainRecognition(lua_State* __ls)
+ {
+ unsigned int numthreads = std::thread::hardware_concurrency();
+ lua_pushnumber(__ls, numthreads);
+ return 1;
+ }
+
+ int BruiserLuaSetMakePath(lua_State* __ls)
+ {
+ int numargs = lua_gettop(__ls);
+
+ if (numargs != 1)
+ {
+ PRINT_WITH_COLOR_LB(RED, "wrong number of args. run help.");
+ return 0;
+ }
+
+ ShellGlobalInstance.MAKEPATH = lua_tostring(__ls, 1);
+
+ return 0;
+ }
+
#define LIST_GENERATOR(__x1) \
int List##__x1(lua_State* __ls)\
{\
@@ -1335,6 +1386,8 @@ int main(int argc, const char **argv)
lua_register(LE.GetLuaState(), "historysize", &LuaDispatch<&LuaWrapper::BruiserLuaChangeHistorySize>);
lua_register(LE.GetLuaState(), "showsource", &LuaDispatch<&LuaWrapper::BruiserLuaShowSourcecode>);
lua_register(LE.GetLuaState(), "extractmutagen", &LuaDispatch<&LuaWrapper::BruiserLuaMutagenExtraction>);
+ lua_register(LE.GetLuaState(), "strainrecognition", &LuaDispatch<&LuaWrapper::BruiserLuaStrainRecognition>);
+ lua_register(LE.GetLuaState(), "setmakepath", &LuaDispatch<&LuaWrapper::BruiserLuaSetMakePath>);
/*its just regisering the List function from LuaWrapper with X-macros.*/
#define X(__x1, __x2) lua_register(LE.GetLuaState(), #__x1, &LuaDispatch<&LuaWrapper::List##__x1>);
diff --git a/bruiser/bruiser.h b/bruiser/bruiser.h
index 4c532b3..cf47924 100644
--- a/bruiser/bruiser.h
+++ b/bruiser/bruiser.h
@@ -131,10 +131,12 @@ help CMDHelp[] = {
{"Structs()", "", "lists all available struct declarations", "none", "returns a string array of the structur declarations"},
{"Arrays()", "", "lists all available array declarations", "none", "returns a string array of the array declarations"},
{"Unions()", "", "lists all available union declarations", "none", "returns a string array of the union declarations"},
- {"make()", "", "runs your make command", "", ""},
+ {"make()", "make(\"all\")", "runs your make command", "", ""},
{"historysize()", "historysize(200)", "sets the history size", "[uint history_size]", ""},
{"showsource()", "showsource(1,5,\"test.cpp\")", "shows the source code for the given range and filename", "[uint beginline, uint endline, string filename]", "returns a string array of the returned source file"},
- {"extractmutagen()", "extractmutagen(\"test.cpp\")", "runs m0 on the source(s)", "[string]", "pid"}
+ {"extractmutagen()", "extractmutagen(\"test.cpp\")", "runs m0 on the source(s)", "[string]", "pid"},
+ {"strainrecognition()", "", "", "", ""},
+ {"setmakepath()", "setmakepath(\"../../myproject\")", "tells bruiser where to execute the make command run from make()", "string", "child pid"}
};
/**********************************************************************************************************************/
/**
diff --git a/bruiser/lua-scripts/mutation-example.lua b/bruiser/lua-scripts/mutation-example.lua
new file mode 100644
index 0000000..b863b71
--- /dev/null
+++ b/bruiser/lua-scripts/mutation-example.lua
@@ -0,0 +1,9 @@
+setmakepath("../test/bruisertest")
+make("clean")
+text = hijackmain()
+file = io.open("../test/bruisertest/mutatant.cpp", "w")
+print("------------------------------------------------------------------")
+print(text)
+print("------------------------------------------------------------------")
+file:write(a)
+file:close()