This page represents our best attempt at gathering the common tools and practices used by engineers on the Ubuntu Foundations team.
We are in alphabetical order, right?! =)
Turns Vim into a fully-functional IDE:
Testing and Debugging
Use pyflakes to check for common errors. Hook this up to your preferred test harness using something akin to the following:
Mock is one of the better mocking libraries and is already used in ubiquity, software-center, and apport.
ipdb iPython like debugging shell with superior tab completion. import ipdb; ipdb.set_trace() is pure heaven.
strace: system call tracing.
ltrace: library function tracing.
atrace.sh: library function and application function tracing
Note: to use memory checkers reliably, you need to tell (e(g))libc and glib to disable all their checks too like this:
Note the trailing underscore at the end of the last variable!
No need to recompile code.
Basic memory checking:
1 valgrind -v myprogram --arg=foo -baz
More aggressive checking:
Deep magic which will spawn gdb when an error is detected (--db-attach=yes):
1 valgrind \ 2 -v \ 3 --trace-children=yes \ 4 --track-fds=yes \ 5 --time-stamp=yes \ 6 --db-attach=yes \ 7 --read-var-info=yes \ 8 --tool=memcheck \ 9 --leak-check=full \ 10 --leak-resolution=high \ 11 --num-callers=40 \ 12 --show-reachable=yes \ 13 --track-origins=yes \ 14 --undef-value-errors=yes \ 15 --freelist-vol=60000000 \ 16 --malloc-fill=0x7 \ 17 --free-fill=0x8 \ 18 myprogram --arg=foo -baz
1 sudo apt-get install -y libdmalloc5 libdmalloc-dev
Using dmalloc with LD_PRELOAD:
1 (eval `dmalloc -b -i 1 -l /tmp/dmalloc.log all`; LD_PRELOAD=libmalloc.so.5; ./myapp --arg=foo -bar)
Simpler more hackable/configurable tool than dmalloc/electric-fence:
Excellent static analysis tool. May now be unmaintained? Does not understand C99 (variadic macros).
1 splint -I/usr/include -I/some/where -DMY_DEFINE=1 -DFOO src/main.c 2>&1|tee splint.log
judge runs two commands 50 times and provides the following report:
ubuntu@server-8149:~$ ./judge/judge ./2281 ./with_changes v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^v^ n mean sd min max cmd 50 10316.2ms 355.7 9945.9 11638.6 ./2281 50 9867.5ms 625.8 9385.6 13061.3 ./with_changes -448.636ms -4.3% p=0.000 difference is significant at 95.0% confidence (p=0.000): based on these samples, suggested sample size is n>=283 to have a 112.16ms confidence interval
cloud-init provides a means to run scripts during the creation of a Canonicloud instance. You can use this to create configurations for the infrastructure you need for a project and rapidly deploy that, either to develop or run tests against. See the code in whoopsie-daisy as an example.
- sbuild (far superior to pbuilder: quicker per-build setup, closer to Launchpad buildd environment, integrates well with schroot for ad-hoc testing)
Efficiently splitting a terminal into several smaller windows
tmux is a terminal multiplexer, similar to GNU Screen, but arguably better.
The default keybindings let you use ^b arrow to move between panes. However, because this is a sequence of keys rather than a modifier, you can easily get into timing issues where you meant to move to the pane above, then downward in the open file, but actually moved to the pane above and back into the previous one. You can fix this by telling tmux to not wait for commands:
set -g escape-time 0
- You can bind a key to take the current tmux selection and put it in the X11 clipboard:
unbind ^C bind ^C run "tmux show-buffer | xclip -i -selection clipboard"
Using the standard keybindings, you would hit ^b^[ to enter copy mode, ^space to mark the beginning of a selection, the arrow keys to mark the end, and alt-w to select. Then press ^b^c to copy that text to the X11 clipboard.