tools/tracing/rtla/tests/unit/utils.c
Source file repositories/reference/linux-study-clean/tools/tracing/rtla/tests/unit/utils.c
File Facts
- System
- Linux kernel
- Corpus path
tools/tracing/rtla/tests/unit/utils.c- Extension
.c- Size
- 2705 bytes
- Lines
- 107
- 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
check.hstdio.hstdlib.hsched.hlimits.hunistd.hsys/sysinfo.h../../src/utils.h
Detected Declarations
function START_TESTfunction START_TEST
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#define _GNU_SOURCE
#include <check.h>
#include <stdio.h>
#include <stdlib.h>
#include <sched.h>
#include <limits.h>
#include <unistd.h>
#include <sys/sysinfo.h>
#include "../../src/utils.h"
extern int nr_cpus;
START_TEST(test_strtoi)
{
int result;
char buf[64];
ck_assert_int_eq(strtoi("123", &result), 0);
ck_assert_int_eq(result, 123);
ck_assert_int_eq(strtoi(" -456", &result), 0);
ck_assert_int_eq(result, -456);
snprintf(buf, sizeof(buf), "%d", INT_MAX);
ck_assert_int_eq(strtoi(buf, &result), 0);
snprintf(buf, sizeof(buf), "%ld", (long)INT_MAX + 1);
ck_assert_int_eq(strtoi(buf, &result), -1);
ck_assert_int_eq(strtoi("", &result), -1);
ck_assert_int_eq(strtoi("123abc", &result), -1);
ck_assert_int_eq(strtoi("123 ", &result), -1);
}
END_TEST
START_TEST(test_parse_cpu_set)
{
cpu_set_t set;
nr_cpus = 8;
ck_assert_int_eq(parse_cpu_set("0", &set), 0);
ck_assert(CPU_ISSET(0, &set));
ck_assert(!CPU_ISSET(1, &set));
ck_assert_int_eq(parse_cpu_set("0,2", &set), 0);
ck_assert(CPU_ISSET(0, &set));
ck_assert(CPU_ISSET(2, &set));
ck_assert_int_eq(parse_cpu_set("0-3", &set), 0);
ck_assert(CPU_ISSET(0, &set));
ck_assert(CPU_ISSET(1, &set));
ck_assert(CPU_ISSET(2, &set));
ck_assert(CPU_ISSET(3, &set));
ck_assert_int_eq(parse_cpu_set("1-3,5", &set), 0);
ck_assert(!CPU_ISSET(0, &set));
ck_assert(CPU_ISSET(1, &set));
ck_assert(CPU_ISSET(2, &set));
ck_assert(CPU_ISSET(3, &set));
ck_assert(!CPU_ISSET(4, &set));
ck_assert(CPU_ISSET(5, &set));
ck_assert_int_eq(parse_cpu_set("-1", &set), 1);
ck_assert_int_eq(parse_cpu_set("abc", &set), 1);
ck_assert_int_eq(parse_cpu_set("9999", &set), 1);
}
END_TEST
START_TEST(test_parse_prio)
{
struct sched_attr attr;
ck_assert_int_eq(parse_prio("f:50", &attr), 0);
ck_assert_uint_eq(attr.sched_policy, SCHED_FIFO);
ck_assert_uint_eq(attr.sched_priority, 50U);
ck_assert_int_eq(parse_prio("r:30", &attr), 0);
ck_assert_uint_eq(attr.sched_policy, SCHED_RR);
ck_assert_int_eq(parse_prio("o:0", &attr), 0);
ck_assert_uint_eq(attr.sched_policy, SCHED_OTHER);
ck_assert_int_eq(attr.sched_nice, 0);
ck_assert_int_eq(parse_prio("d:10ms:100ms", &attr), 0);
ck_assert_uint_eq(attr.sched_policy, 6U);
ck_assert_int_eq(parse_prio("f:999", &attr), -1);
ck_assert_int_eq(parse_prio("o:-20", &attr), -1);
ck_assert_int_eq(parse_prio("d:100ms:10ms", &attr), -1);
Annotation
- Immediate include surface: `check.h`, `stdio.h`, `stdlib.h`, `sched.h`, `limits.h`, `unistd.h`, `sys/sysinfo.h`, `../../src/utils.h`.
- Detected declarations: `function START_TEST`, `function START_TEST`.
- 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.