Skip to content

Commit fbcdf30

Browse files
committed
No logs during verification (closes #160)
1 parent f15b469 commit fbcdf30

File tree

6 files changed

+40
-8
lines changed

6 files changed

+40
-8
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ If you use BPjs in an academic work, please consider citing it as:
6363
* :bug: Verification stops on ECMAScript errors ([#49](https://github.com/bThink-BGU/BPjs/issues/49)).
6464
* :bug: Improved error reporting when trying to sync outside of a b-thread ([#174](https://github.com/bThink-BGU/BPjs/issues/174)).
6565
* :arrow_up: Informative error message when requesting a list of events and one of the events is `null` ([#184](https://github.com/bThink-BGU/BPjs/issues/184)).
66-
66+
* :arrow_up: Loggins is turned off by default during verification. Call `BPjs.setLogDuringVerification(true)` to enable them again ([#160](https://github.com/bThink-BGU/BPjs/issues/160)).
6767

6868
### 2022-02 (Including the 1st BP Day Hackathon)
6969
* :part_alternation_mark: Calling `bp.sync` from global scope during runtime does not cause an ugly exception anymore ([#174](https://github.com/bThink-BGU/BPjs/issues/174)). The error is reported to the listeners.

src/main/java/il/ac/bgu/cs/bp/bpjs/BPjs.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class BPjs {
4545
private static ScriptableObject BPJS_SCOPE;
4646

4747
private static ExecutorServiceMaker executorServiceMaker = new ExecutorServiceMaker();
48+
49+
private static boolean logDuringVerification = false;
4850

4951
static {
5052
ContextFactory.initGlobal( new BPjsRhinoContextFactory()) ;
@@ -124,6 +126,23 @@ public static ExecutorServiceMaker getExecutorServiceMaker() {
124126
public static void setExecutorServiceMaker(ExecutorServiceMaker executorServiceMaker) {
125127
BPjs.executorServiceMaker = executorServiceMaker;
126128
}
129+
130+
/**
131+
* When set to {@code false}, calls to {@code bp.log} during verifications will
132+
* be ignored. Defaults to {@code false}.
133+
* @return Should the system honor logging calls during verifications.
134+
*/
135+
public static boolean isLogDuringVerification() {
136+
return logDuringVerification;
137+
}
138+
139+
/**
140+
* Sets whether calls to the logger should be respected during verification.
141+
* @param logDuringVerification
142+
*/
143+
public static void setLogDuringVerification(boolean logDuringVerification) {
144+
BPjs.logDuringVerification = logDuringVerification;
145+
}
127146

128147

129148
}

src/main/java/il/ac/bgu/cs/bp/bpjs/analysis/DfsBProgramVerifier.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import il.ac.bgu.cs.bp.bpjs.analysis.violations.JsErrorViolation;
2828
import il.ac.bgu.cs.bp.bpjs.analysis.violations.Violation;
2929
import il.ac.bgu.cs.bp.bpjs.exceptions.BPjsRuntimeException;
30+
import il.ac.bgu.cs.bp.bpjs.execution.jsproxy.BpLog;
3031
import java.util.ArrayList;
3132
import java.util.List;
3233

@@ -169,6 +170,10 @@ public VerificationResult verify(BProgram aBp) throws Exception {
169170

170171
ExecutorService execSvc = BPjs.getExecutorServiceMaker().makeWithName("DfsBProgramRunner-" + INSTANCE_COUNTER.incrementAndGet());
171172

173+
BpLog.LogLevel prevLevel = currentBProgram.getLogLevel();
174+
if ( ! BPjs.isLogDuringVerification() ) {
175+
currentBProgram.setLogLevel(BpLog.LogLevel.Off);
176+
}
172177
long start = System.currentTimeMillis();
173178
listener.started(this);
174179
try {
@@ -183,6 +188,9 @@ public VerificationResult verify(BProgram aBp) throws Exception {
183188
} finally {
184189
listener.done(this);
185190
execSvc.shutdown();
191+
if ( ! BPjs.isLogDuringVerification() ) {
192+
currentBProgram.setLogLevel(prevLevel);
193+
}
186194
}
187195
}
188196

src/main/java/il/ac/bgu/cs/bp/bpjs/analysis/ExecutionTraceInspections.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@
5252
public class ExecutionTraceInspections {
5353

5454
/**
55-
* Detects a deadlock in a b-program: where there are requested events, but
56-
* non of them is selectable.
55+
* Detects a deadlock in a b-program: where there are requested events,
56+
* and none of them is selectable.
5757
*/
5858
public static final ExecutionTraceInspection DEADLOCKS = ExecutionTraceInspection.named(
5959
"Deadlocks",
6060
trace -> {
6161
if ( trace.isCyclic() ) return Optional.empty();
6262
BProgramSyncSnapshot curState = trace.getLastState();
63-
if (hasRequestedEvents(curState) &&
63+
if (hasRequestedEvents(curState) &&
6464
trace.getBProgram().getEventSelectionStrategy().selectableEvents(curState).isEmpty()) {
6565
return Optional.of(new DeadlockViolation(trace));
6666
} else return Optional.empty();

src/main/java/il/ac/bgu/cs/bp/bpjs/execution/jsproxy/BpLog.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,22 @@
3030
import java.text.MessageFormat;
3131
import java.util.Arrays;
3232
import java.util.Set;
33-
import org.mozilla.javascript.NativeArray;
3433

3534
/**
3635
* Simple logging mechanism for {@link BProgram}s.
3736
*
3837
* @author michael
3938
*/
4039
public class BpLog implements java.io.Serializable {
41-
private PrintStream out;
40+
4241
public enum LogLevel {
4342
Off, Warn, Info, Fine
4443
}
45-
LogLevel level = LogLevel.Info;
44+
45+
public static final LogLevel DEFAULT_LOG_LEVEL = LogLevel.Info;
46+
47+
LogLevel level = DEFAULT_LOG_LEVEL;
48+
private PrintStream out;
4649

4750
public BpLog( PrintStream aStream ){
4851
out = aStream;

src/main/java/il/ac/bgu/cs/bp/bpjs/model/BProgram.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,9 @@ public void setLoggerOutputStreamer(PrintStream printStream){
519519
}
520520

521521
public BpLog.LogLevel getLogLevel() {
522-
return (jsProxy != null ) ? BpLog.LogLevel.valueOf(jsProxy.log.getLevel()) : null;
522+
return (jsProxy != null )
523+
? BpLog.LogLevel.valueOf(jsProxy.log.getLevel())
524+
: BpLog.DEFAULT_LOG_LEVEL;
523525
}
524526

525527
public StorageModificationStrategy getStorageModificationStrategy() {

0 commit comments

Comments
 (0)