Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/action-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ on:
pull_request:
branches:
- '*'

name: "Check testSAN package"

jobs:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/no-error-package-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ jobs:
uses: ./
with:
location: /tests/TestPackage
time_limit: 5
max_inputs: 3
fail_ci_if_error: 'false'
comment: 'failure'
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ RcppDeepState is a fuzz testing library made as a composition of three tools: Rc
- **seed** (default value: `-1`) - control the randomness of the inputs generated in the fuzzing phase;
- **time_limit** (default value: `5`) - Fuzzing phase's duration in seconds;
- **max_inputs** (default value: `3`) - Maximum number of inputs that will be processed by RcppDeepState;
- **comment** (default value: `false`) - Print the analysis results as a comment if run in a pull request.
- **comment** (default value: `false`) - Print the analysis results as a comment if run in a pull request. If set to `failure` only writes a comment if RcppDeepState discovers at least one issue.

## Outputs

Expand Down Expand Up @@ -54,8 +54,9 @@ Before running this GitHub Action it's mandatory to run the [actions/checkout](h
max_inputs: ''

# If this action is used inside a pull request's pipeline, this parameter
# control wether the analysis result should be printed as a comment in the
# pull request.
# control whether the analysis result should be printed as a comment in the
# pull request. This parameter can be set to 'failure' to write comments
# only if RcppDeepState discovers at least one issue.
# Default: 'false'
comment: ''
```
Expand Down
50 changes: 40 additions & 10 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ runs:
path: RcppDeepState-action

- name: Analyze the package with RcppDeepState
id: rcppdeepstate
uses: ./RcppDeepState-action/docker
with:
fail_ci_if_error: ${{ inputs.fail_ci_if_error }}
Expand All @@ -60,16 +61,45 @@ runs:

- name: Comment on pull requests
uses: actions/github-script@v6
if: inputs.comment == 'true'
if: |
always() && (
inputs.comment == 'true' || (
inputs.comment == 'failure' && steps.rcppdeepstate.outputs.errors == 'true'
)
)
with:
script: |
const fs = require("fs");
const report = fs.readFileSync('./report.md', {encoding:'utf8', flag:'r'});
if (context.issue.number){
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: report
})
if (context.issue.number) {
const fs = require("fs");
const report = fs.readFileSync('./report.md', {encoding:'utf8', flag:'r'});

const response = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
})

const comments = response.data;

// Find the comment generated by RcppDeepState-action
const comment_identifier = "<!-- RcppDeepState-action comment-->"
const action_comment = comments.find(comment => comment.body.includes(comment_identifier))
const new_comment_body = `## RcppDeepState Report\n${report}\n${comment_identifier}`

if (action_comment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: action_comment.id,
body: new_comment_body
})
} else {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: new_comment_body
})
}

}
19 changes: 18 additions & 1 deletion docker/src/analyze_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ if (any(errors)) {
print(result)
print(result$logtable)

output_errors <- paste0("echo ::set-output name=errors::true")
system(output_errors, intern = FALSE)

# extract only the error lines
error_table <- result[errors]
Expand Down Expand Up @@ -132,7 +134,22 @@ if (any(errors)) {
status <- 1
}
}else{
write("No error has been reported by RcppDeepState", report_file)
output_errors <- paste0("echo ::set-output name=errors::false")
system(output_errors, intern = FALSE)

# get all the analyzed functions name
analyzed_functions <- unlist(lapply(result$binaryfile, getFunctionName))
analyzed_table <- cbind(data.table(func=analyzed_functions),result)
colnames(analyzed_table)[1] <- "function_name"

# this table contains for each function analyzed, the number of inputs tested
count_inputs <- analyzed_table[,.N, by=function_name]
colnames(count_inputs)[2] <- "tested_inputs"

no_error_message <- paste("No error has been reported by RcppDeepState",
"### Analyzed functions summary", sep="\n")
write(no_error_message, report_file)
write(knitr::kable(count_inputs), report_file, append=TRUE)
}

quit(status=status) # return an error code
8 changes: 8 additions & 0 deletions tests/TestPackage/R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

multiplication <- function(arg1, arg2) {
.Call(`_TestPackage_multiplication`, arg1, arg2)
}

difference <- function(arg1, arg2) {
.Call(`_TestPackage_difference`, arg1, arg2)
}

sum <- function(arg1, arg2) {
.Call(`_TestPackage_sum`, arg1, arg2)
}
Expand Down
26 changes: 26 additions & 0 deletions tests/TestPackage/src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// multiplication
int multiplication(int arg1, int arg2);
RcppExport SEXP _TestPackage_multiplication(SEXP arg1SEXP, SEXP arg2SEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< int >::type arg1(arg1SEXP);
Rcpp::traits::input_parameter< int >::type arg2(arg2SEXP);
rcpp_result_gen = Rcpp::wrap(multiplication(arg1, arg2));
return rcpp_result_gen;
END_RCPP
}
// difference
int difference(int arg1, int arg2);
RcppExport SEXP _TestPackage_difference(SEXP arg1SEXP, SEXP arg2SEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< int >::type arg1(arg1SEXP);
Rcpp::traits::input_parameter< int >::type arg2(arg2SEXP);
rcpp_result_gen = Rcpp::wrap(difference(arg1, arg2));
return rcpp_result_gen;
END_RCPP
}
// sum
int sum(int arg1, int arg2);
RcppExport SEXP _TestPackage_sum(SEXP arg1SEXP, SEXP arg2SEXP) {
Expand All @@ -24,6 +48,8 @@ END_RCPP
}

static const R_CallMethodDef CallEntries[] = {
{"_TestPackage_multiplication", (DL_FUNC) &_TestPackage_multiplication, 2},
{"_TestPackage_difference", (DL_FUNC) &_TestPackage_difference, 2},
{"_TestPackage_sum", (DL_FUNC) &_TestPackage_sum, 2},
{NULL, NULL, 0}
};
Expand Down
8 changes: 8 additions & 0 deletions tests/TestPackage/src/difference.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <Rcpp.h>

using namespace std;

// [[Rcpp::export]]
int multiplication(int arg1, int arg2){
return(arg1 * arg2);
}
8 changes: 8 additions & 0 deletions tests/TestPackage/src/multiplication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <Rcpp.h>

using namespace std;

// [[Rcpp::export]]
int difference(int arg1, int arg2){
return(arg1 - arg2);
}