By looking at various forums online, I have found one secret code for samsung galaxy s2 i9100. This code is properly working on other samsung devices as well but the images displayed in this post are the images from the test result from Samsung Galaxy S2I9100. The code is *#0*#. Entering this code via your dial pad, you will see the following screen.
Here you will see the heading as LCS test but you can test all the listed things. You can test LCD screen, vibrations, both cameras, sensor, touch screen and speakers. This is very handy to check all the hardware of your phone working fine or having any issue.
Tip: While testing touch, make sure you make all the blocks green or you wont be able to use back button.
Update: Though this was tested only on Samsung Galaxy S2, one of the friends in Android Users Group confirm that it is working on Optimus 2X and Xperia