Experience with CREST (Concolic testing tool for C programs) – How to install?

CREST installation

Tested on Ubuntu 12.04 (32 bit)

Install yices-2.2.2 (CREST DOES NOT WORK WITH VERSION)

  1. Pre-requisites:
    $ sudo apt-get install libgmp-dev gpref gcc
    
  2. Build:
    $ ./configure
    $ make
    

Install yices-1.0.40

  1. Download yices-1.0.40-i686-pc-linux-gnu.tar.gz from here (http://yices.csl.sri.com/download-yices1.shtml)
  2. Extract it somewhere

Install Crest

1. First build CIL

  • Install libraries
    $ sudo apt-get install ocaml ocaml-findlib
  • Build CIL
    $ cd YOUR-CREST-DIR/cil
    $ ./cofigure
    $ make
    

2. Build crest

  • Update src/Makefile by setting Yices_Dir = /path-to-yices-1.0.4
  • Build
    $ cd src/ 
    $ make
    

3. To run crest, use LD_LIBRARY_PATH

$ LD_LIBRARY_PATH=/path-to-yices/lib ./bin/run_crest <program> <iteration> <searcher>

OR create a script named “start-crest” as follows and store it at top directory of crest

 #!/bin/sh
 BASE=$(dirname $0)
 # Run
 LD_LIBRARY_PATH=/path-to-yices-1.0.40/lib $BASE/bin/run_crest "$@"

Using this script, you can run crest as follows

 $ ./start-crest --help

5. Test a program

 $ cd test/
 $ ../bin/crestc uniform_test.c
 $ ../start-crest ./uniform_test 10 -dfs

This should produce output roughly like:

Iteration 0 (0s): covered 0 branches [0 reach funs, 0 reach branches].
 Iteration 1 (0s): covered 1 branches [1 reach funs, 8 reach branches].
 Iteration 2 (0s): covered 3 branches [1 reach funs, 8 reach branches].
 Iteration 3 (0s): covered 5 branches [1 reach funs, 8 reach branches].
 Iteration 4 (0s): covered 7 branches [1 reach funs, 8 reach branches].
 GOAL!
 Iteration 5 (0s): covered 8 branches [1 reach funs, 8 reach branches].

Suspend from system tray menu is not working on Ubuntu 14.04 – how to solve it?

Problem: You click on the system tray menu, typically located at the top right corner of your desktop, and select the suspend menu item. But your computer does not suspend. You may also notice that “suspend” is disabled in the Power Management window (System settings -> Power).

Solution: The quick fix would be to restart the systemd-logind as follows

 sudo restart systemd-logind 

Cheers!

Hide or Remove Network Printers from Printers Dialog in Ubuntu 14.04

Problem: You may find a lot of (unwanted local network) printers listed on Printers management window (Go to Dock and then Printers). You want to remove those printers from your machine so that those printers do not re-appear after reboot.

Solution: There are two ways to deal with it.

  1. Approach 1: Change the CUPS browse protocol (Tested on Ubuntu 14.04) (Found here)
    1. Open ‘/etc/cups/cups-browsed.conf’ and replace the ‘BrowseRemoteProtocols’ with the following line
      BrowseRemoteProtocols none
    2. Restart the service
      $ sudo service cups-browsed restart
  2. Approach 2: Disable cups-browsed service during startup (Not tested, but seems logical) (Found here)
    1. Stop the service
      $ sudo service cups-browsed stop
    2. Create a file named  ‘/etc/init/cups-browsed.override’ and write only one word ‘manual’
      $ sudo touch /etc/init/cups-browsed.override
      $ echo "manual" | sudo tee /etc/init/cups-browsed.override
      
    3. Upon the next reboot, your machine will not start this service anymore. If needed, you may start or stop the service manually.

 

Cheers!

Ignore files/directories from SVN status command

Instead of global configuration for SVN, you can have local configuration for each project. Take a look at the command for ignoring files in SVN

svn propset svn:ignore <file-type | file-name | file-name-with-asterisk> <The-directory-where-to-apply-this-property>

But if you want to have a .gitignore like file and want “svn stat” ignores all such types of files mentioned in the .gitignore file, you can create a file (e.g., .svnignore) with all the file types that you want svn to ignore. This file may look like this:

*.o
*.bin
*.class
log.txt
...

Unlike Git, you’ve got to set the svn:ignore property on every sub-directory of your project recursively. To do this, you can type:

cd project-root-dir/
#['.' is the current dir and .svnignore is in the current dir]
svn propset svn:ignore -RF .svnignore . 

However, if you want to ignore a file which resides under some subdirectories  (e.g., a/b/c.txt), you cannot just append “a/b/c.txt” to .svnignore file as you would do in case of Git. For SVN, first you apply the above command on all the sub-directories recursively and then do as follows:

cd project-root-dir/
svn propedit svn:ignore a/b/

This will open the properties that have been applied to this directory (i.e., a/b) in your editor (e.g., VIM). You can append the specific file name (also file types) that you want to ignore from this directory. In our case, it would be “c.txt”. After edit, save the file. Now try “svn stat” command and this should ignore those files. Once you are satisfied with your modifications (i.e., done with all svn:ignore), do a “svn commit” to commit the modifications you made to all the sub-directories (In this case, just the properties).

To ignore a directory as well as its contents,  make sure you add two entries such as “dirname” and “dirname/” in your .svnignore file or to the svn properties using “svn propedit”.

Hope it helps 🙂

Connecting to HP LaserJet Professional p1606dn printer from Ubuntu 13.04

I wanted to remotely connect to a HP LaserJet Professional p1606dn printer using smb:// URI. I was receiving “Filter Failed” message every time I tried to print something. Updating/Installing hplip driver, as suggested by some forums, didn’t help. Finally I solved the issue as follows.

Target platform
Operating System: Ubuntu 13.04 (64 bit)
Printer: HP LaserJet Professsional p1606dn

Steps:

  1. Open synaptic package manager
  2. Search for “hpijs-ppds” package (version 3.13.3-1) and install it. This will automatically install two other packages– “printer-driver-hpijs” and “libhpmud0”
  3. Open printers and add the specific printer
  4. When you are asked to choose driver
    1. select “HP”
    2. Select “LaserJet p1505n” as the model and “HP LaserJet p1505n hpijs pcl3, 3.13.3, requires …. ” as the driver
  5. Follow the setup wizard for the rest of the configuration
  6. Once your are done with the setup, try to print a test page

Hope it works for you 🙂

Display SVN equivalent revision number for Git in email notification

I have been a SVN user for a long time. Recently I started using Git. Several features of Git are quite fascinating. However, git does not support any human readable revision number (obviously, an increasing number) like SVN. Instead, git uses a hash value to refer to a commit. So when I enabled email notification upon every ‘git push’ command, it appended the hash value to the subject of the email which I didn’t like very much. After googling for a handful of time, I found bits and pieces of the solution, but not a complete one. Some of them didn’t even work for me. After some trial-and-error, I figured out a solution for my problem. I have tried to put together everything below hoping it will be helpful for others.

Enable email notification for Git at every ‘git push’ with SVN like revision number

  1. Create a bare git repository on your server (e.g., my-repo.git)
  2. Go to my-repo.git directory
  3. Assuming that you already have configured git globally as
    git config --global user.name "Your name"
    git config --global user.email "Your email"
    

    Or locally as

    git config user.name "Your name"
    git config user.email "Your email"
    
  4. You MUST download the post-receive-email from here (Some other versions of the script are available out there, but I found this one produced a nice and neat email content. The instructions below may not work for other version.)
  5. Save it under the hooks/ directory with the name ‘post-recevie’
    cp ~/Downloads/post-receive-email hooks/post-receive
    chmod a+x hooks/post-receive
    
  6. Now it’s time to modify the “hooks/post-receive” script
  7. Open “hooks/post-receive” script and replace the following line

    cat $email_tmp_file | mailx -S smtp=”smtp://smtp.cse.ust.hk” -s “$emailsubject” -r $senderemail $recipients

    with

    cat $email_tmp_file | mailx -s “$emailsubject” $recipients

  8. Also replace this line

    custom_showrev=$(git config hooks.showrev)

    with

    revisions=$($(git config hooks.showrev))
    custom_showrev=`echo $revisions | wc -w`

  9. Now replace the email subject line

    emailsubject=`cat emailsubject_tmp_file`

    with

    emailsubject=”Revision $custom_showrev”

  10. Open config file and append
    [hooks]
    mailinglist = your-email-address
    showrev = &quot;git rev-list HEAD&quot;
    emailprefix = [Your-email-prefix]
    

    The “git rev-list HEAD” lists the hash values corresponding to each commit, therefore counting the total number of hash values (i.e., “custom_showrev=`echo $revisions | wc -w`“) would be a reasonable choice for the revision number.

Special thanks to

Integrate R in NS3 program

  1. First you need to install Rcpp and RInside package installed (see here)
  2. Include “<RInside.h>” in your header file.
  3. Adapt one of the examples located in “/usr/local/lib/R/site-library/RInside/examples/standard” and include it into your NS3 code
  4. Modify the “wscript” file (assuming you source location is “NS3-BASE-DIR/examples/myapp/“) as follows
    def build(bld):
     obj = bld.create_ns3_program('myapp', ['core', 'mobility',
     """... modules your program depends on"""])
     obj.source = 'mysrc.cc'
    
     obj.env.append_value("CXXFLAGS", [
     "-I/usr/share/R/include",
     "-I/usr/local/lib/R/site-library/Rcpp/include",
     "-I/usr/local/lib/R/site-library/RInside/include",
     "-pipe"])
    
     obj.env.append_value("LINKFLAGS",
     ["-L/usr/lib/R/lib",
     "-L/usr/local/lib/R/site-library/Rcpp/lib",
     "-Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib",
     "-L/usr/local/lib/R/site-library/RInside/lib",
     "-Wl,-rpath,/usr/local/lib/R/site-library/RInside/lib"])
    
     obj.env.append_value("LIB", ["R", "blas", "lapack", "Rcpp", "RInside"])
    
  5. Now build your NS3 program by running “./waf” by going to the NS3 base directory.

Installing additional packages for R from command line

You can follow the steps below to install additional packages for R on Ubuntu or other Linux dist.

  1. First install R-base, if not installed yet.
  2. Download the compressed tar file of the package, e.g., foo.tar.gz.
  3. Check “DESCRIPTION” file for dependency
  4. Install foo.tar.gz by typing
    R CMD INSTALL path-to-foo.tar.gz

    By default R installs the additional packages to “/usr/local/lib/R/site-library” directory.

Compile and link NS3 program with external library

You can compile and link your NS3 program with an external library. For example, your program “mysrc.cc” is under

NS3-BASE-DIR/examples/myapp/mysrc.cc

and you want to link to, e.g., a static library named “libfoo.a” that is under ~/LIBDIR/lib directory
and library header file exists under ~/LIBDIR/include.
First include the library header file into your “mysrc.cc” as

#include<foo.h>

Now open the NS3-BASE-DIR/examples/myapp/wscript and add build information for your program as follows

def build(bld):
    obj = bld.create_ns3_program('prog_name', ['core', 'network', """... modules your program depends on"""])
    obj.source = 'mysrc.cc'
    obj.env.append_value("CXXFLAGS", "-I/Absolute-path-to-LIBDIR/include")
    obj.env.append_value("LINKFLAGS", ["-L/Absolute-path-to-LIBDIR/lib"])
    obj.env.append_value("LIB", ["foo"])

This method is tested on NS-3.15.

Solving SSH error: Too many authentication failures for

You may encounter the following error when you try to remotely login to a machine using ssh.

Received disconnect from xxx.xxx.xxx.xxx: 2: Too many authentication failures for username

The reason behind this is that your ssh-agent is offering multiple keys to the server. T To see what is happening under the hood, type

ssh -v username@hostname

To solve this issue, create or edit your “~/.ssh/config” file with the following content


HOST the_hostname.the_domain_name
IdentityFile ~/.ssh/your_particular_key
IdentitiesOnly yes
Port 22

To have ssh use only the your_particular_key for all hosts under the same domain, you can replace the first line with “HOST *.the_domain_name”. Enjoy!