diff options
author | Mike Dalessio <mike.dalessio@gmail.com> | 2022-05-23 17:31:14 -0400 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2022-05-24 09:40:03 -0700 |
commit | 0c36ba53192c5a0d245c9b626e4346a32d7d144e (patch) | |
tree | f0865e6e17399998e6e5049edc8969c2da64560c /test/ruby/test_gc_compact.rb | |
parent | 0de1495f358e9b892dfa63d4b74f59b1d2903703 (diff) | |
download | ruby-0c36ba53192c5a0d245c9b626e4346a32d7d144e.tar.gz |
Define unsupported GC compaction methods as rb_f_notimplement
Fixes [Bug #18779]
Define the following methods as `rb_f_notimplement` on unsupported
platforms:
- GC.compact
- GC.auto_compact
- GC.auto_compact=
- GC.latest_compact_info
- GC.verify_compaction_references
This change allows users to call `GC.respond_to?(:compact)` to
properly test for compaction support. Previously, it was necessary to
invoke `GC.compact` or `GC.verify_compaction_references` and check if
those methods raised `NotImplementedError` to determine if compaction
was supported.
This follows the precedent set for other platform-specific
methods. For example, in `process.c` for methods such as
`Process.fork`, `Process.setpgid`, and `Process.getpriority`.
Diffstat (limited to 'test/ruby/test_gc_compact.rb')
-rw-r--r-- | test/ruby/test_gc_compact.rb | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/test/ruby/test_gc_compact.rb b/test/ruby/test_gc_compact.rb index 16b15b39ac..da0023e6f3 100644 --- a/test/ruby/test_gc_compact.rb +++ b/test/ruby/test_gc_compact.rb @@ -9,14 +9,7 @@ if RUBY_PLATFORM =~ /s390x/ end class TestGCCompact < Test::Unit::TestCase - module SupportsCompact - def setup - omit "autocompact not supported on this platform" unless supports_auto_compact? - super - end - - private - + module CompactionSupportInspector def supports_auto_compact? return false if /wasm/ =~ RUBY_PLATFORM return true unless defined?(Etc::SC_PAGE_SIZE) @@ -31,10 +24,19 @@ class TestGCCompact < Test::Unit::TestCase end end - include SupportsCompact + module OmitUnlessCompactSupported + include CompactionSupportInspector + + def setup + omit "autocompact not supported on this platform" unless supports_auto_compact? + super + end + end + + include OmitUnlessCompactSupported class AutoCompact < Test::Unit::TestCase - include SupportsCompact + include OmitUnlessCompactSupported def test_enable_autocompact before = GC.auto_compact @@ -88,13 +90,39 @@ class TestGCCompact < Test::Unit::TestCase end end - def os_page_size - return true unless defined?(Etc::SC_PAGE_SIZE) + class CompactMethodsNotImplemented < Test::Unit::TestCase + include CompactionSupportInspector + + def assert_not_implemented(method, *args) + omit "autocompact is supported on this platform" if supports_auto_compact? + + assert_raise(NotImplementedError) { GC.send(method, *args) } + refute(GC.respond_to?(method), "GC.#{method} should be defined as rb_f_notimplement") + end + + def test_gc_compact_not_implemented + assert_not_implemented(:compact) + end + + def test_gc_auto_compact_get_not_implemented + assert_not_implemented(:auto_compact) + end + + def test_gc_auto_compact_set_not_implemented + assert_not_implemented(:auto_compact=, true) + end + + def test_gc_latest_compact_info_not_implemented + assert_not_implemented(:latest_compact_info) + end + + def test_gc_verify_compaction_references_not_implemented + assert_not_implemented(:verify_compaction_references) + end end - def setup - omit "autocompact not supported on this platform" unless supports_auto_compact? - super + def os_page_size + return true unless defined?(Etc::SC_PAGE_SIZE) end def test_gc_compact_stats |