Pages

BASH file test operators

Here is a summary of BASH file test operators: 
The general form of a file test operation is -operator "filename"

Operator
Returns true if
-e
File exist
-f
It is a regular file
-d
File is not zero size
-s
File has a size greater than zero
-b
File is a block device
-c
File is a character device
-p
File is a pipe (FIFO)
-h
File is a symbolic link
-L
File is a symbolic link
-S
File is a socket
-t
File (descriptor) is associated with a terminal device
-r
File has read permissions (for current user)
-w
File has write permissions (for current user)
-x
File has execute permissions (for current user)
-g
set-group-id (sgid) flag is set on file or directory
-u
set-user-id (suid) flag is set on file
-k
sticky bit is set
-O
File is owned by the effective user id
-G
File is owned by the effective group id
-N
File modified since it was last read
f1 -nt f2
File f1 is newer than file f2
f1 -ot f2
File f1 is older than file f2
f1 -ef f2
Files f1 and f2 are hard links to the same file
!
"NOT" - returns true if condition is absent

Execute man bash for more information

USB plug/unplug automation

The USB plug/unplug process can be easily automated using a USB power relay. In this example I am using the Phidget board 0/0/4 from http://www.phidgets.com/. All you need is to take one of the voltage lines from the USB cable and connect it to the Phidget board in one of the relay ports. The Phidget board can be controlled by a Host using the Phidget drivers. The plug/unplug simulation will occur once you close the circuit in the USB relay port.


Here is small app to control the Phidget board named phtest. 

How to compile?
% gcc phtest.c -o phtest -l phidget21

 /*  
  * phtest demo to control phidget board 0/0/4  
  * Usage: phtest <port> <status>  
  */  
 #include <stdio.h>  
 #include <stdlib.h>  
 #include <unistd.h>  
 #include <phidget21.h>  
 // the following example will turn on or off a Phidgets Output, such as a relay  
 // or IO device pin  
 int IOcontrol(int whichoutput, int value)  
 {  
      int result;  
      int numInputs = 0;  
      int numOutputs = 0;  
      CPhidgetInterfaceKitHandle ifk;     // the "handle" to the interface kit  
      // initialize the handle  
      CPhidgetInterfaceKit_create (&ifk);  
      // open access to the Phidgets hardware  
      CPhidget_open((CPhidgetHandle)ifk, -1);  
      // wait a max of 2 seconds (for example) before reporting  
      // an attachment error  
      if (result = CPhidget_waitForAttachment((CPhidgetHandle)ifk, 2000))     {  
           const char *err;  
           char buf[1000];  
           // get description of error as string, and output  
           CPhidget_getErrorDescription (result, &err);  
           sprintf (buf, "error: %s\n", err);  
           // output with a message box if you like ...  
           return -1;  
      }  
      // if interested, you can query the interface to  
      // determine how many inputs or outputs it may have  
      CPhidgetInterfaceKit_getNumInputs (ifk, &numInputs);  
      CPhidgetInterfaceKit_getNumOutputs (ifk, &numOutputs);  
      // adjust the output status of the device  
      CPhidgetInterfaceKit_setOutputState (ifk, whichoutput, value);  
      // cleanup  
      CPhidget_close ((CPhidgetHandle)ifk);  
      CPhidget_delete ((CPhidgetHandle )ifk);  
      return 0;  
 }     /* end IOcontrol */  
 int main( int argc, char *argv[] )  
 {  
   int port, status;  
   if (argc !=3) {  
     printf("\nUsage: %s <port> <status>\n\n", argv[0]);  
     printf("Where port=0|1|2|3 --> USB port relay\n");  
     printf("   status=0|1  --> 0=OFF 1=ON\n\n");  
     return 0;  
   }  
   port = atoi(argv[1]);  
   status = atoi(argv[2]);  
   IOcontrol (port, status);  
      return 0;  
 }  

Usage: ./phtest <port> <status>

Where port=0|1|2|3  --> USB port relay
      status=0|1    --> 0=OFF 1=ON

Android Monkey

Here is my version of the Android Monkey to make reference to the known embedded test framework in Android systems:



Hello World I am Android Monkey