Skip to content

Commit

Permalink
n-workers: use the max N cores by default
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Aug 11, 2023
1 parent 688ffa8 commit f7d506d
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions lib/grntest/tester.rb
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ def create_option_parser(tester, tag)
end

parser.on("--n-workers=N", Integer,
"Use N workers to run tests") do |n|
"Use N workers to run tests",
"(#{tester.n_workers})") do |n|
tester.n_workers = n
end

Expand Down Expand Up @@ -382,7 +383,7 @@ def initialize
@base_directory = Pathname(".")
@database_path = nil
@reporter = nil
@n_workers = 1
@n_workers = guess_n_cores
@output = $stdout
@keep_database = false
@use_color = nil
Expand Down Expand Up @@ -544,6 +545,28 @@ def run_test_suites(test_suites)
runner.run(test_suites)
end

def guess_n_cores
begin
if command_exist?("nproc")
# Linux
Integer(`nproc`.strip, 10)
elsif command_exist?("sysctl")
# macOS
Integer(`sysctl -n hw.logicalcpu`.strip, 10)
else
# Windows
value = ENV["NUMBER_OF_PROCESSORS"]
if value
Integer(value, 10)
else
1
end
end
rescue ArgumentError
1
end
end

def detect_suitable_diff
if command_exist?("cut-diff")
@diff = "cut-diff"
Expand Down

0 comments on commit f7d506d

Please sign in to comment.