Merge pull request #10 from alexcrichton/fix-ci

Fix CI and 32-bit builds
This commit is contained in:
Alex Crichton 2017-05-30 09:33:26 -05:00 committed by GitHub
commit e8859fb3fe
12 changed files with 158 additions and 144 deletions

View File

@ -1,35 +1,33 @@
language: rust
rust:
- nightly
rust: nightly
sudo: false
matrix:
include:
- env: TARGET=i686-unknown-linux-gnu
addons:
apt:
packages:
- gcc-multilib
after_success:
- travis-cargo doc-upload
- os: osx
env: TARGET=x86_64-apple-darwin NO_ADD=1
- os: osx
env: TARGET=i686-apple-darwin
sudo: false
install:
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then OS=unknown-linux-gnu; else OS=apple-darwin; fi
- export TARGET=$ARCH-$OS
- rustup target list | egrep '\(installed\)|\(default\)' | grep $TARGET || rustup target add $TARGET
before_script:
- pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH
- if [ -z "$TARGET" ]; then export NO_ADD=1; fi
- if [ -z "$TARGET" ]; then export TARGET=x86_64-unknown-linux-gnu; fi
- if [ -z "$NO_ADD" ]; then rustup target add $TARGET; fi
script:
- export RUST_BACKTRACE=1
- cargo build --verbose --target $TARGET
- cargo test --verbose --target $TARGET
- cargo test --verbose --target $TARGET -p jemalloc-sys
- cargo run --target $TARGET --manifest-path systest/Cargo.toml
- cargo build --target $TARGET
- cargo test --target $TARGET
- cargo doc
after_success:
- travis-cargo --only nightly doc-upload
os:
- linux
- osx
env:
global:
secure: "2Z1z4ir++XEQb9eegYTMolsNfTo1aATric2k4KfvRgnG1nAvvccf1Jg0828PVeqqD6w5f+X52AVT4bTDXbSL5L+/cTiBuVmY3943nyNOgHxFBTbVlnLtGnh18bb7AQAhyH1L9KjiLptMtFUfIg3TQ9r0QS+cBEJMFiE8BuuQMq/uPZYF3QMuV8W+9AwnqZPgdZV4q7LRnx2gHyVKifRfa4v0TxJA+fY5euON8CKemw12yVTZyNS5WUq6GLvQa5KsSYOSAIYizxz8Mze8plQytc6VhF3OuFyJ72u5LAx+szyx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FLLUujFmmypgs4Qit5HtzwQ="
notifications:
email:
on_success: never
addons:
apt:
packages:
- g++-multilib

View File

@ -7,11 +7,17 @@ readme = "README.md"
keywords = ["allocator"]
repository = "https://github.com/alexcrichton/jemallocator"
homepage = "https://github.com/alexcrichton/jemallocator"
documentation = "http://alexcrichton.com/jemallocator"
documentation = "https://docs.rs/jemallocator"
description = """
A Rust allocator backed by jemalloc
"""
[lib]
test = false
[workspace]
members = ["systest"]
[dependencies]
jemalloc-sys = { path = "jemalloc-sys", version = "0.1.0" }
libc = { version = "0.2.8", default-features = false }

View File

@ -2,7 +2,7 @@
[![Build Status](https://travis-ci.org/alexcrichton/jemallocator.svg?branch=master)](https://travis-ci.org/alexcrichton/jemallocator)
[Documentation](http://alexcrichton.com/jemallocator)
[Documentation](https://docs.rs/jemallocator)
A nightly-only Rust allocator crate which links to jemalloc and forces all Rust
allocations to use jemalloc as well.

View File

@ -7,11 +7,14 @@ links = "jemalloc"
license = "MIT/Apache-2.0"
repository = "https://github.com/alexcrichton/jemallocator"
homepage = "https://github.com/alexcrichton/jemallocator"
documentation = "http://alexcrichton.com/jemallocator"
documentation = "https://docs.rs/jemallocator-sys"
description = """
Rust FFI bindings to jemalloc
"""
[lib]
test = false
[dependencies]
libc = { version = "0.2.8", default-features = false }

View File

@ -45,7 +45,7 @@ fn main() {
.replace("\\", "/"))
.current_dir(&build_dir)
.env("CC", compiler.path())
.env("EXTRA_CFLAGS", cflags);
.env("CFLAGS", cflags);
if target.contains("ios") {
cmd.arg("--disable-tls");

View File

@ -14,13 +14,15 @@ extern crate libc;
use libc::{c_int, c_void, size_t, c_char};
pub const MALLOCX_ZERO: c_int = 0x40;
extern "C" {
#[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios"),
link_name = "je_mallocx")]
pub fn mallocx(size: size_t, flags: c_int) -> *mut c_void;
#[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios"),
link_name = "je_calloc")]
pub fn calloc(size: size_t, flags: c_int) -> *mut c_void;
pub fn calloc(size: size_t, flags: size_t) -> *mut c_void;
#[cfg_attr(any(target_os = "macos", target_os = "android", target_os = "ios"),
link_name = "je_rallocx")]
pub fn rallocx(ptr: *mut c_void, size: size_t, flags: c_int) -> *mut c_void;
@ -67,83 +69,3 @@ extern "C" {
cbopaque: *mut c_void,
opts: *const c_char);
}
#[cfg(test)]
mod test {
use libc::{c_void, c_char};
use core::{ptr, mem};
#[test]
fn test_basic_alloc() {
unsafe {
let exp_size = super::nallocx(100, 0);
assert!(exp_size >= 100);
let mut ptr = super::mallocx(100, 0);
assert!(!ptr.is_null());
assert_eq!(exp_size, super::malloc_usable_size(ptr));
ptr = super::rallocx(ptr, 50, 0);
let size = super::xallocx(ptr, 30, 20, 0);
assert!(size >= 50);
super::sdallocx(ptr, 50, 0);
}
}
#[test]
fn test_mallctl() {
let ptr = unsafe { super::mallocx(100, 0) };
let mut allocated: usize = 0;
let mut val_len = mem::size_of_val(&allocated);
let field = "stats.allocated\0";
let mut code;
code = unsafe {
super::mallctl(field.as_ptr() as *const _,
&mut allocated as *mut _ as *mut c_void,
&mut val_len,
ptr::null_mut(),
0)
};
assert_eq!(code, 0);
assert!(allocated > 0);
let mut mib = [0, 0];
let mut mib_len = 2;
code = unsafe {
super::mallctlnametomib(field.as_ptr() as *const _, mib.as_mut_ptr(), &mut mib_len)
};
assert_eq!(code, 0);
let mut allocated_by_mib = 0;
let code = unsafe {
super::mallctlbymib(mib.as_ptr(),
mib_len,
&mut allocated_by_mib as *mut _ as *mut c_void,
&mut val_len,
ptr::null_mut(),
0)
};
assert_eq!(code, 0);
assert_eq!(allocated_by_mib, allocated);
unsafe { super::sdallocx(ptr, 100, 0) };
}
#[test]
fn test_stats() {
struct PrintCtx {
called_times: usize,
}
extern "C" fn write_cb(ctx: *mut c_void, _: *const c_char) {
let print_ctx = unsafe { &mut *(ctx as *mut PrintCtx) };
print_ctx.called_times += 1;
}
let mut ctx = PrintCtx { called_times: 0 };
unsafe {
super::malloc_stats_print(write_cb, &mut ctx as *mut _ as *mut c_void, ptr::null());
}
assert_ne!(ctx.called_times,
0,
"print should be triggered at lease once.");
}
}

View File

@ -33,8 +33,6 @@ const MIN_ALIGN: usize = 8;
target_arch = "powerpc64le")))]
const MIN_ALIGN: usize = 16;
const MALLOCX_ZERO: c_int = 0x40;
// MALLOCX_ALIGN(a) macro
fn mallocx_align(a: usize) -> c_int {
a.trailing_zeros() as c_int
@ -59,7 +57,7 @@ pub extern "C" fn __rust_allocate_zeroed(size: usize, align: usize) -> *mut u8 {
if align <= MIN_ALIGN {
unsafe { ffi::calloc(size as size_t, 1) as *mut u8 }
} else {
let flags = align_to_flags(align) | MALLOCX_ZERO;
let flags = align_to_flags(align) | ffi::MALLOCX_ZERO;
unsafe { ffi::mallocx(size as size_t, flags) as *mut u8 }
}
}
@ -110,7 +108,8 @@ pub extern "C" fn pthread_atfork(_prefork: *mut u8,
/// Fetch the value of options `name`.
///
/// Please note that if you want to fetch a string, use char* instead of &str or cstring.
/// Please note that if you want to fetch a string, use char* instead of &str or
/// cstring.
pub unsafe fn mallctl_fetch<T>(name: &[u8], t: &mut T) -> Result<(), i32> {
// make sure name is a valid c string.
if name.is_empty() || *name.last().unwrap() != 0 {
@ -131,7 +130,8 @@ pub unsafe fn mallctl_fetch<T>(name: &[u8], t: &mut T) -> Result<(), i32> {
/// Set a value to option `name`.
///
/// Please note that if you want to set a string, use char* instead of &str or cstring.
/// Please note that if you want to set a string, use char* instead of &str or
/// cstring.
pub unsafe fn mallctl_set<T>(name: &[u8], mut t: T) -> Result<(), i32> {
// make sure name is a valid c string.
if name.is_empty() || *name.last().unwrap() != 0 {
@ -148,30 +148,3 @@ pub unsafe fn mallctl_set<T>(name: &[u8], mut t: T) -> Result<(), i32> {
}
Ok(())
}
#[cfg(test)]
mod tests {
use libc;
#[test]
fn smoke() {
let ptr = super::__rust_allocate(100, 8);
assert!(!ptr.is_null());
super::__rust_deallocate(ptr, 100, 8);
}
#[test]
fn test_mallctl() {
let mut epoch: u64 = 0;
unsafe {
assert_eq!(super::mallctl_fetch(b"", &mut epoch), Err(libc::EINVAL));
assert_eq!(super::mallctl_fetch(b"epoch", &mut epoch),
Err(libc::EINVAL));
super::mallctl_fetch(b"epoch\0", &mut epoch).unwrap();
assert!(epoch > 0);
assert_eq!(super::mallctl_set(b"", epoch), Err(libc::EINVAL));
assert_eq!(super::mallctl_set(b"epoch", epoch), Err(libc::EINVAL));
super::mallctl_set(b"epoch\0", epoch).unwrap();
}
}
}

View File

@ -9,4 +9,4 @@ jemalloc-sys = { path = "../jemalloc-sys" }
libc = "0.1"
[build-dependencies]
ctest = { git = "https://github.com/alexcrichton/ctest" }
ctest = "0.1"

View File

@ -8,6 +8,12 @@ fn main() {
let mut cfg = ctest::TestGenerator::new();
cfg.header("jemalloc/jemalloc.h")
.include(root.join("include"));
.include(root.join("include"))
.fn_cname(|rust, link_name| link_name.unwrap_or(rust).to_string());
if cfg!(target_os = "linux") {
cfg.skip_fn(|f| f == "malloc_usable_size");
}
cfg.generate("../jemalloc-sys/src/lib.rs", "all.rs");
}

View File

@ -5,7 +5,7 @@ extern crate alloc_system;
extern crate jemalloc_sys;
extern crate libc;
use libc::*;
use libc::c_int;
use jemalloc_sys::*;
include!(concat!(env!("OUT_DIR"), "/all.rs"));

82
tests/ffi.rs Normal file
View File

@ -0,0 +1,82 @@
extern crate libc;
extern crate jemalloc_sys as ffi;
extern crate jemallocator;
use std::ptr;
use std::mem;
use libc::{c_void, c_char};
#[test]
fn test_basic_alloc() {
unsafe {
let exp_size = ffi::nallocx(100, 0);
assert!(exp_size >= 100);
let mut ptr = ffi::mallocx(100, 0);
assert!(!ptr.is_null());
assert_eq!(exp_size, ffi::malloc_usable_size(ptr));
ptr = ffi::rallocx(ptr, 50, 0);
let size = ffi::xallocx(ptr, 30, 20, 0);
assert!(size >= 50);
ffi::sdallocx(ptr, 50, 0);
}
}
#[test]
fn test_mallctl() {
let ptr = unsafe { ffi::mallocx(100, 0) };
let mut allocated: usize = 0;
let mut val_len = mem::size_of_val(&allocated);
let field = "stats.allocated\0";
let mut code;
code = unsafe {
ffi::mallctl(field.as_ptr() as *const _,
&mut allocated as *mut _ as *mut c_void,
&mut val_len,
ptr::null_mut(),
0)
};
assert_eq!(code, 0);
assert!(allocated > 0);
let mut mib = [0, 0];
let mut mib_len = 2;
code = unsafe {
ffi::mallctlnametomib(field.as_ptr() as *const _, mib.as_mut_ptr(), &mut mib_len)
};
assert_eq!(code, 0);
let mut allocated_by_mib = 0;
let code = unsafe {
ffi::mallctlbymib(mib.as_ptr(),
mib_len,
&mut allocated_by_mib as *mut _ as *mut c_void,
&mut val_len,
ptr::null_mut(),
0)
};
assert_eq!(code, 0);
assert_eq!(allocated_by_mib, allocated);
unsafe { ffi::sdallocx(ptr, 100, 0) };
}
#[test]
fn test_stats() {
struct PrintCtx {
called_times: usize,
}
extern "C" fn write_cb(ctx: *mut c_void, _: *const c_char) {
let print_ctx = unsafe { &mut *(ctx as *mut PrintCtx) };
print_ctx.called_times += 1;
}
let mut ctx = PrintCtx { called_times: 0 };
unsafe {
ffi::malloc_stats_print(write_cb, &mut ctx as *mut _ as *mut c_void, ptr::null());
}
assert_ne!(ctx.called_times,
0,
"print should be triggered at lease once.");
}

24
tests/malloctl.rs Normal file
View File

@ -0,0 +1,24 @@
extern crate libc;
extern crate jemallocator as alloc;
#[test]
fn smoke() {
let ptr = alloc::__rust_allocate(100, 8);
assert!(!ptr.is_null());
alloc::__rust_deallocate(ptr, 100, 8);
}
#[test]
fn test_mallctl() {
let mut epoch: u64 = 0;
unsafe {
assert_eq!(alloc::mallctl_fetch(b"", &mut epoch), Err(libc::EINVAL));
assert_eq!(alloc::mallctl_fetch(b"epoch", &mut epoch),
Err(libc::EINVAL));
alloc::mallctl_fetch(b"epoch\0", &mut epoch).unwrap();
assert!(epoch > 0);
assert_eq!(alloc::mallctl_set(b"", epoch), Err(libc::EINVAL));
assert_eq!(alloc::mallctl_set(b"epoch", epoch), Err(libc::EINVAL));
alloc::mallctl_set(b"epoch\0", epoch).unwrap();
}
}