Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
add tests for profile and trace output
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNowak committed Aug 29, 2015
1 parent 7c05b9f commit 5160b33
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 1 deletion.
2 changes: 1 addition & 1 deletion posix.mak
Expand Up @@ -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

Expand Down
59 changes: 59 additions & 0 deletions 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
5 changes: 5 additions & 0 deletions test/profile/both.def.exp
@@ -0,0 +1,5 @@

FUNCTIONS
_Dmain
_D4both3fooFkZPS4both3Num
_D4both3Num6__ctorMFNckZS4both3Num
2 changes: 2 additions & 0 deletions test/profile/bothgc.log.exp
@@ -0,0 +1,2 @@
bytes allocated, type, function, file:line
4000 both.Num both.foo src/both.d:15
2 changes: 2 additions & 0 deletions test/profile/myprofilegc.log.exp
@@ -0,0 +1,2 @@
bytes allocated, type, function, file:line
4 uint D main src/profilegc.d:6
4 changes: 4 additions & 0 deletions test/profile/mytrace.def.exp
@@ -0,0 +1,4 @@

FUNCTIONS
_Dmain
_D7profile3fooFkZk
27 changes: 27 additions & 0 deletions 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;
}
16 changes: 16 additions & 0 deletions 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);
}
7 changes: 7 additions & 0 deletions test/profile/src/profilegc.d
@@ -0,0 +1,7 @@
import core.runtime;

void main(string[] args)
{
profilegc_setlogfilename(args[1]);
auto p = new uint;
}

0 comments on commit 5160b33

Please sign in to comment.