summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-03-28 11:49:28 (GMT)
committerBenoit Daloze <eregontp@gmail.com>2020-03-28 11:49:28 (GMT)
commit5b48686691c2443d8d7113e593494c4d9302da0e (patch)
tree8e0948aea7e806ab56ed224d803b99a758c1030c
parent282c9d1bbe9057c6dfd6694a82c9264354f3f23b (diff)
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
-rw-r--r--spec/ruby/core/process/clock_getres_spec.rb30
-rw-r--r--spec/ruby/core/process/fixtures/clocks.rb42
2 files changed, 0 insertions, 72 deletions
diff --git a/spec/ruby/core/process/clock_getres_spec.rb b/spec/ruby/core/process/clock_getres_spec.rb
index 797824f..90f775e 100644
--- a/spec/ruby/core/process/clock_getres_spec.rb
+++ b/spec/ruby/core/process/clock_getres_spec.rb
@@ -1,36 +1,6 @@
require_relative '../../spec_helper'
-require_relative 'fixtures/clocks'
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
it "with :GETTIMEOFDAY_BASED_CLOCK_REALTIME reports 1 microsecond" do
diff --git a/spec/ruby/core/process/fixtures/clocks.rb b/spec/ruby/core/process/fixtures/clocks.rb
index 7537cfa..f043f6a 100644
--- a/spec/ruby/core/process/fixtures/clocks.rb
+++ b/spec/ruby/core/process/fixtures/clocks.rb
@@ -15,46 +15,4 @@ module ProcessSpecs
[c, Process.const_get(c)]
}
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