From 973a473c0ea135c0bf922e2c0fb0f80877d7091a Mon Sep 17 00:00:00 2001 From: Patrick Herrington Date: Tue, 26 Nov 2024 17:18:58 -0600 Subject: [PATCH] Added old trickify test --- test/SIM_trickified/RUN_test/unit_test.py | 4 ++ test/SIM_trickified/S_define | 21 ++++++++++ test/SIM_trickified/S_overrides.mk | 2 + test/SIM_trickified/models/Baz.hh | 9 +++++ .../trickified_project/include/Bar.hh | 17 +++++++++ .../trickified_project/include/Foo.hh | 15 ++++++++ .../trickified_project/trickified/.gitignore | 4 ++ .../trickified_project/trickified/Makefile | 11 ++++++ .../trickified/myproject.mk | 38 +++++++++++++++++++ test_sims.yml | 7 ++++ 10 files changed, 128 insertions(+) create mode 100644 test/SIM_trickified/RUN_test/unit_test.py create mode 100644 test/SIM_trickified/S_define create mode 100644 test/SIM_trickified/S_overrides.mk create mode 100644 test/SIM_trickified/models/Baz.hh create mode 100644 test/SIM_trickified/trickified_project/include/Bar.hh create mode 100644 test/SIM_trickified/trickified_project/include/Foo.hh create mode 100644 test/SIM_trickified/trickified_project/trickified/.gitignore create mode 100644 test/SIM_trickified/trickified_project/trickified/Makefile create mode 100644 test/SIM_trickified/trickified_project/trickified/myproject.mk diff --git a/test/SIM_trickified/RUN_test/unit_test.py b/test/SIM_trickified/RUN_test/unit_test.py new file mode 100644 index 00000000..f74fee0b --- /dev/null +++ b/test/SIM_trickified/RUN_test/unit_test.py @@ -0,0 +1,4 @@ +sandbox.foo.i = 5 +assert sandbox.foo.i == 5 +foo = trick.Foo() +trick.stop(10) diff --git a/test/SIM_trickified/S_define b/test/SIM_trickified/S_define new file mode 100644 index 00000000..f770e2a7 --- /dev/null +++ b/test/SIM_trickified/S_define @@ -0,0 +1,21 @@ +#include "sim_objects/default_trick_sys.sm" +##include "Foo.hh" +##include "Bar.hh" +##include "Baz.hh" + +class Sandbox : public Trick::SimObject { + + public: + + Foo foo; + Bar bar; + Baz baz; + + Sandbox() { + (1, "scheduled") foo.foo(); + } + +}; + + +Sandbox sandbox; diff --git a/test/SIM_trickified/S_overrides.mk b/test/SIM_trickified/S_overrides.mk new file mode 100644 index 00000000..ad344832 --- /dev/null +++ b/test/SIM_trickified/S_overrides.mk @@ -0,0 +1,2 @@ +include trickified_project/trickified/myproject.mk +TRICK_CXXFLAGS += -I$(CURDIR)/models diff --git a/test/SIM_trickified/models/Baz.hh b/test/SIM_trickified/models/Baz.hh new file mode 100644 index 00000000..fc91c1b2 --- /dev/null +++ b/test/SIM_trickified/models/Baz.hh @@ -0,0 +1,9 @@ +// @trick_parse{everything} + +class Baz { + + public: + int i; + int j; + +}; diff --git a/test/SIM_trickified/trickified_project/include/Bar.hh b/test/SIM_trickified/trickified_project/include/Bar.hh new file mode 100644 index 00000000..5640bfb0 --- /dev/null +++ b/test/SIM_trickified/trickified_project/include/Bar.hh @@ -0,0 +1,17 @@ +// @trick_parse{everything} + +#include "trick/Event.hh" + +/** + * Induce an `%import sim_services` statement in this class's Python module by inheriting from a + * Trick class. This allows us to test if `sys.path` contains the correct path to `sim_services.py` + * (and other modules generated during a sim build) for Trickified projects. + */ +class Bar : public Trick::Event { + + int process(long long) {return 0;} + void add() {} + void remove() {} + void restart() {} + +}; diff --git a/test/SIM_trickified/trickified_project/include/Foo.hh b/test/SIM_trickified/trickified_project/include/Foo.hh new file mode 100644 index 00000000..be7e761a --- /dev/null +++ b/test/SIM_trickified/trickified_project/include/Foo.hh @@ -0,0 +1,15 @@ +// @trick_parse{everything} + +#include + +class Foo { + + public: + + int i; + + void foo() { + std::cout << i++ << '\n'; + } + +}; diff --git a/test/SIM_trickified/trickified_project/trickified/.gitignore b/test/SIM_trickified/trickified_project/trickified/.gitignore new file mode 100644 index 00000000..0259157c --- /dev/null +++ b/test/SIM_trickified/trickified_project/trickified/.gitignore @@ -0,0 +1,4 @@ +build +python +trick +*.o diff --git a/test/SIM_trickified/trickified_project/trickified/Makefile b/test/SIM_trickified/trickified_project/trickified/Makefile new file mode 100644 index 00000000..ae6eb310 --- /dev/null +++ b/test/SIM_trickified/trickified_project/trickified/Makefile @@ -0,0 +1,11 @@ +PROJECT_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..) +TRICK_HOME := $(abspath $(PROJECT_HOME)/../../..) + +export TRICKIFY_OBJECT_NAME := trickified_myproject.o +export TRICKIFY_CXX_FLAGS := -I$(PROJECT_HOME)/include -I$(TRICK_HOME)/include + +all: + @$(MAKE) -s -f $(TRICK_HOME)/share/trick/makefiles/trickify.mk + +clean: + @rm -rf build python trick $(TRICKIFY_OBJECT_NAME) diff --git a/test/SIM_trickified/trickified_project/trickified/myproject.mk b/test/SIM_trickified/trickified_project/trickified/myproject.mk new file mode 100644 index 00000000..7abe9af1 --- /dev/null +++ b/test/SIM_trickified/trickified_project/trickified/myproject.mk @@ -0,0 +1,38 @@ +# We know this file's position relative to the root directory of the project, +# and MAKEFILE_LIST will give us the full path to this file no matter where the +# user has installed this project. +export MYPROJECT_HOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST)))/..) + +# Specify include paths for your headers. +MYPROJECT_INCLUDE := -I$(MYPROJECT_HOME)/include + +# Users may set different flags for C and C++, so you should really modify both +# to be safe. +TRICK_CFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) +TRICK_CXXFLAGS += $(MYPROJECT_INCLUDE) $(MYPROJECT_SOURCE) + +MYPROJECT_TRICK := $(MYPROJECT_HOME)/trickified/trickified_myproject.o + +# Tell Trick the headers and source at this location are part of a +# Trickified project +TRICK_EXT_LIB_DIRS += :$(MYPROJECT_HOME) + +# Tell Trick where to find the Python modules generated by SWIG +TRICK_PYTHON_PATH += :$(MYPROJECT_HOME)/trickified/python + +# Tell SWIG where to find py_*.i files +TRICK_SWIG_FLAGS += -I$(MYPROJECT_HOME)/trickified + +# Link in the Trickified object +TRICK_LDFLAGS += $(MYPROJECT_TRICK) + +# Append a prerequisite to the $(SWIG_SRC) target. This will build the +# Trickified library along with the sim if it does not already exist. Using +# $(SWIG_SRC) ensures that all Trickified .i files are created before SWIG is +# run on any simulation .i files, which may %import them. Note that this does +# NOT cause the Trickified library to be rebuilt if it already exists, even if +# the Trickified source code has changed. +$(SWIG_SRC): $(MYPROJECT_TRICK) + +$(MYPROJECT_TRICK): + @$(MAKE) -s -C $(MYPROJECT_HOME)/trickified diff --git a/test_sims.yml b/test_sims.yml index d0ec3077..e30d9cf5 100644 --- a/test_sims.yml +++ b/test_sims.yml @@ -114,6 +114,13 @@ SIM_threads: runs: RUN_test/unit_test.py: returns: 0 +SIM_trickified: + path: test/SIM_trickified + build_args: "-t" + binary: "T_main_{cpu}_test.exe" + runs: + RUN_test/unit_test.py: + returns: 0 SIM_trickified_object: path: test/SIM_trickified_object build_args: "-t"