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

Commit

Permalink
Merge pull request #1356 from MartinNowak/boottime
Browse files Browse the repository at this point in the history
properly fix failing test with missing CLOCK_BOOTTIME support
  • Loading branch information
DmitryOlshansky committed Aug 29, 2015
2 parents 5db7352 + 24e4079 commit d321714
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
21 changes: 13 additions & 8 deletions posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ INSTALL_DIR=../install
DOCDIR=doc
IMPDIR=import

override PIC:=$(if $(PIC),-fPIC,)
OPTIONAL_PIC:=$(if $(PIC),-fPIC,)

ifeq (osx,$(OS))
DOTDLL:=.dylib
Expand All @@ -54,13 +54,13 @@ ifeq (solaris,$(OS))
endif

# Set DFLAGS
UDFLAGS=-conf= -Isrc -Iimport -w -dip25 $(MODEL_FLAG) $(PIC)
UDFLAGS:=-conf= -Isrc -Iimport -w -dip25 $(MODEL_FLAG) $(OPTIONAL_PIC)
ifeq ($(BUILD),debug)
UDFLAGS += -g -debug
DFLAGS=$(UDFLAGS)
DFLAGS:=$(UDFLAGS)
else
UDFLAGS += -O -release
DFLAGS=$(UDFLAGS) -inline # unittests don't compile with -inline
DFLAGS:=$(UDFLAGS) -inline # unittests don't compile with -inline
endif

ROOT_OF_THEM_ALL = generated
Expand Down Expand Up @@ -168,8 +168,7 @@ $(ROOT)/threadasm.o : src/core/threadasm.S

######################## Create a shared library ##############################

$(DRUNTIMESO) $(DRUNTIMESOLIB) dll: override PIC:=-fPIC
$(DRUNTIMESO) $(DRUNTIMESOLIB) dll: DFLAGS+=-version=Shared
$(DRUNTIMESO) $(DRUNTIMESOLIB) dll: DFLAGS+=-version=Shared -fPIC
dll: $(DRUNTIMESOLIB)

$(DRUNTIMESO): $(OBJS) $(SRCS)
Expand Down Expand Up @@ -201,6 +200,13 @@ unittest-%:
$(MAKE) -f $(MAKEFILE) unittest OS=$(OS) MODEL=$(MODEL) DMD=$(DMD) BUILD=$*
endif

ifeq ($(OS),linux)
old_kernel:=$(shell [ "$$(uname -r | cut -d'-' -f1)" \< "2.6.39" ] && echo 1)
ifeq ($(old_kernel),1)
UDFLAGS+=-version=Linux_Pre_2639
endif
endif

ifeq ($(OS),freebsd)
DISABLED_TESTS =
else
Expand All @@ -219,8 +225,7 @@ else

UT_DRUNTIME:=$(ROOT)/unittest/libdruntime-ut$(DOTDLL)

$(UT_DRUNTIME): override PIC:=-fPIC
$(UT_DRUNTIME): UDFLAGS+=-version=Shared
$(UT_DRUNTIME): UDFLAGS+=-version=Shared -fPIC
$(UT_DRUNTIME): $(OBJS) $(SRCS)
$(DMD) $(UDFLAGS) -shared -unittest -of$@ $(SRCS) $(OBJS) $(LINKDL) -debuglib= -defaultlib=

Expand Down
25 changes: 14 additions & 11 deletions src/core/time.d
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ version(CoreDdoc) enum ClockType
/++
$(BLUE Linux-Only)
Uses $(D CLOCK_MONOTONIC_BOOTTIME).
Uses $(D CLOCK_BOOTTIME).
+/
bootTime = 1,

Expand Down Expand Up @@ -2714,15 +2714,20 @@ unittest
auto norm2 = MonoTimeImpl!(ClockType.normal).currTime;
assert(norm1 <= norm2);

static bool clockSupported(ClockType c)
{
version (Linux_Pre_2639) // skip CLOCK_BOOTTIME on older linux kernels
return c != ClockType.second && c != ClockType.bootTime;
else
return c != ClockType.second; // second doesn't work with MonoTimeImpl

}

foreach(typeStr; __traits(allMembers, ClockType))
{
// ClockType.second is currently the only clock type that doesn't work
// with MonoTimeImpl.
static if(typeStr != "second")
mixin("alias type = ClockType." ~ typeStr ~ ";");
static if (clockSupported(type))
{
mixin("alias type = ClockType." ~ typeStr ~ ";");
version (linux) if (typeStr == "bootTime" && !MonoTimeImpl!type.ticksPerSecond)
continue;
auto v1 = MonoTimeImpl!type.currTime;
auto v2 = MonoTimeImpl!type.currTime;
scope(failure)
Expand All @@ -2737,11 +2742,9 @@ unittest

foreach(otherStr; __traits(allMembers, ClockType))
{
static if(otherStr != "second")
mixin("alias other = ClockType." ~ otherStr ~ ";");
static if (clockSupported(other))
{
mixin("alias other = ClockType." ~ otherStr ~ ";");
version (linux) if (typeStr == "bootTime" && !MonoTimeImpl!other.ticksPerSecond)
continue;
static assert(is(typeof({auto o1 = MonTimeImpl!other.currTime; auto b = v1 <= o1;})) ==
is(type == other));
}
Expand Down

0 comments on commit d321714

Please sign in to comment.