]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
trace: Add TEST_FAIL_TAG macro to allow more narrow matching
authorBenjamin Berg <benjamin.berg@intel.com>
Mon, 20 Nov 2023 23:51:50 +0000 (01:51 +0200)
committerJouni Malinen <j@w1.fi>
Sun, 26 Nov 2023 11:00:45 +0000 (13:00 +0200)
The tag is inserted as the first item in the stack trace, making it
trivial to match against it from the test.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
src/utils/os.h
src/utils/os_unix.c

index 83d5ad99b2f7a2ffd6958995344c73e4f6d8a059..07abf7a9a0db18fed0d501a8e577f49a2b33ebf5 100644 (file)
@@ -667,12 +667,14 @@ int os_exec(const char *program, const char *arg, int wait_completion);
 
 
 #if defined(WPA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS)
-#define TEST_FAIL() testing_test_fail(false)
-int testing_test_fail(bool is_alloc);
+#define TEST_FAIL() testing_test_fail(NULL, false)
+#define TEST_FAIL_TAG(tag) testing_test_fail(tag, false)
+int testing_test_fail(const char *tag, bool is_alloc);
 int testing_set_fail_pattern(bool is_alloc, char *patterns);
 int testing_get_fail_pattern(bool is_alloc, char *buf, size_t buflen);
 #else
 #define TEST_FAIL() 0
+#define TEST_FAIL_TAG(tag) 0
 static inline int testing_set_fail_pattern(bool is_alloc, char *patterns)
 {
        return -1;
index 60b88f8179875cb1bf0ab84cdc958a263330a700..d103ae832726474df687151d2dae95f81b87d054 100644 (file)
@@ -545,10 +545,10 @@ struct wpa_trace_test_fail {
        char pattern[256];
 } wpa_trace_test_fail[5][2];
 
-int testing_test_fail(bool is_alloc)
+int testing_test_fail(const char *tag, bool is_alloc)
 {
        const char *ignore_list[] = {
-               __func__, "os_malloc", "os_zalloc", "os_calloc", "os_realloc",
+               "os_malloc", "os_zalloc", "os_calloc", "os_realloc",
                "os_realloc_array", "os_strdup", "os_memdup"
        };
        const char *func[WPA_TRACE_LEN];
@@ -568,9 +568,22 @@ int testing_test_fail(bool is_alloc)
        res = wpa_trace_calling_func(func, WPA_TRACE_LEN);
        i = 0;
 
-       /* Skip this function as well as allocation helpers */
-       for (j = 0; j < ARRAY_SIZE(ignore_list) && i < res; j++) {
-               if (os_strcmp(func[i], ignore_list[j]) == 0)
+       if (is_alloc) {
+               /* Skip our own stack frame */
+               i++;
+
+               /* Skip allocation helpers */
+               for (j = 0; j < ARRAY_SIZE(ignore_list) && i < res; j++) {
+                       if (os_strcmp(func[i], ignore_list[j]) == 0)
+                               i++;
+               }
+       } else {
+               /* Not allocation, we might have a tag, if so, replace our
+                * own stack frame with the tag, otherwise skip it.
+                */
+               if (tag)
+                       func[0] = tag;
+               else
                        i++;
        }
 
@@ -702,7 +715,7 @@ void * os_malloc(size_t size)
 {
        struct os_alloc_trace *a;
 
-       if (testing_test_fail(true))
+       if (testing_test_fail(NULL, true))
                return NULL;
 
        a = malloc(sizeof(*a) + size);