Skip to content

Commit 4e83093

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 rust-lang#10434
1 parent c37aa9b commit 4e83093

File tree

55 files changed

+374
-1
lines changed

Some content is hidden

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

55 files changed

+374
-1
lines changed

mk/tests.mk

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 src/test/run-make/*/)
907+
RMAKE_TESTS := $(RMAKE_TESTS:src/test/run-make/%/=%)
908+
RMAKE_DEPS := src/test/run-make/c-dynamic-rlib/Makefile
909+
910+
define DEF_RMAKE_FOR_T_H
911+
# $(1) the stage
912+
# $(2) target triple
913+
# $(3) host triple
914+
915+
check-stage$(1)-T-$(2)-H-$(3)-rmake-exec: \
916+
$$(call TEST_OK_FILE,$(1),$(2),$(3),rmake)
917+
918+
$$(call TEST_OK_FILE,$(1),$(2),$(3),rmake): \
919+
$$(RMAKE_TESTS:%=$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok)
920+
@touch $$@
921+
922+
$(3)/test/run-make/%-$(1)-T-$(2)-H-$(3).ok: \
923+
src/test/run-make/%/Makefile \
924+
$(3)/stage$(1)/bin/rustc$$(X_$(3))
925+
@mkdir -p $(3)/test/run-make/$$*
926+
@echo maketest: $$*
927+
@python src/etc/maketest.py $$(dir $$<) \
928+
$(S)/$(3)/stage$(1)/bin/rustc$$(X_$(3)) \
929+
$(S)/$(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

Lines changed: 26 additions & 0 deletions
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', sys.argv[2])
8+
os.putenv('TMPDIR', 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+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../tools.mk
2+
3+
all: $(call DYLIB,cfoo)
4+
$(RUSTC) foo.rs
5+
$(RUSTC) bar.rs
6+
$(call RUN,bar)
7+
rm $(TMPDIR)/$(call DYLIB_GLOB,cfoo)
8+
$(call FAIL,bar)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern mod foo;
2+
3+
fn main() {
4+
foo::rsfoo();
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo() { return 0; }
Lines changed: 10 additions & 0 deletions
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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../tools.mk
2+
3+
all: $(call DYLIB,cfoo)
4+
$(RUSTC) foo.rs
5+
$(RUSTC) bar.rs
6+
LD_LIBRARY_PATH=$(TMPDIR) $(call RUN,bar)
7+
rm $(TMPDIR)/$(call DYLIB_GLOB,cfoo)
8+
$(call FAIL,bar)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern mod foo;
2+
3+
fn main() {
4+
foo::rsfoo();
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo() { return 0; }
Lines changed: 10 additions & 0 deletions
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+
}
Lines changed: 9 additions & 0 deletions
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)
Lines changed: 6 additions & 0 deletions
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+
}
Lines changed: 4 additions & 0 deletions
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() {}
Lines changed: 13 additions & 0 deletions
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)
Lines changed: 6 additions & 0 deletions
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+
}
Lines changed: 4 additions & 0 deletions
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() {}
Lines changed: 9 additions & 0 deletions
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)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern mod foo;
2+
3+
fn main() {
4+
foo::rsfoo();
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo() { return 0; }
Lines changed: 10 additions & 0 deletions
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+
}
Lines changed: 8 additions & 0 deletions
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)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern mod foo;
2+
3+
fn main() {
4+
foo::rsfoo();
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
int foo() { return 0; }
Lines changed: 10 additions & 0 deletions
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+
}
Lines changed: 12 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extern mod m3;
2+
3+
fn main() { m3::m3() }
Lines changed: 7 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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;
Lines changed: 6 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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+
}
Lines changed: 9 additions & 0 deletions
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
Lines changed: 4 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#[crate_type = "rlib"];
2+
pub fn rlib() {}
Lines changed: 8 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn bar() {}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern mod bar;
2+
3+
fn main() {
4+
bar::bar();
5+
}
Lines changed: 8 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn bar() {}

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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
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

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

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

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

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

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

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
extern mod m3;
2+
3+
fn main() { m3::m3() }
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-include ../tools.mk
2+
all:
3+
$(RUSTC) bar.rs --dylib
4+
$(RUSTC) foo.rs
5+
$(call RUN,foo)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn bar() {}

0 commit comments

Comments
 (0)