Skip to content

Commit

Permalink
[tests] fix Rust tests to run in-place better/properly
Browse files Browse the repository at this point in the history
nozzle-test now uses the nozzle_open() provided tap name
and creates the up.d/tapname file on-the-fly.

knet-test now uses the build-tree crypto/compress plugins
rather than the installed ones
  • Loading branch information
chrissie-c committed Jun 11, 2021
1 parent 91f66ad commit 70c2e36
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 16 deletions.
1 change: 1 addition & 0 deletions libknet/bindings/rust/src/libknet.rs
Expand Up @@ -368,6 +368,7 @@ fn logging_thread(knet_pipe: i32, sender: Sender<LogMsg>)


#[derive(Copy, Clone, PartialEq)]
#[repr(transparent)]
/// a handle into the knet library, returned from [handle_new]
pub struct Handle {
knet_handle: u64,
Expand Down
3 changes: 2 additions & 1 deletion libknet/bindings/rust/tests/Cargo.toml
Expand Up @@ -4,7 +4,8 @@ version = "0.1.0"
authors = ["Christine Caulfield <ccaulfie@redhat.com>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[build-dependencies]
cc = "1.0"

[dependencies]
kronosnet = { path = ".." }
Expand Down
13 changes: 11 additions & 2 deletions libknet/bindings/rust/tests/build.rs
@@ -1,6 +1,15 @@
//extern crate pkg_config;

fn main() {

// Tell the compiler to use the build-tree libs & headers for compiling
println!("cargo:rustc-link-search=native=../../../.libs/");
println!("cargo:rustc-link-lib=knet");

cc::Build::new()
.file("src/bin/set_plugin_path.c")
.file("../../../tests/test-common.c") // for find_plugins_path()
.flag("-Wno-unused-parameter") // Needed for test-common.c to compile cleanly
.include("../../..") // for internals.h
.include("../../../..") // for config.h
.include("../../../tests") // for test-common.h
.compile("set_plugin_path");
}
10 changes: 10 additions & 0 deletions libknet/bindings/rust/tests/src/bin/knet-test.rs
Expand Up @@ -17,6 +17,11 @@ use std::{thread, time};

const CHANNEL: i8 = 1;

// Dirty C function to set the plugin path for testing (only)
extern {
fn set_plugin_path(knet_h: knet::Handle);
}

// Callbacks
fn sock_notify_fn(private_data: u64,
datafd: i32,
Expand Down Expand Up @@ -107,6 +112,11 @@ fn setup_node(our_hostid: &knet::HostId, other_hostid: &knet::HostId,
}
};

// Make sure we use the build-tree plugins if LD_LIBRRAY_PATH points to them
unsafe {
set_plugin_path(knet_handle);
}

if let Err(e) = knet::host_add(knet_handle, &other_hostid) {
println!("Error from host_add: {}", e);
return Err(e);
Expand Down
2 changes: 1 addition & 1 deletion libknet/tests/test-common.c
Expand Up @@ -427,7 +427,7 @@ static int contains_plugins(char *path)


/* libtool sets LD_LIBRARY_PATH to the build tree when running test in-tree */
static char *find_plugins_path(void)
char *find_plugins_path(void)
{
char *ld_libs_env = getenv("LD_LIBRARY_PATH");
if (ld_libs_env) {
Expand Down
1 change: 1 addition & 0 deletions libknet/tests/test-common.h
Expand Up @@ -89,6 +89,7 @@ int make_local_sockaddr6(struct sockaddr_storage *lo, int offset);
int wait_for_host(knet_handle_t knet_h, uint16_t host_id, int seconds, int logfd, FILE *std);
int wait_for_packet(knet_handle_t knet_h, int seconds, int datafd, int logfd, FILE *std);
void test_sleep(knet_handle_t knet_h, int seconds);
char *find_plugins_path(void);
int wait_for_nodes_state(knet_handle_t knet_h, size_t numnodes,
uint8_t state, uint32_t timeout,
int logfd, FILE *std);
Expand Down
5 changes: 1 addition & 4 deletions libnozzle/bindings/rust/tests/Makefile.am
Expand Up @@ -11,15 +11,12 @@ MAINTAINERCLEANFILES = Makefile.in
include $(top_srcdir)/build-aux/check.mk

EXTRA_DIST = Cargo.toml \
src/bin/nozzle-test.rs \
up.d/tap33
src/bin/nozzle-test.rs

check_PROGRAMS = target/$(RUST_TARGET_DIR)/nozzle-test

noinst_PROGRAMS = $(check_PROGRAMS)

noinst_SCRIPTS = up.d/tap33

testsuitedir = $(TESTDIR)
testsuite_PROGRAMS = $(check_PROGRAMS)

Expand Down
41 changes: 35 additions & 6 deletions libnozzle/bindings/rust/tests/src/bin/nozzle-test.rs
Expand Up @@ -8,9 +8,12 @@
//

use libnozzle::libnozzle as nozzle;
use std::io::{Result, Error, ErrorKind};
use std::io::{Result, Error, ErrorKind, BufWriter, Write};
use std::fmt::Write as fmtwrite;
use std::env;
use std::{thread, time};
use std::fs::File;
use std::fs;

const SKIP: i32 = 77;

Expand All @@ -21,9 +24,7 @@ fn main() -> Result<()>
std::process::exit(SKIP);
}


// Name must be tapXX for it to work on FreeBSD
let mut nozzle_name = String::from("tap33");
let mut nozzle_name = String::from("");
let handle = match nozzle::open(&mut nozzle_name, &String::from(env::current_dir().unwrap().to_str().unwrap())) {
Ok(h) => {
println!("Opened device {}", nozzle_name);
Expand Down Expand Up @@ -75,12 +76,40 @@ fn main() -> Result<()>
return Err(e);
}

if let Err(e) = nozzle::set_up(handle){
if let Err(e) = nozzle::set_up(handle) {
println!("Error from set_up: {}", e);
return Err(e);
}

match nozzle::run_updown(handle, nozzle::Action::Up){
// Create the 'up' script so we can test the run_updown() function
let up_path = std::path::Path::new("up.d");
if let Err(e) = fs::create_dir_all(up_path) {
eprintln!("Error creating up.d directory: {:?}", e);
return Err(e);
}

let mut up_filename = String::new();
if let Err(e) = write!(up_filename, "up.d/{}", nozzle_name) {
eprintln!("Error making up.d filename: {:?}", e);
return Err(Error::new(ErrorKind::Other, "Error making up.d filename"));
}
match File::create(&up_filename) {
Err(e) => {
println!("Cannot create up.d file {}: {}", &up_filename, e);
return Err(e);
}
Ok(fl) => {
let mut f = BufWriter::new(fl);
writeln!(f, "#!/bin/sh\necho 'This is a test of an \"Up\" script'")?;
}
}
// A grotty way to do chmod, but normally this would be distributed by the sysadmin
unsafe {
let up_cstring = std::ffi::CString::new(up_filename).unwrap();
libc::chmod(up_cstring.as_ptr(), 0700);
}

match nozzle::run_updown(handle, nozzle::Action::Up) {
Ok(s) => println!("Returned from Up script: {}", s),
Err(e) => {
println!("Error from run_updown: {}", e);
Expand Down
2 changes: 0 additions & 2 deletions libnozzle/bindings/rust/tests/up.d/tap33

This file was deleted.

0 comments on commit 70c2e36

Please sign in to comment.