|
|
Subscribe / Log in / New account

RTLWS: Modeling systems with Alloy

By Jake Edge
November 7, 2012

The final day of this year's Real Time Linux Workshop (RTLWS) had talks from a number of different researchers and others from the realtime Linux community. It also featured a talk from outside of that community, but on a topic—as might be guessed—that may be important to users and developers of realtime systems: modeling system behavior for better reliability. Eunsuk Kang from MIT gave an introduction to the Alloy language, which has been used to model and find bugs in systems ranging from network protocols to filesystems.

RTLWS organizer Nicholas Mc Guire prefaced the talk by noting that "Z" is used widely for modeling and design verification, but that there is no free Z support. Alloy, on the other hand, is similar to Z, but is free software. The availability of a free alternative will make this kind of analysis more widespread.

Kang is part of a group at MIT that focuses on how to build more reliable software, which is the motivation behind Alloy. Software design often starts with sketches, then moves into creating design documents in various formats. "Is this the best way to design software?" is one question to ask, he said.

Sketches are good because they are lightweight and informal. That allows people to brainstorm and to quickly prototype ideas. Documents are much more heavyweight and are geared toward completeness. But those documents can't be used to answer questions about the design, nor to determine whether the system design is consistent.

So, they set out to create a new language that is "simple" and would be easy to learn, so it would impose a low burden on its users. It could be used in a step between sketches and design documents. The language would be "precise and analyzable", so that one could ask questions about the system described. The language and tools would provide instant feedback in support of rapid prototyping. That new language is Alloy.

As a demonstration of Alloy and its development environment, Kang created a model of a filesystem in the language. The model consisted of several different kinds of objects, such as files, paths, and filesystems, as well as operations for things like adding and deleting files. The model didn't describe the implementation of the filesystem, just the relationships between the objects—and how they change based on the operations.

The model can then be "run" in the GUI. There is a built-in visualization component, which shows solutions that satisfy the constraints set out in the model. One can add assertions to the model, which can either be confirmed to a certain search depth or a counterexample can be found. Alloy is, in many ways, a descendant of languages like Prolog and automated theorem proving systems.

In the demo, Kang's seemingly reasonable model was missing a key constraint. Alloy was able to find a counterexample to an assertion because the model did not preclude multiple file objects having the same path. Once the add-file operation was changed to eliminate that possibility, no counterexample to the assertion (which essentially stated that the delete operation undoes the add operation) could be found.

Alloy has a small number of constructs, purposely. It is a declarative language that describes the system, but, importantly, not the implementation, in "pure first-order logic". Alloy allows for two different kinds of analysis, Kang said, simulation or assertion. The models get translated into a "constraint solving engine" that can find problems that testing misses.

Standard software testing tries to cover as many different behaviors of the system as possible, but one of its weaknesses is that it can't show the absence of bugs. The analyzer in Alloy is exhaustive, and can be used to "verify very deep properties" about the model, he said. The analyzer allows the designer to "reason about the behavior" of systems.

That kind of reasoning has been done using Alloy, Kang said, both by his group and other researchers and universities. One of his examples was not directly computer-related, instead concerning the beam-scheduling policies for radiation therapy at Massachusetts General Hospital. There are multiple treatment rooms, where several different kinds of requests for radiation from a single cyclotron can be made. There are multiple doctors and nurses making the requests, which get funneled to a master control room that enforces various safety requirements. By modeling the system, several race conditions and other problems were found that had the potential to silently drop requests.

In addition, Stanford and Berkeley have applied Alloy to web security protocols and found previously unknown vulnerabilities in HTML 5 and WebAuth. In fact, researchers using Alloy have found problems in protocols that had previously been "proved" correct. Pamela Zave analyzed the Chord peer-to-peer distributed hash table protocol, which had proofs of its correctness in one of the most cited papers in computer science, Kang said. But Zave found that it is not correct according to its specification, and that six properties believed to be true were not.

There are lots of other examples, he said, including smart card security, the flash filesystem for a Mars rover, and Java virtual machine security. What his group has found is that by using Alloy one will often "find very surprising results". There is ongoing work to generate test cases for the actual implementation from the models to help ensure that the code matches the model. There are also efforts to generate code from the models, but it is a difficult problem.

Going the other way, from existing code to models, is even more difficult. It is far more efficient to start modeling at the design stage, Kang said. The key observation from the team is that spending the time to model a system (or a portion of a larger system) is worth it because it will uncover "a lot of surprises". Those surprises are typically bugs, of course, so finding them—early or late—can only lead to better systems.

[ I would like to thank the RTLWS and OSADL for travel assistance to attend the conference. ]

Index entries for this article
ConferenceRealtime Linux Workshop/2012


to post comments

RTLWS: Modeling systems with Alloy

Posted Nov 8, 2012 10:13 UTC (Thu) by epa (subscriber, #39769) [Link] (2 responses)

The analyzer in Alloy is exhaustive
I understood that the analysis is not 'exhaustive' in the sense that it will find any counterexample that exists. Instead you specify a maximum structure size to check against - a counterexample might be found with 4 elements, or 5 elements, but the larger the number of elements you test the longer it takes to run. I suspect, but do not know for sure, that the Alloy language is Turing-complete and therefore an exhaustive analysis would be impossible.

RTLWS: Modeling systems with Alloy

Posted Nov 8, 2012 19:12 UTC (Thu) by david.a.wheeler (subscriber, #72896) [Link] (1 responses)

That's my understanding as well, it's not completely exhaustive. But because of the way it works, it can go through exponentially more possibilities than traditional testing could in the same time.

It's actually an interesting compromise compared to traditional formal methods. It doesn't prove *absolutely* something in most cases, but it's a far more rigorous analysis approach than many approaches.

RTLWS: Modeling systems with Alloy

Posted Nov 8, 2012 23:04 UTC (Thu) by epa (subscriber, #39769) [Link]

The point is that Alloy has just the same downside as traditional testing: it can be used to prove the presence of bugs, but not their absence. Nothing wrong with that, but the article seems to suggest otherwise.

RTLWS: Modeling systems with Alloy

Posted Nov 8, 2012 15:48 UTC (Thu) by dashesy (guest, #74652) [Link]

Thanks for the great article, I think I am lucky to get to read this exactly when I needed one.

RTLWS: Modeling systems with Alloy

Posted Nov 8, 2012 17:37 UTC (Thu) by jimparis (guest, #38647) [Link] (1 responses)

This article could benefit from even a minimal example of what the Alloy language looks like. None of the immediate links in the article show any examples, either. To those of us unfamiliar with Z and Alloy, this just seems like magic fairy pixie dust that solves problems in some unknown way.

RTLWS: Modeling systems with Alloy

Posted Nov 8, 2012 18:10 UTC (Thu) by jake (editor, #205) [Link]

> minimal example of what the Alloy language looks like

Unfortunately, my note taking was not fast enough to capture enough of the syntax to provide that example. I didn't find a definitive link for a quick look at the language either, unfortunately, but the tutorial at http://alloy.mit.edu/alloy/tutorials/online/ will certainly give you the flavor of things ...

jake

If you are interested in this..

Posted Nov 8, 2012 18:24 UTC (Thu) by hisdad (subscriber, #5375) [Link]

Check out mCRL2.

The learning curve is steep, though
--Dad

RTLWS: Modeling systems with Alloy

Posted Nov 8, 2012 23:38 UTC (Thu) by mhelsley (guest, #11324) [Link]

I wonder how Alloy compares to Spin/Promela. Alloy sounds like a different way to do precisely the same things. Has it made any progress in reducing the resource requirements via improved algorithms/data structures? That would enable it to model/check larger systems. Or is it just a better language/UI wrapping the same methods?

RTLWS: Modeling systems with Alloy

Posted Nov 17, 2012 23:43 UTC (Sat) by twm (guest, #67436) [Link]

I wholeheartedly recommend Daniel Jackson's "Software Abstractions: Logic, Language and Analysis" to anyone interested in the use of Alloy. It's by far the best textbook I encountered while at school.


Copyright © 2012, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds