oracle / ktf

Kernel Test Framework - a unit test framework for the Linux kernel
Other
95 stars 43 forks source link

Duplicate parameterized test name error #15

Open pfourguet opened 5 years ago

pfourguet commented 5 years ago

Hi, I'm having some issues executing a simple test with ktf. I'm cross-compiling ktf for arm64 architecture. I'm using the latests revisions of KTF and googletest on a 4.14.115 Linux kernel. After inserting KTF and my test module (insmod ktf.ko; insmod test.ko), i'm trying to list the registered test using the command ktfrun --gtest_list_tests. ktfrun creates a coredump and gives me the following error:

[ FATAL ] /usr/include/gtest/internal/gtest-param-util.h:562:: Condition test_param_names.count(param_name) == 0 failed. Duplicate parameterized test name 't1', in Aborted (core dumped)

I wasn't able to understand what is going on. My test source code is the default one created using the ktfnew script. Activating the debug messages gives me the following messages:

[ FATAL ] /usr/include/gtest/internal/gtest-param-util.h:562:: Condition test_param_names.count(param_name) == 0 failed. Duplicate parameterized test name 't1', in Aborted (core dumped)

It seems that it acts like the same test was registered twice. But there is only one test in test source code. Here is the test source code as a reminder:

include <linux/module.h>

include "ktf.h"

MODULE_LICENSE("GPL");

KTF_INIT();

TEST(simple, t1) { EXPECT_TRUE(true); }

static void add_tests(void) { ADD_TEST(t1); }

static int init tests_init(void) { add_tests(); return 0; } static void exit tests_exit(void) { KTF_CLEANUP(); }

module_init(tests_init); module_exit(tests_exit);

Have you already encountered this type of error ? Thanks in advance for your help. Pascal

knuto commented 5 years ago

This code looks fine to me, it also executes perfectly in my setup on x86. I even tried with the latest upstream googletest. Could it be that you already had managed to load another module with a test named "t1"? lsmod | grep ktf should give you the modules you have loaded that depends on ktf.

pfourguet commented 5 years ago

Hi, thank you for your answser. I think i've found my error root cause. It may be a link error as disabling the use of libktf as a shared library enables me to run ktfrun without error. I could see in KTF source code that the registration of kernel test is done while initializing the gtest_registeringdummy variable. So if the shared ktf library is loaded twice (may be because of the use of preload on my target or to another link problem, still no sure ..), you can get this error (Duplicate parameterized test name). Pascal

knuto commented 5 years ago

If you still see ktf initialized as a side effect of the gtest_registeringdummy variable, you are likely not running off the latest KTF. I had people observing issues with the shared library on Ubuntu, so after some struggles I decided to back out on the completely transparent initialization, and replaced the implicit initialization with a need for a call to ktf::setup(). See commits 20d9cf8a71 and a8e13f791. I realize the gtest_registeringdummy variable is still lingering, but it is no longer used anywhere so it should have been removed. I'll fix that.