1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Remove Process.clock_getres "matches the resolution in practice" specs

* Almost all platforms return incorrect values for Process.clock_getres,
  it should be removed: https://bugs.ruby-lang.org/issues/16740
This commit is contained in:
Benoit Daloze 2020-03-28 12:49:28 +01:00
parent 282c9d1bbe
commit 5b48686691
2 changed files with 0 additions and 72 deletions

View file

@ -1,36 +1,6 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
require_relative 'fixtures/clocks'
describe "Process.clock_getres" do describe "Process.clock_getres" do
# clock_getres() seems completely buggy on FreeBSD:
# https://rubyci.org/logs/rubyci.s3.amazonaws.com/freebsd11zfs/ruby-trunk/log/20190428T093003Z.fail.html.gz
platform_is_not :freebsd, :openbsd, :android do
# NOTE: Look at fixtures/clocks.rb for clock and OS-specific exclusions
ProcessSpecs.clock_constants_for_resolution_checks.each do |name, value|
it "matches the clock in practice for Process::#{name}" do
times = 100_000.times.map { Process.clock_gettime(value, :nanosecond) }
reported = Process.clock_getres(value, :nanosecond)
# The clock should not be more accurate than reported (times should be
# a multiple of reported precision.)
times.select { |t| t % reported > 0 }.should be_empty
# We're assuming precision is a multiple of ten - it may or may not
# be an incompatibility if it isn't but we'd like to notice this,
# and the spec following these wouldn't work if it isn't.
reported.should > 0
(reported == 1 || reported % 10 == 0).should be_true
# The clock should not be less accurate than reported (times should
# not all be a multiple of the next precision up, assuming precisions
# are multiples of ten.)
if times.all? { |t| t % (reported * 10) == 0 }
times.uniq.should be_empty
end
end
end
end
# These are documented # These are documented
it "with :GETTIMEOFDAY_BASED_CLOCK_REALTIME reports 1 microsecond" do it "with :GETTIMEOFDAY_BASED_CLOCK_REALTIME reports 1 microsecond" do

View file

@ -15,46 +15,4 @@ module ProcessSpecs
[c, Process.const_get(c)] [c, Process.const_get(c)]
} }
end end
def self.clock_constants_for_resolution_checks
clocks = clock_constants
# These clocks in practice on Linux do not seem to match their reported resolution.
platform_is :linux do
clocks = clocks.reject { |clock, value|
[:CLOCK_REALTIME_COARSE, :CLOCK_MONOTONIC_COARSE].include?(clock)
}
end
# These clocks in practice on macOS seem to be less precise than advertised by clock_getres
platform_is :darwin do
clocks = clocks.reject { |clock, value|
[:CLOCK_UPTIME_RAW_APPROX, :CLOCK_MONOTONIC_RAW_APPROX].include?(clock)
}
end
# These clocks in practice on ARM on Linux do not seem to match their reported resolution.
platform_is :armv7, :armv8, :aarch64 do
clocks = clocks.reject { |clock, value|
[:CLOCK_PROCESS_CPUTIME_ID, :CLOCK_THREAD_CPUTIME_ID, :CLOCK_MONOTONIC_RAW].include?(clock)
}
end
# These clocks in practice on AIX seem to be more precise than their reported resolution.
platform_is :aix do
clocks = clocks.reject { |clock, value|
[:CLOCK_REALTIME, :CLOCK_MONOTONIC].include?(clock)
}
end
# On a Hyper-V Linux guest machine, these clocks in practice
# seem to be less precise than advertised by clock_getres
platform_is :linux do
clocks = clocks.reject { |clock, value|
clock == :CLOCK_MONOTONIC_RAW
}
end
clocks
end
end end