Concurrent Software Fine-Coarse-Grained Automatic Modeling Method For Algorithm Error Detection
Concurrent Software Fine-Coarse-Grained Automatic Modeling Method For Algorithm Error Detection
1 Introduction
Abstract technique reduces the size of model and state space effectively, but the
abstract model lacks partial information relative to the source program, which may lead
to some invalid counterexamples. In this case, the abstract part of the model needs to be
refined to eliminate invalid counterexamples, and then verify the model whether sat-
isfies the properties again. The above three tools reduce the state space in different
degrees through abstraction technology, but the invalid counter-example caused by
abstraction still need to perform multiple abstraction and verification operations on the
program, which requires a lot of time and resources.
Literature [5] proposed the fine-grained automatic modeling method based on
HCPN (Hierarchical Coloured Petri Net). HCPN is a high-level Petri net. It realized
hierarchical model on the basis of CPN (Coloured Petri Net), which can describe the
complex systems with call relationships more efficiently. This method is different from
the above tools, it does not use the abstraction, and that is, the execution of each
statement in the program remains in the model. So the modeling and verification
process only needs to be done once and does not lead to invalid counter-examples.
However, this method lead to too many transitions in the model, and the state space is
too large that need to be simplified for carry out model checking.
Only the property-related parts in the HCPN model are concerned when performs
model checking. This paper proposes the fine-coarse-grained automatic modeling
method. Use the fine-grained modeling method retains the execution path of the
interactive statements and the property-related statements related to model checking;
use the coarse-grained modeling method reduces the generation of the information
about other unrelated statements. Thereby reducing the size of the model and state
space and ensuring that model checking results is not affected. Finally, the HCPN
model is verified to determine if there is a corresponding algorithm error in the pro-
gram. We divide the fine-coarse-grained automatic modeling method into two parts:
Source program labeling and storage and Construct model. They are detailed in
Sects. 2 and 3 respectively.
facilitate the conversion process. We need to set the Type and the conversion gran-
ularity of each node during construct the statement binary tree. Type is statement type,
for example, if, else, declarations, etc. Conversion granularity is divided into two
types: fine and coarse. The granularity setting principles are as follows:
(1) For property-related statement, it must be set to fine-grained.
(2) Nodes are set to fine-grained which corresponding the statements that include
inter-process interaction or object-oriented, such as shared variables, creating
objects, etc. Coarse-grained conversion converts multiple statements into a
complex arc expression, while HCPN only supports partial type statements, and
the rest of the statements need to be represented by model elements (fine-grained
conversion).
(3) Node n1 with coarse-grained, then the granularity of the node n2 in its left subtree
must be coarse-grained. If n2 is fine-grained, then the node n1 should be reset to
fine-grained.
(4) Node n1 with fine-grained and n1 corresponds to a branch statement, then the
node corresponding to a statement that matching this branch statement should be
set to fine-grained. The setting of rule (3), (4) is because the coarse-grained
modeling is converted in units of multiple lines of statement (code segments), that
is, all the statement in the code segment must be coarse-grained.
3 Construct Model
statement; each statement is converted into different model fragments, and finally
connected according to the relationship between the statements to form a complete
structure. As shown in Fig. 1, (a) is a branch structure, output transitions (T1, …, Tn)
of place (P1) are used to represent N branches. For the loop structure, we can use the
ring structure in (b) to represent. The two output transitions T1, T3 after place P1
represent entering loop and exiting loop respectively. Other statements except branch
and loop statements are order statements. Such as multi-threading and function calls
statements, Fig. 1(c), (d) are the model fragments of them respectively.
CPN Tools Standard Model File: The information such as place, transition and arc
generated during the conversion are recorded in the corresponding table. When con-
verted to an XML file, the information is read from the table and converted into
corresponding tags in the XML file. The XML file can be opened with the CPN Tools.
Model checker takes the HCPN model and the ASK_CTL formula as inputs. If the
output is true, the model satisfies the property, and the program does not have the
Concurrent Software Fine-Coarse-Grained Automatic Modeling Method 621
algorithm error; If the output is false, the model does not satisfy the property, there is an
algorithm error in the program.
4 Application
There are two threads (Producer, Consumer) in this program. The products pro-
duced are put into a buffer (variable count), and the Consumers take the products from
the buffer. The property to be verification is the number of products produced by
Producer is equal to the sum of the number of products consumed by Consumer and the
number of products remaining in the buffer (sum(Consumer) + count = sum(Pro-
ducer)). Firstly, we model the program using the fine-coarse-grained modeling method,
and we get a fine-coarse-grained model that including 32 places and 22 transitions. It
has 110444 states pace nodes. Then we using the fine-grained modeling method in
literature [5] to model the program, and obtain the fine-grained model that includes 40
places and 28 transitions. It has 154630 states pace nodes. The state space reduction
rate of fine-coarse-grained method is 28.58% compared with the fine-grained method.
Finally, we use CPN Tools own tool to verify the two models. The results are shown in
Fig. 4(a), (b) are the model checking result of fine-coarse-grained model and fine-
grained model respectively, and the results of are the same (both true), indicate that the
program satisfies the property.
622 T. Sun et al.
5 Conclusion
Acknowledgement. This work was supported by National Natural Science Foundation of China
under Grant No. 61562064 and No. 61661041.
References
1. Holzmann, G.J., Smith, M.H.: Software model checking. In: Wu, J., Chanson, S.T., Gao, Q.
(eds.) Formal Methods for Protocol Engineering and Distributed Systems. IAICT, vol. 28,
pp. 481–497. Springer, Boston, MA (1999). https://doi.org/10.1007/978-0-387-35578-8_28
2. Ball, T., Levin, V., Rajamani, S.K.: A decade of software model checking with SLAM.
Commun. ACM 54(7), 68–76 (2011)
3. Chaki, S., Clarke, E.M., Groce, A., Jha, S., Veith, H.: Modular verification of software
components in C. IEEE Trans. Softw. Eng. 30(6), 388–402 (2004)
4. Beyer, D., Henzinger, T.A., Jhala, R., Majumdar, R.: The software model checker BLAST:
applications to software engineering. Int. J. Softw. Tools Technol. Transf. 9(5), 505–525
(2007)
5. Sun, T., Liu, Y.Y.: A hierarchical CPN model automatically generating method aiming at
multithreading program algorithm error detection. In: 17th IEEE International Symposium
on Parallel and Distributed Processing with Applications. IEEE, Melbourne (2018)
6. Jensen, K., Kristensen, L.M.: Coloured Petri Nets: Modelling and Validation of Concurrent
Systems. Springer, Heidelberg (2009). https://doi.org/10.1007/b95112
Concurrent Software Fine-Coarse-Grained Automatic Modeling Method 623
7. Jensen, K., Kristensen, L.M.: Formal definition of hierarchical coloured petri nets. In:
Jensen, K., Kristensen, L.M. (eds.) Coloured Petri Nets, pp. 127–149. Springer, Heidelberg
(2009). https://doi.org/10.1007/b95112_6
8. Huang, W., Hong, M., Yang, Q.H., et al.: C/C++ program memory leaked detection based
on bounded model checking. Appl. Res. Comput. 33(06), 1762–1766 (2016)
9. Wei, O., Shi, Y.F., Xu, B.F., Huang, Z.Q., Chen, Z.: Abstract modeling formalisms in
software model checking. J. Comp. Res. Dev. 52(7), 1580–1603 (2015)
10. Fehnker, A., Huuck, R.: Model checking driven static analysis for the real world: designing
and tuning large scale bug detection. Innov. Syst. Softw. Eng. 9(1), 45–56 (2013)
11. Wang, B., Wu, T.W., Hu, P.P.: Research on software defect classification and analysis.
Comput. Sci. 40(9), 16–20 (2013)