NASA’s 10 rules for developing safety-critical code

1: Restrict all code to very simple control flow constructs. Do not use GOTO statements, setjmp or longjmp constructs, or direct or indirect recursion.

2: All loops must have a fixed upper bound. It must be trivially possible for a checking tool to statically prove that a preset upper bound on the number of iterations of a loop cannot be exceeded. If the loop-bound cannot be proven statically, the rule is considered violated.

3: Do not use dynamic memory allocation after initialization.

4: No function should be longer than what can be printed on a single sheet of paper (in a standard reference format with one line per statement and one line per declaration.) Typically, this means no more than about 60 lines of code per function.

5: The assertion density of the code should average a minimum of two assertions per function. Assertions must always be side effect-free and should be defined as Boolean tests.

6: Data objects must be declared at the smallest possible level of scope.

7: Each calling function must check non-void function return values, and the validity of parameters must be checked inside each function.

8: Preprocessor use must be limited to the inclusion of header files and simple macro definitions. Token pasting, variable argument lists (ellipses), and recursive macro calls are not allowed.

9: The use of pointers should be restricted. Specifically, no more than one level of dereferencing is allowed. Pointer dereference operations may not be hidden in macro definitions or inside typedef declarations. Function pointers are not permitted.

10: All code must be compiled, from the first day of development, with all compiler warnings enabled at the compiler’s most pedantic setting. All code must compile with these setting without any warnings. All code must be checked daily with at least one—but preferably more than one—state-of-the-art static source code analyzer, and should pass the analyses with zero warnings.

Advertisements

ScreenShots

A screenshot, screen capture (or screen-cap), screen dump,screengrab is an image taken by the computer user to record the visible items displayed on the monitor, television, or another visual output device. Usually, this is a digital image using the operating system or software running on the computer, but it can also be a capture made by a camera or a device intercepting the video output of the display.

 

1. PicPick

PicPick, all-in-one design tool for everyone

A full-featured screen capture tool, Intuitive image editor, color picker, color palette, pixel-ruler, protractor, crosshair, whiteboard and more.

User friendly and full of features for creating your image, Suitable for software developers, graphic designers and home users.

Please note that free version may only be used for personal use in non-commercial environments.

2. GreenShot

Greenshot is a light-weight screenshot software tool for Windows with the following key features:

  • Quickly create screenshots of a selected region, window or fullscreen; you can even capture complete (scrolling) web pages from Internet Explorer.
  • Easily annotate, highlight or obfuscate parts of the screenshot.
  • Export the screenshot in various ways: save to file, send to printer, copy to clipboard, attach to e-mail, send Office programs or upload to photo sites like Flickr or Picasa, and others.
  • …and a lot more options simplyfying creation of and work with screenshots every day.

Greenshot is free and open source.

Also See

UML with Plant – PlantUML extension for MediaWiki

The Unified Modeling Language™ – UML – is OMG’s most-used specification, and the way the world models not only application structure, behavior, and architecture, but also business process and data structure.

Draw professional looking UML diagrams just with simple textual descriptions. Check out how.

 

Achieve using PlantUML extension for MediaWiki.

1. MediaWiki

MediaWiki is a free software open source wiki package written in PHP, originally for use on Wikipedia. It is now also used by several other projects of the non-profit Wikimedia Foundation and by many other wikis, including this website, the home of MediaWiki.
http://www.mediawiki.org/wiki/MediaWiki

Procedure to install Media Wiki on Ubuntu is here.

2. PlantUML

PlantUML is an open-source tool that uses simple textual descriptions to draw UML diagrams.
http://www.mediawiki.org/wiki/Extension:PlantUML

Procedure to install PlantUML extension on Media Wiki is here.

Interesting Libraries/Frameworks for Linux (C/C++)

 

1. CLISH (Command Line Interface SHell)

A modular framework for implementing a CISCO-like CLI on a *NIX system. Arbitary command menus and actions can be defined using XML files. This software handles the user interaction, and forks the appropriate system commands to perform any actions.
http://clish.sourceforge.net/

2. Libconfig – C/C++ Configuration File Library

Libconfig is a simple library for processing structured configuration files, like this one: test.cfg. This file format is more compact and more readable than XML. And unlike XML, it is type-aware, so it is not necessary to do string parsing in application code.
Libconfig is very compact — a fraction of the size of the expat XML parser library. This makes it well-suited for memory-constrained systems like handheld devices.
http://www.hyperrealm.com/libconfig/

3. libevent – an event notification library

The libevent API provides a mechanism to execute a callback function when a specific event occurs on a file descriptor or after a timeout has been reached. Furthermore, libevent also support callbacks due to signals or regular timeouts.
libevent is meant to replace the event loop found in event driven network servers. An application just needs to call event_dispatch() and then add or remove events dynamically without having to change the event loop.
http://libevent.org/

4. libcurl – the multiprotocol file transfer library

libcurl is a free and easy-to-use client-side URL transfer library, supporting DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3, POP3S, RTMP, RTSP, SCP, SFTP, SMTP, SMTPS, Telnet and TFTP. libcurl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, Kerberos), file transfer resume, http proxy tunneling and more!
libcurl is highly portable, it builds and works identically on numerous platforms, including Solaris, NetBSD, FreeBSD, OpenBSD, Darwin, HPUX, IRIX, AIX, Tru64, Linux, UnixWare, HURD, Windows, Amiga, OS/2, BeOs, Mac OS X, Ultrix, QNX, OpenVMS, RISC OS, Novell NetWare, DOS and more…
libcurl is free, thread-safe, IPv6 compatible, feature rich, well supported, fast, thoroughly documented and is already used by many known, big and successful companies and numerous applications.
http://curl.haxx.se/libcurl/

5. jsmn – Minimalistic JSON parser in C

jsmn (pronounced like ‘jasmine’) is a minimalistic JSON parser in C. It can be easily integrated into resource-limited or embedded projects.
jsmn is designed to be robust (it should work fine even with erroneous data), fast (it should parse data on the fly), portable (no superfluous dependencies or non-standard C extensions). An of course, simplicity is a key feature – simple code style, simple algorithm, simple integration into other projects.
http://zserge.bitbucket.org/jsmn.html

6. libmraa – Low Level Skeleton Library for Communication on GNU/Linux platforms

Libmraa is a C/C++ library with bindings to javascript & python to interface with the IO on Galileo, Edison & other platforms, with a structured and sane API where port names/numbering matches the board that you are on. Use of libmraa does not tie you to specific hardware with board detection done at runtime you can create portable code that will work across the supported platforms.

The intent is to make it easier for developers and sensor manufacturers to map their sensors & actuators on top of supported hardware and to allow control of low level communication protocol by high level languages & constructs.
https://github.com/intel-iot-devkit/mraa

Method Call Interception (MCI) in C++

Method Call Interception (MCI) is the technique of intercepting methods, and performing certain extra, specified, operations before / instead of / after the called method. MCI while not the same as Aspect Oriented Programming is the most common technique, used to implement AOP.

As such MCI is often used for

  • Tracing
  • Code Profiling
  • Transaction management
  • Thread safety (locking)

MCI with VC++

When you compile your code with the /Gh option, the compiler automatically adds a call to a function with the prototypeextern "C" void __declspec(naked) _penter(void);

More…

MCI with GCC

GCC has the -finstrument-functions flag which allows you to define two functions that will be called at the beginning and end of each function call:

  • void __cyg_profile_func_enter(void *this_fn, void *call_site);
  • void __cyg_profile_func_exit(void *this_fn, void *call_site);

More…

Also See

Browsing Source Code with OpenGrok

“A wicked fast source browser”

{OpenGrok is a fast and usable source code search and cross reference engine. It helps you search, cross-reference and navigate your source tree. It can understand various program file formats and version control histories like Mercurial, Git, SCCS, RCS, CVS, Subversion, Teamware, ClearCase, Perforce, Monotone and Bazaar. In other words it lets you grok (profoundly understand) source code and is developed in the open, hence the name OpenGrok. It is written in Java. OpenGrok is an open source project and is distributed under CDDL. OpenGrok uses software libraries from Apache Software Foundation.

Steps to get OpenGrok on Ubuntu and Browsing your source code

1. Install Java and TomCat 7

  • $sudo apt-get install default-jdk tomcat7

In case old version of tomcat is installed, check and uninstall before installing Tomcat 7

  • $dpkg --get-selections | grep tomcat
  • $sudo apt-get purge tomcat*

2. Check the details about tomcat

  • $cd /usr/share/tomcat7/bin/
  • $./catalina.sh

Output

    Using CATALINA_BASE: /usr/share/tomcat7
    Using CATALINA_HOME: /usr/share/tomcat7
    Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
    Using JRE_HOME: /usr
    Using CLASSPATH: /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar

3. Adding export vars
Edit your ~/.bashrc and include using the directory pointed by CATALINA_BASE include the following vars:
export CATALINA_HOME=/usr/share/tomcat7/
export OPENGROK_TOMCAT_BASE=$CATALINA_HOME

4. Run the tomcat and check if it is working:

  • $sudo /etc/init.d/tomcat7

Done!!! installed!!!! Check if it is running now!!! Using your favorite browser type in the web address: http://localhost:8080/
If ok you should see a web page with message “It works!”

    5. Install C tags

    • sudo apt-get install exuberant-ctags

    6. Installing OpenGrok

    • Download opengrok-0.11.1.tar.gz from java.net/projects
    • unpack into /tools
      $sudo mkdir /tools
      $sudo cd /tools
      $sudo tar –xvzf ~/opengrok-0.11.1.tar.gz
      $sudo chmod 777 –Rv /tools
    • Creating OpenGrok working directories
      $sudo mkdir -p /var/opengrok/src
      $sudo mkdir -p /var/opengrok/data
      $sudo mkdir -p /var/opengrok/etc
      $sudo chmod 777 –Rv /var
    • Deploying Opengrok
      /tools/opengrok-0.11.1/bin$sudo ./OpenGrok deploy
      Alternatively, copy OpenGrok all into Tomcat’s webapp folder
      $sudo cp /tools/opengrok-0.11.1/lib/source.war /var/lib/tomcat7/webapps
    • Checking OpenGrok – Visit http://localhost:8080/source/

    7. Specifying Source folder

    • $sudo cd /var/opengrok/src
    • $sudo ln -s /home/<username>/src_base/ src_base

    8. Indexing your source code

    • $sudo /tools/opengrok-0.11.1/bin/OpenGrok index
      Alternatively, You can invoke with path containing your source code.
    • $sudo /tools/opengrok-0.11.1/bin/OpenGrok index /home/<username>/src_base/

    9. Visit http://localhost:8080/source/ and start browsing your code!!