libfiu: Do not build with -O3 for debug/profile builds

By default, we shouldn't use -O3 for debug/profile builds, as it can make the
debugging/profiling information much harder to follow.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
libfiu: Use a separate data structure to track enabled failure points

This patch introduces a new simple data structure, the wtable, which is used
to store key-value pairs (with \0-terminated keys and void * values), that
supports wildcarded keys.

It is then used to replace the open-coded enabled_fails structure in fiu.c.

Incidentally, that fixes a couple of races at insertion time (e.g. in
fiu_enable_external() we could attempt to call the external function pointer
before we had properly set it in our pf_info structure).

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
tests: Introduce three new tests

This patch introduces three new tests:

 - test-manyfps.py: Test the creation of many failure points.
 - test-onetime.py: Test that we fail ONETIME points only one time.
 - test-parallel.c: Test creation and removal of failure points while checking
   them on a different thread.

The latter, in particular, stresses thread safety for most of the common code.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
libfiu: Fix FIU_ONETIME races

This patch fixes some problems with FIU_ONETIME where it could be ran twice,
or could cause corruption when removing from the running list.

To fix them, we introduce locking on those failure points, to prevent taking
decisions concurrently.

The normal failure points remain unaffected by this locking, so they continue
to have better performance.

Thanks a lot to Chaitanya Patel <cvcpatel@gmail.com> for the bug report.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
libfiu: Do not crash if fiu_fail() is run before fiu_init()

Under some circumstances (e.g. some preload invocations) it can happen that
fiu_fail() gets called before fiu_init().

In that case, our enabled_fails table is NULL, so we shouldn't try to access
it. This patch changes fiu_fail() to do that.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
tests: Add a wildcards test

This patch adds a few tests for the wildcard matching.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
tests: Add a performance test

This patch adds a simple performance test which runs "e2fsck" using the posix
preloader and under various conditions, timing how much it takes.

It is useful as a real-life syscall-intensive load test, which can give us an
indication of libfiu's overhead.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
tests: Improve the parallel test

This patch introduces small improvements in the parallel test, such as the use
of a rwlock, pre-calculating all the failure points names, and counting the
cycles of each function.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
tests: Add a "parallel wildcard" test

This patch introduces a "parallel wildcard" test, similar to the existing
"parallel" one, which stress-tests failure points with wildcards.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
libfiu: Use a hash table for the final entries

This patch makes wtable use a hash for the final entries.

This passes the tests, and improves the performance massively when the failure
points are non-wildcarded.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
libfiu: Add a cache for the wildcard entries

This patch adds a cache for the wildcard entries.
It caches both positive and negative lookups into the wildcard list.

It brings a very significant performance improvement when several wildcarded
failure points are enabled.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
libfiu 0.92

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>