diff --git a/posix.mak b/posix.mak index 0cca8a08efb..7be92c3debe 100644 --- a/posix.mak +++ b/posix.mak @@ -152,7 +152,7 @@ $(DRUNTIME): $(OBJS) $(SRCS) UT_MODULES:=$(patsubst src/%.d,$(OBJDIR)/%,$(SRCS)) HAS_ADDITIONAL_TESTS:=$(shell test -d test && echo 1) ifeq ($(HAS_ADDITIONAL_TESTS),1) - ADDITIONAL_TESTS:=test/init_fini test/exceptions test/coverage + ADDITIONAL_TESTS:=test/init_fini test/exceptions test/coverage test/profile ADDITIONAL_TESTS+=$(if $(SHARED),test/shared,) endif diff --git a/test/profile/Makefile b/test/profile/Makefile new file mode 100644 index 00000000000..0b97fc8a086 --- /dev/null +++ b/test/profile/Makefile @@ -0,0 +1,59 @@ +# set from top makefile +OS:= +MODEL:= +DMD:= +DRUNTIME:= +DRUNTIMESO:= +QUIET:= +LINKDL:= + +SRC:=src +ROOT:=./obj/$(OS)/$(MODEL) +TESTS:=$(addprefix $(ROOT)/,$(addsuffix .done,profile profilegc both)) + +DIFF:=diff +GREP:=grep + +ifneq (default,$(MODEL)) + MODEL_FLAG:=-m$(MODEL) +endif +CFLAGS:=$(MODEL_FLAG) -Wall +DFLAGS:=$(MODEL_FLAG) -w -I../../src -I../../import -I$(SRC) -L$(DRUNTIME) -defaultlib= -debuglib= + +.PHONY: all clean +all: $(TESTS) + +$(ROOT)/profile.done: DFLAGS+=-profile +$(ROOT)/profile.done: $(ROOT)/%.done: $(ROOT)/% + @echo Testing $* + @rm -f $(ROOT)/mytrace.log $(ROOT)/mytrace.def + $(QUIET)$(ROOT)/$* $(ROOT)/mytrace.log $(ROOT)/mytrace.def + $(QUIET)$(GREP) -q '1 .*_Dmain' $(ROOT)/mytrace.log + $(QUIET)$(GREP) -q '1000 .*uint profile.foo(uint)' $(ROOT)/mytrace.log + $(QUIET)$(DIFF) mytrace.def.exp $(ROOT)/mytrace.def + @touch $@ + +$(ROOT)/profilegc.done: DFLAGS+=-profile=gc +$(ROOT)/profilegc.done: $(ROOT)/%.done: $(ROOT)/% + @echo Testing $* + @rm -f $(ROOT)/myprofilegc.log + $(QUIET)$(ROOT)/$* $(ROOT)/myprofilegc.log + $(QUIET)$(DIFF) myprofilegc.log.exp $(ROOT)/myprofilegc.log + @touch $@ + +$(ROOT)/both.done: DFLAGS+=-profile -profile=gc +$(ROOT)/both.done: $(ROOT)/%.done: $(ROOT)/% + @echo Testing $* + @rm -f $(ROOT)/both.log $(ROOT)/both.def $(ROOT)/bothgc.log + $(QUIET)$(ROOT)/$* $(ROOT)/both.log $(ROOT)/both.def $(ROOT)/bothgc.log + $(QUIET)$(GREP) -q '1 .*_Dmain' $(ROOT)/mytrace.log + $(QUIET)$(GREP) -q '1000 .*both.Num\* both.foo(uint)' $(ROOT)/both.log + $(QUIET)$(DIFF) both.def.exp $(ROOT)/both.def + $(QUIET)$(DIFF) bothgc.log.exp $(ROOT)/bothgc.log + @touch $@ + +$(ROOT)/%: $(SRC)/%.d + $(QUIET)$(DMD) $(DFLAGS) -of$(ROOT)/$* $< + +clean: + rm -rf obj *.log *.def diff --git a/test/profile/both.def.exp b/test/profile/both.def.exp new file mode 100644 index 00000000000..d78877d587e --- /dev/null +++ b/test/profile/both.def.exp @@ -0,0 +1,5 @@ + +FUNCTIONS + _Dmain + _D4both3fooFkZPS4both3Num + _D4both3Num6__ctorMFNckZS4both3Num diff --git a/test/profile/bothgc.log.exp b/test/profile/bothgc.log.exp new file mode 100644 index 00000000000..122e78a4a5b --- /dev/null +++ b/test/profile/bothgc.log.exp @@ -0,0 +1,2 @@ +bytes allocated, type, function, file:line + 4000 both.Num both.foo src/both.d:15 diff --git a/test/profile/myprofilegc.log.exp b/test/profile/myprofilegc.log.exp new file mode 100644 index 00000000000..f59380ce113 --- /dev/null +++ b/test/profile/myprofilegc.log.exp @@ -0,0 +1,2 @@ +bytes allocated, type, function, file:line + 4 uint D main src/profilegc.d:6 diff --git a/test/profile/mytrace.def.exp b/test/profile/mytrace.def.exp new file mode 100644 index 00000000000..69b187c7bf9 --- /dev/null +++ b/test/profile/mytrace.def.exp @@ -0,0 +1,4 @@ + +FUNCTIONS + _Dmain + _D7profile3fooFkZk diff --git a/test/profile/src/both.d b/test/profile/src/both.d new file mode 100644 index 00000000000..5cf7d68fdd7 --- /dev/null +++ b/test/profile/src/both.d @@ -0,0 +1,27 @@ +import core.runtime; + +struct Num +{ + pragma(inline, false) this(uint val) + { + this.val = val; + } + + uint val; +} + +pragma(inline, false) Num* foo(uint val) +{ + return new Num(val); +} + +__gshared uint sum; + +void main(string[] args) +{ + trace_setlogfilename(args[1]); + trace_setdeffilename(args[2]); + profilegc_setlogfilename(args[3]); + foreach (uint i; 0 .. 1_000) + sum += foo(i).val; +} diff --git a/test/profile/src/profile.d b/test/profile/src/profile.d new file mode 100644 index 00000000000..b818617b4e8 --- /dev/null +++ b/test/profile/src/profile.d @@ -0,0 +1,16 @@ +import core.runtime; + +pragma(inline, false) uint foo(uint val) +{ + return val * 2; +} + +__gshared uint sum; + +void main(string[] args) +{ + trace_setlogfilename(args[1]); + trace_setdeffilename(args[2]); + foreach (uint i; 0 .. 1_000) + sum += foo(i); +} diff --git a/test/profile/src/profilegc.d b/test/profile/src/profilegc.d new file mode 100644 index 00000000000..25e76fbe68c --- /dev/null +++ b/test/profile/src/profilegc.d @@ -0,0 +1,7 @@ +import core.runtime; + +void main(string[] args) +{ + profilegc_setlogfilename(args[1]); + auto p = new uint; +}