tools/tracing/rtla/tests/unit/cli_opt_callback.c

Source file repositories/reference/linux-study-clean/tools/tracing/rtla/tests/unit/cli_opt_callback.c

File Facts

System
Linux kernel
Corpus path
tools/tracing/rtla/tests/unit/cli_opt_callback.c
Extension
.c
Size
20937 bytes
Lines
717
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.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0

#define _GNU_SOURCE
#include <stdio.h>
#include <check.h>

#define RTLA_ALLOW_CLI_P_H
#include "../../src/cli_p.h"
#include "cli_params_assert.h"

#define TEST_CALLBACK(value, cb) OPT_CALLBACK('t', "test", value, "test value", "test help", cb)

START_TEST(test_opt_llong_callback_simple)
{
	long long test_value = 0;
	const struct option opt = TEST_CALLBACK(&test_value, opt_llong_callback);

	ck_assert_int_eq(opt_llong_callback(&opt, "1234567890", 0), 0);
	ck_assert_int_eq(test_value, 1234567890);
}
END_TEST

START_TEST(test_opt_llong_callback_max)
{
	long long test_value = 0;
	const struct option opt = TEST_CALLBACK(&test_value, opt_llong_callback);

	ck_assert_int_eq(opt_llong_callback(&opt, "9223372036854775807", 0), 0);
	ck_assert_int_eq(test_value, 9223372036854775807LL);
}
END_TEST

START_TEST(test_opt_llong_callback_min)
{
	long long test_value = 0;
	const struct option opt = TEST_CALLBACK(&test_value, opt_llong_callback);

	ck_assert_int_eq(opt_llong_callback(&opt, "-9223372036854775808", 0), 0);
	ck_assert_int_eq(test_value, ~9223372036854775807LL);
}
END_TEST

START_TEST(test_opt_int_callback_simple)
{
	int test_value = 0;
	const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback);

	ck_assert_int_eq(opt_int_callback(&opt, "1234567890", 0), 0);
	ck_assert_int_eq(test_value, 1234567890);
}
END_TEST

START_TEST(test_opt_int_callback_max)
{
	int test_value = 0;
	const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback);

	ck_assert_int_eq(opt_int_callback(&opt, "2147483647", 0), 0);
	ck_assert_int_eq(test_value, 2147483647);
}
END_TEST

START_TEST(test_opt_int_callback_min)
{
	int test_value = 0;
	const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback);

	ck_assert_int_eq(opt_int_callback(&opt, "-2147483648", 0), 0);
	ck_assert_int_eq(test_value, -2147483648);
}
END_TEST

START_TEST(test_opt_int_callback_non_numeric)
{
	int test_value = 0;
	const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback);

	ck_assert_int_eq(opt_int_callback(&opt, "abc", 0), -1);
	ck_assert_int_eq(test_value, 0);
}
END_TEST

START_TEST(test_opt_int_callback_non_numeric_suffix)
{
	int test_value = 0;
	const struct option opt = TEST_CALLBACK(&test_value, opt_int_callback);

	ck_assert_int_eq(opt_int_callback(&opt, "1234567890abc", 0), -1);
	ck_assert_int_eq(test_value, 0);
}

Annotation

Implementation Notes