Sunday, March 9, 2014

Cmock and Unity - Test Framework

Cmock and Unity

Unity - a unit test framework


Unity
•What is Unity?
–Unity is a unit test framework written entirely in the C language.
–Possesses special features for embedded systems
–can be used for any C project.
–only one source file and a couple of header files
–It uses cross-platform Ruby for all the optional add-on scripts.
•src –This is where Unityheader and source file exists
•auto –This contains a collection of Ruby scripts which helps in using unity
–eg. generate_test_runner.rb
-This script will allows to specify any test file name in project and will automatically create a test runner (which includes “main”) to run that test

Unity Test API

RUN_TEST(func)-Each Test is run within the macro RUN_TEST.Thismacro performs necessary setup before thetest is called .
TEST_IGNORE()-Ignore this test and return immediately
TEST_IGNORE_MESSAGE (message)-Ignore this test and return immediately. Output amessage stating why the test was ignored.

Unity Assertion Summary

TEST_ASSERT_TRUE(condition)-Evaluates whatever code is in condition and failsif it evaluates to false
TEST_ASSERT_FALSE(condition)-Evaluates whatever code is in condition and fails
if it evaluates to true
TEST_ASSERT(condition )-Another way of calling TEST_ASSERT_TRUE
TEST_ASSERT_UNLESS(condition)-Another way of calling TEST_ASSERT_FALSE
TEST_FAIL(message)-This test is automatically marked as a failure. The
message is output stating why.

Numerical Assertions:


TEST_ASSERT_EQUAL(expected, actual)-Another way of callingTEST_ASSERT_EQUAL_INT
TEST_ASSERT_EQUAL_INT(expected, actual)-Compare two integers for equality and display
errors as signed integers.
TEST_ASSERT_EQUAL_HEX8(expected, actual)-Compare two integers for equality and display
errors as an 8-bit hex value
TEST_ASSERT_EQUAL_INT_ARRAY(mask, expected, num_elem, actual)-compares 'num_elem' elements of the integer arrays and reports if there are any differences.
TEST_ASSERT_BITS(mask, expected, actual)-Use an integer mask to specify which bits should
be compared between two other integers. High bits in the mask are compared, low bits ignored.
TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual)-Asserts that the actual value is within plus or
minus delta of the expected value.
TEST_ASSERT_EQUAL_STRING(expected, actual)-Compare two null-terminate strings. Fail if any
character is different or if the lengths are different.

How To Use Unity
•Assume a C source file
unity_example.c
#include"unity_example.h"
int sum(int a, int b){
return a + b;
}
int multiply(int x, int y){
return x*y;
}
And......
unity_example.h
int sum(int, int);
int multiply(int, int);
8
Create example test as below.....
unity_example_test.c
#include"unity_example.h"
#include "Unity.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_sum(void){
TEST_ASSERT_EQUAL_INT(0, sum(0, 0));
TEST_ASSERT_EQUAL_INT(5, sum(5, 0));
TEST_ASSERT_EQUAL_INT(10, sum(5, 5));
}
void test_multiply(void){
TEST_ASSERT_EQUAL_INT(0, multiply(0, 0));
TEST_ASSERT_EQUAL_INT(0, multiply(5, 0));
TEST_ASSERT_EQUAL_INT(25, multiply(5, 5));
}

Note:
-setup() function is called at
the start of each test function.
-teardown() function is called at
end of each test function.

Create test runner
Create Test runner using generarte_test_runner.rb in auto directory of unity

Generated runner
Generated runner look like this (it includes "main" having all the tests)
unity_example_test_Runner.c
/* AUTOGENERATED FILE. DO NOT EDIT. */
#include "unity.h"
#include
#include
char MessageBuffer[50];
extern void setUp(void);
extern void tearDown(void);
extern void test_sum(void);
extern void test_multiply(void);
11
static void runTest(UnityTestFunction test)
{
if (TEST_PROTECT())
{
setUp();
test();
}
if (TEST_PROTECT())
{
tearDown();
}
}
void resetTest()
{
tearDown();
setUp();
}
int main(void)
{
Unity.TestFile = "unity_example_test.c";
UnityBegin();
// RUN_TEST calls runTest
RUN_TEST(test_sum);
RUN_TEST(test_multiply);
UnityEnd();
getch();
return 0;
}


Running generated test runnner
The generated test runner are build and run to perform the test.
Result of the test :

Cmock-a mocking framework

CMOCK -module/object mocking framework for C projects
What is Cmock ?
–takes header files and creates a Mock interface for it so that you can
more easily Unit test modules that touch other modules.
–uses Ruby to auto-generate C source code mock object modules conforming to the interfaces specified in C header files.
How it works ?
–searches header files for function declarations
eg. int sum(int, int); (in header file CmockTry.h)
-creates a set of Mock objects and helpers
eg. void sum_ExpectAndReturn(int cmock_arg1,
int cmock_arg2, int toReturn);
in file:-
MockCmockTry.h
MockCmockTry.c
-mock are generated using command
ruby cmock.rb CmockTry.h

Write a test ...
CmockTryTest.c
#include"CmockTry.h"
#include"unity.h"
#include"MockCmockTry.h"
void setUp(void)
{
}
void tearDown(void)
{
}
void test_sum(void){
sum_ExpectAndReturn(5, 5, 10);
TEST_ASSERT_EQUAL(10, sum(5, 5));
sum_ExpectAndReturn(1, 1, 2);
TEST_ASSERT_EQUAL(2, sum(1, 1));
}


•Create a test runner using generate_test_runner.rb file in auto directory
ruby generate_test_runner.rb CmockTryTest.c

Generated Mock Module

void func(void)-------void func_Expect(void)
void func(params)--------void func_Expect(expected_params)
retvalfunc(void)------------void func_ExpectAndReturn(retval_to_return)
retvalfunc(params)----------void func_ExpectAndReturn(expected_params, retval_to_return)

Expect:
Note: The expect functions are always generated. The other functions are only generated if those plugins are enabled:

Generated Mock Module

Original Function Generated Mock Function
void func(void)---(nothing. In fact, an additional function is only generated if the paramslist contains pointers)
void func(ptr* param, other)----void func_ExpectWithArray(ptr* param, intparam_depth, other)
retvalfunc(void)---(nothing. In fact, an additional function is only generated if the paramslist contains pointers)
retvalfunc(other, ptr* param)---void func_ExpectWithArrayAndReturn(other, ptr* param, intparam_depth, retval_to_return)

Array:
Note: An ExpectWithArray will check as many elements as you specify. If you specify zero elements, it will check just the pointer if :smart mode is configured or fail if :compare_data is set.
19
Mocking from the Command Line
Example:
•this will create mocks using the configuration specified in MyConfig.yml:
ruby cmock.rb -oMyConfig.yml super.h duper.h awesome.h
•this will create mocks using the default configuration:
ruby cmock.rb ../mocking/stuff/is/fun.h ../try/it/yourself.h
•inject options directly to the command
ruby cmock.rb --mock_path=”build/mocks” blah.h

Mocking From Scripts or Rake
•default settings:
cmock = CMock.new
•Specify a YAML file containing the configuration options you desire:
cmock = CMock.new('../MyConfig.yml')
•Specify the options explicitly:
cmock = Cmock.new(:plugins => [:cexception, :ignore], :mock_path => 'my/mocks/')

Thursday, January 5, 2012

AAKASH TABLET PC


The Aakash is an Android tablet computer jointly developed by the London-based company DataWind with the Indian Institute of Technology Rajasthan. It is manufactured by the India-based company Quad, at a new production centre in Hyderabad — under a trial run of 100,000 units. The tablet was officially launched as the Aakash in New Delhi on Oct 5, 2011. A substantially upgraded second generation model called UbiSlate 7+ is projected for manufacture beginning in early 2012.
The 7-inch touch screen tablet features 256 MB RAM memory, uses an ARM 11 processor with the Android 2.2 operating system, has two universal serial bus (USB) ports and delivers high definition (HD) quality video.For applications, the Aakash will have access to Getjar, an independent market, rather than the Android Market.
As a multi-media platform, the Aakash project was beset by delays and setbacks. The device was developed as part of the country's aim to link 25,000 colleges and 400 universities in an e-learning program. Originally projected as a "$35 laptop", the device will be sold to the Government of India at $50 and will be distributed at a government subsidized price of $35. A commercial version of Aakash is currently marketed as UbiSlate 7+ at a price of $60.
By January 3, 2012 1.4 million online orders for the Aakash had been received.
  • Earlier it was referred to as the Sakshat table. Later the name has been changed as Aakash.
  • Aspiration to create a "Made in India" computer was first reflected in a prototype "Simputer" that went into production in a small way. Bangalore based CPSU, Bharat Electronics Ltd manufactured around 5,000 Simputers to Indian Customers during 2002-07. In 2011, Kapil Sibal announced an anticipated low-cost computing device to compete with the One Laptop Per Child (OLPC) — though intended for urban college students rather than the OLPC's rural, underprivileged students.
  • The device was projected to be designed by the students of Indian Institute of Technology Rajasthan – at the time uncredentialed in research or product development. The announced computer had been purchased off the shelf. The project remained dormant for about a year.A year later, the MHRD announced that the low cost computer would be launched in 6 weeks. Nine weeks later the MHRD showcased a tablet named "Aakash", not nearly what had been projected and at $60 rather than the projected $35. "NDTV" reported that the new low cost tablet was not a patch that was shown as a prototype and was going to cost about twice as much.
  • While it was once projected as a laptop computer, the design has evolved into a tablet computer. At the inauguration of the national Mission on Education Programme organized by the Union HRD Ministry in 2009, joint secretary N. K. Sinha had said that the computing device is 10 inches (which is around 25.5 cm) long and 5 inches (12.5 cm) wide and priced at around $30.
  • Doubts about the tablet were dismissed in a television program "Gadget Guru" aired on NDTV in August 2010, when it was shown to have 256 MB RAM and 2 GB of internal flash-memory storage and demonstrated running the Android operating system featuring video playback, internal Wi-Fi and cellular data via an external 3G modem

Specifications

As released on 5 October 2011, the Aakash features an overall size of 190.5 x 118.5 x 15.7mm with a 7 inches (180 mm) resistive screen, a weight of 350 grams (12 oz) and using the Android 2.2 operating system with access to the proprietary marketplace Getjar (not the Android marketplace), developed by DataWind.
The processor is 366 MHz with Graphics Accelerator and HD Video Co-processor and the tablet features 256 MB RAM, a Micro SD slot with a 2 GB Micro SD card (expandable to 32 GB), two full-size USB ports, a 2100 mAh battery, Wi-fi capability, a browser developed by DataWind, an internal cellular and Subscriber Identity Module (SIM) modem, using a power consumption of 2 watts with a solar charging option. The device features 3.5 mm audio output and input jack.
The Aakash is designed to support various document (DOC, DOCX, PPT, PPTX, XLS, XLSX, ODT, ODP,PDF), image (PNG, JPG, BMP and GIF), audio (MP3, AAC, AC3, WAV, WMA) and video (MPEG2, MPEG4, AVI, FLV) formats and includes an application for access to YouTube video content.
Specifications Aakash UbiSlate 7+
Price Rs.2,500 Rs.2,999
Central Processor speed Arm11 – 366Mhz Cortex A8 – 700 Mhz
Random Access Memory (RAM) 256 MB RAM 256 MB RAM {http://www.ubislate.com/specifications.html }
Battery 2100 mAh 3200 mAh
OS Android 2.2 Froyo Android 2.3 Gingerbread
Network WiFi WiFi & GPRS Phone network
Made in India Taiwan
Rebate 50% off for Indian Students Foreign product
Storage: Both tablets will have a micro-SD slot, and a 2GB micro-SD flash memory card, upgradable to 32GB. This is the storage for documents, photos, music, videos, etc. Used in Android devices, it is also a good substitute for USB flash memory drive. In Gingerbread, part of applications and data can be moved to the SD card, from the RAM.
Memory: ROM is a device's main memory, and is unannounced by Datawind, estimated to be the same ammount: 256MB. RAM is the secondary memory. It is used to run the Operating System and it's applications. In Android devices, all applications are installed on the RAM. Graphics/Video memory is the tertiary memory, is also unannounced. Both tablets do have graphics processing card(GPU).
Google Android Market: Aakash-1 has too little processing power and no SIM card, therefore no access to Google's Android Market. It will have to suffice with GetJar Marketplace. UbiSlate-7+ does have access to Google's Android Market.
Network: Aakash-1 does not have Direct Internet connection, it only has a Wireless Local-Area Network(WiFi). UbiSlate-7+ has GPRS Internet connection, a 1st generation internet connection, which most Feature phones can access through WAP Browser. Both tablets support external 3G USB modem (dongle).

 Browser

Datawind announced their GPRS modem and browser will use compression technology to speed up Data Transmission (Download/Upload) Rate. Theoretically, if we assume a base speed of 5KB/s, that means already-compressed files(ZIP files, JPEG images, MP3 audio, MPEG video) will transmit at the 5KBps normal speed, uncompressed files at 15KBps (3x base speed), and pure text files at 30KBps (6x base speed).[23] If and when sucessfully combined with Server-side web compression, 1G analog Internet service might actually be able to compete with 3G digital internet service.

 


Development and testing

Kapil Sibal has stated that a million devices would be made available to students in 2011. The devices will be manufactured at a cost of INR1500 (€23 Euro) each, half of which will be paid by the government and half by the institutions that would use it. In January 2011, the company initially chosen to build the Sakshat, HCL Infosystems, failed to provide evidence that they had at least INR600 million (INR60 crore) ($12.2 million) in bank guaranteed funds, as required by the Indian government, which has allocated $6.5 million to the project. As a result, the government put the project out for bidding again.
In June 2011,the HRD announced that it received a few samples from the production process which are under testing. Also it mentions that each state in India provided 3000 samples for testing on their functionality, utility and durability in field conditions.
The Government of India announced that 10,000 (Sakshat) tablet will be delivered to IIT Rajasthan in late June and over the next four months 90,000 more would be made available at a price of INR2500 device. Government will subsidize the cost by about 50%, so a student would have to pay less than INR1,500 for the device.
35% of hardware components were sourced from South Korea, 25% from China, 16% from the USA, 16% from India and 8% from other countries.
Software Development DataWind, the maker of Aakash, has announced a contest for students wherein their best applications will be embedded in the Ubislate(Aakash Tablet). Top 5 application winners will be awarded Rs. 1 Lakh each.
Nasscom Foundation has partnered with DataWind and announced a contest wherein 10 NGOs will have an opportunity to win 20 tablets each, mainly to improve their operations and programme implementation.
Indian Ministry of Education is releasing educational videos in conjunction with IGNOU and IIT at sakshat.ac.in. This preparation of content is meant for students with access to the Internet, India's first law-biding Online Video Library.

Reception

Problems such as low memory, frequent system freezes, poor sound quality, absence of support for all formats and inability to install free software available online were also cited by users. Technical commentator Prasanto Roy criticized issues such as a low battery life, an insufficient 7" screen and absence of training and support infrastructure, especially in rural areas.UbiSlate 7+ will be released by 2012. IIT Rajasthan has finalized the improvements of Aakash-1.
After receiving feedback of the early release model from over 500 users from IITs and other institutions, DataWind announced the next iteration that will have a new microprocessor of 700 megahertz as compared to the present 366 megahertz processor. This will improve the speed of the tablet and solve the existing problems of quick overheating, frequent system freeze, poor sound quality, absence of support for all formats and inability to install free online software. Amount of memory, storage, and USB ports will remain the same.
On 16 December 2011, DataWind opened Aakash ordering online in their Official website at INR 2500 with one week Delivery time and Cash on Delivery facility and its upgraded version Ubislate 7+ is available for pre-order at INR 2999.
On 19 December 2011, DataWind reported that the first phase of Aakash-1 tablet has been sold-out completely, just three days since it was opened for Online order. UbiSlate 7+ production capacity of January and February has already been sold. Now, March production is open for pre-Booking.
By 3 January 2012 1.4 million orders had been received since the Aakash was put up for sale online.

Future plans

Made in Taiwan, the UbiSlate 7+ will be launched between January and February of 2012.
DataWind is already working on giving the device a capacitive touch screen and 3G connectivity. This version will be priced around Rs.7,000, making it, when it releases, the cheapest 3G tablet in the market. The aim thereafter is to bring down the price - through sheer volume sales - to INR 3,000.
Reliance Industries Limited (RIL) has announced the plan to launch LTE(4G) Tablet between 3500-5000 Rupees, with low cost Internet service. This tablet will be an upgraded version of Aakash developed by DataWind.
Datawind had also announced an upgraded verison of Aakash with a front-facing camera and 1GB RAM.

Tuesday, October 4, 2011

A story of blind science-Believers and a Scientist with open mind


This was a question in a physics degree exam at the university of Copenhagen:
"Describe how to determine the height of a sky-scraper with a barometer."
One student replied: "You tie a long piece of string to the neck of the barometer, then lower the barometer from the top of the skyscraper to the ground. The length of the string
plus the length of the barometer gives the height of the building."

This highly original answer so incensed the examiner that the student was failed immediately.

The student appealed on the grounds that his answer was in-disputably correct and the University appointed an independent arbiter to decide the case.

The arbiter judged that the answer was indeed correct but did not display any noticeable knowledge of physics. To resolve the problem, it was decided to call the student in and allow him six minutes to provide a verbal answer that showed at least a minimal familiarity with the basic principles of physics.

For five minutes, the student sat silent, forehead creased in thought.

The arbiter reminded him that time was running out, to which the student replied that he had several extremely relevant answers, but couldn't  make up his mind which to use. On being advised to hurry up the student replied: "Firstly, you could take the barometer up to the roof of the skyscraper, drop it over the edge and measure the time(in t sec) it takes to reach the ground.
The height of the building can then be worked out from the formula H=0.5g*t^2(g is gravity). But bad luck on the barometer."

"Or if the sun is shining, you cound measure the height of the barometer, then set it on end and measure the length of its shadow. Then measure the length of the skyscraper. But if you want highly scientific about it, you can tie a short piece of string to the barometer and swing it like a pendulum(length=l), first at ground level and then on the roof . The height is worked out by the difference in gravitational restoring force T=2*pi*root over(l/g)."

"Or if the skyscraper has an emergency staircase, it would be easier to walk up it and mark off the height of the skyscrapers in barometer lengths, then add up."

"If you merely wanted to be boring and orthodox about it, of course you could use the barometer to measure the airpressure on the roof of the skyscraper and on the ground and convert the difference in millibars into metres to give the height of the building."

"But since we are constantly being exhorted to exercise independence of mind and apply scientific methods, undoubtedly the best way would be to
knock on the janitor's door and say to him,'If you would like a nice new barometer, I will give this one if you tell me the height of this skyscraper'."

(That student was indeed Neils Bohr, the only dane to win the Nobel prize for Physics)




Friday, March 25, 2011

Tathagat Avatar Tulsi

250px-Tathagat

Tathagat Avatar Tulsi (born 9 September 1987) is an Indian physicist, best known as a child prodigy. He completed high school at the age of 9, earned a B.Sc. at the age of 10 and a M.Sc. at the age of 12 from Patna Science College (Patna University). In August 2009, he got his Ph.D. from the Indian Institute of Science, Bangalore at the age of 21. In 2010, he was offered a position as Assistant Professor on contract (a non-permanent teaching position for fresh PhD graduates) at IIT Bombay.Various Indian newspapers claimed that this made him the youngest faculty member ever at an IIT.

Tulsi was born in Patna, Bihar. He completed high school at the age of nine, earned a B.Sc. at the age of ten and a M.Sc. at the age of twelve from Patna Science College (Patna University).

He received wide public attention in 2001, when he was shortlisted by the Indian Department of Science and Technology (DST) to participate in a Nobel laureates conference in Germany. Later, the DST officials claimed that it was a mistake to shortlist him, and that he was a "fake prodigy".[6] Tulsi alleges that some students who accompanied him to Germany asked him to prove his brilliance, but he refused to share his research as it was incomplete. This resulted in him being labeled a "fraud", whose father had forced him to mug up physics without any actual understanding. Following the controversy, Tulsi suffered from depression, which he says, cost him a Ph.D. seat at IIT. He decided to "fight back" by earning a Ph.D. and gaining recognition as a scientist.

Tulsi was admitted by the Indian Institute of Science (IISc)., where he wrote a 33-page long Ph.D. thesis on "Generalizations of the Quantum Search Algorithm". He has the special distinction of being one of the world's youngest scientists. At the age of 17, he co-authored a research manuscript ("A New Algorithm for Fixed-point Quantum Search") with Lov Grover, the inventor of a quantum search algorithm that goes by his name.

Tulsi is listed as one of the most gifted Asian youngsters by TIME magazine, mentioned as "Superteen" by SCIENCE, "Physics Prodigy" by The TIMES, "Master Mind" by The WEEK and listed by OUTLOOK as one of the smartest Indian youngsters. Tathagat Avatar Tulsi participated in the Stock Exchange of Visions project of Fabrica, Benetton's research centre in 2007. He was invited by Luciano Benetton for a dinner in honor of Al Gore on Jun. 14, 2007 in Milano, Italy. Tathagat's story was showcased by National Geographic Channel in the program My Brilliant Brain. The episode named "India's Geniuses" was aired on 13 Dec. 07 and was hosted by Bollywood actress Konkona Sen Sharma.

 

Research

Tulsi worked on quantum search algorithms for his Ph.D. Tulsi at 21 is often claimed by news reporters as the youngest person in India to hold a doctorate. Some of his research publications are listed below (in chronological order of dispatch to the scientific magazines).

Saturday, October 16, 2010

:::::::BLACK HOLE::::::::::

star is a huge, amazing fusion reactor. Because stars are so massive and made out of gas, there is an intense gravitational field that is always trying to collapse the star. The fusion reactions happening in the core are like a giant fusion bomb that is trying to explode the star. The balance between the gravitational forces and the explosive forces is what defines the size of the star.
As the star dies, the nuclear fusion reactions stop because the fuel for these reactions gets burned up. At the same time, the star's gravity pulls material inward and compresses the core. As the core compresses, it heats up and eventually creates a supernova explosion in which the material and radiation blasts out into space. What remains is the highly compressed, and extremely massive,
core. The core's gravity is so strong that even
light cannot escape.


Artist concept of a black hole: The arrows show the paths of objects in and around the opening of the black hole.Photo courtesy NASA
Artist concept of a black hole: The arrows show the paths of objects in and around the opening of the black hole.




This object is now a black hole and literally disappears from view. Because the core's gravity is so strong, the core sinks through the fabric of space-time, creating a hole in space-time -- this is why the object is called a black hole.
The core becomes the central part of the black hole called the singularity. The opening of the hole is called the event horizon.
You can think of the event horizon as the mouth of the black hole. Once something passes the event horizon, it is gone for good. Once inside the event horizon, all "events" (points in space-time) stop, and nothing (even light) can escape. The radius of the event horizon is called the Schwarzschild radius, named after astronomer Karl Schwarzschild, whose work led to the theory of black holes. 








 Supermassive black holes in some giant galaxies create such a hostile environment, they shut down the formation of new stars. Strangely, black holes lie at the center of most galaxies, as shown in the next image.
 Dark matter composition is up for debate, with subatomic particles and black holes considered as candidates.
 This is a new composite image of a galaxy cluster located about 2.6 billion light-years away. The three views of the region were taken with NASA's Hubble Space Telescope in February 2006. See a massive radio telescope in the next photo.
 Like most galaxies, NGC 1097, a barred spiral galaxy, has a supermassive black hole at its center.
 In this artist's rendition, the yellow region at the center represents a supermassive black hole. Around are dust grains mixed with heated, outflowing gas. But just how big is "supermassive?" Find out in the next photo!
This is a depiction of a wormhole, or an Einstein-Rosen bridge, bursting open in the vacuum of space. Many believe these curves in spacetime could enable time travel.