1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.mms.ui;
18 
19 import android.os.Environment;
20 import android.test.suitebuilder.annotation.LargeTest;
21 import android.util.Log;
22 
23 import java.io.BufferedWriter;
24 import java.io.File;
25 import java.io.FileWriter;
26 
27 /**
28  * Sms stress test. Send muliptle sms each with multiple segments.
29  * To run this test
30  * adb shell am instrument -e class com.android.mms.ui.SmsStressTest
31  *  -w com.android.mms.tests/com.android.mms.SmsTestRunner
32  */
33 public class SmsStressTest extends SmsTest {
34     private final static String TAG = "SmsStressTest";
35     private final static String OUTPUT = "result.txt";
36     private long mSendInterval = 10 * 1000; // 10 seconds
37     protected int mIteration = 100;
38     protected BufferedWriter mWriter = null;
39 
40     @Override
setUp()41     protected void setUp() throws Exception {
42         super.setUp();
43         // Get input value for this test
44         if (mInst.mNumberMessages > 0) {
45             mIteration = mInst.mNumberMessages;
46         }
47         if (mInst.mSendInterval > 0) {
48             mSendInterval = mInst.mSendInterval;
49         }
50         Log.v(TAG, String.format("mIteration: %d, mSendInterval: %d",
51                                  mIteration, mSendInterval));
52         mWriter = new BufferedWriter(new FileWriter(new File(
53             Environment.getExternalStorageDirectory(), OUTPUT), true));
54     }
55 
56     @Override
tearDown()57     protected void tearDown() throws Exception {
58         Log.v(TAG, "tearDown");
59         if (mWriter != null) {
60             mWriter.close();
61         }
62         super.tearDown();
63     }
64 
65     /**
66      * Sending multiple sms over a single thread
67      */
68     @LargeTest
testMultiMessageOverSingleThread()69     public void testMultiMessageOverSingleThread() throws Throwable {
70         int i;
71         for (i = 0; i < mIteration; i++) {
72             Log.v(TAG, "iteration: " + i);
73             assertTrue("send & receive message failed",
74                     sendAndReceiveMessage());
75             sleep(mSendInterval);
76             mWriter.write(String.format("send message %d out of %d\n",
77                                         (i+1), mIteration));
78         }
79     }
80 }
81