-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for stubbing out extern functions
Signed-off-by: Felipe R. Monteiro <felisous@amazon.com>
- Loading branch information
1 parent
7fc9fa7
commit fbc7abd
Showing
4 changed files
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// | ||
//! Check support for stubbing out extern C functions. | ||
|
||
#![feature(rustc_private)] | ||
extern crate libc; | ||
|
||
use libc::c_char; | ||
use libc::c_int; | ||
use libc::c_longlong; | ||
use libc::size_t; | ||
|
||
#[allow(dead_code)] // Avoid warning when using stubs. | ||
#[allow(unused_variables)] | ||
mod stubs { | ||
use super::*; | ||
|
||
pub unsafe extern "C" fn strlen(cs: *const c_char) -> size_t { | ||
4 | ||
} | ||
|
||
pub unsafe extern "C" fn sysconf(_input: c_int) -> c_longlong { | ||
10 | ||
} | ||
} | ||
|
||
#[kani::proof] | ||
#[kani::stub(libc::strlen, stubs::strlen)] | ||
#[kani::stub(libc::sysconf, stubs::sysconf)] | ||
fn harness() { | ||
let str: Box<i8> = Box::new(4); | ||
let str_ptr: *const i8 = &*str; | ||
assert_eq!(unsafe { libc::strlen(str_ptr) }, 4); | ||
assert_eq!(unsafe { libc::sysconf(libc::_SC_PAGESIZE) } as usize, 10); | ||
} |