[clang] 5521236 - [analyzer] Re-land 0aba69e "Add test directory for scan-build."

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 3 13:00:17 PST 2020


Author: Artem Dergachev
Date: 2020-02-03T23:59:57+03:00
New Revision: 5521236a18074584542b81fd680158d89a845fca

URL: https://github.com/llvm/llvm-project/commit/5521236a18074584542b81fd680158d89a845fca
DIFF: https://github.com/llvm/llvm-project/commit/5521236a18074584542b81fd680158d89a845fca.diff

LOG: [analyzer] Re-land 0aba69e "Add test directory for scan-build."

The tool is now looked for in the source directory rather than in the
install directory, which should exclude the problems with not being able
to find it.

The tests still aren't being run on Windows, but they hopefully will run
on other platforms that have shell, which hopefully also means Perl.

Differential Revision: https://reviews.llvm.org/D69781

Added: 
    clang/test/Analysis/scan-build/Inputs/multidirectory_project/directory1/file1.c
    clang/test/Analysis/scan-build/Inputs/multidirectory_project/directory2/file2.c
    clang/test/Analysis/scan-build/Inputs/single_null_dereference.c
    clang/test/Analysis/scan-build/exclude_directories.test
    clang/test/Analysis/scan-build/help.test
    clang/test/Analysis/scan-build/html_output.test
    clang/test/Analysis/scan-build/lit.local.cfg
    clang/test/Analysis/scan-build/plist_html_output.test
    clang/test/Analysis/scan-build/plist_output.test

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/clang/test/Analysis/scan-build/Inputs/multidirectory_project/directory1/file1.c b/clang/test/Analysis/scan-build/Inputs/multidirectory_project/directory1/file1.c
new file mode 100644
index 000000000000..7fffb69e01a0
--- /dev/null
+++ b/clang/test/Analysis/scan-build/Inputs/multidirectory_project/directory1/file1.c
@@ -0,0 +1,9 @@
+int main() {
+  return 0;
+}
+
+void function1(int *p) {
+  if (!p) {
+    *p = 7; // This will emit a null pointer diagnostic.
+  }
+}

diff  --git a/clang/test/Analysis/scan-build/Inputs/multidirectory_project/directory2/file2.c b/clang/test/Analysis/scan-build/Inputs/multidirectory_project/directory2/file2.c
new file mode 100644
index 000000000000..ed0e17212337
--- /dev/null
+++ b/clang/test/Analysis/scan-build/Inputs/multidirectory_project/directory2/file2.c
@@ -0,0 +1,5 @@
+void function2(int *o) {
+  if (!o) {
+    *o = 7; // This will emit a null pointer diagnostic.
+  }
+}

diff  --git a/clang/test/Analysis/scan-build/Inputs/single_null_dereference.c b/clang/test/Analysis/scan-build/Inputs/single_null_dereference.c
new file mode 100644
index 000000000000..21a43dfd08a5
--- /dev/null
+++ b/clang/test/Analysis/scan-build/Inputs/single_null_dereference.c
@@ -0,0 +1,5 @@
+int main() {
+  int *p = 0;
+  *p = 7; // We expect a diagnostic about this.
+  return 0;
+}

diff  --git a/clang/test/Analysis/scan-build/exclude_directories.test b/clang/test/Analysis/scan-build/exclude_directories.test
new file mode 100644
index 000000000000..b73d6270c1ba
--- /dev/null
+++ b/clang/test/Analysis/scan-build/exclude_directories.test
@@ -0,0 +1,40 @@
+// FIXME: Actually, "perl".
+REQUIRES: shell
+
+// FIXME: Should ideally work on Windows.
+UNSUPPORTED: system-windows
+
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -o %t.output_dir %clang \
+RUN:     %S/Inputs/multidirectory_project/directory1/file1.c \
+RUN:     %S/Inputs/multidirectory_project/directory2/file2.c \
+RUN:     | FileCheck %s -check-prefix CHECK-NO-EXCLUDE
+
+// The purpose of this test is to ensure that the --exclude command line option
+// actually excludes reports from inside the specified directories.
+
+
+// First, let's make sure that without --exclude issues in both
+// directory1 and directory2 are found.
+CHECK-NO-EXCLUDE: scan-build: 2 bugs found.
+
+
+// Only one issue should be found when directory1 is excluded.
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -o %t.output_dir --exclude directory1 %clang \
+RUN:     %S/Inputs/multidirectory_project/directory1/file1.c \
+RUN:     %S/Inputs/multidirectory_project/directory2/file2.c \
+RUN:     | FileCheck %s -check-prefix CHECK-EXCLUDE1
+
+CHECK-EXCLUDE1: scan-build: 1 bug found.
+
+
+// When both directories are excluded, no issues should be reported.
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -o %t.output_dir --exclude directory1 --exclude directory2 %clang \
+RUN:     %S/Inputs/multidirectory_project/directory1/file1.c \
+RUN:     %S/Inputs/multidirectory_project/directory2/file2.c \
+RUN:     | FileCheck %s -check-prefix CHECK-EXCLUDE-BOTH
+
+CHECK-EXCLUDE-BOTH: scan-build: 0 bugs found.
+

diff  --git a/clang/test/Analysis/scan-build/help.test b/clang/test/Analysis/scan-build/help.test
new file mode 100644
index 000000000000..556a4a74e82b
--- /dev/null
+++ b/clang/test/Analysis/scan-build/help.test
@@ -0,0 +1,24 @@
+// FIXME: Actually, "perl".
+REQUIRES: shell
+
+// FIXME: Should ideally work on Windows.
+UNSUPPORTED: system-windows
+
+RUN: %scan-build -h | FileCheck %s
+RUN: %scan-build --help | FileCheck %s
+
+Test for help output from scan-build.
+
+
+CHECK: USAGE: scan-build [options] <build command> [build options]
+
+...
+
+CHECK: AVAILABLE CHECKERS:
+...
+CHECK:  + core.NullDereference
+CHECK:    optin.performance.GCDAntipattern
+...
+
+
+

diff  --git a/clang/test/Analysis/scan-build/html_output.test b/clang/test/Analysis/scan-build/html_output.test
new file mode 100644
index 000000000000..1f56d17cd3fb
--- /dev/null
+++ b/clang/test/Analysis/scan-build/html_output.test
@@ -0,0 +1,36 @@
+// FIXME: Actually, "perl".
+REQUIRES: shell
+
+// FIXME: Should ideally work on Windows.
+UNSUPPORTED: system-windows
+
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -o %t.output_dir %clang %S/Inputs/single_null_dereference.c \
+RUN:     | FileCheck %s -check-prefix CHECK-STDOUT
+
+// Test html output
+
+CHECK-STDOUT: scan-build: Using '{{.*}}' for static analysis
+CHECK-STDOUT: scan-build: 1 bug found.
+CHECK-STDOUT: scan-build: Run 'scan-view {{.*}}' to examine bug reports.
+
+// We expect an index file, a file for the report, and sibling support files.
+RUN: ls %t.output_dir/*/ | FileCheck %s -check-prefix CHECK-FILENAMES
+
+CHECK-FILENAMES: index.html
+CHECK-FILENAMES: report-{{.*}}.html
+CHECK-FILENAMES: scanview.css
+CHECK-FILENAMES: sorttable.js
+
+
+// The index should have a link to the report for the single issue.
+RUN: cat %t.output_dir/*/index.html \
+RUN:     | FileCheck %s -check-prefix CHECK-INDEX-HTML
+
+CHECK-INDEX-HTML: <!-- REPORTBUG id="report-{{.*}}.html" -->
+
+// The report should describe the issue.
+RUN: cat %t.output_dir/*/report-*.html \
+RUN:     | FileCheck %s -check-prefix CHECK-REPORT-HTML
+
+CHECK-REPORT-HTML: <!-- BUGTYPE Dereference of null pointer -->

diff  --git a/clang/test/Analysis/scan-build/lit.local.cfg b/clang/test/Analysis/scan-build/lit.local.cfg
new file mode 100644
index 000000000000..b4e097d4bab9
--- /dev/null
+++ b/clang/test/Analysis/scan-build/lit.local.cfg
@@ -0,0 +1,18 @@
+# -*- Python -*-
+
+import lit.util
+import lit.formats
+import os
+
+use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL")
+config.test_format = lit.formats.ShTest(use_lit_shell == "0")
+
+config.substitutions.append(('%scan-build',
+                             '\'%s\' --use-analyzer=%s ' % (
+                                 lit.util.which('scan-build',
+                                                os.path.join(
+                                                    config.clang_src_dir,
+                                                    'tools',
+                                                    'scan-build',
+                                                    'bin')),
+                                 config.clang)))

diff  --git a/clang/test/Analysis/scan-build/plist_html_output.test b/clang/test/Analysis/scan-build/plist_html_output.test
new file mode 100644
index 000000000000..8af35e6be7fc
--- /dev/null
+++ b/clang/test/Analysis/scan-build/plist_html_output.test
@@ -0,0 +1,26 @@
+// FIXME: Actually, "perl".
+REQUIRES: shell
+
+// FIXME: Should ideally work on Windows.
+UNSUPPORTED: system-windows
+
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -plist-html -o %t.output_dir %clang %S/Inputs/single_null_dereference.c \
+RUN:     | FileCheck %s -check-prefix CHECK-STDOUT
+
+// Test combined plist and html output with -plist-html
+
+CHECK-STDOUT: scan-build: Using '{{.*}}' for static analysis
+CHECK-STDOUT: scan-build: Analysis run complete.
+CHECK-STDOUT: scan-build: Analysis results (plist files) deposited in '{{.*}}'
+CHECK-STDOUT: scan-build: 1 bug found.
+CHECK-STDOUT: scan-build: Run 'scan-view {{.*}}' to examine bug reports.
+
+// We expect both html files and the plist files.
+RUN: ls %t.output_dir/*/ | FileCheck %s -check-prefix CHECK-FILENAMES
+
+CHECK-FILENAMES: index.html
+CHECK-FILENAMES-DAG: report-{{.*}}.html
+CHECK-FILENAMES-DAG: report-{{.*}}.plist
+CHECK-FILENAMES: scanview.css
+CHECK-FILENAMES: sorttable.js

diff  --git a/clang/test/Analysis/scan-build/plist_output.test b/clang/test/Analysis/scan-build/plist_output.test
new file mode 100644
index 000000000000..1a921a4af5ad
--- /dev/null
+++ b/clang/test/Analysis/scan-build/plist_output.test
@@ -0,0 +1,26 @@
+// FIXME: Actually, "perl".
+REQUIRES: shell
+
+// FIXME: Should ideally work on Windows.
+UNSUPPORTED: system-windows
+
+RUN: rm -rf %t.output_dir && mkdir %t.output_dir
+RUN: %scan-build -plist -o %t.output_dir %clang %S/Inputs/single_null_dereference.c \
+RUN:     | FileCheck %s -check-prefix CHECK-STDOUT
+
+// Test plist output
+
+CHECK-STDOUT: scan-build: Using '{{.*}}' for static analysis
+CHECK-STDOUT: scan-build: Analysis run complete.
+CHECK-STDOUT: scan-build: Analysis results (plist files) deposited in '{{.*}}'
+
+// We expect a single plist file
+RUN: ls %t.output_dir/*/ | FileCheck %s -check-prefix CHECK-FILENAMES
+
+CHECK-FILENAMES: report-{{.*}}.plist
+
+// The report should describe the issue.
+RUN: cat %t.output_dir/*/report-*.plist \
+RUN:     | FileCheck %s -check-prefix CHECK-REPORT-PLIST-CONTENTS
+
+CHECK-REPORT-PLIST-CONTENTS: <key>type</key><string>Dereference of null pointer</string>


        


More information about the cfe-commits mailing list