Skip to content

Commit f283251

Browse files
committed
Initial TestSuite setup for make check-rust
This is an initial basic testsuite with one file with expected failures for now.
1 parent 0db8774 commit f283251

File tree

11 files changed

+841
-1
lines changed

11 files changed

+841
-1
lines changed

Makefile.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ languages = { language=brig; gcc-check-target=check-brig;
642642
lib-check-target=check-target-libhsail-rt; };
643643
languages = { language=d; gcc-check-target=check-d;
644644
lib-check-target=check-target-libphobos; };
645+
languages = { language=rust; gcc-check-target=check-rust; };
645646

646647
// Toplevel bootstrap
647648
bootstrap_stage = { id=1 ; };

Makefile.in

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55553,6 +55553,14 @@ check-gcc-d:
5555355553
(cd gcc && $(MAKE) $(GCC_FLAGS_TO_PASS) check-d);
5555455554
check-d: check-gcc-d check-target-libphobos
5555555555

55556+
.PHONY: check-gcc-rust check-rust
55557+
check-gcc-rust:
55558+
r=`${PWD_COMMAND}`; export r; \
55559+
s=`cd $(srcdir); ${PWD_COMMAND}`; export s; \
55560+
$(HOST_EXPORTS) \
55561+
(cd gcc && $(MAKE) $(GCC_FLAGS_TO_PASS) check-rust);
55562+
check-rust: check-gcc-rust
55563+
5555655564

5555755565
# The gcc part of install-no-fixedincludes, which relies on an intimate
5555855566
# knowledge of how a number of gcc internal targets (inter)operate. Delegate.

gcc/rust/Make-lang.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ GCCRS_INSTALL_NAME := $(shell echo gccrs|sed '$(program_transform_name)')
3030
GCCRS_TARGET_INSTALL_NAME := $(target_noncanonical)-$(shell echo gccrs|sed '$(program_transform_name)')
3131

3232
# Define the names for selecting rust in LANGUAGES.
33-
rust: gccrs$(exeext) rust1$(exeext)
33+
rust: rust1$(exeext)
3434

3535
# Tell GNU make to ignore files by these names if they exist.
3636
.PHONY: rust
@@ -88,6 +88,10 @@ rust1$(exeext): $(RUST_ALL_OBJS) attribs.o $(BACKEND) $(LIBDEPS)
8888

8989
# Build hooks.
9090

91+
lang_checks += check-rust
92+
lang_checks_parallelized += check-rust
93+
check_rust_parallelize = 10
94+
9195
# Copies its dependencies into the source directory. This generally should be used for generated files
9296
# such as Bison output files which are not version-controlled, but should be included in any release
9397
# tarballs. This target will be executed during a bootstrap if ‘--enable-generated-files-in-srcdir’

gcc/testsuite/lib/rust-dg.exp

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Copyright (C) 2012-2019 Free Software Foundation, Inc.
2+
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with GCC; see the file COPYING3. If not see
15+
# <http://www.gnu.org/licenses/>.
16+
17+
load_lib gcc-dg.exp
18+
19+
# Define rust callbacks for dg.exp.
20+
21+
proc rust-dg-test { prog do_what extra_tool_flags } {
22+
upvar dg-do-what dg-do-what
23+
24+
# Demote link and run tests to compile-only if D runtime is missing.
25+
if ![check_effective_target_d_runtime] {
26+
switch $do_what {
27+
link -
28+
run {
29+
set do_what compile
30+
set dg-do-what compile
31+
}
32+
}
33+
}
34+
35+
# Strip rust.test prefix off test names to avoid pathname failures in
36+
# some tests.
37+
set prog [dg-trim-dirname rust.test $prog]
38+
39+
set result \
40+
[gcc-dg-test-1 rust_target_compile $prog $do_what $extra_tool_flags]
41+
42+
set comp_output [lindex $result 0]
43+
set output_file [lindex $result 1]
44+
45+
return [list $comp_output $output_file]
46+
}
47+
48+
proc rust-dg-prune { system text } {
49+
return [gcc-dg-prune $system $text]
50+
}
51+
52+
# Utility routines.
53+
54+
#
55+
# Modified dg-runtest that can cycle through a list of optimization options
56+
# as c-torture does.
57+
#
58+
59+
proc rust-dg-runtest { testcases flags default-extra-flags } {
60+
global runtests
61+
62+
foreach test $testcases {
63+
# If we're only testing specific files and this isn't one of
64+
# them, skip it.
65+
66+
if ![runtest_file_p $runtests $test] {
67+
continue
68+
}
69+
70+
# Use TORTURE_OPTIONS to cycle through an option list.
71+
if [torture-options-exist] then {
72+
global torture_with_loops
73+
set option_list $torture_with_loops
74+
} else {
75+
set option_list { "" }
76+
}
77+
78+
set nshort [file tail [file dirname $test]]/[file tail $test]
79+
80+
foreach flags_t $option_list {
81+
verbose "Testing $nshort, $flags $flags_t" 1
82+
dg-test $test "$flags $flags_t" ${default-extra-flags}
83+
}
84+
}
85+
}
86+
87+
#
88+
# rust_load -- wrapper around default rust_load to handle tests that
89+
# require program arguments passed to them.
90+
#
91+
92+
if { [info procs rust_load] != [list] \
93+
&& [info procs prev_rust_load] == [list] } {
94+
rename rust_load prev_rust_load
95+
96+
proc rust_load { program args } {
97+
global RUST_EXECUTE_ARGS
98+
if [info exists RUST_EXECUTE_ARGS] then {
99+
set args [concat "{$RUST_EXECUTE_ARGS}"]
100+
}
101+
#print "Running: $program [lindex $args 0]"
102+
set result [eval [list prev_rust_load $program] $args ]
103+
return $result
104+
}
105+
}
106+

gcc/testsuite/lib/rust.exp

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
# Copyright (C) 2012-2020 Free Software Foundation, Inc.
2+
3+
# This program is free software; you can redistribute it and/or modify
4+
# it under the terms of the GNU General Public License as published by
5+
# the Free Software Foundation; either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU General Public License
14+
# along with GCC; see the file COPYING3. If not see
15+
# <http://www.gnu.org/licenses/>.
16+
17+
#
18+
# rust support library routines
19+
#
20+
21+
load_lib prune.exp
22+
load_lib gcc-defs.exp
23+
load_lib timeout.exp
24+
load_lib target-libpath.exp
25+
26+
#
27+
# RUST_UNDER_TEST is the compiler under test.
28+
#
29+
30+
set rust_compile_options ""
31+
32+
33+
#
34+
# rust_version -- extract and print the version number of the compiler
35+
#
36+
37+
proc rust_version { } {
38+
global RUST_UNDER_TEST
39+
40+
rust_init
41+
42+
# ignore any arguments after the command
43+
set compiler [lindex $RUST_UNDER_TEST 0]
44+
45+
# verify that the compiler exists
46+
if { [is_remote host] || [which $compiler] != 0 } then {
47+
set tmp [remote_exec host "$compiler -v"]
48+
set status [lindex $tmp 0]
49+
set output [lindex $tmp 1]
50+
regexp " version \[^\n\r\]*" $output version
51+
if { $status == 0 && [info exists version] } then {
52+
if [is_remote host] {
53+
clone_output "$compiler $version\n"
54+
} else {
55+
clone_output "[which $compiler] $version\n"
56+
}
57+
} else {
58+
clone_output "Couldn't determine version of $output [which $compiler]\n"
59+
}
60+
} else {
61+
# compiler does not exist (this should have already been detected)
62+
warning "$compiler does not exist"
63+
}
64+
}
65+
66+
#
67+
# rust_include_flags -- include flags for the gcc tree structure
68+
#
69+
70+
proc rust_include_flags { paths } {
71+
global srcdir
72+
global TESTING_IN_BUILD_TREE
73+
74+
set flags ""
75+
76+
if { [is_remote host] || ![info exists TESTING_IN_BUILD_TREE] } {
77+
return "${flags}"
78+
}
79+
80+
set gccpath ${paths}
81+
82+
return "$flags"
83+
}
84+
85+
#
86+
# rust_link_flags -- linker flags for the gcc tree structure
87+
#
88+
89+
proc rust_link_flags { paths } {
90+
global srcdir
91+
global ld_library_path
92+
global RUST_UNDER_TEST
93+
global shlib_ext
94+
global SHARED_OPTION
95+
96+
set gccpath ${paths}
97+
set libio_dir ""
98+
set flags ""
99+
set ld_library_path "."
100+
set shlib_ext [get_shlib_extension]
101+
set SHARED_OPTION ""
102+
verbose "shared lib extension: $shlib_ext"
103+
104+
set_ld_library_path_env_vars
105+
106+
return "$flags"
107+
}
108+
109+
#
110+
# rust_init -- called at the start of each subdir of tests
111+
#
112+
113+
proc rust_init { args } {
114+
global subdir
115+
global rust_initialized
116+
global base_dir
117+
global tmpdir
118+
global libdir
119+
global gluefile wrap_flags
120+
global objdir srcdir
121+
global ALWAYS_DFLAGS
122+
global TOOL_EXECUTABLE TOOL_OPTIONS
123+
global RUST_UNDER_TEST
124+
global TESTING_IN_BUILD_TREE
125+
global TEST_ALWAYS_FLAGS
126+
global gcc_warning_prefix
127+
global gcc_error_prefix
128+
129+
# We set LC_ALL and LANG to C so that we get the same error messages as expected.
130+
setenv LC_ALL C
131+
setenv LANG C
132+
133+
if ![info exists RUST_UNDER_TEST] then {
134+
if [info exists TOOL_EXECUTABLE] {
135+
set RUST_UNDER_TEST $TOOL_EXECUTABLE
136+
} else {
137+
if { [is_remote host] || ! [info exists TESTING_IN_BUILD_TREE] } {
138+
set RUST_UNDER_TEST [transform gccrs]
139+
} else {
140+
set RUST_UNDER_TEST [findfile $base_dir/../../gccrs "$base_dir/../../gccrs -B$base_dir/../../" [findfile $base_dir/gccrs "$base_dir/gccrs -B$base_dir/" [transform gccrs]]]
141+
}
142+
}
143+
}
144+
145+
if ![is_remote host] {
146+
if { [which $RUST_UNDER_TEST] == 0 } then {
147+
perror "RUST_UNDER_TEST ($RUST_UNDER_TEST) does not exist"
148+
exit 1
149+
}
150+
}
151+
if ![info exists tmpdir] {
152+
set tmpdir "/tmp"
153+
}
154+
155+
if [info exists gluefile] {
156+
unset gluefile
157+
}
158+
159+
rust_maybe_build_wrapper "${tmpdir}/rust-testglue.o"
160+
161+
set ALWAYS_RUSTFLAGS ""
162+
163+
# TEST_ALWAYS_FLAGS are flags that should be passed to every
164+
# compilation. They are passed first to allow individual
165+
# tests to override them.
166+
if [info exists TEST_ALWAYS_FLAGS] {
167+
lappend ALWAYS_DFLAGS "additional_flags=$TEST_ALWAYS_FLAGS"
168+
}
169+
170+
if ![is_remote host] {
171+
if [info exists TOOL_OPTIONS] {
172+
lappend ALWAYS_DFLAGS "additional_flags=[rust_include_flags [get_multilibs ${TOOL_OPTIONS}] ]"
173+
lappend ALWAYS_DFLAGS "ldflags=[rust_link_flags [get_multilibs ${TOOL_OPTIONS}] ]"
174+
} else {
175+
lappend ALWAYS_DFLAGS "additional_flags=[rust_include_flags [get_multilibs] ]"
176+
lappend ALWAYS_DFLAGS "ldflags=[rust_link_flags [get_multilibs] ]"
177+
}
178+
}
179+
180+
if [info exists TOOL_OPTIONS] {
181+
lappend ALWAYS_DFLAGS "additional_flags=$TOOL_OPTIONS"
182+
}
183+
184+
verbose -log "ALWAYS_DFLAGS set to $ALWAYS_DFLAGS"
185+
186+
set gcc_warning_prefix "warning:"
187+
set gcc_error_prefix "(fatal )?error:"
188+
189+
verbose "rust is initialized" 3
190+
}
191+
192+
#
193+
# rust_target_compile -- compile a source file
194+
#
195+
196+
proc rust_target_compile { source dest type options } {
197+
global tmpdir
198+
global gluefile wrap_flags
199+
global ALWAYS_DFLAGS
200+
global RUST_UNDER_TEST
201+
202+
if { [target_info needs_status_wrapper] != "" && [info exists gluefile] } {
203+
lappend options "libs=${gluefile}"
204+
lappend options "ldflags=${wrap_flags}"
205+
}
206+
207+
lappend options "timeout=[timeout_value]"
208+
lappend options "compiler=$RUST_UNDER_TEST"
209+
210+
set options [concat "$ALWAYS_DFLAGS" $options]
211+
set options [dg-additional-files-options $options $source]
212+
return [target_compile $source $dest $type $options]
213+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
fn main() {
2+
let mut x = 5;
3+
4+
if x == 5 {
5+
x = 1;
6+
} else if x == 3 {
7+
x = 2;
8+
} else {
9+
x = 3;
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
struct Foo {
2+
one: i32,
3+
two: i32,
4+
}
5+
6+
impl Foo {
7+
fn new(a: i32, b: i32) -> Foo {
8+
return Foo { one: a, two: b };
9+
}
10+
}
11+
12+
fn main() {
13+
let cake = Foo::new(3, 4);
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn test(x: i32) -> i32 {
2+
return x + 1;
3+
}
4+
5+
fn main() {
6+
let call_test = test(1);
7+
}

0 commit comments

Comments
 (0)