diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/static-lib-test.c | 14 | ||||
-rw-r--r-- | tests/static-lib.h | 3 | ||||
-rw-r--r-- | tests/static-lib1.c | 7 | ||||
-rw-r--r-- | tests/static-lib2-long-name.c | 8 | ||||
-rw-r--r-- | tests/tests.rs | 47 |
5 files changed, 79 insertions, 0 deletions
diff --git a/tests/static-lib-test.c b/tests/static-lib-test.c new file mode 100644 index 0000000..2b4d1dd --- /dev/null +++ b/tests/static-lib-test.c @@ -0,0 +1,14 @@ +#include "static-lib.h" + +#include <stdlib.h> +#include <stdio.h> + +int main(void) { + printf("%d\n",f()); + printf("%d\n",f()); + return 0; +} + +void entry(void) { + exit(main()); +} diff --git a/tests/static-lib.h b/tests/static-lib.h new file mode 100644 index 0000000..c848962 --- /dev/null +++ b/tests/static-lib.h @@ -0,0 +1,3 @@ +extern int p; +int f(); +int g(); diff --git a/tests/static-lib1.c b/tests/static-lib1.c new file mode 100644 index 0000000..56a5c00 --- /dev/null +++ b/tests/static-lib1.c @@ -0,0 +1,7 @@ +#include "static-lib.h" + +int p; + +int f() { + return 17 + g(); +} diff --git a/tests/static-lib2-long-name.c b/tests/static-lib2-long-name.c new file mode 100644 index 0000000..13b9854 --- /dev/null +++ b/tests/static-lib2-long-name.c @@ -0,0 +1,8 @@ +#include "static-lib.h" +#include <stdio.h> + +int g() { + ++p; + printf("call %d\n", p); + return p; +} diff --git a/tests/tests.rs b/tests/tests.rs index 14f90bc..24e1881 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -92,6 +92,53 @@ mod tests { } #[test] + fn static_lib_c() { + // compile .o files + let status = Command::new("gcc") + .args(&[ + "-m32", + "-fno-pic", + "-c", + &file("static-lib1.c"), + "-o", + &file("static-lib1.o"), + ]) + .status() + .unwrap(); + assert!(status.success()); + let status = Command::new("gcc") + .args(&[ + "-m32", + "-fno-pic", + "-c", + &file("static-lib2-long-name.c"), + "-o", + &file("static-lib2-long-name.o"), + ]) + .status() + .unwrap(); + assert!(status.success()); + // make .a file + let status = Command::new("ar") + .args(&[ + "rc", + &file("static-lib.a"), + &file("static-lib1.o"), + &file("static-lib2-long-name.o"), + ]) + .status() + .unwrap(); + assert!(status.success()); + let mut linker = test_linker(); + add(&mut linker, "static-lib.a", true); + add(&mut linker, "static-lib-test.c", true); + add(&mut linker, "libc.so.6", false); + link(&linker, "static-lib-test.out", "entry"); + let output = run("static-lib-test.out"); + assert_eq!(output.stdout, b"call 1\n18\ncall 2\n19\n"); + } + + #[test] fn cpp() { let mut linker = test_linker(); add(&mut linker, "cpp.cpp", true); |