Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ jobs:
- run:
command: ./.circleci/run.sh codecov
name: Upload coverage files to CodeCov
- run:
command: ./.circleci/run.sh betterc
name: Run @betterC tests
7 changes: 7 additions & 0 deletions .circleci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ coverage() {
TEST_COVERAGE="1" make -j$N -C . -f posix.mak MODEL=$MODEL unittest-debug
}

betterc()
{
clone https://github.com/dlang/tools.git ../tools master --depth 1
make -f posix.mak betterc -j$N DUB="$HOME/dlang/dmd-${HOST_DMD_VER}/linux/bin64/dub"
}

codecov()
{
# CodeCov gets confused by lst files which it can't matched
Expand All @@ -115,6 +121,7 @@ case $1 in
install-deps) install_deps ;;
setup-repos) setup_repos ;;
style) style ;;
betterc) betterc ;;
coverage) coverage ;;
codecov) codecov ;;
esac
1 change: 1 addition & 0 deletions mak/COPY
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ COPY=\
\
$(IMPDIR)\core\internal\abort.d \
$(IMPDIR)\core\internal\arrayop.d \
$(IMPDIR)\core\internal\attributes.d \
$(IMPDIR)\core\internal\convert.d \
$(IMPDIR)\core\internal\dassert.d \
$(IMPDIR)\core\internal\hash.d \
Expand Down
3 changes: 3 additions & 0 deletions mak/WINDOWS
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ $(IMPDIR)\core\internal\abort.d : src\core\internal\abort.d
$(IMPDIR)\core\internal\arrayop.d : src\core\internal\arrayop.d
copy $** $@

$(IMPDIR)\core\internal\attributes.d : src\core\internal\attributes.d
copy $** $@

$(IMPDIR)\core\internal\convert.d : src\core\internal\convert.d
copy $** $@

Expand Down
41 changes: 41 additions & 0 deletions posix.mak
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
QUIET:=

DMD_DIR=../dmd
DUB=dub
TOOLS_DIR=../tools

include $(DMD_DIR)/src/osmodel.mak

Expand Down Expand Up @@ -315,6 +317,9 @@ $(ROOT)/unittest/test_runner: $(UT_DRUNTIME) src/test_runner.d $(DMD)

endif

TESTS_EXTRACTOR=$(ROOT)/tests_extractor
BETTERCTESTS_DIR=$(ROOT)/betterctests

# macro that returns the module name given the src path
moduleName=$(subst rt.invariant,invariant,$(subst object_,object,$(subst /,.,$(1))))

Expand Down Expand Up @@ -385,6 +390,42 @@ clean: $(addsuffix /.clean,$(ADDITIONAL_TESTS))
test/%/.clean: test/%/Makefile
$(MAKE) -C test/$* clean

%/.directory :
mkdir -p $* || exists $*
touch $@

################################################################################
# Build the test extractor.
# - extracts and runs public unittest examples to checks for missing imports
# - extracts and runs @betterC unittests
################################################################################

$(TESTS_EXTRACTOR): $(TOOLS_DIR)/tests_extractor.d | $(LIB)
$(DUB) build --force --single $<
mv $(TOOLS_DIR)/tests_extractor $@

test_extractor: $(TESTS_EXTRACTOR)

################################################################################
# Check and run @betterC tests
# ----------------------------
#
# Extract @betterC tests of a module and run them in -betterC
#
# make -f betterc -j20 # all tests
# make -f posix.mak src/core/memory.betterc # individual module
################################################################################

betterc: | $(TESTS_EXTRACTOR) $(BETTERCTESTS_DIR)/.directory
$(MAKE) -f posix.mak $$(find src -type f -name '*.d' | sed 's/[.]d/.betterc/')

%.betterc: %.d | $(TESTS_EXTRACTOR) $(BETTERCTESTS_DIR)/.directory
@$(TESTS_EXTRACTOR) --betterC --attributes betterC \
--inputdir $< --outputdir $(BETTERCTESTS_DIR)
@$(DMD) $(NODEFAULTLIB) -betterC $(UDFLAGS) $(UTFLAGS) -od$(BETTERCTESTS_DIR) -run $(BETTERCTESTS_DIR)/$(subst /,_,$<)

################################################################################

# Submission to Druntime are required to conform to the DStyle
# The tests below automate some, but not all parts of the DStyle guidelines.
# See: http://dlang.org/dstyle.html
Expand Down
18 changes: 12 additions & 6 deletions src/core/atomic.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

module core.atomic;

import core.internal.attributes : betterC;

version (D_InlineAsm_X86)
{
version = AsmX86;
Expand Down Expand Up @@ -1471,7 +1473,7 @@ version (unittest)
testLoadStore!(MemoryOrder.raw, T)( val );
}

@safe pure nothrow unittest
@betterC @safe pure nothrow unittest
{
testType!(bool)();

Expand All @@ -1483,6 +1485,10 @@ version (unittest)

testType!(int)();
testType!(uint)();
}

@safe pure nothrow unittest
{

testType!(shared int*)();

Expand Down Expand Up @@ -1518,7 +1524,7 @@ version (unittest)
}
}

pure nothrow unittest
@betterC pure nothrow unittest
{
static if (has128BitCAS)
{
Expand Down Expand Up @@ -1558,7 +1564,7 @@ version (unittest)
}
}

pure nothrow unittest
@betterC pure nothrow unittest
{
static struct S { int val; }
auto s = shared(S)(1);
Expand Down Expand Up @@ -1621,7 +1627,7 @@ version (unittest)
}

// === atomicFetchAdd and atomicFetchSub operations ====
pure nothrow @nogc @safe unittest
@betterC pure nothrow @nogc @safe unittest
{
shared ubyte u8 = 1;
shared ushort u16 = 2;
Expand All @@ -1645,7 +1651,7 @@ version (unittest)
}
}

pure nothrow @nogc @safe unittest
@betterC pure nothrow @nogc @safe unittest
{
shared ubyte u8 = 1;
shared ushort u16 = 2;
Expand All @@ -1669,7 +1675,7 @@ version (unittest)
}
}

pure nothrow @nogc @safe unittest // issue 16651
@betterC pure nothrow @nogc @safe unittest // issue 16651
{
shared ulong a = 2;
uint b = 1;
Expand Down
11 changes: 11 additions & 0 deletions src/core/internal/attributes.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module core.internal.attributes;

/**
Used to annotate `unittest`s which need to be tested in a `-betterC` environment.

Such `unittest`s will be compiled and executed without linking druntime in, with
a `__traits(getUnitTests, mixin(__MODULE__))` style test runner.
Note that just like any other `unittest` in druntime, they will also be compiled
and executed without `-betterC`.
*/
package(core) enum betterC = 1;