Sfoglia il codice sorgente

Merge pull request #23 from badboy/appveyor-ci

Build and test on Windows
Quentin Monnet 7 anni fa
parent
commit
391a0be023
8 ha cambiato i file con 137 aggiunte e 6 eliminazioni
  1. 18 0
      appveyor.yml
  2. 12 3
      examples/load_elf.rs
  3. 13 2
      examples/uptime.rs
  4. 68 0
      mk/appveyor.bat
  5. 2 1
      src/helpers.rs
  6. 13 0
      src/lib.rs
  7. 10 0
      tests/misc.rs
  8. 1 0
      tests/ubpf_jit_x86_64.rs

+ 18 - 0
appveyor.yml

@@ -0,0 +1,18 @@
+version: 1.0.{build}
+os:
+  - Visual Studio 2015
+clone_depth: 1
+configuration:
+  - Debug
+platform:
+  - x64
+environment:
+  matrix:
+    - TOOLCHAIN_VERSION: 14.0
+      RUST: 1.20.0
+    - TOOLCHAIN_VERSION: 14.0
+      RUST: beta
+    - TOOLCHAIN_VERSION: 14.0
+      RUST: nightly
+
+build_script: mk/appveyor.bat

+ 12 - 3
examples/load_elf.rs

@@ -118,9 +118,18 @@ fn main() {
     println!("Packet #1, program returned: {:?} ({:#x})", res, res);
     assert_eq!(res, 0xffffffff);
 
-    vm.jit_compile();
-    unsafe {
-        let res = vm.prog_exec_jit(packet2);
+    #[cfg(not(windows))]
+    {
+        vm.jit_compile();
+
+        let res = unsafe { vm.prog_exec_jit(packet2) };
+        println!("Packet #2, program returned: {:?} ({:#x})", res, res);
+        assert_eq!(res, 0);
+    }
+
+    #[cfg(windows)]
+    {
+        let res = vm.prog_exec(packet2);
         println!("Packet #2, program returned: {:?} ({:#x})", res, res);
         assert_eq!(res, 0);
     }

+ 13 - 2
examples/uptime.rs

@@ -54,8 +54,19 @@ fn main() {
     vm.set_prog(prog2);
     vm.register_helper(helpers::BPF_KTIME_GETNS_IDX, helpers::bpf_time_getns);
 
-    vm.jit_compile();
-    let time = unsafe { vm.prog_exec_jit() };
+    let time;
+
+    #[cfg(not(windows))]
+    {
+        vm.jit_compile();
+
+        time = unsafe { vm.prog_exec_jit() };
+    }
+
+    #[cfg(windows)]
+    {
+        time = vm.prog_exec();
+    }
 
     let days    =  time / 10u64.pow(9)  / 60   / 60  / 24;
     let hours   = (time / 10u64.pow(9)  / 60   / 60) % 24;

+ 68 - 0
mk/appveyor.bat

@@ -0,0 +1,68 @@
+echo on
+SetLocal EnableDelayedExpansion
+
+REM This is the recommended way to choose the toolchain version, according to
+REM Appveyor's documentation.
+SET PATH=C:\Program Files (x86)\MSBuild\%TOOLCHAIN_VERSION%\Bin;%PATH%
+
+set VCVARSALL="C:\Program Files (x86)\Microsoft Visual Studio %TOOLCHAIN_VERSION%\VC\vcvarsall.bat"
+
+if [%Platform%] NEQ [x64] goto win32
+set TARGET_ARCH=x86_64
+set TARGET_PROGRAM_FILES=%ProgramFiles%
+call %VCVARSALL% amd64
+if %ERRORLEVEL% NEQ 0 exit 1
+goto download
+
+:win32
+echo on
+if [%Platform%] NEQ [Win32] exit 1
+set TARGET_ARCH=i686
+set TARGET_PROGRAM_FILES=%ProgramFiles(x86)%
+call %VCVARSALL% amd64_x86
+if %ERRORLEVEL% NEQ 0 exit 1
+goto download
+
+:download
+REM vcvarsall turns echo off
+echo on
+
+mkdir windows_build_tools
+mkdir windows_build_tools\
+echo Downloading Yasm...
+powershell -Command "(New-Object Net.WebClient).DownloadFile('http://www.tortall.net/projects/yasm/releases/yasm-1.3.0-win64.exe', 'windows_build_tools\yasm.exe')"
+if %ERRORLEVEL% NEQ 0 (
+  echo ...downloading Yasm failed.
+  exit 1
+)
+
+set RUST_URL=https://static.rust-lang.org/dist/rust-%RUST%-%TARGET_ARCH%-pc-windows-msvc.msi
+echo Downloading %RUST_URL%...
+mkdir build
+powershell -Command "(New-Object Net.WebClient).DownloadFile('%RUST_URL%', 'build\rust-%RUST%-%TARGET_ARCH%-pc-windows-msvc.msi')"
+if %ERRORLEVEL% NEQ 0 (
+  echo ...downloading Rust failed.
+  exit 1
+)
+
+start /wait msiexec /i build\rust-%RUST%-%TARGET_ARCH%-pc-windows-msvc.msi INSTALLDIR="%TARGET_PROGRAM_FILES%\Rust %RUST%" /quiet /qn /norestart
+if %ERRORLEVEL% NEQ 0 exit 1
+
+set PATH="%TARGET_PROGRAM_FILES%\Rust %RUST%\bin";%cd%\windows_build_tools;%PATH%
+
+if [%Configuration%] == [Release] set CARGO_MODE=--release
+
+set
+
+link /?
+cl /?
+rustc --version
+cargo --version
+
+cargo test -vv %CARGO_MODE%
+if %ERRORLEVEL% NEQ 0 exit 1
+
+REM Verify that `cargo build`, independent from `cargo test`, works; i.e.
+REM verify that non-test builds aren't trying to use test-only features.
+cargo build -vv %CARGO_MODE%
+if %ERRORLEVEL% NEQ 0 exit 1

+ 2 - 1
src/helpers.rs

@@ -251,9 +251,10 @@ pub fn strcmp (arg1: u64, arg2: u64, arg3: u64, unused4: u64, unused5: u64) -> u
 /// ```
 /// extern crate libc;
 /// extern crate rbpf;
+/// extern crate time;
 ///
 /// unsafe {
-///     libc::srand(libc::time(std::ptr::null_mut()) as u32);
+///     libc::srand(time::precise_time_ns() as u32)
 /// }
 ///
 /// let n = rbpf::helpers::rand(3, 6, 0, 0, 0);

+ 13 - 0
src/lib.rs

@@ -31,6 +31,7 @@ pub mod ebpf;
 pub mod helpers;
 pub mod insn_builder;
 mod asm_parser;
+#[cfg(not(windows))]
 mod jit;
 mod verifier;
 
@@ -553,6 +554,7 @@ impl<'a> EbpfVmMbuff<'a> {
     ///
     /// vm.jit_compile();
     /// ```
+    #[cfg(not(windows))]
     pub fn jit_compile(&mut self) {
         self.jit = jit::compile(self.prog, &self.helpers, true, false);
     }
@@ -603,9 +605,11 @@ impl<'a> EbpfVmMbuff<'a> {
     /// // Instantiate a VM.
     /// let mut vm = rbpf::EbpfVmMbuff::new(prog);
     ///
+    /// # #[cfg(not(windows))]
     /// vm.jit_compile();
     ///
     /// // Provide both a reference to the packet data, and to the metadata buffer.
+    /// # #[cfg(not(windows))]
     /// unsafe {
     ///     let res = vm.prog_exec_jit(mem, &mut mbuff);
     ///     assert_eq!(res, 0x2211);
@@ -910,6 +914,7 @@ impl<'a> EbpfVmFixedMbuff<'a> {
     ///
     /// vm.jit_compile();
     /// ```
+    #[cfg(not(windows))]
     pub fn jit_compile(&mut self) {
         self.parent.jit = jit::compile(self.parent.prog, &self.parent.helpers, true, true);
     }
@@ -954,9 +959,11 @@ impl<'a> EbpfVmFixedMbuff<'a> {
     /// // Instantiate a VM. Note that we provide the start and end offsets for mem pointers.
     /// let mut vm = rbpf::EbpfVmFixedMbuff::new(prog, 0x40, 0x50);
     ///
+    /// # #[cfg(not(windows))]
     /// vm.jit_compile();
     ///
     /// // Provide only a reference to the packet data. We do not manage the metadata buffer.
+    /// # #[cfg(not(windows))]
     /// unsafe {
     ///     let res = vm.prog_exec_jit(mem);
     ///     assert_eq!(res, 0xdd);
@@ -1162,6 +1169,7 @@ impl<'a> EbpfVmRaw<'a> {
     ///
     /// vm.jit_compile();
     /// ```
+    #[cfg(not(windows))]
     pub fn jit_compile(&mut self) {
         self.parent.jit = jit::compile(self.parent.prog, &self.parent.helpers, false, false);
     }
@@ -1198,8 +1206,10 @@ impl<'a> EbpfVmRaw<'a> {
     ///
     /// let mut vm = rbpf::EbpfVmRaw::new(prog);
     ///
+    /// # #[cfg(not(windows))]
     /// vm.jit_compile();
     ///
+    /// # #[cfg(not(windows))]
     /// unsafe {
     ///     let res = vm.prog_exec_jit(mem);
     ///     assert_eq!(res, 0x22cc);
@@ -1373,6 +1383,7 @@ impl<'a> EbpfVmNoData<'a> {
     ///
     /// vm.jit_compile();
     /// ```
+    #[cfg(not(windows))]
     pub fn jit_compile(&mut self) {
         self.parent.jit_compile();
     }
@@ -1431,8 +1442,10 @@ impl<'a> EbpfVmNoData<'a> {
     ///
     /// let mut vm = rbpf::EbpfVmNoData::new(prog);
     ///
+    /// # #[cfg(not(windows))]
     /// vm.jit_compile();
     ///
+    /// # #[cfg(not(windows))]
     /// unsafe {
     ///     let res = vm.prog_exec_jit();
     ///     assert_eq!(res, 0x1122);

+ 10 - 0
tests/misc.rs

@@ -170,6 +170,7 @@ fn test_vm_block_port() {
     assert_eq!(res, 0xffffffff);
 }
 
+#[cfg(not(windows))]
 #[test]
 fn test_jit_block_port() {
     // To load the bytecode from an object file instead of using the hardcoded instructions,
@@ -308,6 +309,7 @@ fn test_vm_mbuff_with_rust_api() {
 }
 
 // Program and memory come from uBPF test ldxh.
+#[cfg(not(windows))]
 #[test]
 fn test_jit_mbuff() {
     let prog = &[
@@ -336,6 +338,7 @@ fn test_jit_mbuff() {
     }
 }
 
+#[cfg(not(windows))]
 #[test]
 fn test_vm_jit_ldabsb() {
     let prog = &[
@@ -355,6 +358,7 @@ fn test_vm_jit_ldabsb() {
     };
 }
 
+#[cfg(not(windows))]
 #[test]
 fn test_vm_jit_ldabsh() {
     let prog = &[
@@ -374,6 +378,7 @@ fn test_vm_jit_ldabsh() {
     };
 }
 
+#[cfg(not(windows))]
 #[test]
 fn test_vm_jit_ldabsw() {
     let prog = &[
@@ -393,6 +398,7 @@ fn test_vm_jit_ldabsw() {
     };
 }
 
+#[cfg(not(windows))]
 #[test]
 fn test_vm_jit_ldabsdw() {
     let prog = &[
@@ -442,6 +448,7 @@ fn test_vm_err_ldabsb_nomem() {
     // Memory check not implemented for JIT yet.
 }
 
+#[cfg(not(windows))]
 #[test]
 fn test_vm_jit_ldindb() {
     let prog = &[
@@ -462,6 +469,7 @@ fn test_vm_jit_ldindb() {
     };
 }
 
+#[cfg(not(windows))]
 #[test]
 fn test_vm_jit_ldindh() {
     let prog = &[
@@ -482,6 +490,7 @@ fn test_vm_jit_ldindh() {
     };
 }
 
+#[cfg(not(windows))]
 #[test]
 fn test_vm_jit_ldindw() {
     let prog = &[
@@ -502,6 +511,7 @@ fn test_vm_jit_ldindw() {
     };
 }
 
+#[cfg(not(windows))]
 #[test]
 fn test_vm_jit_ldinddw() {
     let prog = &[

+ 1 - 0
tests/ubpf_jit_x86_64.rs

@@ -21,6 +21,7 @@
 // These are unit tests for the eBPF JIT compiler.
 
 #![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))]
+#![cfg(not(windows))]
 
 extern crate rbpf;
 mod common;