tests: only cleanup the gpio-mockup module from the main process
authorBartosz Golaszewski <bartekgola@gmail.com>
Tue, 16 May 2017 09:14:45 +0000 (11:14 +0200)
committerBartosz Golaszewski <bartekgola@gmail.com>
Tue, 16 May 2017 09:14:45 +0000 (11:14 +0200)
In preparation for adding support for subprocesses: store the pid of
the main process and use it such that we don't try to unload the
mockup module twice leading to a splat from libkmod.

Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
tests/gpiod-test.c

index 11330c4d5866b631632c3dd4518669a5286c34a1..bccf02f83eaee444a85ad831a7ea90cfc8884719 100644 (file)
@@ -61,6 +61,7 @@ static struct {
        struct kmod_ctx *module_ctx;
        struct kmod_module *module;
        struct test_context test_ctx;
+       pid_t main_pid;
 } globals;
 
 enum {
@@ -232,6 +233,10 @@ static bool mockup_loaded(void)
 
 static void module_cleanup(void)
 {
+       /* Don't cleanup from child processes. */
+       if (globals.main_pid != getpid())
+               return;
+
        msg("cleaning up");
 
        if (mockup_loaded())
@@ -566,6 +571,7 @@ int main(int argc TEST_UNUSED, char **argv TEST_UNUSED)
 {
        struct _test_case *test;
 
+       globals.main_pid = getpid();
        atexit(module_cleanup);
 
        msg("libgpiod test suite");