tools/perf/tests/subcmd-help.c
Source file repositories/reference/linux-study-clean/tools/perf/tests/subcmd-help.c
File Facts
- System
- Linux kernel
- Corpus path
tools/perf/tests/subcmd-help.c- Extension
.c- Size
- 4455 bytes
- Lines
- 135
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
tests.hlinux/compiler.hsubcmd/help.h
Detected Declarations
function test__load_cmdnamesfunction test__uniq_cmdnamesfunction test__exclude_cmdnamesfunction test__exclude_cmdnames_no_overlap
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include "tests.h"
#include <linux/compiler.h>
#include <subcmd/help.h>
static int test__load_cmdnames(struct test_suite *test __maybe_unused,
int subtest __maybe_unused)
{
struct cmdnames cmds = {};
add_cmdname(&cmds, "aaa", 3);
add_cmdname(&cmds, "foo", 3);
add_cmdname(&cmds, "xyz", 3);
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds, "aaa") == 1);
TEST_ASSERT_VAL("wrong cmd", is_in_cmdlist(&cmds, "bar") == 0);
TEST_ASSERT_VAL("case sensitive", is_in_cmdlist(&cmds, "XYZ") == 0);
clean_cmdnames(&cmds);
return TEST_OK;
}
static int test__uniq_cmdnames(struct test_suite *test __maybe_unused,
int subtest __maybe_unused)
{
struct cmdnames cmds = {};
/* uniq() assumes it's sorted */
add_cmdname(&cmds, "aaa", 3);
add_cmdname(&cmds, "aaa", 3);
add_cmdname(&cmds, "bbb", 3);
TEST_ASSERT_VAL("invalid original size", cmds.cnt == 3);
/* uniquify command names (to remove second 'aaa') */
uniq(&cmds);
TEST_ASSERT_VAL("invalid final size", cmds.cnt == 2);
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds, "aaa") == 1);
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds, "bbb") == 1);
TEST_ASSERT_VAL("wrong cmd", is_in_cmdlist(&cmds, "ccc") == 0);
clean_cmdnames(&cmds);
return TEST_OK;
}
static int test__exclude_cmdnames(struct test_suite *test __maybe_unused,
int subtest __maybe_unused)
{
struct cmdnames cmds1 = {};
struct cmdnames cmds2 = {};
add_cmdname(&cmds1, "aaa", 3);
add_cmdname(&cmds1, "bbb", 3);
add_cmdname(&cmds1, "ccc", 3);
add_cmdname(&cmds1, "ddd", 3);
add_cmdname(&cmds1, "eee", 3);
add_cmdname(&cmds1, "fff", 3);
add_cmdname(&cmds1, "ggg", 3);
add_cmdname(&cmds1, "hhh", 3);
add_cmdname(&cmds1, "iii", 3);
add_cmdname(&cmds1, "jjj", 3);
add_cmdname(&cmds2, "bbb", 3);
add_cmdname(&cmds2, "eee", 3);
add_cmdname(&cmds2, "jjj", 3);
TEST_ASSERT_VAL("invalid original size", cmds1.cnt == 10);
TEST_ASSERT_VAL("invalid original size", cmds2.cnt == 3);
/* remove duplicate command names in cmds1 */
exclude_cmds(&cmds1, &cmds2);
TEST_ASSERT_VAL("invalid excluded size", cmds1.cnt == 7);
TEST_ASSERT_VAL("invalid excluded size", cmds2.cnt == 3);
/* excluded commands should not belong to cmds1 */
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds1, "aaa") == 1);
TEST_ASSERT_VAL("wrong cmd", is_in_cmdlist(&cmds1, "bbb") == 0);
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds1, "ccc") == 1);
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds1, "ddd") == 1);
TEST_ASSERT_VAL("wrong cmd", is_in_cmdlist(&cmds1, "eee") == 0);
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds1, "fff") == 1);
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds1, "ggg") == 1);
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds1, "hhh") == 1);
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds1, "iii") == 1);
TEST_ASSERT_VAL("wrong cmd", is_in_cmdlist(&cmds1, "jjj") == 0);
/* they should be only in cmds2 */
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds2, "bbb") == 1);
TEST_ASSERT_VAL("cannot find cmd", is_in_cmdlist(&cmds2, "eee") == 1);
Annotation
- Immediate include surface: `tests.h`, `linux/compiler.h`, `subcmd/help.h`.
- Detected declarations: `function test__load_cmdnames`, `function test__uniq_cmdnames`, `function test__exclude_cmdnames`, `function test__exclude_cmdnames_no_overlap`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.