Skip to content

Commit 0a91ec8

Browse files
Merge pull request #12 from FabrizioSandri/fuzz-compiled
Fuzz only supported functions
2 parents 7b2220d + 8da251e commit 0a91ec8

File tree

8 files changed

+55
-26
lines changed

8 files changed

+55
-26
lines changed

R/analyze_binary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ deepstate_fuzz_fun_analyze<- function(test_function,seed=-1, time.limit.seconds,
8383
log_file <- file.path(output_folder,paste0(seed,"_log"))
8484
valgrind.log.text <- file.path(output_folder,"seed_valgrind_log_text")
8585
if(!file.exists(test_harness.o)){
86-
deepstate_compile_fun(test_function, verbose)
86+
deepstate_compile_fun(test_function, verbose=verbose)
8787
}
8888
if(time.limit.seconds <= 0){
8989
stop("time.limit.seconds should always be greater than zero")

R/fun_harness_create.R

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@
1111
##' @return The TestHarness file that is generated
1212
##' @export
1313
deepstate_fun_create<-function(package_path,function_name,sep="infun"){
14-
fun_path <- file.path(package_path, "inst", "testfiles", function_name)
15-
if(!dir.exists(fun_path)){
16-
dir.create(fun_path, showWarnings = FALSE, recursive = TRUE)
17-
}
18-
14+
1915
packagename <- basename(package_path)
2016
functions.list <- deepstate_get_function_body(package_path)
2117
functions.list$argument.type<-gsub("Rcpp::","",functions.list$argument.type)
@@ -68,7 +64,12 @@ deepstate_fun_create<-function(package_path,function_name,sep="infun"){
6864
}else{
6965
paste0(function_name,"_DeepState_TestHarness.cpp")
7066
}
71-
67+
68+
fun_path <- file.path(package_path, "inst", "testfiles", function_name)
69+
if(!dir.exists(fun_path)){
70+
dir.create(fun_path, showWarnings = FALSE, recursive = TRUE)
71+
}
72+
7273
if(sep == "generation" || sep == "checks"){
7374
write_to_file <- paste0(headers)
7475
makesep.path <- file.path(fun_path,paste0(sep,".Makefile"))

R/pkg_harness_compile.R

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,19 @@ deepstate_harness_compile_run <- function(package_path,time.limit.seconds=5,seed
2525
functions.list <- Sys.glob(file.path(test_path,"*"))
2626
#no harness created
2727
if(length(functions.list)){
28-
if(length(testharness) == length(basename(functions.list)) &&
29-
length(intersect(basename(functions.list),testharness)) == length(testharness)){
30-
uncompiled_count = 0
31-
log_count = 0
32-
for(fun.path in functions.list){
33-
compile.res <- deepstate_fuzz_fun(package_path, basename(fun.path), time.limit.seconds, seed=seed, verbose=verbose)
34-
if(!is.na(compile.res) && compile.res == basename(fun.path)){
35-
compiled.code <-c(compiled.code,compile.res)
36-
}
37-
else{
38-
uncompiled.code <- c(uncompiled.code,basename(fun.path))
39-
}
28+
for(fun.path in functions.list){
29+
compile.res <- deepstate_fuzz_fun(package_path, basename(fun.path), time.limit.seconds, seed=seed, verbose=verbose)
30+
if(!is.na(compile.res) && compile.res == basename(fun.path)){
31+
compiled.code <-c(compiled.code,compile.res)
32+
}else {
33+
uncompiled.code <- c(uncompiled.code,basename(fun.path))
4034
}
41-
if(length(uncompiled.code) > 0)
42-
message(sprintf("Uncompiled functions : %s\n",paste(uncompiled.code, collapse=", ")))
43-
return(as.character(compiled.code))
4435
}
45-
}
46-
else{
36+
if(length(uncompiled.code) > 0)
37+
message(sprintf("Uncompiled functions : %s\n",paste(uncompiled.code, collapse=", ")))
38+
return(as.character(compiled.code))
39+
40+
}else {
4741
stop("TestHarness are not created for all the function that are returned by pkg create")
4842
}
4943
}

inst/testpkgs/testSAN/R/RcppExports.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ rcpp_read_out_of_bound <- function(rbound) {
55
.Call('_testSAN_rcpp_read_out_of_bound', PACKAGE = 'testSAN', rbound)
66
}
77

8+
unsupported_datatype <- function(param) {
9+
.Call('_testSAN_unsupported_datatype', PACKAGE = 'testSAN', param)
10+
}
11+
812
rcpp_use_after_deallocate <- function(array_size) {
913
.Call('_testSAN_rcpp_use_after_deallocate', PACKAGE = 'testSAN', array_size)
1014
}

inst/testpkgs/testSAN/src/RcppExports.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
using namespace Rcpp;
77

8+
#ifdef RCPP_USE_GLOBAL_ROSTREAM
9+
Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
10+
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
11+
#endif
12+
813
// rcpp_read_out_of_bound
914
int rcpp_read_out_of_bound(int rbound);
1015
RcppExport SEXP _testSAN_rcpp_read_out_of_bound(SEXP rboundSEXP) {
@@ -16,6 +21,17 @@ BEGIN_RCPP
1621
return rcpp_result_gen;
1722
END_RCPP
1823
}
24+
// unsupported_datatype
25+
int unsupported_datatype(Rcpp::LogicalVector param);
26+
RcppExport SEXP _testSAN_unsupported_datatype(SEXP paramSEXP) {
27+
BEGIN_RCPP
28+
Rcpp::RObject rcpp_result_gen;
29+
Rcpp::RNGScope rcpp_rngScope_gen;
30+
Rcpp::traits::input_parameter< Rcpp::LogicalVector >::type param(paramSEXP);
31+
rcpp_result_gen = Rcpp::wrap(unsupported_datatype(param));
32+
return rcpp_result_gen;
33+
END_RCPP
34+
}
1935
// rcpp_use_after_deallocate
2036
int rcpp_use_after_deallocate(int array_size);
2137
RcppExport SEXP _testSAN_rcpp_use_after_deallocate(SEXP array_sizeSEXP) {
@@ -74,6 +90,7 @@ END_RCPP
7490

7591
static const R_CallMethodDef CallEntries[] = {
7692
{"_testSAN_rcpp_read_out_of_bound", (DL_FUNC) &_testSAN_rcpp_read_out_of_bound, 1},
93+
{"_testSAN_unsupported_datatype", (DL_FUNC) &_testSAN_unsupported_datatype, 1},
7794
{"_testSAN_rcpp_use_after_deallocate", (DL_FUNC) &_testSAN_rcpp_use_after_deallocate, 1},
7895
{"_testSAN_rcpp_use_after_free", (DL_FUNC) &_testSAN_rcpp_use_after_free, 1},
7996
{"_testSAN_rcpp_use_uninitialized", (DL_FUNC) &_testSAN_rcpp_use_uninitialized, 1},
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include <Rcpp.h>
2+
using namespace std;
3+
4+
// [[Rcpp::export]]
5+
int unsupported_datatype(Rcpp::LogicalVector param){
6+
7+
return param.size();
8+
9+
}
10+

tests/testthat/test-new-test.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ test_that("inputfolder files existence", {
8181
})
8282

8383
functions.list <- deepstate_get_function_body(path)
84-
args.list <- gsub(" ","",functions.list$argument.name)
84+
compiled_functions.list <- functions.list[funName!="unsupported_datatype"]
85+
args.list <- gsub(" ","",compiled_functions.list$argument.name)
8586
path.args.list <- file.path(funpath.list,"inputs",paste0(args.list,".qs"))
8687
#print(path.args.list)
8788
#print(file.exists(path.args.list))

tests/testthat/test-debug-symbols.R renamed to tests/testthat/test-testSAN.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ library(RcppDeepState)
33
testSAN_path <- system.file("testpkgs/testSAN", package = "RcppDeepState")
44

55

6-
test_that("Check debug symbols", {
6+
test_that("Test on the testSAN package", {
77

88
# We choose seed=1000 since it has been demonstrated locally that
99
# RcppDeepState detects several issues when using this number.
@@ -14,6 +14,8 @@ test_that("Check debug symbols", {
1414
# If debug symbols are included in the final binary, then the resulting
1515
# table will contain some information. On the other hand, if the resulting
1616
# table is empty, it means that the library is missing debug symbols.
17+
# This test is also used to check if RcppDeepState returns correct analysis
18+
# results when run on the testSAN package.
1719
logtable_is_empty <- all(sapply(result$logtable, function(table) nrow(table) == 0))
1820

1921
expect_false(logtable_is_empty)

0 commit comments

Comments
 (0)