diff --git a/test/agent/.gitignore b/test/agent/.gitignore index a39bc478f1648bc10c8420d593657451c84907bd..ebd0cf8acc12ad985d1a2264c54d9752ddb23c0c 100644 --- a/test/agent/.gitignore +++ b/test/agent/.gitignore @@ -3,4 +3,5 @@ agent *.txt *.log .gdbinit -*.gdb \ No newline at end of file +*.gdb +*.go \ No newline at end of file diff --git a/test/agent/Makefile.am b/test/agent/Makefile.am index 0427168e28b4b261d468e35cae5d4ff9b663b049..b031ff6e33fcbbc4623bc99f9767336e569d8320 100644 --- a/test/agent/Makefile.am +++ b/test/agent/Makefile.am @@ -17,3 +17,21 @@ agent_exe_SOURCES = \ src/bindings/signal.h agent_exe_LDADD = $(top_builddir)/src/libring.la + +MODULES = \ + agent.scm \ + examples/active-agent.scm \ + examples/passive-agent.scm \ + jami/logger.scm \ + scenarios/peer-monitor/scenario.scm + +GOBJECTS = $(MODULES:%=%.go) + +%.go: % | agent.exe + @echo "agent.exe compile $^" + @ASAN_OPTIONS=alloc_dealloc_mismatch=0:detect_leaks=0 \ + ./agent.exe compile $< $@ + +compile: $(GOBJECTS) + +CLEANFILES = $(GOBJECTS) diff --git a/test/agent/src/main.cpp b/test/agent/src/main.cpp index 8c4da751a178c581a1eb51815778ff7a98e416f1..5a1346571e411a2b3ddac375a82b4868095ebc3f 100644 --- a/test/agent/src/main.cpp +++ b/test/agent/src/main.cpp @@ -33,6 +33,11 @@ struct args { char** argv; }; +static bool streq(const char* A, const char* B) +{ + return 0 == strcmp(A, B); +} + void* main_in_guile(void* args_raw) { @@ -48,18 +53,49 @@ main_in_guile(void* args_raw) return nullptr; } +void* +compile_in_guile(void* args_raw) +{ + struct args* args = static_cast<struct args*>(args_raw); + char buf[4096]; + + if (args->argc < 4) { + fprintf(stderr, "Usage: agent.exe compile FILE OUT\n"); + exit(EXIT_FAILURE); + } + + install_scheme_primitives(); + + snprintf(buf, sizeof(buf), + "(use-modules (system base compile)) (compile-file \"%s\" #:output-file \"%s\")", + args->argv[2], args->argv[3]); + + scm_c_eval_string(buf); + scm_gc(); + + return nullptr; +} + int main(int argc, char* argv[]) { + struct args args = { argc, argv }; + setenv("GUILE_LOAD_PATH", ".", 1); + setenv("GUILE_LOAD_COMPILED_PATH", ".", 1); - /* NOTE! It's very important to initialize the daemon before entering Guile!!! */ - DRing::init(DRing::InitFlag(DRing::DRING_FLAG_DEBUG)); + if (argc > 1 && streq(argv[1], "compile")) { + scm_with_guile(compile_in_guile, (void*)&args); + } else { - AGENT_ASSERT(DRing::start(""), "Failed to start daemon"); + /* NOTE! It's very important to initialize the daemon before entering Guile!!! */ + DRing::init(DRing::InitFlag(DRing::DRING_FLAG_DEBUG)); - struct args args = { argc, argv }; + AGENT_ASSERT(DRing::start(""), "Failed to start daemon"); + + /* Entering guile context - This never returns */ + scm_with_guile(main_in_guile, (void*)&args); + } - /* Entering guile context - This never returns */ - scm_with_guile(main_in_guile, (void*)&args); + exit(EXIT_SUCCESS); }