From 484480f72fa1f8d67b64b6e47b840243ec0903fd Mon Sep 17 00:00:00 2001 From: Nikos Gorogiannis Date: Wed, 14 Mar 2018 02:58:10 -0700 Subject: [PATCH] [deadlock] regression tests Reviewed By: sblackshear Differential Revision: D7238932 fbshipit-source-id: 923e18e --- Makefile | 2 +- .../java/deadlock/Interclass.java | 44 ++++++++++++++++ .../java/deadlock/Interproc.java | 50 +++++++++++++++++++ .../java/deadlock/Intraproc.java | 34 +++++++++++++ .../codetoanalyze/java/deadlock/Makefile | 15 ++++++ .../codetoanalyze/java/deadlock/issues.exp | 3 ++ 6 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 infer/tests/codetoanalyze/java/deadlock/Interclass.java create mode 100644 infer/tests/codetoanalyze/java/deadlock/Interproc.java create mode 100644 infer/tests/codetoanalyze/java/deadlock/Intraproc.java create mode 100644 infer/tests/codetoanalyze/java/deadlock/Makefile create mode 100644 infer/tests/codetoanalyze/java/deadlock/issues.exp diff --git a/Makefile b/Makefile index 1fbc60138..e531fecd8 100644 --- a/Makefile +++ b/Makefile @@ -89,7 +89,7 @@ BUILD_SYSTEMS_TESTS += \ DIRECT_TESTS += \ java_checkers java_eradicate java_infer java_lab java_tracing java_quandary \ - java_racerd java_stability java_crashcontext + java_racerd java_stability java_crashcontext java_deadlock ifneq ($(ANT),no) BUILD_SYSTEMS_TESTS += ant endif diff --git a/infer/tests/codetoanalyze/java/deadlock/Interclass.java b/infer/tests/codetoanalyze/java/deadlock/Interclass.java new file mode 100644 index 000000000..eafe8632d --- /dev/null +++ b/infer/tests/codetoanalyze/java/deadlock/Interclass.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2018 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +class Interclass { + synchronized void interclass1_bad(InterclassA a) { + a.interclass1_bad(); + } + + synchronized void interclass2_bad() {} + + synchronized void interclass1_ok(InterclassB b) { + b.interclass1_ok(); + } + + void interclass2_ok(InterclassB b) { + synchronized(b) {} + } + + void reentrant_ok(InterclassB b) { + synchronized(this) { synchronized(b) { b.interclass1_ok(); } } + } +} + +class InterclassA { + synchronized void interclass1_bad() {} + + synchronized void interclass2_bad(Interclass i) { + i.interclass2_bad(); + } +} + +class InterclassB { + synchronized void interclass1_ok() {} + + void interclass2_ok(Interclass c) { + synchronized(c) { c.interclass2_ok(this); } + } +} diff --git a/infer/tests/codetoanalyze/java/deadlock/Interproc.java b/infer/tests/codetoanalyze/java/deadlock/Interproc.java new file mode 100644 index 000000000..d53c0bc38 --- /dev/null +++ b/infer/tests/codetoanalyze/java/deadlock/Interproc.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2018 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +class Interproc { + synchronized void interproc1_bad(InterprocA a) { + interproc2_bad(a); + } + + void interproc2_bad(InterprocA b) { + synchronized(b) {} + } + + synchronized void interproc1_ok(InterprocB a) { + interproc2_ok(a); + } + + void interproc2_ok(InterprocB b) { + synchronized(b) {} + } + + void reentrant1_ok(InterprocB b) { + synchronized(this) { synchronized(b) { reentrant2_ok(); } } + } + + synchronized void reentrant2_ok() {} +} + +class InterprocA { + synchronized void interproc1_bad(Interproc c) { + interproc2_bad(c); + } + + void interproc2_bad(Interproc d) { + synchronized(d) {} + } +} + +class InterprocB { + void interproc1_ok(Interproc c) { + synchronized(c) { interproc2_ok(c); } + } + + synchronized void interproc2_ok(Interproc d) {} +} diff --git a/infer/tests/codetoanalyze/java/deadlock/Intraproc.java b/infer/tests/codetoanalyze/java/deadlock/Intraproc.java new file mode 100644 index 000000000..6d4d9e008 --- /dev/null +++ b/infer/tests/codetoanalyze/java/deadlock/Intraproc.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2018 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +class Intraproc { + void intra_bad(IntraprocA o) { + synchronized(this) { synchronized(o) {} } + } + + void intra_ok(IntraprocB o) { + synchronized(this) { synchronized(o) {} } + } + + void reentrant_ok(IntraprocB b) { + synchronized(this) { synchronized(b) { synchronized(this) {} } } + } +} + +class IntraprocA { + void intra_bad(Intraproc o) { + synchronized(this) { synchronized(o) {} } + } +} + +class IntraprocB { + void intra_ok(Intraproc o) { + synchronized(o) { synchronized(this) {} } + } +} diff --git a/infer/tests/codetoanalyze/java/deadlock/Makefile b/infer/tests/codetoanalyze/java/deadlock/Makefile new file mode 100644 index 000000000..95a78029c --- /dev/null +++ b/infer/tests/codetoanalyze/java/deadlock/Makefile @@ -0,0 +1,15 @@ +# Copyright (c) 2018 - present Facebook, Inc. +# All rights reserved. +# +# This source code is licensed under the BSD style license found in the +# LICENSE file in the root directory of this source tree. An additional grant +# of patent rights can be found in the PATENTS file in the same directory. + +TESTS_DIR = ../../.. + +ANALYZER = checkers +INFER_OPTIONS = --deadlock-only --debug-exceptions +INFERPRINT_OPTIONS = --issues-tests +SOURCES = $(wildcard *.java) + +include $(TESTS_DIR)/javac.make diff --git a/infer/tests/codetoanalyze/java/deadlock/issues.exp b/infer/tests/codetoanalyze/java/deadlock/issues.exp new file mode 100644 index 000000000..3d00001fd --- /dev/null +++ b/infer/tests/codetoanalyze/java/deadlock/issues.exp @@ -0,0 +1,3 @@ +codetoanalyze/java/deadlock/Interclass.java, void Interclass.interclass1_bad(InterclassA), 0, DEADLOCK, ERROR, [[Trace 1] Lock acquisition: locks &this in class Interclass*,Method call: void InterclassA.interclass1_bad(),Lock acquisition: locks &this in class InterclassA*,[Trace 2] Lock acquisition: locks &this in class InterclassA*,Method call: void Interclass.interclass2_bad(),Lock acquisition: locks &this in class Interclass*] +codetoanalyze/java/deadlock/Interproc.java, void Interproc.interproc1_bad(InterprocA), 0, DEADLOCK, ERROR, [[Trace 1] Lock acquisition: locks &this in class Interproc*,Method call: void Interproc.interproc2_bad(InterprocA),Lock acquisition: locks &b in class InterprocA*,[Trace 2] Lock acquisition: locks &this in class InterprocA*,Method call: void InterprocA.interproc2_bad(Interproc),Lock acquisition: locks &d in class Interproc*] +codetoanalyze/java/deadlock/Intraproc.java, void IntraprocA.intra_bad(Intraproc), 0, DEADLOCK, ERROR, [[Trace 1] Method start: void IntraprocA.intra_bad(Intraproc),Lock acquisition: locks &this in class IntraprocA*,Lock acquisition: locks &o in class Intraproc*,[Trace 2] Method start: void Intraproc.intra_bad(IntraprocA),Lock acquisition: locks &this in class Intraproc*,Lock acquisition: locks &o in class IntraprocA*]