diff options
author | Alex Crichton <alex@alexcrichton.com> | 2015-10-07 10:21:47 -0700 |
---|---|---|
committer | Alex Crichton <alex@alexcrichton.com> | 2015-10-07 10:21:47 -0700 |
commit | 251ec8bdd0f8010ffb1f82853652d6566e1e6a13 (patch) | |
tree | da235d261e73fe3c42698bfe4a38e50db148227e | |
parent | d5b69eb0db8f1054246c273a3d49c6209dc90366 (diff) | |
download | ssh2-rs-251ec8bdd0f8010ffb1f82853652d6566e1e6a13.zip |
Add automated testing of FFI bindings
-rw-r--r-- | .travis.yml | 5 | ||||
-rw-r--r-- | appveyor.yml | 3 | ||||
-rw-r--r-- | libssh2-sys/lib.rs | 70 | ||||
-rw-r--r-- | src/channel.rs | 14 | ||||
-rw-r--r-- | src/session.rs | 12 | ||||
-rw-r--r-- | systest/Cargo.toml | 12 | ||||
-rw-r--r-- | systest/build.rs | 24 | ||||
-rw-r--r-- | systest/src/main.rs | 9 | ||||
-rw-r--r-- | tests/session.rs | 2 |
9 files changed, 102 insertions, 49 deletions
diff --git a/.travis.yml b/.travis.yml index 6f1149e..c8fe3be 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,9 +13,10 @@ before_script: - telnet localhost 22 & script: - export CARGO_TARGET_DIR=`pwd`/target - - cargo build --verbose - - cargo test --verbose + - cargo build + - cargo test - rustdoc --test README.md -L target + - cargo run --manifest-path systest/Cargo.toml - cargo doc --no-deps - cargo doc --no-deps --manifest-path libssh2-sys/Cargo.toml after_success: diff --git a/appveyor.yml b/appveyor.yml index 9644648..66ff0c0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,4 +13,5 @@ install: build: false test_script: - - cargo test --verbose --no-run + - cargo test --no-run + - cargo run --manifest-path systest/Cargo.toml diff --git a/libssh2-sys/lib.rs b/libssh2-sys/lib.rs index f2ddebd..20396f3 100644 --- a/libssh2-sys/lib.rs +++ b/libssh2-sys/lib.rs @@ -151,13 +151,16 @@ pub enum LIBSSH2_KNOWNHOSTS {} pub enum LIBSSH2_SFTP {} pub enum LIBSSH2_SFTP_HANDLE {} +pub type libssh2_int64_t = i64; +pub type libssh2_uint64_t = u64; + #[repr(C)] pub struct libssh2_agent_publickey { pub magic: c_uint, pub node: *mut c_void, pub blob: *mut c_uchar, pub blob_len: size_t, - pub comment: *const c_char, + pub comment: *mut c_char, } #[repr(C)] @@ -173,7 +176,7 @@ pub struct libssh2_knownhost { #[derive(Copy, Clone)] pub struct LIBSSH2_SFTP_ATTRIBUTES { pub flags: c_ulong, - pub filesize: u64, + pub filesize: libssh2_uint64_t, pub uid: c_ulong, pub gid: c_ulong, pub permissions: c_ulong, @@ -184,17 +187,17 @@ pub struct LIBSSH2_SFTP_ATTRIBUTES { #[repr(C)] #[derive(Copy, Clone)] pub struct LIBSSH2_SFTP_STATVFS { - pub f_bsize: u64, - pub f_frsize: u64, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - pub f_files: u64, - pub f_ffree: u64, - pub f_favail: u64, - pub f_fsid: u64, - pub f_flag: u64, - pub f_namemax: u64, + pub f_bsize: libssh2_uint64_t, + pub f_frsize: libssh2_uint64_t, + pub f_blocks: libssh2_uint64_t, + pub f_bfree: libssh2_uint64_t, + pub f_bavail: libssh2_uint64_t, + pub f_files: libssh2_uint64_t, + pub f_ffree: libssh2_uint64_t, + pub f_favail: libssh2_uint64_t, + pub f_fsid: libssh2_uint64_t, + pub f_flag: libssh2_uint64_t, + pub f_namemax: libssh2_uint64_t, } pub type LIBSSH2_ALLOC_FUNC = extern fn(size_t, *mut *mut c_void) -> *mut c_void; @@ -220,7 +223,8 @@ extern { // session pub fn libssh2_session_init_ex(alloc: Option<LIBSSH2_ALLOC_FUNC>, free: Option<LIBSSH2_FREE_FUNC>, - realloc: Option<LIBSSH2_REALLOC_FUNC>) + realloc: Option<LIBSSH2_REALLOC_FUNC>, + abstrakt: *mut c_void) -> *mut LIBSSH2_SESSION; pub fn libssh2_session_free(sess: *mut LIBSSH2_SESSION) -> c_int; pub fn libssh2_session_banner_get(sess: *mut LIBSSH2_SESSION) -> *const c_char; @@ -257,7 +261,7 @@ extern { socket: libssh2_socket_t) -> c_int; pub fn libssh2_keepalive_config(sess: *mut LIBSSH2_SESSION, want_reply: c_int, - interval: c_uint) -> c_int; + interval: c_uint); pub fn libssh2_keepalive_send(sess: *mut LIBSSH2_SESSION, seconds_to_next: *mut c_int) -> c_int; @@ -290,8 +294,8 @@ extern { streamid: c_int) -> c_int; pub fn libssh2_channel_write_ex(chan: *mut LIBSSH2_CHANNEL, stream_id: c_int, - buf: *mut c_char, - buflen: size_t) -> c_int; + buf: *const c_char, + buflen: size_t) -> ssize_t; pub fn libssh2_channel_get_exit_signal(chan: *mut LIBSSH2_CHANNEL, exitsignal: *mut *mut c_char, exitsignal_len: *mut size_t, @@ -310,7 +314,7 @@ extern { pub fn libssh2_channel_read_ex(chan: *mut LIBSSH2_CHANNEL, stream_id: c_int, buf: *mut c_char, - buflen: size_t) -> c_int; + buflen: size_t) -> ssize_t; pub fn libssh2_channel_setenv_ex(chan: *mut LIBSSH2_CHANNEL, var: *const c_char, varlen: c_uint, @@ -332,14 +336,14 @@ extern { width_px: c_int, height_px: c_int) -> c_int; pub fn libssh2_channel_window_read_ex(chan: *mut LIBSSH2_CHANNEL, - read_avail: *mut c_uint, - window_size_initial: *mut c_uint) - -> c_uint; + read_avail: *mut c_ulong, + window_size_initial: *mut c_ulong) + -> c_ulong; pub fn libssh2_channel_window_write_ex(chan: *mut LIBSSH2_CHANNEL, - window_size_initial: *mut c_uint) - -> c_uint; + window_size_initial: *mut c_ulong) + -> c_ulong; pub fn libssh2_channel_receive_window_adjust2(chan: *mut LIBSSH2_CHANNEL, - adjust: c_uint, + adjust: c_ulong, force: c_uchar, window: *mut c_uint) -> c_int; pub fn libssh2_channel_direct_tcpip_ex(ses: *mut LIBSSH2_SESSION, @@ -353,7 +357,7 @@ extern { pub fn libssh2_channel_forward_cancel(listener: *mut LIBSSH2_LISTENER) -> c_int; pub fn libssh2_channel_forward_listen_ex(sess: *mut LIBSSH2_SESSION, - host: *mut c_char, + host: *const c_char, port: c_int, bound_port: *mut c_int, queue_maxsize: c_int) @@ -363,7 +367,7 @@ extern { pub fn libssh2_userauth_authenticated(sess: *mut LIBSSH2_SESSION) -> c_int; pub fn libssh2_userauth_list(sess: *mut LIBSSH2_SESSION, username: *const c_char, - username_len: c_uint) -> *const c_char; + username_len: c_uint) -> *mut c_char; pub fn libssh2_userauth_hostbased_fromfile_ex(sess: *mut LIBSSH2_SESSION, username: *const c_char, username_len: c_uint, @@ -393,9 +397,9 @@ extern { // knownhost pub fn libssh2_knownhost_free(hosts: *mut LIBSSH2_KNOWNHOSTS); pub fn libssh2_knownhost_addc(hosts: *mut LIBSSH2_KNOWNHOSTS, - host: *mut c_char, - salt: *mut c_char, - key: *mut c_char, + host: *const c_char, + salt: *const c_char, + key: *const c_char, keylen: size_t, comment: *const c_char, commentlen: size_t, @@ -447,7 +451,7 @@ extern { pub fn libssh2_scp_send64(sess: *mut LIBSSH2_SESSION, path: *const c_char, mode: c_int, - size: u64, + size: libssh2_int64_t, mtime: libc::time_t, atime: libc::time_t) -> *mut LIBSSH2_CHANNEL; @@ -498,8 +502,10 @@ extern { pub fn libssh2_sftp_write(handle: *mut LIBSSH2_SFTP_HANDLE, buffer: *const c_char, len: size_t) -> ssize_t; - pub fn libssh2_sftp_tell64(handle: *mut LIBSSH2_SFTP_HANDLE) -> u64; - pub fn libssh2_sftp_seek64(handle: *mut LIBSSH2_SFTP_HANDLE, off: u64); + pub fn libssh2_sftp_tell64(handle: *mut LIBSSH2_SFTP_HANDLE) + -> libssh2_uint64_t; + pub fn libssh2_sftp_seek64(handle: *mut LIBSSH2_SFTP_HANDLE, + off: libssh2_uint64_t); pub fn libssh2_sftp_readdir_ex(handle: *mut LIBSSH2_SFTP_HANDLE, buffer: *mut c_char, buffer_len: size_t, diff --git a/src/channel.rs b/src/channel.rs index 40933a1..cb4cf0f 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -2,7 +2,7 @@ use std::cmp; use std::io::prelude::*; use std::io::{self, ErrorKind}; use std::slice; -use libc::{c_uint, c_int, size_t, c_char, c_void, c_uchar}; +use libc::{c_uint, c_int, size_t, c_char, c_void, c_uchar, c_ulong}; use {raw, Session, Error}; use util::{Binding, SessionBinding}; @@ -274,17 +274,17 @@ impl<'sess> Channel<'sess> { /// /// This function returns the new size of the receive window (as understood /// by remote end) on success. - pub fn adjust_receive_window(&mut self, adjust: u32, force: bool) - -> Result<u32, Error> { + pub fn adjust_receive_window(&mut self, adjust: u64, force: bool) + -> Result<u64, Error> { let mut ret = 0; let rc = unsafe { raw::libssh2_channel_receive_window_adjust2(self.raw, - adjust as c_uint, + adjust as c_ulong, force as c_uchar, &mut ret) }; try!(self.sess.rc(rc)); - Ok(ret as u32) + Ok(ret as u64) } /// Artificially limit the number of bytes that will be read from this @@ -390,7 +390,7 @@ impl<'channel, 'sess> Read for Stream<'channel, 'sess> { self.id as c_int, data.as_mut_ptr() as *mut _, data.len() as size_t); - self.channel.sess.rc(rc).map(|()| rc as usize) + self.channel.sess.rc(rc as c_int).map(|()| rc as usize) }; match ret { Ok(n) => { @@ -411,7 +411,7 @@ impl<'channel, 'sess> Write for Stream<'channel, 'sess> { self.id as c_int, data.as_ptr() as *mut _, data.len() as size_t); - self.channel.sess.rc(rc).map(|()| rc as usize) + self.channel.sess.rc(rc as c_int).map(|()| rc as usize) }.map_err(|e| { io::Error::new(ErrorKind::Other, e) }) diff --git a/src/session.rs b/src/session.rs index 30ac664..1a23f5b 100644 --- a/src/session.rs +++ b/src/session.rs @@ -37,7 +37,8 @@ impl Session { pub fn new() -> Option<Session> { ::init(); unsafe { - let ret = raw::libssh2_session_init_ex(None, None, None); + let ret = raw::libssh2_session_init_ex(None, None, None, + 0 as *mut _); if ret.is_null() {None} else {Some(Binding::from_raw(ret))} } } @@ -455,7 +456,7 @@ impl Session { let ret = raw::libssh2_scp_send64(self.raw, path.as_ptr(), mode as c_int, - size, + size as i64, mtime as libc::time_t, atime as libc::time_t); SessionBinding::from_raw_opt(self, ret) @@ -562,11 +563,10 @@ impl Session { /// The interval argument is number of seconds that can pass without any /// I/O, use 0 (the default) to disable keepalives. To avoid some busy-loop /// corner-cases, if you specify an interval of 1 it will be treated as 2. - pub fn set_keepalive(&self, want_reply: bool, interval: u32) - -> Result<(), Error> { + pub fn set_keepalive(&self, want_reply: bool, interval: u32) { unsafe { - self.rc(raw::libssh2_keepalive_config(self.raw, want_reply as c_int, - interval as c_uint)) + raw::libssh2_keepalive_config(self.raw, want_reply as c_int, + interval as c_uint) } } diff --git a/systest/Cargo.toml b/systest/Cargo.toml new file mode 100644 index 0000000..af981da --- /dev/null +++ b/systest/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "systest" +version = "0.1.0" +authors = ["Alex Crichton <alex@alexcrichton.com>"] +build = "build.rs" + +[dependencies] +libssh2-sys = { path = "../libssh2-sys" } +libc = "0.1" + +[build-dependencies] +ctest = { git = "https://github.com/alexcrichton/ctest" } diff --git a/systest/build.rs b/systest/build.rs new file mode 100644 index 0000000..4a2d2b4 --- /dev/null +++ b/systest/build.rs @@ -0,0 +1,24 @@ +extern crate ctest; + +use std::env; + +fn main() { + let mut cfg = ctest::TestGenerator::new(); + cfg.header("libssh2.h") + .header("libssh2_publickey.h") + .header("libssh2_sftp.h") + .include(env::var("DEP_SSH2_INCLUDE").unwrap()) + .type_name(|s, is_struct| { + if (is_struct || s == "stat") && !s.starts_with("LIB") { + format!("struct {}", s) + } else { + s.to_string() + } + }) + .skip_type(|t| t.ends_with("FUNC")) + .skip_fn(|f| { + f == "libssh2_userauth_password_ex" || + f == "libssh2_session_init_ex" + }); + cfg.generate("../libssh2-sys/lib.rs", "all.rs"); +} diff --git a/systest/src/main.rs b/systest/src/main.rs new file mode 100644 index 0000000..7fe430a --- /dev/null +++ b/systest/src/main.rs @@ -0,0 +1,9 @@ +#![allow(bad_style, improper_ctypes)] + +extern crate libssh2_sys; +extern crate libc; + +use libc::*; +use libssh2_sys::*; + +include!(concat!(env!("OUT_DIR"), "/all.rs")); diff --git a/tests/session.rs b/tests/session.rs index f8b378e..85fa321 100644 --- a/tests/session.rs +++ b/tests/session.rs @@ -49,7 +49,7 @@ fn smoke_handshake() { #[test] fn keepalive() { let (_tcp, sess) = ::authed_session(); - sess.set_keepalive(false, 10).unwrap(); + sess.set_keepalive(false, 10); sess.keepalive_send().unwrap(); } |