27.03.2014 Views

SEKE 2012 Proceedings - Knowledge Systems Institute

SEKE 2012 Proceedings - Knowledge Systems Institute

SEKE 2012 Proceedings - Knowledge Systems Institute

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

sequence. Each t i θ i in the firing sequence is a test input if t i is<br />

not a hidden event (Lines 5-8). Each predicate in M i is<br />

corresponding to a test oracle if p is not hidden (Lines 11-13).<br />

f e (t i (f o (V 1 ),…, f o (V k ))) means that each model -level actual<br />

parameter V j of transition t i is first replaced with the<br />

corresponding implementation-level parameter from object<br />

mapping f o and then the implementation code for transition t i is<br />

obtained from f e . f a (p(f o (V 1 ),…, f o (V k ))) means that each model -<br />

level actual param eter V j of p is first replaced with the<br />

corresponding implementation-level parameter from object<br />

mapping f o and then the accessor code for transition t i is<br />

obtained from event mapping f e .<br />

Algorithm 3 below generates a C file, which contains<br />

multiple pthreads for a nondeterministic test sequence.<br />

Algorithm 3. Generate multi-threaded test code in C from a<br />

nondeterministic test sequence<br />

Input: test ID, nondeterministic test sequence ,, , MIM(ID, f o, f e, f a, l h, h)<br />

Output: testCode file<br />

Declare: f i is the thread function for F i(generated by Algorithm2)<br />

1. begin<br />

2. testCode ← h<br />

3. for i=1 to n do<br />

4. testCode ← testCode + thread declaration for r i<br />

5. endfor<br />

6. for i=1 to n do<br />

7. fi ← call Algorithm 2 with F i and MIM<br />

8. testCode ← testCode + f i<br />

9. endfor<br />

10. testCode ← testCode + signature of main function<br />

11. testCode ← testCode + ”{”<br />

12. testCode ← testCode + setup call if setup is defined<br />

13. for i=1 to n do<br />

14. testCode ← testCode + thread creation for r i<br />

15. endfor<br />

16. for i=1 to n do<br />

17. testCode ← testCode + thread join for r i<br />

18. endfor<br />

19. testCode ← testCode + teardown call if is defined<br />

20. testCode ← testCode + “}”<br />

21. save test code to a file named after system ID + test ID<br />

22. end<br />

The code snippet below shows the test code for concurrent test<br />

sequence , .<br />

#include <br />

<br />

pthread_t tidproducer;<br />

void *producer(void * parm) {<br />

pch = item[1];<br />

printf("Producing %c ...\n", pch);<br />

put(pch);<br />

pch = item[2];<br />

printf("Producing %c ...\n", pch);<br />

<br />

pthread_exit(0);<br />

}<br />

void *consumer(void * parm) {<br />

// thread declaration<br />

// produce(1)<br />

// produce(1)<br />

// put(1)<br />

// produce(2)<br />

// produce(2)<br />

gch=get();<br />

// get<br />

printf("Consuming %c ... \n", gch); // consume<br />

<br />

}<br />

main(int argc, char *argv[]) {<br />

pthread_create(&tidproducer, NULL, producer, NULL);<br />

<br />

pthread_join(tidconsumer, NULL);<br />

}<br />

Obviously, Algorithm 3 can be called to generate test code<br />

for a set of non-deterministic test sequences, e.g., produced by<br />

Algorithm 1.<br />

V. CASE STUDIES<br />

We have implemented our approach based on the M ISTA<br />

tool. Our case studies focus on demonstrating that our approach<br />

can generate concurrent test code from test models.<br />

A. Bounded Buffer<br />

Bounded buffer is a classical example for demonstrating the<br />

synchronization problem of multi-threaded programming. It<br />

involves two types of threads, producer and consumer, that<br />

share a fixed-size buffer. A producer generates a piece of data,<br />

puts it into the buffer, and starts again. A t the sam e time a<br />

consumer consumes the data one piece at a time. Existing work<br />

often focuses on the testing of given producer and consumer<br />

programs together with the bounde r buffer (Strictly speaking,<br />

producer and consumer are only one test for bounded buffer).<br />

Our work, however, focuses on the testing of the bounded<br />

buffer. We view producer and consumer programs as test cases<br />

for the bounded buffer. As shown in Section IV, we use test<br />

models to generate different kinds of producers and consumers.<br />

For example, a concurrent test may have different number of<br />

producers and consumers. The producer and consumer in one<br />

test may have different numbers of calls to put and get.<br />

B. ATM<br />

ATM [5] is a client/server program for managing ATM<br />

accounts, e.g., querying the current balance of an account,<br />

depositing money to an account, and withdrawing money from<br />

an account. The server program can accept requests from<br />

different clients by using mu lti-threaded programming. The<br />

multiple threads can access account data sim ultaneously. For<br />

the ATM program, testing can be done from the client side. For<br />

example, a test case can first deposit money to an account and<br />

then withdraw money from the same account. Such traditional<br />

test cases can be generated by the existing MISTA tool. In this<br />

study, we focus on generation of concurrent tests with m ultiple<br />

threads. Each thread sends requests to the server. D ifferent<br />

threads may operate on the same account to check if th e server<br />

fails to respond correctly.<br />

For each case study, we were able to generate executable<br />

pthread code for many concurrent tests. This has demonstrated<br />

the technical feasibility. W e are currently applying the<br />

approach to an industry project at Samsung.<br />

VI. RELATED WORK<br />

Our approach is related to code-based and specification -<br />

based testing of concurrent programs and testing with Petri<br />

350

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!