GSM unit test

From Openmoko

(Difference between revisions)
Jump to: navigation, search
 
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
GSM unit test is for testing the interactions between [http://wiki.openmoko.org/wiki/Gsmd#libgsmd-tool libgsmd-tool] and [http://wiki.openmoko.org/wiki/Gsmd gsmd].  Here is a [Python] script to execute commands via libgsmd-tool.  We can write our own test cases to let GSM modem execute AT commands automatically.  It allows us to verify GSM basic functions, such like making phone calls, sending SMS, or registering to the network.
+
GSM unit test is for testing the interactions between [http://wiki.openmoko.org/wiki/Gsmd#libgsmd-tool libgsmd-tool] and [http://wiki.openmoko.org/wiki/Gsmd gsmd].  Here is a [[Python]] script to execute commands via libgsmd-tool.  We can write our own test cases to let GSM modem execute AT commands automatically.  It allows us to verify [[GSM]] basic functions, such like making phone calls, sending SMS, or registering to the network.
  
 
This python script is based on [http://wiki.openmoko.org/wiki/Pexpect Python Expect].  Pexpect is a pure Python module for spawning child applications; controlling them; and responding to expected patterns in their output.  We use this module to spawn [libgsmd-tool] and then can send commands to GSM modem via gsmd.
 
This python script is based on [http://wiki.openmoko.org/wiki/Pexpect Python Expect].  Pexpect is a pure Python module for spawning child applications; controlling them; and responding to expected patterns in their output.  We use this module to spawn [libgsmd-tool] and then can send commands to GSM modem via gsmd.
Line 5: Line 5:
 
== How to use this python script ==
 
== How to use this python script ==
  
  code is [[ here]]
+
* python script  [[http://people.openmoko.org/erin_yueh/UnitTestv2.py  1]]
sample test case is [[here]]
+
* sample test case [[http://people.openmoko.org/erin_yueh/casev1 2]]
 +
* register the network test case [[http://cs.nyu.edu/~wcy203/RegistertoNetwork 3]]
 +
* dial out test case [[http://people.openmoko.org/erin_yueh//DialOut 4]]
 +
* send/receive SMS test case  [[http://people.openmoko.org/erin_yueh/SendReceiveSMS 5]]
  
 
   usage:  python UnivTestv1.py  -t  casename  -c  libgsmd-tool  -m  shell
 
   usage:  python UnivTestv1.py  -t  casename  -c  libgsmd-tool  -m  shell
Line 18: Line 21:
 
  it should be written as below:  
 
  it should be written as below:  
 
   
 
   
  <b>C:r </b>['C:' means it's a command]
+
  C:r  
  <b>E:Register,error </b>['E:' means it's an expect list]
+
  E:Register,error  
  <b>E:Netreg registered(home network),error,OK </b>['E:' means it's an expect list]
+
  E:Netreg registered(home network),OK,error
 
+
 
  From above case, it sends 'r' command to libgsmd-tool and it tries to register the network.
 
  From above case, it sends 'r' command to libgsmd-tool and it tries to register the network.
  
Line 36: Line 38:
 
From above real output from libgsmd-tool, it's very easy to detect the expect behavior. The first expect, it prints the command descriptions. The second expect, we can use some keywords like 'Netreg registered' for this case.
 
From above real output from libgsmd-tool, it's very easy to detect the expect behavior. The first expect, it prints the command descriptions. The second expect, we can use some keywords like 'Netreg registered' for this case.
  
==== Always put the most matched one on the first element ====
+
* use ',' for the delimiter
There can be a lot of matched elements in an expect list. For this python script, please put the most matched element on the expect list.  
+
 
 +
* always put the most matched one on the first element: There can be a lot of matched elements in an expect list. Put this list before using 'error'
 +
 
 +
* append .EOF and .TIMEOUT elements to the expect list: When it reads the second expect line, it appends these two more elements to the list.  
  
==== Append .EOF and .TIMEOUT elements to the expect list ====
+
* how to know it's failed or passed: there are 4 cases
When it reads the second expect line, it appends these two more elements to the list.
+
# correct: passed
 +
# error: failed
 +
# EOF: failed
 +
# timeout: failed
  
==== How to know it's failed or passed ====
+
* script log: It also stores the session log from 'libgsmd-tool', and the default file name is 'script.log'.
After sending a command, it will print <b>'correct'</b> if it's passed. If it's failed, it will print <b>'Timeout'</b> on the screen
+
  
==== Script log ====
+
[[Category:Test]]
It also stores the session log from 'libgsmd-tool', and the default file name is 'script.log'.
+

Latest revision as of 13:30, 18 March 2008

GSM unit test is for testing the interactions between libgsmd-tool and gsmd. Here is a Python script to execute commands via libgsmd-tool. We can write our own test cases to let GSM modem execute AT commands automatically. It allows us to verify GSM basic functions, such like making phone calls, sending SMS, or registering to the network.

This python script is based on Python Expect. Pexpect is a pure Python module for spawning child applications; controlling them; and responding to expected patterns in their output. We use this module to spawn [libgsmd-tool] and then can send commands to GSM modem via gsmd.

Contents

[edit] How to use this python script

  • python script [1]
  • sample test case [2]
  • register the network test case [3]
  • dial out test case [4]
  • send/receive SMS test case [5]
 usage:  python UnivTestv1.py  -t  casename  -c  libgsmd-tool  -m  shell
 -t :  testcase file
 -c :  libgsmd-tool
 -m : atcmd or shell

[edit] How to write a test case file

[edit] text format

it should be written as below: 

C:r 
E:Register,error 
E:Netreg registered(home network),OK,error
From above case, it sends 'r' command to libgsmd-tool and it tries to register the network.

[edit] real output from libgsmd-tool

below texts are copied from libgsmd-tool shell mode 

r
# Register
EVENT: Netreg searching for network 
EVENT: Signal Quality: 22
EVENT: Netreg registered (home network) LocationAreaCode = 0x2C27 CellID = 0x498C

[edit] how to write expect list to match the result

From above real output from libgsmd-tool, it's very easy to detect the expect behavior. The first expect, it prints the command descriptions. The second expect, we can use some keywords like 'Netreg registered' for this case.

  • use ',' for the delimiter
  • always put the most matched one on the first element: There can be a lot of matched elements in an expect list. Put this list before using 'error'
  • append .EOF and .TIMEOUT elements to the expect list: When it reads the second expect line, it appends these two more elements to the list.
  • how to know it's failed or passed: there are 4 cases
  1. correct: passed
  2. error: failed
  3. EOF: failed
  4. timeout: failed
  • script log: It also stores the session log from 'libgsmd-tool', and the default file name is 'script.log'.
Personal tools

GSM unit test is for testing the interactions between libgsmd-tool and gsmd. Here is a [Python] script to execute commands via libgsmd-tool. We can write our own test cases to let GSM modem execute AT commands automatically. It allows us to verify GSM basic functions, such like making phone calls, sending SMS, or registering to the network.

This python script is based on Python Expect. Pexpect is a pure Python module for spawning child applications; controlling them; and responding to expected patterns in their output. We use this module to spawn [libgsmd-tool] and then can send commands to GSM modem via gsmd.

How to use this python script

 code is  here
sample test case is here
 usage:  python UnivTestv1.py  -t  casename  -c  libgsmd-tool  -m  shell
 -t :  testcase file
 -c :  libgsmd-tool
 -m : atcmd or shell

How to write a test case file

text format

it should be written as below: 

C:r ['C:' means it's a command]
E:Register,error ['E:' means it's an expect list]
E:Netreg registered(home network),error,OK ['E:' means it's an expect list]
From above case, it sends 'r' command to libgsmd-tool and it tries to register the network.

real output from libgsmd-tool

below texts are copied from libgsmd-tool shell mode 

r
# Register
EVENT: Netreg searching for network 
EVENT: Signal Quality: 22
EVENT: Netreg registered (home network) LocationAreaCode = 0x2C27 CellID = 0x498C

how to write expect list to match the result

From above real output from libgsmd-tool, it's very easy to detect the expect behavior. The first expect, it prints the command descriptions. The second expect, we can use some keywords like 'Netreg registered' for this case.

Always put the most matched one on the first element

There can be a lot of matched elements in an expect list. For this python script, please put the most matched element on the expect list.

Append .EOF and .TIMEOUT elements to the expect list

When it reads the second expect line, it appends these two more elements to the list.

How to know it's failed or passed

After sending a command, it will print 'correct' if it's passed. If it's failed, it will print 'Timeout' on the screen

Script log

It also stores the session log from 'libgsmd-tool', and the default file name is 'script.log'.