• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

OISF / suricata / 23374838686

21 Mar 2026 07:29AM UTC coverage: 59.341% (-20.0%) from 79.315%
23374838686

Pull #15075

github

web-flow
Merge 90b4e834f into 6587e363a
Pull Request #15075: Stack 8001 v16.4

38 of 70 new or added lines in 10 files covered. (54.29%)

34165 existing lines in 563 files now uncovered.

119621 of 201584 relevant lines covered (59.34%)

650666.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/threads.c
1
/* Copyright (C) 2007-2010 Open Information Security Foundation
2
 *
3
 * You can copy, redistribute or modify this Program under the terms of
4
 * the GNU General Public License version 2 as published by the Free
5
 * Software Foundation.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * version 2 along with this program; if not, write to the Free Software
14
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15
 * 02110-1301, USA.
16
 */
17

18
/**
19
 * \file
20
 *
21
 * \author Victor Julien <victor@inliniac.net>
22
 * \author Pablo Rincon Crespo <pablo.rincon.crespo@gmail.com>
23
 *
24
 * This file now only contains unit tests see macros in threads.h
25
 */
26

27
#include "suricata-common.h"
28
#include "thread-storage.h"
29
#include "util-unittest.h"
30
#include "util-debug.h"
31
#include "threads.h"
32

33
thread_local char t_thread_name[THREAD_NAME_LEN + 1];
34
#ifdef UNITTESTS /* UNIT TESTS */
35

36
/**
37
 * \brief Test Mutex macros
38
 */
39
static int ThreadMacrosTest01Mutex(void)
40
{
41
    SCMutex mut;
42
    FAIL_IF(SCMutexInit(&mut, NULL) != 0);
43
    FAIL_IF(SCMutexLock(&mut) != 0);
44
    FAIL_IF(SCMutexTrylock(&mut) != EBUSY);
45
    FAIL_IF(SCMutexIsLocked(&mut) == 0);
46
    FAIL_IF(SCMutexUnlock(&mut) != 0);
47
    FAIL_IF(SCMutexDestroy(&mut) != 0);
48

49
    PASS;
50
}
51

52
/**
53
 * \brief Test Spinlock Macros
54
 *
55
 * Valgrind's DRD tool (valgrind-3.5.0-Debian) reports:
56
 *
57
 * ==31156== Recursive locking not allowed: mutex 0x7fefff97c, recursion count 1, owner 1.
58
 * ==31156==    at 0x4C2C77E: pthread_spin_trylock (drd_pthread_intercepts.c:829)
59
 * ==31156==    by 0x40EB3E: ThreadMacrosTest02Spinlocks (threads.c:40)
60
 * ==31156==    by 0x532E8A: UtRunTests (util-unittest.c:182)
61
 * ==31156==    by 0x4065C3: main (suricata.c:789)
62
 *
63
 * To me this is a false positive, as the whole point of "trylock" is to see
64
 * if a spinlock is actually locked.
65
 *
66
 */
67
static int ThreadMacrosTest02Spinlocks(void)
68
{
69
    SCSpinlock mut;
70
    FAIL_IF(SCSpinInit(&mut, 0) != 0);
71
    FAIL_IF(SCSpinLock(&mut) != 0);
72
#ifndef __OpenBSD__
73
    FAIL_IF(SCSpinTrylock(&mut) != EBUSY);
74
#else
75
    FAIL_IF(SCSpinTrylock(&mut) != EDEADLK);
76
#endif
77
    FAIL_IF(SCSpinUnlock(&mut) != 0);
78
    FAIL_IF(SCSpinDestroy(&mut) != 0);
79

80
    PASS;
81
}
82

83
/**
84
 * \brief Test RWLock macros
85
 */
86
static int ThreadMacrosTest03RWLocks(void)
87
{
88
    SCRWLock rwl_write;
89
    FAIL_IF(SCRWLockInit(&rwl_write, NULL) != 0);
90
    FAIL_IF(SCRWLockWRLock(&rwl_write) != 0);
91
/* OS X/macOS 10.10 (Yosemite) and newer return EDEADLK. Older versions
92
 * and other tested OS's return EBUSY. */
93
#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__>=101000
94
    FAIL_IF(SCRWLockTryWRLock(&rwl_write) != EDEADLK);
95
#else
96
    FAIL_IF(SCRWLockTryWRLock(&rwl_write) != EBUSY);
97
#endif
98
    FAIL_IF(SCRWLockUnlock(&rwl_write) != 0);
99
    FAIL_IF(SCRWLockDestroy(&rwl_write) != 0);
100

101
    PASS;
102
}
103

104
/**
105
 * \brief Test RWLock macros
106
 */
107
static int ThreadMacrosTest04RWLocks(void)
108
{
109
    SCRWLock rwl_read;
110
    FAIL_IF(SCRWLockInit(&rwl_read, NULL) != 0);
111
    FAIL_IF(SCRWLockRDLock(&rwl_read) != 0);
112
    FAIL_IF(SCRWLockTryWRLock(&rwl_read) != EBUSY);
113
    FAIL_IF(SCRWLockUnlock(&rwl_read) != 0);
114
    FAIL_IF(SCRWLockDestroy(&rwl_read) != 0);
115

116
    PASS;
117
}
118

119
#if 0 // broken on OSX
120
/**
121
 * \brief Test RWLock macros
122
 */
123
static int ThreadMacrosTest05RWLocks(void)
124
{
125
    SCRWLock rwl_read;
126
    int r = 0;
127
    r |= SCRWLockInit(&rwl_read, NULL);
128
    r |= SCRWLockWRLock(&rwl_read);
129
    r |= (SCRWLockTryRDLock(&rwl_read) == EBUSY)? 0 : 1;
130
    r |= SCRWLockUnlock(&rwl_read);
131
    r |= SCRWLockDestroy(&rwl_read);
132

133
    return (r == 0)? 1 : 0;
134
}
135
#endif
136

137
#endif /* UNIT TESTS */
138

139
/**
140
 * \brief this function registers unit tests for DetectId
141
 */
142
void ThreadMacrosRegisterTests(void)
UNCOV
143
{
×
144
#ifdef UNITTESTS /* UNIT TESTS */
145
    UtRegisterTest("ThreadMacrosTest01Mutex", ThreadMacrosTest01Mutex);
146
    UtRegisterTest("ThreadMacrosTest02Spinlocks", ThreadMacrosTest02Spinlocks);
147
    UtRegisterTest("ThreadMacrosTest03RWLocks", ThreadMacrosTest03RWLocks);
148
    UtRegisterTest("ThreadMacrosTest04RWLocks", ThreadMacrosTest04RWLocks);
149
//    UtRegisterTest("ThreadMacrosTest05RWLocks", ThreadMacrosTest05RWLocks);
150
    RegisterThreadStorageTests();
151
#endif /* UNIT TESTS */
UNCOV
152
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc