Embedded Systems Design - March 2008 - (Page 52) 0308esd.p49to52 2/13/08 8:11 PM Page 52 break points untestable chunk of code, it’s hard to testing is enough?” That’s a tough to create more meaningful tests. For imagine what 725 implies. question, but, since v(G) is exactly instance, see the paper “Structured What about Linux? Kernel verthe number of paths through the Testing: A Testing Methodology sion 2.6.23 is composed of 161k func- function, it’s clear that the metric is Using the Cyclomatic Complexity tions. RSM, which was nearly instanalso exactly the minimum number of Metric” (Thomas McCabe and taneous in most of the other tests needed to completely exercise Arthur Watson, NIST Special Publiexperiments, needed 3 hours to digest the routine. If your regimen has less cation 500-235, http://hissa.nist.gov/ the over 3 million lines of code. It then v(G) tests, the code is not comHHRFdata/Artifacts/ITLdoc/235/ generated a 200-MB HTML file that pletely tested. title.htm). crashed Internet Explorer and Firefox, Cyclomatic complexity doesn’t although trusty Ultraedit handled it, tell us how many tests are required; GOTTA START SOMEWHERE albeit slowly. Functions averaged a the number could be much higher Plenty of vendors sell tools to measvery respectable complexity of 4.94, than v(G). And the number by itself ure v(G). McCabe himself has highly with one peaking regarded, although pricey, at 352. That 1,800products. See www.mccabe. v(G) is not the only measure of line function is com. It’s one of the few practically devoid complexity, and a lot of researchers prefer tools that will draw graphs of comments and of each function to clearly alternatives. But it’s easy to interpret and is unacceptable illustrate the possible plenty of tools exist. software. paths. Over 54,000 There’s a freebie scored 1, suggestEclipse plug-in available ing that a third of all Linux functions tells us nothing about whether the from http://eclipse-metrics.source are tremendously simple. 144k were correct tests have been run. But it’s a forge.net/ that looks interesting. Othunder 10, but 764 are in the scary quick sanity check that lets us know er open-source products are available over-50 category, with 125 falling if we have conducted the necessary on Chris Lott’s site (www.chrislott.org/ into the “untestable” over-100 bin. minimum number of tests. resources/cmetrics/). I used RSM from M Squared Linux scored far better than the So that 2,700-line Apache funcTechnologies (www.msquaredtechhandful of GNU tools I checked. tion needs—for one function—at nologies.com/index.htm) for gatherGrep, for instance, averages 13.52. least 725 tests. Ouch! ing the numbers here. It’s an inexThe worst function’s v(G) of 53 (in Of the three RTOSes I looked at pensive tool that acquires lots of 128 lines of code) is lightly com(µC/OS-II, eCos, and FreeRTOS), useful metrics from source files. An mented and almost exuberantly total cyclomatic complexity (the evaluation version limited to 10 files sprinkled with gotos, continues, and sum of all of the individual v(G)s) is is free. It’s fast (except on insanely breaks. 690, 445, and 258 respectively. Note huge code basis like Linux) and easy On the embedded front, the that these numbers say nothing open source RTOS eCos’s 175 funcabout the comparative quality of the to use with practically no learning curve. Highly recommended. tions averages a remarkably low 2.54 code as those that offer more funcv(G) is not the only measure of with only six over 10. tionality will have more functions complexity, and a lot of researchers With only 2,495 lines of code and higher total complexity. But to prefer alternatives. But it’s easy to inand 75 functions, FreeRTOS, anoththose of you who think you can er open source RTOS, is much write an operating system in a week- terpret and plenty of tools exist. Like a lot of things, it’s imperfect, but in smaller than Linux. It’s average v(G) end, well, it’s clear that just writing life, just as in school, a 90% is often is just 3.44. One function scored 11; the tests will consume far more time an A grade. It’s a step in the right diall the rest are under 10. than that. rection of being more quantitative µC/OS-II averaged a very reApache’s total complexity is about software engineering. spectable 5.85 for its 118 functions, 34,764; Linux sums to a whopping Finally, cyclomatic complexity with one outlier at 25. That outlying 798.092. If each test requires merely says nothing about the “goodness” of function was composed of the four lines of code, the test suite will the code. I ran this truly horrible switch structure McCabe says equal the size of Linux itself. program (www0.us.ioccc.org/2001/ shouldn’t be counted when running And that says something about williams.c), an entry from the Interthese metrics. the difficulty and expense of creatnational Obfuscated C Coding Coning comprehensive tests. test, and found its average v(G) is TESTING McCabe and others have created A lot of people ask me “how much ways of using the complexity metrics about half of Grep’s! ■ 52 MARCH 2008 | embedded systems design | www.embedded.com http://hissa.nist.gov/HHRFdata/Artifacts/ITLdoc/235/title.htm http://hissa.nist.gov/HHRFdata/Artifacts/ITLdoc/235/title.htm http://hissa.nist.gov/HHRFdata/Artifacts/ITLdoc/235/title.htm http://www.mccabe.com http://www.mccabe.com http://eclipse-metrics.sourceforge.net/ http://eclipse-metrics.sourceforge.net/ http://www.chris-lott.org/resources/cmetrics/ http://www.chris-lott.org/resources/cmetrics/ http://www.msquaredtechnologies.com/index.htm http://www.msquaredtechnologies.com/index.htm http://www0.us.ioccc.org/2001/williams.c http://www0.us.ioccc.org/2001/williams.c http://www.embedded.com
Table of Contents Feed for the Digital Edition of Embedded Systems Design - March 2008 Embedded Systems Design - March 2008 Contents #Include Programming Pointers Designing DSP-based Motor Control Using Fuzzy Logic Hardware/Software Verification Enters the Atomic Age Efficient CRC Calculation with Minimal Memory Footprint Programming Your Own Microcontroller Advertising Index Break Points Marketplace Embedded Systems Design - March 2008 Embedded Systems Design - March 2008 - (Page BB1) Embedded Systems Design - March 2008 - (Page BB2) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page Cover1) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page Cover2) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page 1) Embedded Systems Design - March 2008 - Embedded Systems Design - March 2008 (Page 2) Embedded Systems Design - March 2008 - Contents (Page 3) Embedded Systems Design - March 2008 - #Include (Page 4) Embedded Systems Design - March 2008 - #Include (Page 5) Embedded Systems Design - March 2008 - #Include (Page 6) Embedded Systems Design - March 2008 - #Include (Page 7) Embedded Systems Design - March 2008 - #Include (Page 8) Embedded Systems Design - March 2008 - Programming Pointers (Page 9) Embedded Systems Design - March 2008 - Programming Pointers (Page 10) Embedded Systems Design - March 2008 - Programming Pointers (Page 11) Embedded Systems Design - March 2008 - Programming Pointers (Page 12) Embedded Systems Design - March 2008 - Programming Pointers (Page 13) Embedded Systems Design - March 2008 - Programming Pointers (Page 14) Embedded Systems Design - March 2008 - Programming Pointers (Page 15) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 16) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 17) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 18) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 19) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 20) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 21) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 22) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 23) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 24) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 25) Embedded Systems Design - March 2008 - Designing DSP-based Motor Control Using Fuzzy Logic (Page 26) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 27) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 28) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 29) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 30) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 31) Embedded Systems Design - March 2008 - Hardware/Software Verification Enters the Atomic Age (Page 32) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 33) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 34) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 35) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 36) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 37) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 38) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 39) Embedded Systems Design - March 2008 - Efficient CRC Calculation with Minimal Memory Footprint (Page 40) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 41) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 42) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 43) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 44) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 45) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 46) Embedded Systems Design - March 2008 - Programming Your Own Microcontroller (Page 47) Embedded Systems Design - March 2008 - Advertising Index (Page 48) Embedded Systems Design - March 2008 - Break Points (Page 49) Embedded Systems Design - March 2008 - Break Points (Page 50) Embedded Systems Design - March 2008 - Marketplace (Page 51) Embedded Systems Design - March 2008 - Marketplace (Page 52) Embedded Systems Design - March 2008 - Marketplace (Page Cover3) Embedded Systems Design - March 2008 - Marketplace (Page Cover4)
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.