Skip to content

Commit

Permalink
Merge branch 'master' of github.com:csmith-project/csmith
Browse files Browse the repository at this point in the history
  • Loading branch information
regehr committed Nov 8, 2011
2 parents 462bf41 + a5cbda6 commit 535a8b5
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 9 deletions.
4 changes: 4 additions & 0 deletions BUGS_REPORTED.TXT
@@ -1,5 +1,9 @@
===================================================================

11/07/2011 (total 396)
1 clang crash bug reported
http://llvm.org/bugs/show_bug.cgi?id=11327

08/10/2011 (total 395)
1 gcc crash bug reported by Arthur O'Dwyer
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50039
Expand Down
4 changes: 2 additions & 2 deletions runtime/csmith_minimal.h
Expand Up @@ -28,6 +28,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

extern int printf (const char *, ...);

// FIXME-- need more versions, and a way to figure out which is needed
#include "custom_stdint_x86.h"

Expand Down Expand Up @@ -60,8 +62,6 @@ static inline void crc32_gentab (void)

int crc32_context;

extern int printf (const char *, ...);

#ifdef TCC
int strcmp (const char *s1, const char *s2)
{
Expand Down
92 changes: 85 additions & 7 deletions utah/scripts/reduce/simple_delta.pl
Expand Up @@ -19,26 +19,34 @@
my $CSMITH_HOME = $ENV{"CSMITH_HOME"};
die "please set CSMITH_HOME env first!" if (!defined($CSMITH_HOME));

my $VOLATILE = $ENV{"VOLATILE_HOME"};
die "please set VOLATILE_HOME env first!" if (!defined($VOLATILE));
#my $VOLATILE = $ENV{"VOLATILE_HOME"};
#die "please set VOLATILE_HOME env first!" if (!defined($VOLATILE));

$ENV{"PATH"} = "$ENV{VOLATILE_HOME}:$ENV{PATH}";
#$ENV{"PATH"} = "$ENV{VOLATILE_HOME}:$ENV{PATH}";

my $COMPILER_TIMEOUT = 600;
my $PROG_TIMEOUT = 2;

if (@ARGV != 4 && @ARGV != 3) {
die "usage: simple_delta.pl <seed> <compiler1> <compiler2> <csmith-options>\n\n";
# in second
my $TEST_TIMEOUT = 20 * 60;

if (@ARGV != 4 && @ARGV != 3 && @ARGV != 5) {
die "usage: simple_delta.pl <seed> <compiler1> <compiler2> <csmith-options> <crash string>\n\n";
}

my $seed = $ARGV[0];
my $COMPILER1 = $ARGV[1];
my $COMPILER2 = $ARGV[2];
my $OPTS = "--concise ";
if (@ARGV == 4) {
if (@ARGV >= 4) {
$OPTS = "$OPTS$ARGV[3]";
}

my $crash_string = "";
if (@ARGV == 5) {
$crash_string = $ARGV[4];
}

my $cfile = "small.c";
my $tmp_cfile = "small_tmp.c";
my $backup_cfile = "works.c";
Expand Down Expand Up @@ -81,6 +89,21 @@ ($\@$)
return $cnt;
}

sub read_file_with_substring($\@$) {
my ($input, $out, $substring) = @_;
my $cnt = 0;
open INF1, "<$input" or die;
while (my $line = <INF1>) {
chomp $line;
if (index($line, $substring) != -1) {
push @$out, $line;
$cnt++;
}
}
close INF1;
return $cnt;
}

sub compile($$$$) {
my ($compiler, $src_file, $exe, $out) = @_;
my $res = 0;
Expand Down Expand Up @@ -157,7 +180,7 @@ ($\@$\@$$)
my $EXTRA='-Wuninitialized -Werror=uninitialized';
# flag1 == 1: we check if two outputs have the same lines.
# flag2 == 1: we check the line which is "checksum = xxxx".
sub run_test ($$$) {
sub run_wrong_code_test ($$$) {
my ($test_file, $flag1, $match) = @_;
system "rm -f gcc.txt";
system "gcc $ARGS $EXTRA -O0 $test_file -o a.out > gcc.txt 2>&1";
Expand Down Expand Up @@ -207,6 +230,50 @@ ($$$)
return $res;
}

sub run_crash_test($$) {
my ($test_file, $match) = @_;
system "rm -f gcc.txt";
system "gcc $ARGS $EXTRA -O0 $test_file -o a.out > gcc.txt 2>&1";
my @tmp = ();
if (read_file("gcc.txt", @tmp, "no return statement") ||
read_file("gcc.txt", @tmp, "control reaches") ||
# read_file("gcc.txt", @tmp, "initia") ||
read_file("gcc.txt", @tmp, "proto")) {
system("cp $test_file gcc_fail.c");
print "$indent compiler error! Can't compile $test_file with gcc\n";
return 0;
}

$test_count++;
my $res;
$res = compile($COMPILER1, $test_file, "$EXE1$test_count", "$COMPILER_OUT1$test_count");
if ($res) {
if (read_file_with_substring("$COMPILER_OUT1$test_count", @tmp, $match)) {
print "$indent crash string $match found for $test_file with $COMPILER1\n";
return 1;
}
else {
print "$indent no crash string $match found for $test_file with $COMPILER1\n";
return 0;
}
}
else {
print "$indent no crash error found for $test_file with $COMPILER1\n";
return 0;
}
}

sub run_test($$$) {
my ($test_file, $flag1, $match) = @_;

if ($crash_string eq "") {
return run_wrong_code_test($test_file, $flag1, $match);
}
else {
return run_crash_test($test_file, $crash_string);
}
}

sub get_score ($) {
(my $fn) = @_;
return stat($fn)->size;
Expand All @@ -227,6 +294,8 @@ ($)

print "seed = $seed\n";

$OPTS =~ s/-s\s+[0-9]+//g;

system "${CSMITH_HOME}/src/csmith -s $seed $OPTS --delta-monitor simple --delta-output $deltafile > $cfile";

my $res = run_test($cfile, 0, "checksum ");
Expand All @@ -247,6 +316,8 @@ ($)
my $orig_sz = get_score($cfile);

my $n = 0;
my $prev_time = time();
my $total_time = 0;

print "initial score = $orig_sz\n";
while (1) {
Expand Down Expand Up @@ -289,6 +360,13 @@ ($)
} else {
$sz = $new_sz;
}
my $curr_time = time();
$total_time += ($curr_time - $prev_time);
$prev_time = $curr_time;
print "elapsed time: $total_time\n";
if ($total_time > $TEST_TIMEOUT) {
last;
}
}
system "cp $cfile simple$seed.c";
my $sz = get_score($cfile);
Expand Down

0 comments on commit 535a8b5

Please sign in to comment.