Skip to content

Commit ab06539

Browse files
committed
test/zdtm: Add ZDTM test for dynamic bfd expansion on massive group
Add a new ZDTM test case `massive_groups` to verify the dynamic buffer expansion logic in `bfd.c` Signed-off-by: dong sunchao <dongsunchao@gmail.com>
1 parent a1de59b commit ab06539

3 files changed

Lines changed: 79 additions & 0 deletions

File tree

test/zdtm/static/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ TST_NOFILE := \
287287
sigtrap01 \
288288
change_mnt_context \
289289
fd_offset \
290+
massive_groups \
290291
# jobctl00 \
291292
292293
PKG_CONFIG ?= pkg-config
@@ -736,6 +737,8 @@ cgroupv2_01: LDLIBS += -pthread
736737
uprobes: CFLAGS += $(call pkg-cflags, libtracefs libtraceevent)
737738
uprobes: LDLIBS += $(call pkg-libs, libtracefs libelf)
738739

740+
massive_groups: LDLIBS += -lrt -pthread
741+
739742
$(LIB): force
740743
$(Q) $(MAKE) -C $(LIBDIR)
741744

test/zdtm/static/massive_groups.c

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <grp.h>
2+
#include <sys/types.h>
3+
#include <unistd.h>
4+
#include <stdlib.h>
5+
6+
#include "zdtmtst.h"
7+
8+
const char *test_doc = "Test dumping a process with many supplementary groups (Trigger bfd dynamic expansion)";
9+
const char *test_author = "DongSunchao";
10+
11+
/*
12+
* _SC_NGROUPS_MAX beyond parasite's maximum supported groups, so we use a hardcoded value.
13+
* Use 900 groups: enough to test the "Groups:" line in /proc/pid/status
14+
* and triggering dynamic expansion,
15+
* but still within the PARASITE_MAX_GROUPS limit (~952).
16+
*/
17+
#define TEST_NGROUPS 900
18+
19+
int main(int argc, char **argv)
20+
{
21+
gid_t *group;
22+
gid_t *restored_groups;
23+
int i, ngroups;
24+
int restored_ngroups;
25+
26+
test_init(argc, argv);
27+
28+
ngroups = TEST_NGROUPS;
29+
30+
group = malloc(ngroups * sizeof(gid_t));
31+
if (!group) {
32+
fail("Failed to allocate memory for group IDs: %s", strerror(errno));
33+
return 1;
34+
}
35+
36+
/*
37+
* Fill the group array with unique group IDs to reach the maximum limit.
38+
* This will trigger the dynamic expansion of the BFD buffer when dumping
39+
* the process.
40+
*/
41+
for (i = 0; i < ngroups; i++) {
42+
group[i] = i + 1000;
43+
}
44+
45+
if (setgroups(ngroups, group) < 0) {
46+
fail("Failed to set supplementary groups: %s", strerror(errno));
47+
free(group);
48+
return 1;
49+
}
50+
51+
test_daemon();
52+
53+
test_waitsig();
54+
55+
restored_ngroups = getgroups(0, NULL);
56+
if (restored_ngroups != ngroups) {
57+
fail("Restored number of supplementary groups (%d) does not match expected (%d)", restored_ngroups, ngroups);
58+
free(group);
59+
return 1;
60+
}
61+
62+
restored_groups = malloc(restored_ngroups * sizeof(gid_t));
63+
getgroups(restored_ngroups, restored_groups);
64+
65+
for (i = 0; i < ngroups; i++) {
66+
if (restored_groups[i] != group[i]) {
67+
fail("Restored group ID at index %d (%d) does not match expected (%d)", i, restored_groups[i], group[i]);
68+
}
69+
}
70+
71+
free(restored_groups);
72+
free(group);
73+
pass();
74+
return 0;
75+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{'flavor': 'h', 'flags': 'suid'}

0 commit comments

Comments
 (0)