Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
… into master
  • Loading branch information
chengniansun committed Nov 11, 2020
2 parents 2789444 + 5f0fba3 commit dbae221
Show file tree
Hide file tree
Showing 66 changed files with 2,238 additions and 340 deletions.
4 changes: 3 additions & 1 deletion benchmark/benchmark.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def reduction_golden_test(
statistics_file = None,
progress_dump_file = None,
golden_progress_file = None,
enable_query_caching = None):
enable_query_caching = None,
enable_edit_caching = None):
if "/" in source_file:
fail("The source file should be in the current folder.")
if "/" in test_script:
Expand All @@ -49,6 +50,7 @@ def reduction_golden_test(
statistics_file = statistics_file,
progress_dump_file = progress_dump_file,
enable_query_caching = enable_query_caching,
enable_edit_caching = enable_edit_caching,
code_format = "COMPACT_ORIG_FORMAT",
)

Expand Down
6 changes: 6 additions & 0 deletions benchmark/rust-44800/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
!r.sh
!mutant.rs
!info.properties
!.gitignore

152 changes: 152 additions & 0 deletions benchmark/rust-44800/mutant.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
use std::collections::VecDeque;
use std::fmt;

pub struct Packet
{
pub payload: VecDeque<u8>,
}

pub struct Header
{
pub data: Vec<u8>,
}

impl Packet
{
pub fn new() -> Self
{
let payload = VecDeque::with_capacity(32);
Packet{payload}
}

pub fn len(&self) -> usize
{
self.payload.len()
}

pub fn push_header(&mut self, header: &Header)
{
self.payload.reserve(header.data.len());
for b in header.data.iter().rev() {
self.payload.push_front(*b);
}
}

pub fn push_back_bytes(&mut self, data: &[u8])
{
self.payload.extend(data.iter());
}
}

impl fmt::Debug for Packet
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
{
let mut bytes = String::with_capacity(3*self.len());
for i in 0..self.payload.len() {
bytes.push_str(&format!(" {:02X}", self.payload[i]));
}

write!(f, "{}", bytes)
}
}

impl Header
{
pub fn new() -> Self
{
let data = Vec::with_capacity(20);
Header{data}
}

pub fn with_capacity(capacity: usize) -> Self
{
let data = Vec::with_capacity(capacity);
Header{data}
}

pub fn push8(&mut self, data: u8)
{
self.data.push(data);
}

pub fn push16(&mut self, data: u16)
{
self.data.push((data >> 8) as u8);
self.data.push((data & 0xFF) as u8);
}

pub fn push32(&mut self, data: u32)
{
self.data.push((data >> 24) as u8);
self.data.push(((data >> 16) & 0xFF) as u8);
self.data.push(((data >> 8) & 0xFF) as u8);
self.data.push((data & 0xFF) as u8);
}

pub fn push_bytes(&mut self, data: &[u8])
{
self.data.extend(data);
}
}

fn push_ipv4(packet: &mut Packet)
{
let payload_len = packet.len();
let mut header = Header::with_capacity(20);

let b = 0x45; // version + IHL (we don't support options so length is fixed)
header.push8(b);

header.push8(20);

let hw = 20 + payload_len; // total length
header.push16(hw as u16);

header.push16(21); // identification
header.push16(23);

packet.push_header(&header);
}

fn push_mac(packet: &mut Packet)
{
let mut header = Header::with_capacity(30);

let hw = 0b1000_10_00; // frame control, see 9.2.4.1
header.push16(hw);

let addr = [1, 2, 3, 4, 5, 6];
for &b in addr.iter() { // address 1, see 9.3.2.1
header.push8(b);
}

for &b in addr.iter() { // address 2
header.push8(b);
}

for &b in addr.iter() {// address 3
header.push8(b);
}

header.push16(55);

let hw = 0b111_0_00_0_000; // QoS control, see 9.2.4.5.1
header.push16(hw);

packet.push_header(&header);

let fcs = [0xD9, 0x58, 0xFB, 0xA8];
println!("old packet = {:?}", packet);
println!("pushing {:X} {:X} {:X} {:X} ", fcs[0], fcs[1], fcs[2], fcs[3]);
packet.push_back_bytes(&fcs);

println!("new packet = {:?}", packet);
}

fn main()
{
let mut packet = Packet::new();
push_ipv4(&mut packet);
push_mac(&mut packet);
}
58 changes: 58 additions & 0 deletions benchmark/rust-44800/r.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash

set -o nounset

readonly FILE="mutant.rs"

readonly BUGGY_RUSTC_VERSION="1.20.0"
readonly CORRECT_RUSTC_VERSION="1.47.0"
readonly CORRECT_RUSTC_VERSION_2="1.47.0"
rustup toolchain install "${BUGGY_RUSTC_VERSION}" --force
rustup toolchain install "${CORRECT_RUSTC_VERSION}" --force
rustup toolchain install "${CORRECT_RUSTC_VERSION_2}" --force

if ! command -v valgrind > /dev/null ; then
echo "valgrind is not installed"
exit 100
fi

readonly EXE_WRONG="./wrong.out"
if ! timeout -s 9 60 rustup run "${BUGGY_RUSTC_VERSION}" rustc -o "${EXE_WRONG}" "${FILE}"; then
exit 1
fi

readonly EXE_CORRECT="./correct.out"
if ! timeout -s 9 60 rustup run "${CORRECT_RUSTC_VERSION}" rustc -o "${EXE_CORRECT}" "${FILE}" ; then
exit 1
fi

readonly EXE_CORRECT_2="./correct_2.out"
if ! timeout -s 9 60 rustup run "${CORRECT_RUSTC_VERSION_2}" rustc -o "${EXE_CORRECT_2}" "${FILE}" ; then
exit 1
fi

readonly OUTPUT_WRONG="wrong_output.txt"

if (timeout -s 9 30 valgrind "${EXE_WRONG}") &> "${OUTPUT_WRONG}" ; then
exit 1
fi

readonly OUTPUT_CORRECT_1="correct_output.txt"
readonly OUTPUT_CORRECT_2="correct_output_2.txt"
if ! timeout -s 9 30 valgrind "${EXE_CORRECT}"; then
exit 1
fi

timeout -s 9 30 "${EXE_CORRECT}" &> "${OUTPUT_CORRECT_1}"

if ! timeout -s 9 30 valgrind "${EXE_CORRECT_2}" ; then
exit 1
fi
timeout -s 9 30 "${EXE_CORRECT_2}" &> "${OUTPUT_CORRECT_2}"

if ! diff "${OUTPUT_CORRECT_1}" "${OUTPUT_CORRECT_2}" ; then
exit 1
fi

exit 0

6 changes: 6 additions & 0 deletions benchmark/rust-63791/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
!r.sh
!mutant.rs
!info.properties
!.gitignore

4 changes: 4 additions & 0 deletions benchmark/rust-63791/info.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
buggy_compiler_version_file=compiler_version.txt
script_file=r.sh
reduced_file=reduced_mutant.rs
source_file=mutant.rs
Loading

0 comments on commit dbae221

Please sign in to comment.