Skip to content

Commit 6d6ccb7

Browse files
committed
Add a new run-make test directory
This infrastructure is meant to support runnings tests that involve various interesting interdependencies about the types of crates being linked or possibly interacting with C libraries. The goal of these make tests is to not restrict them to a particular test runner, but allow each test to run its own tests. To this end, there is a new src/test/run-make directory which has sub-folders of tests. Each test requires a `Makefile`, and running the tests constitues simply running `make` inside the directory. The new target is `check-stageN-rmake`. These tests will have the destination directory (as TMPDIR) and the local rust compiler (as RUSTC) passed along to them. There is also some helpful cross-platform utilities included in src/test/run-make/tools.mk to aid with compiling C programs and running them. The impetus for adding this new test suite is to allow various interesting forms of testing rust linkage. All of the tests initially added are various flavors of compiling Rust and C with one another as well as just making sure that rust linkage works in general. Closes #10434
1 parent 9fbba7b commit 6d6ccb7

File tree

58 files changed

+433
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+433
-2
lines changed

mk/tests.mk

+37-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ check-lite: cleantestlibs cleantmptestlogs \
193193
check-stage2-std check-stage2-extra check-stage2-rpass \
194194
check-stage2-rustuv \
195195
check-stage2-rustpkg \
196-
check-stage2-rfail check-stage2-cfail
196+
check-stage2-rfail check-stage2-cfail check-stage2-rmake
197197
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
198198

199199
.PHONY: cleantmptestlogs cleantestlibs
@@ -284,7 +284,8 @@ check-stage$(1)-T-$(2)-H-$(3)-exec: \
284284
check-stage$(1)-T-$(2)-H-$(3)-rfail-exec \
285285
check-stage$(1)-T-$(2)-H-$(3)-cfail-exec \
286286
check-stage$(1)-T-$(2)-H-$(3)-rpass-full-exec \
287-
check-stage$(1)-T-$(2)-H-$(3)-crates-exec \
287+
check-stage$(1)-T-$(2)-H-$(3)-rmake-exec \
288+
check-stage$(1)-T-$(2)-H-$(3)-crates-exec \
288289
check-stage$(1)-T-$(2)-H-$(3)-bench-exec \
289290
check-stage$(1)-T-$(2)-H-$(3)-debuginfo-exec \
290291
check-stage$(1)-T-$(2)-H-$(3)-codegen-exec \
@@ -770,6 +771,7 @@ TEST_GROUPS = \
770771
cfail \
771772
bench \
772773
perf \
774+
rmake \
773775
debuginfo \
774776
codegen \
775777
doc \
@@ -900,3 +902,36 @@ endef
900902

901903
$(foreach host,$(CFG_HOST), \
902904
$(eval $(call DEF_CHECK_FAST_FOR_H,$(host))))
905+
906+
RMAKE_TESTS := $(shell ls -d $(S)src/test/run-make/*/)
907+
RMAKE_TESTS := $(RMAKE_TESTS:$(S)src/test/run-make/%/=%)
908+
909+
define DEF_RMAKE_FOR_T_H
910+
# $(1) the stage
911+
# $(2) target triple
912+
# $(3) host triple
913+
914+
check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
915+
$$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)
916+
917+
$$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
918+
$$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
919+
@touch $$@
920+
921+
$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
922+
$(S)src/test/run-make/%/Makefile \
923+
$$(HBIN$(1)_H_$(3))/rustc$$(X_$(3))
924+
@rm -rf $(3)/test/run-make/$$*
925+
@mkdir -p $(3)/test/run-make/$$*
926+
@echo maketest: $$*
927+
@python $(S)src/etc/maketest.py $$(dir $$<) \
928+
$$(HBIN$(1)_H_$(3))/rustc$$(X_$(3)) \
929+
$(3)/test/run-make/$$*
930+
@touch $$@
931+
932+
endef
933+
934+
$(foreach stage,$(STAGES), \
935+
$(foreach target,$(CFG_TARGET), \
936+
$(foreach host,$(CFG_HOST), \
937+
$(eval $(call DEF_RMAKE_FOR_T_H,$(stage),$(target),$(host))))))

src/etc/maketest.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# xfail-license
2+
3+
import subprocess
4+
import os
5+
import sys
6+
7+
os.putenv('RUSTC', os.path.abspath(sys.argv[2]))
8+
os.putenv('TMPDIR', os.path.abspath(sys.argv[3]))
9+
10+
proc = subprocess.Popen(['make', '-C', sys.argv[1]],
11+
stdout = subprocess.PIPE,
12+
stderr = subprocess.PIPE)
13+
out, err = proc.communicate()
14+
i = proc.wait()
15+
16+
if i != 0:
17+
18+
print '----- ' + sys.argv[1] + """ --------------------
19+
------ stdout ---------------------------------------------
20+
""" + out + """
21+
------ stderr ---------------------------------------------
22+
""" + err + """
23+
------ ---------------------------------------------
24+
"""
25+
sys.exit(i)
26+
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-include ../tools.mk
2+
3+
# This hits an assertion in the linker on older versions of osx apparently
4+
ifeq ($(shell uname),Darwin)
5+
all:
6+
echo ignored
7+
else
8+
all: $(call DYLIB,cfoo)
9+
$(RUSTC) foo.rs
10+
$(RUSTC) bar.rs
11+
$(call RUN,bar)
12+
rm $(TMPDIR)/$(call DYLIB_GLOB,cfoo)
13+
$(call FAIL,bar)
14+
endif
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern mod foo;
2+
3+
fn main() {
4+
foo::rsfoo();
5+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo() { return 0; }
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[crate_type = "dylib"];
2+
3+
#[link(name = "cfoo")]
4+
extern {
5+
fn foo();
6+
}
7+
8+
pub fn rsfoo() {
9+
unsafe { foo() }
10+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-include ../tools.mk
2+
3+
# This hits an assertion in the linker on older versions of osx apparently
4+
ifeq ($(shell uname),Darwin)
5+
all:
6+
echo ignored
7+
else
8+
all: $(call DYLIB,cfoo)
9+
$(RUSTC) foo.rs
10+
$(RUSTC) bar.rs
11+
LD_LIBRARY_PATH=$(TMPDIR) $(call RUN,bar)
12+
rm $(TMPDIR)/$(call DYLIB_GLOB,cfoo)
13+
$(call FAIL,bar)
14+
endif
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern mod foo;
2+
3+
fn main() {
4+
foo::rsfoo();
5+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo() { return 0; }
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[crate_type = "rlib"];
2+
3+
#[link(name = "cfoo")]
4+
extern {
5+
fn foo();
6+
}
7+
8+
pub fn rsfoo() {
9+
unsafe { foo() }
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) foo.rs
5+
ln -s $(call DYLIB,foo-*) $(call DYLIB,foo)
6+
$(CC) bar.c -lfoo -o $(call RUN,bar) -Wl,-rpath,$(TMPDIR)
7+
$(call RUN,bar)
8+
rm $(call DYLIB,foo)
9+
$(call FAIL,bar)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
void foo();
2+
3+
int main() {
4+
foo();
5+
return 0;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[crate_type = "dylib"];
2+
3+
#[no_mangle]
4+
pub extern "C" fn foo() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-include ../tools.mk
2+
3+
ifneq ($(shell uname),Darwin)
4+
EXTRAFLAGS := -lm -lrt -ldl -lpthread
5+
endif
6+
7+
all:
8+
$(RUSTC) foo.rs -Z gen-crate-map
9+
ln -s $(call STATICLIB,foo-*) $(call STATICLIB,foo)
10+
$(CC) bar.c -lfoo -o $(call RUN,bar) $(EXTRAFLAGS) -lstdc++
11+
$(call RUN,bar)
12+
rm $(call STATICLIB,foo*)
13+
$(call RUN,bar)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
void foo();
2+
3+
int main() {
4+
foo();
5+
return 0;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[crate_type = "staticlib"];
2+
3+
#[no_mangle]
4+
pub extern "C" fn foo() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-include ../tools.mk
2+
3+
all: $(call STATICLIB,cfoo)
4+
$(RUSTC) foo.rs
5+
$(RUSTC) bar.rs
6+
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
7+
$(call RUN,bar)
8+
rm $(TMPDIR)/$(call DYLIB_GLOB,foo)
9+
$(call FAIL,bar)
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern mod foo;
2+
3+
fn main() {
4+
foo::rsfoo();
5+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo() { return 0; }
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[crate_type = "dylib"];
2+
3+
#[link(name = "cfoo")]
4+
extern {
5+
fn foo();
6+
}
7+
8+
pub fn rsfoo() {
9+
unsafe { foo() }
10+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../tools.mk
2+
3+
all: $(call STATICLIB,cfoo)
4+
$(RUSTC) foo.rs
5+
$(RUSTC) bar.rs
6+
rm $(TMPDIR)/$(call RLIB_GLOB,foo)
7+
rm $(TMPDIR)/$(call STATICLIB_GLOB,cfoo)
8+
$(call RUN,bar)
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern mod foo;
2+
3+
fn main() {
4+
foo::rsfoo();
5+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo() { return 0; }
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#[crate_type = "rlib"];
2+
3+
#[link(name = "cfoo")]
4+
extern {
5+
fn foo();
6+
}
7+
8+
pub fn rsfoo() {
9+
unsafe { foo() }
10+
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) m1.rs
5+
$(RUSTC) m2.rs
6+
$(RUSTC) m3.rs
7+
$(RUSTC) m4.rs
8+
$(call RUN,m4)
9+
rm $(TMPDIR)/$(call DYLIB_GLOB,m1)
10+
rm $(TMPDIR)/$(call DYLIB_GLOB,m2)
11+
rm $(TMPDIR)/$(call DYLIB_GLOB,m3)
12+
$(call FAIL,m4)

src/test/run-make/dylib-chain/m1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[crate_type = "dylib"];
2+
pub fn m1() {}

src/test/run-make/dylib-chain/m2.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[crate_type = "dylib"];
2+
extern mod m1;
3+
4+
pub fn m2() { m1::m1() }

src/test/run-make/dylib-chain/m3.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[crate_type = "dylib"];
2+
extern mod m2;
3+
4+
pub fn m3() { m2::m2() }

src/test/run-make/dylib-chain/m4.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extern mod m3;
2+
3+
fn main() { m3::m3() }
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) both.rs
5+
$(RUSTC) dylib.rs -Z prefer-dynamic
6+
$(RUSTC) prog.rs
7+
$(call RUN,prog)

src/test/run-make/mixing-deps/both.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[crate_type = "rlib"];
2+
#[crate_type = "dylib"];
3+
4+
pub static foo: int = 4;
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[crate_type = "dylib"];
2+
extern mod both;
3+
4+
use std::cast;
5+
6+
pub fn addr() -> uint { unsafe { cast::transmute(&both::foo) } }

src/test/run-make/mixing-deps/prog.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extern mod dylib;
2+
extern mod both;
3+
4+
use std::cast;
5+
6+
fn main() {
7+
assert_eq!(unsafe { cast::transmute::<&int, uint>(&both::foo) },
8+
dylib::addr());
9+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) rlib.rs
5+
$(RUSTC) dylib.rs && exit 1 || exit 0
6+
$(RUSTC) rlib.rs --dylib
7+
$(RUSTC) dylib.rs
8+
rm $(call DYLIB,rlib-*)
9+
$(RUSTC) prog.rs && exit 1 || exit 0
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[crate_type = "dylib"];
2+
extern mod rlib;
3+
4+
pub fn dylib() { rlib::rlib() }

src/test/run-make/mixing-libs/prog.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
extern mod dylib;
2+
extern mod rlib;
3+
4+
fn main() {
5+
dylib::dylib();
6+
rlib::rlib();
7+
}

src/test/run-make/mixing-libs/rlib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[crate_type = "rlib"];
2+
pub fn rlib() {}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) bar.rs --dylib --rlib
5+
$(RUSTC) foo.rs -Z prefer-dynamic
6+
$(call RUN,foo)
7+
rm $(TMPDIR)/*bar*
8+
$(call FAILS,foo)

src/test/run-make/prefer-dylib/bar.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn bar() {}

src/test/run-make/prefer-dylib/foo.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern mod bar;
2+
3+
fn main() {
4+
bar::bar();
5+
}
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) bar.rs --dylib --rlib
5+
ls $(TMPDIR)/$(call RLIB_GLOB,bar)
6+
$(RUSTC) foo.rs
7+
rm $(TMPDIR)/*bar*
8+
$(call RUN,foo)

src/test/run-make/prefer-rlib/bar.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn bar() {}

src/test/run-make/prefer-rlib/foo.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern mod bar;
2+
3+
fn main() {
4+
bar::bar();
5+
}

src/test/run-make/rlib-chain/Makefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) m1.rs
5+
$(RUSTC) m2.rs
6+
$(RUSTC) m3.rs
7+
$(RUSTC) m4.rs
8+
$(call RUN,m4)
9+
rm $(TMPDIR)/*lib
10+
$(call RUN,m4)

src/test/run-make/rlib-chain/m1.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[crate_type = "rlib"];
2+
pub fn m1() {}

0 commit comments

Comments
 (0)