Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated verify_policy tool #7142

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Updated VerifyPolicy
- Added flag to turn on debug mode.
- made CLI more conventional
- documented tool
- added a few more log stmts
  • Loading branch information
alxmrs committed Apr 30, 2021
commit ec36bd6c7f5c5c39b2ad483a757668554b90b6d9
8 changes: 8 additions & 0 deletions java/arcs/core/analysis/InformationFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,14 @@ private fun Predicate.labels(): List<InformationFlowLabel> = when (this) {

/** Returns true if the [check] is satisfied by the labels computed for [particle]. */
fun InformationFlow.AnalysisResult.verify(particle: Recipe.Particle, check: Check): Boolean {
val log = TaggedLog { "AnalysisResult.verify" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too much debug information. Let us not keep these log.debug statements.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, just pushed a reversion.


log.debug { "checking $check in $particle"}

val result = fixpoint.getValue(particle)

log.debug { "result: $result" }

// Unreachable particle => check is trivially satisfied.
if (result.isBottom) return true

Expand All @@ -703,6 +709,8 @@ fun InformationFlow.AnalysisResult.verify(particle: Recipe.Particle, check: Chec

val accessPathLabels = result.getLabels(check.accessPath)

log.debug { "accessPathLabels: $accessPathLabels" }

// Unreachable => check is trivially satisfied.
if (accessPathLabels.isBottom) return true
// All possible values => check is unsatisfied.
Expand Down
12 changes: 12 additions & 0 deletions java/arcs/tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,15 @@ into textprotos.
```
$ bazel run --run_under="cd $PWD && " //java/arcs/tools:inspect_manifest -- ./ok_check_multiple_or_tags.binarypb ./ok_check_multiple_or_tags.textproto
```

## verify_policy

Verifies that all recipes in an Arcs manifest file comply with their policies.

```
# bazel run //java/arcs/tools:verify_policy -- /absolute/path/to/binary_manifest.binarypb
```

Options:
- `-d, --debug`: Turn on debug tracing
- `--help`: Display usage info
17 changes: 13 additions & 4 deletions java/arcs/tools/VerifyPolicy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@ import arcs.core.analysis.PolicyVerifier
import arcs.core.data.proto.ManifestProto
import arcs.core.data.proto.decodeRecipes
import arcs.core.policy.proto.decode
import arcs.core.util.Log
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.CliktError
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.options.required
import com.github.ajalt.clikt.parameters.types.file

class VerifyPolicy : CliktCommand(
name = "verify_policy",
help = "Verifies that all recipes in an Arcs manifest file comply with their policies."
help = "Verifies that all recipes in an Arcs manifest file comply with their policies.",
printHelpOnEmptyArgs = true
) {
val manifest by option(
val manifest by argument(
help = "Arcs manifest to check, encoded as a binary proto file (.binarypb)"
).file().required()
).file()

val debug by option("-d", "--debug", help = "Turn on debug tracing")
.flag(default = false)

override fun run() {
if (debug) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My pleasure!

Log.level = Log.Level.Debug
}
val manifestProto = ManifestProto.parseFrom(manifest.readBytes())

val recipes = manifestProto.decodeRecipes()
Expand Down