Skip to content

Commit

Permalink
Split std_specs in 32 bits ci (#8065)
Browse files Browse the repository at this point in the history
* Skip some specs for 32 bits
* Restrict threads used in the compiler during the specs
* Split std_specs in 32 bits ci
  • Loading branch information
Brian J. Cardiff authored and bcardiff committed Aug 12, 2019
1 parent 3993854 commit 2fd45cc
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 7 deletions.
24 changes: 23 additions & 1 deletion bin/ci
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,29 @@ prepare_system() {

build() {
with_build_env 'make std_spec clean threads=1'
with_build_env 'make crystal std_spec compiler_spec docs threads=1'

case $ARCH in
i386)
with_build_env 'make crystal threads=1'
with_build_env 'SPEC_SPLIT="0%4" make std_spec threads=1'
with_build_env 'SPEC_SPLIT="1%4" make std_spec threads=1'
with_build_env 'SPEC_SPLIT="2%4" make std_spec threads=1'
with_build_env 'SPEC_SPLIT="3%4" make std_spec threads=1'

parts=16
i=0
while [ $i -lt $parts ]; do
with_build_env "CRYSTAL_SPEC_COMPILER_THREADS=1 SPEC_SPLIT=\"$i%$parts\" make compiler_spec threads=1"
i=$((i + 1))
done

with_build_env 'make docs threads=1'
;;
*)
with_build_env 'make crystal std_spec compiler_spec docs threads=1'
;;
esac

with_build_env 'find samples -name "*.cr" | xargs -L 1 ./bin/crystal build --no-codegen'
}

Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/codegen/private_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "../../spec_helper"

describe "Codegen: private" do
it "codegens private def in same file" do
compiler = Compiler.new
compiler = create_spec_compiler
sources = [
Compiler::Source.new("foo.cr", %(
private def foo
Expand All @@ -22,7 +22,7 @@ describe "Codegen: private" do
end

it "codegens overloaded private def in same file" do
compiler = Compiler.new
compiler = create_spec_compiler
sources = [
Compiler::Source.new("foo.cr", %(
private def foo(x : Int32)
Expand Down
2 changes: 1 addition & 1 deletion spec/compiler/codegen/warnings_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ describe "Code gen: warnings" do
end
)

compiler = Compiler.new
compiler = create_spec_compiler
compiler.warnings = Warnings::All
compiler.warnings_exclude << Crystal.normalize_path "lib"
compiler.prelude = "empty"
Expand Down
2 changes: 2 additions & 0 deletions spec/compiler/crystal/tools/format_spec.cr
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% skip_file if flag?(:bits32) %}

require "spec"
require "compiler/crystal/formatter"
require "compiler/crystal/command/format"
Expand Down
23 changes: 20 additions & 3 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def warnings_result(code, inject_primitives = true)

output_filename = Crystal.tempfile("crystal-spec-output")

compiler = Compiler.new
compiler = create_spec_compiler
compiler.warnings = Warnings::All
compiler.error_on_warnings = false
compiler.prelude = "empty" # avoid issues in the current std lib
Expand Down Expand Up @@ -174,14 +174,22 @@ private def apply_program_flags(target)
ENV["CRYSTAL_SPEC_COMPILER_FLAGS"]?.try { |f| target.concat(f.split) }
end

private def spec_compiler_threads
ENV["CRYSTAL_SPEC_COMPILER_THREADS"]?.try(&.to_i)
end

private def encode_program_flags : String
program_flags_options.join(' ')
end

def program_flags_options : Array(String)
f = [] of String
apply_program_flags(f)
f.map { |x| "-D#{x}" }
options = f.map { |x| "-D#{x}" }
if (n_threads = spec_compiler_threads)
options << "--threads=#{n_threads}"
end
options
end

class Crystal::SpecRunOutput
Expand All @@ -201,6 +209,15 @@ class Crystal::SpecRunOutput
end
end

def create_spec_compiler
compiler = Compiler.new
if (n_threads = spec_compiler_threads)
compiler.n_threads = n_threads
end

compiler
end

def run(code, filename = nil, inject_primitives = true, debug = Crystal::Debug::None, flags = nil)
code = inject_primitives(code) if inject_primitives

Expand All @@ -220,7 +237,7 @@ def run(code, filename = nil, inject_primitives = true, debug = Crystal::Debug::

output_filename = Crystal.tempfile("crystal-spec-output")

compiler = Compiler.new
compiler = create_spec_compiler
compiler.debug = debug
compiler.flags.concat flags if flags
apply_program_flags(compiler.flags)
Expand Down
2 changes: 2 additions & 0 deletions src/spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ if ENV["SPEC_VERBOSE"]? == "1"
Spec.override_default_formatter(Spec::VerboseFormatter.new)
end

Spec.add_split_filter ENV["SPEC_SPLIT"]?

{% unless flag?(:win32) %}
# TODO(windows): re-enable this once Signal is ported
Signal::INT.trap { Spec.abort! }
Expand Down
24 changes: 24 additions & 0 deletions src/spec/dsl.cr
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,30 @@ module Spec
lines << line
end

@@split_filter : NamedTuple(remainder: Int32, quotient: Int32)? = nil

def self.add_split_filter(filter)
if filter
r, m = filter.split('%').map &.to_i
@@split_filter = {remainder: r, quotient: m}
else
@@split_filter = nil
end
end

@@spec_counter = -1

def self.split_filter_matches
split_filter = @@split_filter

if split_filter
@@spec_counter += 1
@@spec_counter % split_filter[:quotient] == split_filter[:remainder]
else
true
end
end

# :nodoc:
def self.matches?(description, file, line, end_line = line)
spec_pattern = @@pattern
Expand Down
1 change: 1 addition & 0 deletions src/spec/methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module Spec::Methods
def it(description = "assert", file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block)
description = description.to_s
Spec::RootContext.check_nesting_spec(file, line) do
return unless Spec.split_filter_matches
return unless Spec.matches?(description, file, line, end_line)

Spec.formatters.each(&.before_example(description))
Expand Down

0 comments on commit 2fd45cc

Please sign in to comment.