Skip to content

Commit 9f0ba56

Browse files
committed
Fix running MRI C extension and C-API tests in CI, auto mx sforceimports
PullRequest: truffleruby/657
2 parents beefa4f + d6bfcc7 commit 9f0ba56

File tree

4 files changed

+65
-79
lines changed

4 files changed

+65
-79
lines changed

mx.truffleruby/mx_truffleruby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def ruby_testdownstream_sulong(args):
122122
jt('test', 'specs', ':capi')
123123
jt('test', 'specs', ':truffle_capi')
124124
jt('test', 'specs', ':library_cext')
125-
jt('test', 'mri', '--cext')
125+
jt('test', 'mri', '--all-sulong')
126126
jt('test', 'cexts')
127127
jt('test', 'bundle')
128128

test/mri/sulong.exclude renamed to test/mri/capi_tests.list

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -69,38 +69,4 @@ cext-ruby/wait_for_single_fd/test_wait_for_single_fd.rb
6969
cext-ruby/win32/test_console_attr.rb
7070
cext-ruby/win32/test_dln.rb
7171
cext-ruby/win32/test_fd_setsize.rb
72-
etc/test_etc.rb
73-
nkf/test_kconv.rb
74-
nkf/test_nkf.rb
75-
openssl/test_asn1.rb
76-
openssl/test_bn.rb
77-
openssl/test_buffering.rb
78-
openssl/test_cipher.rb
79-
openssl/test_config.rb
80-
openssl/test_digest.rb
81-
openssl/test_engine.rb
82-
openssl/test_fips.rb
83-
openssl/test_hmac.rb
84-
openssl/test_ns_spki.rb
85-
openssl/test_ocsp.rb
86-
openssl/test_pair.rb
87-
openssl/test_partial_record_read.rb
88-
openssl/test_pkcs12.rb
89-
openssl/test_pkcs5.rb
90-
openssl/test_pkcs7.rb
91-
openssl/test_pkey_dh.rb
92-
openssl/test_pkey_dsa.rb
93-
openssl/test_pkey_ec.rb
94-
openssl/test_pkey_rsa.rb
95-
openssl/test_ssl.rb
96-
openssl/test_ssl_session.rb
97-
openssl/test_x509cert.rb
98-
openssl/test_x509crl.rb
99-
openssl/test_x509ext.rb
100-
openssl/test_x509name.rb
101-
openssl/test_x509req.rb
102-
openssl/test_x509store.rb
10372
ruby/test_file_exhaustive.rb
104-
syslog/test_syslog_logger.rb
105-
test_syslog.rb
106-
zlib/test_zlib.rb

test/mri/excludes/TestFileExhaustive.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
exclude :test_expand_path_memsize, "needs investigation"
1212
exclude :test_lchmod, "needs investigation"
1313
exclude :test_test, "needs investigation"
14+
exclude :test_expand_path, "needs investigation"
15+
exclude :test_expand_path_for_existent_username, "needs investigation"

tool/jt.rb

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
require 'pathname'
2222

2323
TRUFFLERUBY_DIR = File.expand_path('../..', File.realpath(__FILE__))
24-
MRI_TEST_CEXT_DIR = "#{TRUFFLERUBY_DIR}/test/mri/tests/cext-c"
25-
MRI_TEST_CEXT_LIB_DIR = "#{TRUFFLERUBY_DIR}/.ext/c"
2624
PROFILES_DIR = "#{TRUFFLERUBY_DIR}/profiles"
2725

2826
TRUFFLERUBY_GEM_TEST_PACK_VERSION = "8b57f6022f0fa17ace7c8d2a3af730357715e0a2"
@@ -52,29 +50,47 @@
5250

5351
require "#{TRUFFLERUBY_DIR}/lib/truffle/truffle/openssl-prefix.rb"
5452

53+
MRI_TEST_RELATIVE_PREFIX = "test/mri/tests"
54+
MRI_TEST_PREFIX = "#{TRUFFLERUBY_DIR}/#{MRI_TEST_RELATIVE_PREFIX}"
55+
MRI_TEST_CEXT_DIR = "#{MRI_TEST_PREFIX}/cext-c"
56+
MRI_TEST_CEXT_LIB_DIR = "#{TRUFFLERUBY_DIR}/.ext/c"
57+
58+
# A list of MRI C API tests we can load. Tests that do not load at all are in failing.exclude.
59+
MRI_TEST_CAPI_TESTS = File.readlines("#{TRUFFLERUBY_DIR}/test/mri/capi_tests.list").map(&:chomp)
60+
5561
MRI_TEST_MODULES = {
56-
'--no-sulong' => {
57-
help: 'exclude all tests requiring Sulong',
58-
exclude: "#{TRUFFLERUBY_DIR}/test/mri/sulong.exclude"
59-
},
6062
'--openssl' => {
6163
help: 'include only openssl tests',
62-
include: openssl = ["#{TRUFFLERUBY_DIR}/test/mri/tests/openssl/test_*.rb"],
64+
include: openssl = ["openssl/test_*.rb"],
6365
},
6466
'--syslog' => {
6567
help: 'include only syslog tests',
6668
include: syslog = [
67-
"#{TRUFFLERUBY_DIR}/test/mri/tests/test_syslog.rb",
68-
"#{TRUFFLERUBY_DIR}/test/mri/tests/syslog/test_syslog_logger.rb"
69+
"test_syslog.rb",
70+
"syslog/test_syslog_logger.rb"
6971
]
7072
},
71-
'--cext' => {
72-
help: 'include only tests requiring Sulong',
73-
include: openssl + syslog + [
74-
"#{TRUFFLERUBY_DIR}/test/mri/tests/cext-ruby/**/test_*.rb",
75-
"#{TRUFFLERUBY_DIR}/test/mri/tests/etc/test_etc.rb",
73+
'--cexts' => {
74+
help: 'run all MRI tests testing C extensions',
75+
include: cexts = openssl + syslog + [
76+
"etc/test_etc.rb",
77+
"nkf/test_kconv.rb",
78+
"nkf/test_nkf.rb",
79+
"zlib/test_zlib.rb",
7680
]
77-
}
81+
},
82+
'--capi' => {
83+
help: 'run all C-API MRI tests',
84+
include: capi = MRI_TEST_CAPI_TESTS,
85+
},
86+
'--all-sulong' => {
87+
help: 'run all tests requiring Sulong (C exts and C API)',
88+
include: all_sulong = cexts + capi
89+
},
90+
'--no-sulong' => {
91+
help: 'exclude all tests requiring Sulong',
92+
exclude: all_sulong
93+
},
7894
}
7995

8096
SUBPROCESSES = []
@@ -970,55 +986,55 @@ def test_mri(*args)
970986
end
971987

972988
mri_args = []
973-
prefix = "#{TRUFFLERUBY_DIR}/test/mri/tests/"
974-
exclusions = ["#{TRUFFLERUBY_DIR}/test/mri/failing.exclude"]
989+
excluded_files = File.readlines("#{TRUFFLERUBY_DIR}/test/mri/failing.exclude").
990+
map { |line| line.gsub(/#.*/, '').strip }.reject(&:empty?)
975991
patterns = []
976992

977993
args.each do |arg|
978994
test_module = MRI_TEST_MODULES[arg]
979995
if test_module
980996
patterns.push(*test_module[:include])
981-
exclusions.push(*test_module[:exclude])
997+
excluded_files.push(*test_module[:exclude])
982998
elsif arg.start_with?('-')
983999
mri_args.push arg
9841000
else
9851001
patterns.push arg
9861002
end
9871003
end
9881004

989-
patterns.push "#{TRUFFLERUBY_DIR}/test/mri/tests/**/test_*.rb" if patterns.empty?
990-
991-
excluded_files = exclusions.
992-
flat_map { |f| File.readlines(f) }.
993-
map { |l| l.gsub(/#.*/, '').strip }.
994-
reject(&:empty?)
1005+
patterns.push "#{MRI_TEST_PREFIX}/**/test_*.rb" if patterns.empty?
9951006

9961007
files_to_run = patterns.flat_map do |pattern|
997-
Dir.glob(pattern).map do |path|
998-
expanded_path = File.expand_path path
999-
raise 'pattern does not match test files' unless expanded_path.start_with?(prefix)
1000-
expanded_path[prefix.size..-1]
1001-
end.reject do |path|
1002-
path.empty?
1008+
if pattern.start_with?(MRI_TEST_RELATIVE_PREFIX)
1009+
pattern = "#{TRUFFLERUBY_DIR}/#{pattern}"
1010+
elsif !pattern.start_with?(MRI_TEST_PREFIX)
1011+
pattern = "#{MRI_TEST_PREFIX}/#{pattern}"
10031012
end
1004-
end.sort - excluded_files
1013+
glob = Dir.glob(pattern)
1014+
abort "pattern #{pattern} matched no files" if glob.empty?
1015+
glob.map { |path| mri_test_name(path) }
1016+
end.sort
1017+
files_to_run -= excluded_files
10051018

10061019
run_mri_tests(mri_args, files_to_run, runner_args, use_exec: true)
10071020
end
10081021
private :test_mri
10091022

1023+
def mri_test_name(test)
1024+
prefix = "#{MRI_TEST_RELATIVE_PREFIX}/"
1025+
abs_prefix = "#{MRI_TEST_PREFIX}/"
1026+
if test.start_with?(prefix)
1027+
test[prefix.size..-1]
1028+
elsif test.start_with?(abs_prefix)
1029+
test[abs_prefix.size..-1]
1030+
else
1031+
test
1032+
end
1033+
end
1034+
private :mri_test_name
1035+
10101036
def run_mri_tests(extra_args, test_files, runner_args, run_options)
1011-
prefix = "test/mri/tests/"
1012-
abs_prefix = "#{TRUFFLERUBY_DIR}/#{prefix}"
1013-
test_files = test_files.map { |file|
1014-
if file.start_with?(prefix)
1015-
file[prefix.size..-1]
1016-
elsif file.start_with?(abs_prefix)
1017-
file[abs_prefix.size..-1]
1018-
else
1019-
file
1020-
end
1021-
}
1037+
test_files = test_files.map { |file| mri_test_name(file) }
10221038

10231039
truffle_args = []
10241040
if !extra_args.include?('--native')
@@ -1027,7 +1043,7 @@ def run_mri_tests(extra_args, test_files, runner_args, run_options)
10271043

10281044
env_vars = {
10291045
"EXCLUDES" => "test/mri/excludes",
1030-
"RUBYGEMS_TEST_PATH" => "#{TRUFFLERUBY_DIR}/test/mri/tests",
1046+
"RUBYGEMS_TEST_PATH" => MRI_TEST_PREFIX,
10311047
"RUBYOPT" => [*ENV['RUBYOPT'], '--disable-gems'].join(' '),
10321048
"TRUFFLERUBY_RESILIENT_GEM_HOME" => nil,
10331049
}
@@ -1043,7 +1059,7 @@ def run_mri_tests(extra_args, test_files, runner_args, run_options)
10431059
cext_tests.each do |test|
10441060
puts
10451061
puts test
1046-
test_path = "#{TRUFFLERUBY_DIR}/test/mri/tests/#{test}"
1062+
test_path = "#{MRI_TEST_PREFIX}/#{test}"
10471063
match = File.read(test_path).match(/\brequire ['"]c\/(.*?)["']/)
10481064
if match
10491065
cext_name = match[1]
@@ -1935,6 +1951,8 @@ def install_graal(*options)
19351951
end
19361952

19371953
def build_graalvm(*options)
1954+
mx('-p', TRUFFLERUBY_DIR, 'sforceimports') unless ci?
1955+
19381956
java_home = ci? ? nil : ENV["JVMCI_HOME"] || install_jvmci
19391957
mx_args = ['-p', TRUFFLERUBY_DIR, '--dynamicimports', '/vm']
19401958

0 commit comments

Comments
 (0)