Merge 194fcd20eb ("Merge tag 'linux_kselftest-kunit-6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest") into android-mainline
Steps on the way to 6.12-rc1 Bug: 367265496 Change-Id: Ic1fb2db90a8bdea62f02235567cb404effd2bfb2 Signed-off-by: Matthias Maennich <maennich@google.com>
This commit is contained in:
@@ -188,15 +188,26 @@ For example, a Kconfig entry might look like:
|
||||
Test File and Module Names
|
||||
==========================
|
||||
|
||||
KUnit tests can often be compiled as a module. These modules should be named
|
||||
after the test suite, followed by ``_test``. If this is likely to conflict with
|
||||
non-KUnit tests, the suffix ``_kunit`` can also be used.
|
||||
KUnit tests are often compiled as a separate module. To avoid conflicting
|
||||
with regular modules, KUnit modules should be named after the test suite,
|
||||
followed by ``_kunit`` (e.g. if "foobar" is the core module, then
|
||||
"foobar_kunit" is the KUnit test module).
|
||||
|
||||
The easiest way of achieving this is to name the file containing the test suite
|
||||
``<suite>_test.c`` (or, as above, ``<suite>_kunit.c``). This file should be
|
||||
placed next to the code under test.
|
||||
Test source files, whether compiled as a separate module or an
|
||||
``#include`` in another source file, are best kept in a ``tests/``
|
||||
subdirectory to not conflict with other source files (e.g. for
|
||||
tab-completion).
|
||||
|
||||
Note that the ``_test`` suffix has also been used in some existing
|
||||
tests. The ``_kunit`` suffix is preferred, as it makes the distinction
|
||||
between KUnit and non-KUnit tests clearer.
|
||||
|
||||
So for the common case, name the file containing the test suite
|
||||
``tests/<suite>_kunit.c``. The ``tests`` directory should be placed at
|
||||
the same level as the code under test. For example, tests for
|
||||
``lib/string.c`` live in ``lib/tests/string_kunit.c``.
|
||||
|
||||
If the suite name contains some or all of the name of the test's parent
|
||||
directory, it may make sense to modify the source filename to reduce redundancy.
|
||||
For example, a ``foo_firmware`` suite could be in the ``foo/firmware_test.c``
|
||||
file.
|
||||
directory, it may make sense to modify the source filename to reduce
|
||||
redundancy. For example, a ``foo_firmware`` suite could be in the
|
||||
``foo/tests/firmware_kunit.c`` file.
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
* EXPORTED_FOR_KUNIT_TESTING namespace only if CONFIG_KUNIT is
|
||||
* enabled. Must use MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING)
|
||||
* in test file in order to use symbols.
|
||||
* @symbol: the symbol identifier to export
|
||||
*/
|
||||
#define EXPORT_SYMBOL_IF_KUNIT(symbol) EXPORT_SYMBOL_NS(symbol, \
|
||||
EXPORTED_FOR_KUNIT_TESTING)
|
||||
|
||||
@@ -3059,3 +3059,19 @@ config RUST_KERNEL_DOCTESTS
|
||||
endmenu # "Rust"
|
||||
|
||||
endmenu # Kernel hacking
|
||||
|
||||
config INT_POW_TEST
|
||||
tristate "Integer exponentiation (int_pow) test" if !KUNIT_ALL_TESTS
|
||||
depends on KUNIT
|
||||
default KUNIT_ALL_TESTS
|
||||
help
|
||||
This option enables the KUnit test suite for the int_pow function,
|
||||
which performs integer exponentiation. The test suite is designed to
|
||||
verify that the implementation of int_pow correctly computes the power
|
||||
of a given base raised to a given exponent.
|
||||
|
||||
Enabling this option will include tests that check various scenarios
|
||||
and edge cases to ensure the accuracy and reliability of the exponentiation
|
||||
function.
|
||||
|
||||
If unsure, say N
|
||||
|
||||
@@ -5,5 +5,6 @@ obj-$(CONFIG_CORDIC) += cordic.o
|
||||
obj-$(CONFIG_PRIME_NUMBERS) += prime_numbers.o
|
||||
obj-$(CONFIG_RATIONAL) += rational.o
|
||||
|
||||
obj-$(CONFIG_INT_POW_TEST) += tests/int_pow_kunit.o
|
||||
obj-$(CONFIG_TEST_DIV64) += test_div64.o
|
||||
obj-$(CONFIG_RATIONAL_KUNIT_TEST) += rational-test.o
|
||||
|
||||
3
lib/math/tests/Makefile
Normal file
3
lib/math/tests/Makefile
Normal file
@@ -0,0 +1,3 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
obj-$(CONFIG_INT_POW_TEST) += int_pow_kunit.o
|
||||
52
lib/math/tests/int_pow_kunit.c
Normal file
52
lib/math/tests/int_pow_kunit.c
Normal file
@@ -0,0 +1,52 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
#include <kunit/test.h>
|
||||
#include <linux/math.h>
|
||||
|
||||
struct test_case_params {
|
||||
u64 base;
|
||||
unsigned int exponent;
|
||||
u64 expected_result;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
static const struct test_case_params params[] = {
|
||||
{ 64, 0, 1, "Power of zero" },
|
||||
{ 64, 1, 64, "Power of one"},
|
||||
{ 0, 5, 0, "Base zero" },
|
||||
{ 1, 64, 1, "Base one" },
|
||||
{ 2, 2, 4, "Two squared"},
|
||||
{ 2, 3, 8, "Two cubed"},
|
||||
{ 5, 5, 3125, "Five raised to the fifth power" },
|
||||
{ U64_MAX, 1, U64_MAX, "Max base" },
|
||||
{ 2, 63, 9223372036854775808ULL, "Large result"},
|
||||
};
|
||||
|
||||
static void get_desc(const struct test_case_params *tc, char *desc)
|
||||
{
|
||||
strscpy(desc, tc->name, KUNIT_PARAM_DESC_SIZE);
|
||||
}
|
||||
|
||||
KUNIT_ARRAY_PARAM(int_pow, params, get_desc);
|
||||
|
||||
static void int_pow_test(struct kunit *test)
|
||||
{
|
||||
const struct test_case_params *tc = (const struct test_case_params *)test->param_value;
|
||||
|
||||
KUNIT_EXPECT_EQ(test, tc->expected_result, int_pow(tc->base, tc->exponent));
|
||||
}
|
||||
|
||||
static struct kunit_case math_int_pow_test_cases[] = {
|
||||
KUNIT_CASE_PARAM(int_pow_test, int_pow_gen_params),
|
||||
{}
|
||||
};
|
||||
|
||||
static struct kunit_suite int_pow_test_suite = {
|
||||
.name = "math-int_pow",
|
||||
.test_cases = math_int_pow_test_cases,
|
||||
};
|
||||
|
||||
kunit_test_suites(&int_pow_test_suite);
|
||||
|
||||
MODULE_DESCRIPTION("math.int_pow KUnit test suite");
|
||||
MODULE_LICENSE("GPL");
|
||||
@@ -35,6 +35,7 @@ all_files := \
|
||||
stackprotector.h \
|
||||
std.h \
|
||||
stdarg.h \
|
||||
stdbool.h \
|
||||
stdint.h \
|
||||
stdlib.h \
|
||||
string.h \
|
||||
|
||||
@@ -142,13 +142,13 @@
|
||||
})
|
||||
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"mov x0, sp\n" /* save stack pointer to x0, as arg1 of _start_c */
|
||||
"and sp, x0, -16\n" /* sp must be 16-byte aligned in the callee */
|
||||
"bl _start_c\n" /* transfer to c runtime */
|
||||
);
|
||||
__builtin_unreachable();
|
||||
__nolibc_entrypoint_epilogue();
|
||||
}
|
||||
#endif /* _NOLIBC_ARCH_AARCH64_H */
|
||||
|
||||
@@ -185,15 +185,15 @@
|
||||
})
|
||||
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"mov %r0, sp\n" /* save stack pointer to %r0, as arg1 of _start_c */
|
||||
"and ip, %r0, #-8\n" /* sp must be 8-byte aligned in the callee */
|
||||
"mov r0, sp\n" /* save stack pointer to %r0, as arg1 of _start_c */
|
||||
"and ip, r0, #-8\n" /* sp must be 8-byte aligned in the callee */
|
||||
"mov sp, ip\n"
|
||||
"bl _start_c\n" /* transfer to c runtime */
|
||||
);
|
||||
__builtin_unreachable();
|
||||
__nolibc_entrypoint_epilogue();
|
||||
}
|
||||
|
||||
#endif /* _NOLIBC_ARCH_ARM_H */
|
||||
|
||||
@@ -162,7 +162,7 @@
|
||||
* 2) The deepest stack frame should be set to zero
|
||||
*
|
||||
*/
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"xor %ebp, %ebp\n" /* zero the stack frame */
|
||||
@@ -174,7 +174,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
|
||||
"call _start_c\n" /* transfer to c runtime */
|
||||
"hlt\n" /* ensure it does not return */
|
||||
);
|
||||
__builtin_unreachable();
|
||||
__nolibc_entrypoint_epilogue();
|
||||
}
|
||||
|
||||
#endif /* _NOLIBC_ARCH_I386_H */
|
||||
|
||||
@@ -149,14 +149,14 @@
|
||||
#endif
|
||||
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"move $a0, $sp\n" /* save stack pointer to $a0, as arg1 of _start_c */
|
||||
LONG_BSTRINS " $sp, $zero, 3, 0\n" /* $sp must be 16-byte aligned */
|
||||
"bl _start_c\n" /* transfer to c runtime */
|
||||
);
|
||||
__builtin_unreachable();
|
||||
__nolibc_entrypoint_epilogue();
|
||||
}
|
||||
|
||||
#endif /* _NOLIBC_ARCH_LOONGARCH_H */
|
||||
|
||||
@@ -179,7 +179,7 @@
|
||||
})
|
||||
|
||||
/* startup code, note that it's called __start on MIPS */
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector __start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector __start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
".set push\n"
|
||||
@@ -194,11 +194,13 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
|
||||
"li $t0, -8\n"
|
||||
"and $sp, $sp, $t0\n" /* $sp must be 8-byte aligned */
|
||||
"addiu $sp, $sp, -16\n" /* the callee expects to save a0..a3 there */
|
||||
"jal _start_c\n" /* transfer to c runtime */
|
||||
"lui $t9, %hi(_start_c)\n" /* ABI requires current function address in $t9 */
|
||||
"ori $t9, %lo(_start_c)\n"
|
||||
"jalr $t9\n" /* transfer to c runtime */
|
||||
" nop\n" /* delayed slot */
|
||||
".set pop\n"
|
||||
);
|
||||
__builtin_unreachable();
|
||||
__nolibc_entrypoint_epilogue();
|
||||
}
|
||||
|
||||
#endif /* _NOLIBC_ARCH_MIPS_H */
|
||||
|
||||
@@ -172,7 +172,7 @@
|
||||
_ret; \
|
||||
})
|
||||
|
||||
#ifndef __powerpc64__
|
||||
#if !defined(__powerpc64__) && !defined(__clang__)
|
||||
/* FIXME: For 32-bit PowerPC, with newer gcc compilers (e.g. gcc 13.1.0),
|
||||
* "omit-frame-pointer" fails with __attribute__((no_stack_protector)) but
|
||||
* works with __attribute__((__optimize__("-fno-stack-protector")))
|
||||
@@ -184,7 +184,7 @@
|
||||
#endif /* !__powerpc64__ */
|
||||
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
{
|
||||
#ifdef __powerpc64__
|
||||
#if _CALL_ELF == 2
|
||||
@@ -215,7 +215,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
|
||||
"bl _start_c\n" /* transfer to c runtime */
|
||||
);
|
||||
#endif
|
||||
__builtin_unreachable();
|
||||
__nolibc_entrypoint_epilogue();
|
||||
}
|
||||
|
||||
#endif /* _NOLIBC_ARCH_POWERPC_H */
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
})
|
||||
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
".option push\n"
|
||||
@@ -151,7 +151,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
|
||||
"andi sp, a0, -16\n" /* sp must be 16-byte aligned */
|
||||
"call _start_c\n" /* transfer to c runtime */
|
||||
);
|
||||
__builtin_unreachable();
|
||||
__nolibc_entrypoint_epilogue();
|
||||
}
|
||||
|
||||
#endif /* _NOLIBC_ARCH_RISCV_H */
|
||||
|
||||
@@ -139,7 +139,7 @@
|
||||
})
|
||||
|
||||
/* startup code */
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"lgr %r2, %r15\n" /* save stack pointer to %r2, as arg1 of _start_c */
|
||||
@@ -147,7 +147,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
|
||||
"xc 0(8,%r15), 0(%r15)\n" /* clear backchain */
|
||||
"brasl %r14, _start_c\n" /* transfer to c runtime */
|
||||
);
|
||||
__builtin_unreachable();
|
||||
__nolibc_entrypoint_epilogue();
|
||||
}
|
||||
|
||||
struct s390_mmap_arg_struct {
|
||||
|
||||
@@ -161,7 +161,7 @@
|
||||
* 2) The deepest stack frame should be zero (the %rbp).
|
||||
*
|
||||
*/
|
||||
void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_stack_protector _start(void)
|
||||
void __attribute__((weak, noreturn)) __nolibc_entrypoint __no_stack_protector _start(void)
|
||||
{
|
||||
__asm__ volatile (
|
||||
"xor %ebp, %ebp\n" /* zero the stack frame */
|
||||
@@ -170,7 +170,7 @@ void __attribute__((weak, noreturn, optimize("Os", "omit-frame-pointer"))) __no_
|
||||
"call _start_c\n" /* transfer to c runtime */
|
||||
"hlt\n" /* ensure it does not return */
|
||||
);
|
||||
__builtin_unreachable();
|
||||
__nolibc_entrypoint_epilogue();
|
||||
}
|
||||
|
||||
#define NOLIBC_ARCH_HAS_MEMMOVE
|
||||
@@ -193,10 +193,10 @@ __asm__ (
|
||||
"movq %rdi, %rdx\n\t"
|
||||
"subq %rsi, %rdx\n\t"
|
||||
"cmpq %rcx, %rdx\n\t"
|
||||
"jb .Lbackward_copy\n\t"
|
||||
"jb 1f\n\t"
|
||||
"rep movsb\n\t"
|
||||
"retq\n"
|
||||
".Lbackward_copy:"
|
||||
"1:" /* backward copy */
|
||||
"leaq -1(%rdi, %rcx, 1), %rdi\n\t"
|
||||
"leaq -1(%rsi, %rcx, 1), %rsi\n\t"
|
||||
"std\n\t"
|
||||
|
||||
@@ -6,20 +6,30 @@
|
||||
#ifndef _NOLIBC_COMPILER_H
|
||||
#define _NOLIBC_COMPILER_H
|
||||
|
||||
#if defined(__has_attribute)
|
||||
# define __nolibc_has_attribute(attr) __has_attribute(attr)
|
||||
#else
|
||||
# define __nolibc_has_attribute(attr) 0
|
||||
#endif
|
||||
|
||||
#if __nolibc_has_attribute(naked)
|
||||
# define __nolibc_entrypoint __attribute__((naked))
|
||||
# define __nolibc_entrypoint_epilogue()
|
||||
#else
|
||||
# define __nolibc_entrypoint __attribute__((optimize("Os", "omit-frame-pointer")))
|
||||
# define __nolibc_entrypoint_epilogue() __builtin_unreachable()
|
||||
#endif /* __nolibc_has_attribute(naked) */
|
||||
|
||||
#if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) || defined(__SSP_EXPLICIT__)
|
||||
|
||||
#define _NOLIBC_STACKPROTECTOR
|
||||
|
||||
#endif /* defined(__SSP__) ... */
|
||||
|
||||
#if defined(__has_attribute)
|
||||
# if __has_attribute(no_stack_protector)
|
||||
# define __no_stack_protector __attribute__((no_stack_protector))
|
||||
# else
|
||||
# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
|
||||
# endif
|
||||
#if __nolibc_has_attribute(no_stack_protector)
|
||||
# define __no_stack_protector __attribute__((no_stack_protector))
|
||||
#else
|
||||
# define __no_stack_protector __attribute__((__optimize__("-fno-stack-protector")))
|
||||
#endif /* defined(__has_attribute) */
|
||||
#endif /* __nolibc_has_attribute(no_stack_protector) */
|
||||
|
||||
#endif /* _NOLIBC_COMPILER_H */
|
||||
|
||||
@@ -13,23 +13,24 @@ const unsigned long *_auxv __attribute__((weak));
|
||||
static void __stack_chk_init(void);
|
||||
static void exit(int);
|
||||
|
||||
extern void (*const __preinit_array_start[])(void) __attribute__((weak));
|
||||
extern void (*const __preinit_array_end[])(void) __attribute__((weak));
|
||||
extern void (*const __preinit_array_start[])(int, char **, char**) __attribute__((weak));
|
||||
extern void (*const __preinit_array_end[])(int, char **, char**) __attribute__((weak));
|
||||
|
||||
extern void (*const __init_array_start[])(void) __attribute__((weak));
|
||||
extern void (*const __init_array_end[])(void) __attribute__((weak));
|
||||
extern void (*const __init_array_start[])(int, char **, char**) __attribute__((weak));
|
||||
extern void (*const __init_array_end[])(int, char **, char**) __attribute__((weak));
|
||||
|
||||
extern void (*const __fini_array_start[])(void) __attribute__((weak));
|
||||
extern void (*const __fini_array_end[])(void) __attribute__((weak));
|
||||
|
||||
__attribute__((weak))
|
||||
__attribute__((weak,used))
|
||||
void _start_c(long *sp)
|
||||
{
|
||||
long argc;
|
||||
char **argv;
|
||||
char **envp;
|
||||
int exitcode;
|
||||
void (* const *func)(void);
|
||||
void (* const *ctor_func)(int, char **, char **);
|
||||
void (* const *dtor_func)(void);
|
||||
const unsigned long *auxv;
|
||||
/* silence potential warning: conflicting types for 'main' */
|
||||
int _nolibc_main(int, char **, char **) __asm__ ("main");
|
||||
@@ -66,16 +67,16 @@ void _start_c(long *sp)
|
||||
;
|
||||
_auxv = auxv;
|
||||
|
||||
for (func = __preinit_array_start; func < __preinit_array_end; func++)
|
||||
(*func)();
|
||||
for (func = __init_array_start; func < __init_array_end; func++)
|
||||
(*func)();
|
||||
for (ctor_func = __preinit_array_start; ctor_func < __preinit_array_end; ctor_func++)
|
||||
(*ctor_func)(argc, argv, envp);
|
||||
for (ctor_func = __init_array_start; ctor_func < __init_array_end; ctor_func++)
|
||||
(*ctor_func)(argc, argv, envp);
|
||||
|
||||
/* go to application */
|
||||
exitcode = _nolibc_main(argc, argv, envp);
|
||||
|
||||
for (func = __fini_array_end; func > __fini_array_start;)
|
||||
(*--func)();
|
||||
for (dtor_func = __fini_array_end; dtor_func > __fini_array_start;)
|
||||
(*--dtor_func)();
|
||||
|
||||
exit(exitcode);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,8 @@
|
||||
* -I../nolibc -o hello hello.c -lgcc
|
||||
*
|
||||
* The available standard (but limited) include files are:
|
||||
* ctype.h, errno.h, signal.h, stdarg.h, stdio.h, stdlib.h, string.h, time.h
|
||||
* ctype.h, errno.h, signal.h, stdarg.h, stdbool.h stdio.h, stdlib.h,
|
||||
* string.h, time.h
|
||||
*
|
||||
* In addition, the following ones are expected to be provided by the compiler:
|
||||
* float.h, stddef.h
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* triggering stack protector errors themselves
|
||||
*/
|
||||
|
||||
__attribute__((weak,noreturn,section(".text.nolibc_stack_chk")))
|
||||
__attribute__((weak,used,noreturn,section(".text.nolibc_stack_chk")))
|
||||
void __stack_chk_fail(void)
|
||||
{
|
||||
pid_t pid;
|
||||
@@ -34,7 +34,7 @@ void __stack_chk_fail_local(void)
|
||||
__stack_chk_fail();
|
||||
}
|
||||
|
||||
__attribute__((weak,section(".data.nolibc_stack_chk")))
|
||||
__attribute__((weak,used,section(".data.nolibc_stack_chk")))
|
||||
uintptr_t __stack_chk_guard;
|
||||
|
||||
static __no_stack_protector void __stack_chk_init(void)
|
||||
|
||||
16
tools/include/nolibc/stdbool.h
Normal file
16
tools/include/nolibc/stdbool.h
Normal file
@@ -0,0 +1,16 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1 OR MIT */
|
||||
/*
|
||||
* Boolean types support for NOLIBC
|
||||
* Copyright (C) 2024 Thomas Weißschuh <linux@weissschuh.net>
|
||||
*/
|
||||
|
||||
#ifndef _NOLIBC_STDBOOL_H
|
||||
#define _NOLIBC_STDBOOL_H
|
||||
|
||||
#define bool _Bool
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
#define __bool_true_false_are_defined 1
|
||||
|
||||
#endif /* _NOLIBC_STDBOOL_H */
|
||||
@@ -7,6 +7,7 @@
|
||||
#ifndef _NOLIBC_STRING_H
|
||||
#define _NOLIBC_STRING_H
|
||||
|
||||
#include "arch.h"
|
||||
#include "std.h"
|
||||
|
||||
static void *malloc(size_t len);
|
||||
|
||||
@@ -72,7 +72,8 @@ class LinuxSourceTreeOperations:
|
||||
raise ConfigError(e.output.decode())
|
||||
|
||||
def make(self, jobs: int, build_dir: str, make_options: Optional[List[str]]) -> None:
|
||||
command = ['make', 'ARCH=' + self._linux_arch, 'O=' + build_dir, '--jobs=' + str(jobs)]
|
||||
command = ['make', 'all', 'compile_commands.json', 'ARCH=' + self._linux_arch,
|
||||
'O=' + build_dir, '--jobs=' + str(jobs)]
|
||||
if make_options:
|
||||
command.extend(make_options)
|
||||
if self._cross_compile:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
TARGETS += acct
|
||||
TARGETS += alsa
|
||||
TARGETS += amd-pstate
|
||||
TARGETS += arm64
|
||||
@@ -109,7 +110,6 @@ TARGETS += tmpfs
|
||||
TARGETS += tpm2
|
||||
TARGETS += tty
|
||||
TARGETS += uevent
|
||||
TARGETS += user
|
||||
TARGETS += user_events
|
||||
TARGETS += vDSO
|
||||
TARGETS += mm
|
||||
|
||||
3
tools/testing/selftests/acct/.gitignore
vendored
Normal file
3
tools/testing/selftests/acct/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
acct_syscall
|
||||
config
|
||||
process_log
|
||||
5
tools/testing/selftests/acct/Makefile
Normal file
5
tools/testing/selftests/acct/Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
TEST_GEN_PROGS := acct_syscall
|
||||
CFLAGS += -Wall
|
||||
|
||||
include ../lib.mk
|
||||
78
tools/testing/selftests/acct/acct_syscall.c
Normal file
78
tools/testing/selftests/acct/acct_syscall.c
Normal file
@@ -0,0 +1,78 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
/* kselftest for acct() system call
|
||||
* The acct() system call enables or disables process accounting.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "../kselftest.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char filename[] = "process_log";
|
||||
FILE *fp;
|
||||
pid_t child_pid;
|
||||
int sz;
|
||||
|
||||
// Setting up kselftest framework
|
||||
ksft_print_header();
|
||||
ksft_set_plan(1);
|
||||
|
||||
// Check if test is run a root
|
||||
if (geteuid()) {
|
||||
ksft_test_result_skip("This test needs root to run!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create file to log closed processes
|
||||
fp = fopen(filename, "w");
|
||||
|
||||
if (!fp) {
|
||||
ksft_test_result_error("%s.\n", strerror(errno));
|
||||
ksft_finished();
|
||||
return 1;
|
||||
}
|
||||
|
||||
acct(filename);
|
||||
|
||||
// Handle error conditions
|
||||
if (errno) {
|
||||
ksft_test_result_error("%s.\n", strerror(errno));
|
||||
fclose(fp);
|
||||
ksft_finished();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Create child process and wait for it to terminate.
|
||||
|
||||
child_pid = fork();
|
||||
|
||||
if (child_pid < 0) {
|
||||
ksft_test_result_error("Creating a child process to log failed\n");
|
||||
acct(NULL);
|
||||
return 1;
|
||||
} else if (child_pid > 0) {
|
||||
wait(NULL);
|
||||
fseek(fp, 0L, SEEK_END);
|
||||
sz = ftell(fp);
|
||||
|
||||
acct(NULL);
|
||||
|
||||
if (sz <= 0) {
|
||||
ksft_test_result_fail("Terminated child process not logged\n");
|
||||
ksft_exit_fail();
|
||||
return 1;
|
||||
}
|
||||
|
||||
ksft_test_result_pass("Successfully logged terminated process.\n");
|
||||
fclose(fp);
|
||||
ksft_exit_pass();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
CFLAGS += -g $(KHDR_INCLUDES)
|
||||
|
||||
TEST_GEN_PROGS := close_range_test
|
||||
TEST_GEN_PROGS := close_range_test unshare_test
|
||||
|
||||
include ../lib.mk
|
||||
|
||||
|
||||
94
tools/testing/selftests/core/unshare_test.c
Normal file
94
tools/testing/selftests/core/unshare_test.c
Normal file
@@ -0,0 +1,94 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <syscall.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/resource.h>
|
||||
#include <linux/close_range.h>
|
||||
|
||||
#include "../kselftest_harness.h"
|
||||
#include "../clone3/clone3_selftests.h"
|
||||
|
||||
TEST(unshare_EMFILE)
|
||||
{
|
||||
pid_t pid;
|
||||
int status;
|
||||
struct __clone_args args = {
|
||||
.flags = CLONE_FILES,
|
||||
.exit_signal = SIGCHLD,
|
||||
};
|
||||
int fd;
|
||||
ssize_t n, n2;
|
||||
static char buf[512], buf2[512];
|
||||
struct rlimit rlimit;
|
||||
int nr_open;
|
||||
|
||||
fd = open("/proc/sys/fs/nr_open", O_RDWR);
|
||||
ASSERT_GE(fd, 0);
|
||||
|
||||
n = read(fd, buf, sizeof(buf));
|
||||
ASSERT_GT(n, 0);
|
||||
ASSERT_EQ(buf[n - 1], '\n');
|
||||
|
||||
ASSERT_EQ(sscanf(buf, "%d", &nr_open), 1);
|
||||
|
||||
ASSERT_EQ(0, getrlimit(RLIMIT_NOFILE, &rlimit));
|
||||
|
||||
/* bump fs.nr_open */
|
||||
n2 = sprintf(buf2, "%d\n", nr_open + 1024);
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
write(fd, buf2, n2);
|
||||
|
||||
/* bump ulimit -n */
|
||||
rlimit.rlim_cur = nr_open + 1024;
|
||||
rlimit.rlim_max = nr_open + 1024;
|
||||
EXPECT_EQ(0, setrlimit(RLIMIT_NOFILE, &rlimit)) {
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
write(fd, buf, n);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* get a descriptor past the old fs.nr_open */
|
||||
EXPECT_GE(dup2(2, nr_open + 64), 0) {
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
write(fd, buf, n);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* get descriptor table shared */
|
||||
pid = sys_clone3(&args, sizeof(args));
|
||||
EXPECT_GE(pid, 0) {
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
write(fd, buf, n);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
int err;
|
||||
|
||||
/* restore fs.nr_open */
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
write(fd, buf, n);
|
||||
/* ... and now unshare(CLONE_FILES) must fail with EMFILE */
|
||||
err = unshare(CLONE_FILES);
|
||||
EXPECT_EQ(err, -1)
|
||||
exit(EXIT_FAILURE);
|
||||
EXPECT_EQ(errno, EMFILE)
|
||||
exit(EXIT_FAILURE);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
EXPECT_EQ(waitpid(pid, &status, 0), pid);
|
||||
EXPECT_EQ(true, WIFEXITED(status));
|
||||
EXPECT_EQ(0, WEXITSTATUS(status));
|
||||
}
|
||||
|
||||
TEST_HARNESS_MAIN
|
||||
@@ -231,6 +231,21 @@ do_suspend()
|
||||
|
||||
for i in `seq 1 $2`; do
|
||||
printf "Starting $1\n"
|
||||
|
||||
if [ "$3" = "rtc" ]; then
|
||||
if ! command -v rtcwake &> /dev/null; then
|
||||
printf "rtcwake could not be found, please install it.\n"
|
||||
return 1
|
||||
fi
|
||||
|
||||
rtcwake -m $filename -s 15
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
printf "Failed to suspend using RTC wake alarm\n"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
echo $filename > $SYSFS/power/state
|
||||
printf "Came out of $1\n"
|
||||
|
||||
|
||||
@@ -24,6 +24,8 @@ helpme()
|
||||
[-t <basic: Basic cpufreq testing
|
||||
suspend: suspend/resume,
|
||||
hibernate: hibernate/resume,
|
||||
suspend_rtc: suspend/resume back using the RTC wakeup alarm,
|
||||
hibernate_rtc: hibernate/resume back using the RTC wakeup alarm,
|
||||
modtest: test driver or governor modules. Only to be used with -d or -g options,
|
||||
sptest1: Simple governor switch to produce lockdep.
|
||||
sptest2: Concurrent governor switch to produce lockdep.
|
||||
@@ -76,7 +78,8 @@ parse_arguments()
|
||||
helpme
|
||||
;;
|
||||
|
||||
t) # --func_type (Function to perform: basic, suspend, hibernate, modtest, sptest1/2/3/4 (default: basic))
|
||||
t) # --func_type (Function to perform: basic, suspend, hibernate,
|
||||
# suspend_rtc, hibernate_rtc, modtest, sptest1/2/3/4 (default: basic))
|
||||
FUNC=$OPTARG
|
||||
;;
|
||||
|
||||
@@ -121,6 +124,14 @@ do_test()
|
||||
do_suspend "hibernate" 1
|
||||
;;
|
||||
|
||||
"suspend_rtc")
|
||||
do_suspend "suspend" 1 rtc
|
||||
;;
|
||||
|
||||
"hibernate_rtc")
|
||||
do_suspend "hibernate" 1 rtc
|
||||
;;
|
||||
|
||||
"modtest")
|
||||
# Do we have modules in place?
|
||||
if [ -z $DRIVER_MOD ] && [ -z $GOVERNOR_MOD ]; then
|
||||
|
||||
@@ -257,12 +257,6 @@ TEST_F(attest_fixture, att_inval_addr)
|
||||
att_inval_addr_test(&self->uvio_attest.meas_addr, _metadata, self);
|
||||
}
|
||||
|
||||
static void __attribute__((constructor)) __constructor_order_last(void)
|
||||
{
|
||||
if (!__constructor_order)
|
||||
__constructor_order = _CONSTRUCTOR_ORDER_BACKWARD;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int fd = open(UV_PATH, O_ACCMODE);
|
||||
|
||||
@@ -117,7 +117,7 @@ static int check_execveat_invoked_rc(int fd, const char *path, int flags,
|
||||
}
|
||||
if ((WEXITSTATUS(status) != expected_rc) &&
|
||||
(WEXITSTATUS(status) != expected_rc2)) {
|
||||
ksft_print_msg("child %d exited with %d not %d nor %d\n",
|
||||
ksft_print_msg("child %d exited with %d neither %d nor %d\n",
|
||||
child, WEXITSTATUS(status), expected_rc,
|
||||
expected_rc2);
|
||||
ksft_test_result_fail("%s\n", test_name);
|
||||
|
||||
@@ -319,8 +319,11 @@ static void test_listmount_ns(void)
|
||||
* Tell our parent how many mounts we have, and then wait for it
|
||||
* to tell us we're done.
|
||||
*/
|
||||
write(child_ready_pipe[1], &nr_mounts, sizeof(nr_mounts));
|
||||
read(parent_ready_pipe[0], &cval, sizeof(cval));
|
||||
if (write(child_ready_pipe[1], &nr_mounts, sizeof(nr_mounts)) !=
|
||||
sizeof(nr_mounts))
|
||||
ret = NSID_ERROR;
|
||||
if (read(parent_ready_pipe[0], &cval, sizeof(cval)) != sizeof(cval))
|
||||
ret = NSID_ERROR;
|
||||
exit(NSID_PASS);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,18 @@ original_group=`stat -c "%g" .`
|
||||
original_owner=`stat -c "%u" .`
|
||||
|
||||
mount_point=`stat -c '%m' .`
|
||||
|
||||
# If stat -c '%m' does not work (e.g. busybox) or failed, try to use the
|
||||
# current working directory (which should be a tracefs) as the mount point.
|
||||
if [ ! -d "$mount_point" ]; then
|
||||
if mount | grep -qw $PWD ; then
|
||||
mount_point=$PWD
|
||||
else
|
||||
# If PWD doesn't work, that is an environmental problem.
|
||||
exit_unresolved
|
||||
fi
|
||||
fi
|
||||
|
||||
mount_options=`mount | grep "$mount_point" | sed -e 's/.*(\(.*\)).*/\1/'`
|
||||
|
||||
# find another owner and group that is not the original
|
||||
@@ -83,32 +95,38 @@ run_tests() {
|
||||
done
|
||||
}
|
||||
|
||||
mount -o remount,"$new_options" .
|
||||
# Run the tests twice as leftovers can cause issues
|
||||
for loop in 1 2 ; do
|
||||
|
||||
run_tests
|
||||
echo "Running iteration $loop"
|
||||
|
||||
mount -o remount,"$mount_options" .
|
||||
mount -o remount,"$new_options" .
|
||||
|
||||
for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
|
||||
test "$d" $original_group
|
||||
done
|
||||
run_tests
|
||||
|
||||
mount -o remount,"$mount_options" .
|
||||
|
||||
for d in "." "events" "events/sched" "events/sched/sched_switch" "events/sched/sched_switch/enable" $canary; do
|
||||
test "$d" $original_group
|
||||
done
|
||||
|
||||
# check instances as well
|
||||
|
||||
chgrp $other_group instances
|
||||
chgrp $other_group instances
|
||||
|
||||
instance="$(mktemp -u test-XXXXXX)"
|
||||
instance="$(mktemp -u test-XXXXXX)"
|
||||
|
||||
mkdir instances/$instance
|
||||
mkdir instances/$instance
|
||||
|
||||
cd instances/$instance
|
||||
cd instances/$instance
|
||||
|
||||
run_tests
|
||||
run_tests
|
||||
|
||||
cd ../..
|
||||
cd ../..
|
||||
|
||||
rmdir instances/$instance
|
||||
rmdir instances/$instance
|
||||
|
||||
chgrp $original_group instances
|
||||
chgrp $original_group instances
|
||||
done
|
||||
|
||||
exit 0
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
# description: Generic dynamic event - add/remove/test uprobe events
|
||||
# requires: uprobe_events
|
||||
|
||||
echo 0 > events/enable
|
||||
echo > dynamic_events
|
||||
|
||||
echo 'cat /proc/$$/maps' | /bin/sh | \
|
||||
grep "r-xp .*/bin/.*sh$" | \
|
||||
awk '{printf "p:myevent %s:0x%s\n", $6,$3 }' >> uprobe_events
|
||||
|
||||
grep -q myevent uprobe_events
|
||||
test -d events/uprobes/myevent
|
||||
|
||||
echo 1 > events/uprobes/myevent/enable
|
||||
echo 'ls' | /bin/sh > /dev/null
|
||||
echo 0 > events/uprobes/myevent/enable
|
||||
grep -q myevent trace
|
||||
|
||||
echo "-:myevent" >> uprobe_events
|
||||
! grep -q myevent uprobe_events
|
||||
|
||||
echo > uprobe_events
|
||||
|
||||
clear_trace
|
||||
@@ -19,7 +19,14 @@ fail() { # mesg
|
||||
|
||||
FILTER=set_ftrace_filter
|
||||
FUNC1="schedule"
|
||||
FUNC2="sched_tick"
|
||||
if grep '^sched_tick\b' available_filter_functions; then
|
||||
FUNC2="sched_tick"
|
||||
elif grep '^scheduler_tick\b' available_filter_functions; then
|
||||
FUNC2="scheduler_tick"
|
||||
else
|
||||
exit_unresolved
|
||||
fi
|
||||
|
||||
|
||||
ALL_FUNCS="#### all functions enabled ####"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
# description: Kprobe event char type argument
|
||||
# requires: kprobe_events
|
||||
# requires: kprobe_events available_filter_functions
|
||||
|
||||
case `uname -m` in
|
||||
x86_64)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
# description: Kprobe event string type argument
|
||||
# requires: kprobe_events
|
||||
# requires: kprobe_events available_filter_functions
|
||||
|
||||
case `uname -m` in
|
||||
x86_64)
|
||||
|
||||
@@ -1357,12 +1357,6 @@ static int libbpf_print_fn(enum libbpf_print_level level,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __attribute__((constructor)) __constructor_order_last(void)
|
||||
{
|
||||
if (!__constructor_order)
|
||||
__constructor_order = _CONSTRUCTOR_ORDER_BACKWARD;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
/* Use libbpf 1.0 API mode */
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
|
||||
#endif
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__) /* arch */
|
||||
/*
|
||||
* gcc cpuid.h provides __cpuid_count() since v4.4.
|
||||
* Clang/LLVM cpuid.h provides __cpuid_count() since v3.4.0.
|
||||
@@ -75,6 +76,7 @@
|
||||
: "=a" (a), "=b" (b), "=c" (c), "=d" (d) \
|
||||
: "0" (level), "2" (count))
|
||||
#endif
|
||||
#endif /* end arch */
|
||||
|
||||
/* define kselftest exit codes */
|
||||
#define KSFT_PASS 0
|
||||
@@ -371,15 +373,7 @@ static inline __noreturn __printf(1, 2) void ksft_exit_fail_msg(const char *msg,
|
||||
|
||||
static inline __noreturn void ksft_exit_fail_perror(const char *msg)
|
||||
{
|
||||
#ifndef NOLIBC
|
||||
ksft_exit_fail_msg("%s: %s (%d)\n", msg, strerror(errno), errno);
|
||||
#else
|
||||
/*
|
||||
* nolibc doesn't provide strerror() and it seems
|
||||
* inappropriate to add one, just print the errno.
|
||||
*/
|
||||
ksft_exit_fail_msg("%s: %d)\n", msg, errno);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline __noreturn void ksft_exit_xfail(void)
|
||||
|
||||
@@ -488,12 +488,6 @@
|
||||
* Use once to append a main() to the test file.
|
||||
*/
|
||||
#define TEST_HARNESS_MAIN \
|
||||
static void __attribute__((constructor)) \
|
||||
__constructor_order_last(void) \
|
||||
{ \
|
||||
if (!__constructor_order) \
|
||||
__constructor_order = _CONSTRUCTOR_ORDER_BACKWARD; \
|
||||
} \
|
||||
int main(int argc, char **argv) { \
|
||||
return test_harness_run(argc, argv); \
|
||||
}
|
||||
@@ -824,7 +818,7 @@
|
||||
item->prev = item; \
|
||||
return; \
|
||||
} \
|
||||
if (__constructor_order == _CONSTRUCTOR_ORDER_FORWARD) { \
|
||||
if (__constructor_order_forward) { \
|
||||
item->next = NULL; \
|
||||
item->prev = head->prev; \
|
||||
item->prev->next = item; \
|
||||
@@ -888,10 +882,7 @@ struct __test_xfail {
|
||||
}
|
||||
|
||||
static struct __fixture_metadata *__fixture_list = &_fixture_global;
|
||||
static int __constructor_order;
|
||||
|
||||
#define _CONSTRUCTOR_ORDER_FORWARD 1
|
||||
#define _CONSTRUCTOR_ORDER_BACKWARD -1
|
||||
static bool __constructor_order_forward;
|
||||
|
||||
static inline void __register_fixture(struct __fixture_metadata *f)
|
||||
{
|
||||
@@ -942,7 +933,7 @@ static inline bool __test_passed(struct __test_metadata *metadata)
|
||||
* list so tests are run in source declaration order.
|
||||
* https://gcc.gnu.org/onlinedocs/gccint/Initialization.html
|
||||
* However, it seems not all toolchains do this correctly, so use
|
||||
* __constructor_order to detect which direction is called first
|
||||
* __constructor_order_foward to detect which direction is called first
|
||||
* and adjust list building logic to get things running in the right
|
||||
* direction.
|
||||
*/
|
||||
@@ -1337,8 +1328,7 @@ static int test_harness_run(int argc, char **argv)
|
||||
|
||||
static void __attribute__((constructor)) __constructor_order_first(void)
|
||||
{
|
||||
if (!__constructor_order)
|
||||
__constructor_order = _CONSTRUCTOR_ORDER_FORWARD;
|
||||
__constructor_order_forward = true;
|
||||
}
|
||||
|
||||
#endif /* __KSELFTEST_HARNESS_H */
|
||||
|
||||
@@ -4,6 +4,5 @@
|
||||
# No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
|
||||
all:
|
||||
|
||||
TEST_PROGS := printf.sh bitmap.sh prime_numbers.sh scanf.sh strscpy.sh
|
||||
|
||||
TEST_PROGS := printf.sh bitmap.sh prime_numbers.sh scanf.sh
|
||||
include ../lib.mk
|
||||
|
||||
@@ -2,5 +2,4 @@ CONFIG_TEST_PRINTF=m
|
||||
CONFIG_TEST_SCANF=m
|
||||
CONFIG_TEST_BITMAP=m
|
||||
CONFIG_PRIME_NUMBERS=m
|
||||
CONFIG_TEST_STRSCPY=m
|
||||
CONFIG_TEST_BITOPS=m
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-2.0+
|
||||
$(dirname $0)/../kselftest/module.sh "strscpy*" test_strscpy
|
||||
@@ -1,19 +1,21 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
# Makefile for nolibc tests
|
||||
include ../../../scripts/Makefile.include
|
||||
include ../../../scripts/utilities.mak
|
||||
# We need this for the "cc-option" macro.
|
||||
include ../../../build/Build.include
|
||||
# we're in ".../tools/testing/selftests/nolibc"
|
||||
ifeq ($(srctree),)
|
||||
srctree := $(patsubst %/tools/testing/selftests/,%,$(dir $(CURDIR)))
|
||||
endif
|
||||
|
||||
include $(srctree)/tools/scripts/utilities.mak
|
||||
# We need this for the "__cc-option" macro.
|
||||
include $(srctree)/scripts/Makefile.compiler
|
||||
|
||||
ifneq ($(O),)
|
||||
ifneq ($(call is-absolute,$(O)),y)
|
||||
$(error Only absolute O= parameters are supported)
|
||||
endif
|
||||
endif
|
||||
|
||||
# we're in ".../tools/testing/selftests/nolibc"
|
||||
ifeq ($(srctree),)
|
||||
srctree := $(patsubst %/tools/testing/selftests/,%,$(dir $(CURDIR)))
|
||||
objtree := $(O)
|
||||
else
|
||||
objtree ?= $(srctree)
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),)
|
||||
@@ -21,7 +23,7 @@ include $(srctree)/scripts/subarch.include
|
||||
ARCH = $(SUBARCH)
|
||||
endif
|
||||
|
||||
objtree ?= $(srctree)
|
||||
cc-option = $(call __cc-option, $(CC),$(CLANG_CROSS_FLAGS),$(1),$(2))
|
||||
|
||||
# XARCH extends the kernel's ARCH with a few variants of the same
|
||||
# architecture that only differ by the configuration, the toolchain
|
||||
@@ -155,9 +157,22 @@ CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wex
|
||||
$(CFLAGS_$(XARCH)) $(CFLAGS_STACKPROTECTOR) $(CFLAGS_EXTRA)
|
||||
LDFLAGS :=
|
||||
|
||||
LIBGCC := -lgcc
|
||||
|
||||
ifneq ($(LLVM),)
|
||||
# Not needed for clang
|
||||
LIBGCC :=
|
||||
endif
|
||||
|
||||
# Modify CFLAGS based on LLVM=
|
||||
include $(srctree)/tools/scripts/Makefile.include
|
||||
|
||||
# GCC uses "s390", clang "systemz"
|
||||
CLANG_CROSS_FLAGS := $(subst --target=s390-linux,--target=systemz-linux,$(CLANG_CROSS_FLAGS))
|
||||
|
||||
REPORT ?= awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{if (!f) printf("\n"); f++; print;} /\[SKIPPED\][\r]*$$/{s++} \
|
||||
END{ printf("\n%3d test(s): %3d passed, %3d skipped, %3d failed => status: ", p+s+f, p, s, f); \
|
||||
if (f) printf("failure\n"); else if (s) printf("warning\n"); else printf("success\n");; \
|
||||
if (f || !p) printf("failure\n"); else if (s) printf("warning\n"); else printf("success\n");; \
|
||||
printf("\nSee all results in %s\n", ARGV[1]); }'
|
||||
|
||||
help:
|
||||
@@ -204,11 +219,11 @@ sysroot/$(ARCH)/include:
|
||||
ifneq ($(NOLIBC_SYSROOT),0)
|
||||
nolibc-test: nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH)/include
|
||||
$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
|
||||
-nostdlib -nostdinc -static -Isysroot/$(ARCH)/include nolibc-test.c nolibc-test-linkage.c -lgcc
|
||||
-nostdlib -nostdinc -static -Isysroot/$(ARCH)/include nolibc-test.c nolibc-test-linkage.c $(LIBGCC)
|
||||
else
|
||||
nolibc-test: nolibc-test.c nolibc-test-linkage.c
|
||||
$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
|
||||
-nostdlib -static -include $(srctree)/tools/include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c -lgcc
|
||||
-nostdlib -static -include $(srctree)/tools/include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c $(LIBGCC)
|
||||
endif
|
||||
|
||||
libc-test: nolibc-test.c nolibc-test-linkage.c
|
||||
|
||||
@@ -542,7 +542,7 @@ int expect_strzr(const char *expr, int llen)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
llen += printf(" = <%s> ", expr);
|
||||
llen += printf(" = <%s> ", expr ? expr : "(null)");
|
||||
if (expr) {
|
||||
ret = 1;
|
||||
result(llen, FAIL);
|
||||
@@ -561,7 +561,7 @@ int expect_strnz(const char *expr, int llen)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
llen += printf(" = <%s> ", expr);
|
||||
llen += printf(" = <%s> ", expr ? expr : "(null)");
|
||||
if (!expr) {
|
||||
ret = 1;
|
||||
result(llen, FAIL);
|
||||
@@ -686,9 +686,10 @@ static void constructor1(void)
|
||||
}
|
||||
|
||||
__attribute__((constructor))
|
||||
static void constructor2(void)
|
||||
static void constructor2(int argc, char **argv, char **envp)
|
||||
{
|
||||
constructor_test_value *= 2;
|
||||
if (argc && argv && envp)
|
||||
constructor_test_value *= 2;
|
||||
}
|
||||
|
||||
int run_startup(int min, int max)
|
||||
|
||||
@@ -15,10 +15,11 @@ download_location="${cache_dir}/crosstools/"
|
||||
build_location="$(realpath "${cache_dir}"/nolibc-tests/)"
|
||||
perform_download=0
|
||||
test_mode=system
|
||||
CFLAGS_EXTRA="-Werror"
|
||||
werror=1
|
||||
llvm=
|
||||
archs="i386 x86_64 arm64 arm mips32le mips32be ppc ppc64 ppc64le riscv s390 loongarch"
|
||||
|
||||
TEMP=$(getopt -o 'j:d:c:b:a:m:peh' -n "$0" -- "$@")
|
||||
TEMP=$(getopt -o 'j:d:c:b:a:m:pelh' -n "$0" -- "$@")
|
||||
|
||||
eval set -- "$TEMP"
|
||||
unset TEMP
|
||||
@@ -42,6 +43,7 @@ Options:
|
||||
-b [DIR] Build location (default: ${build_location})
|
||||
-m [MODE] Test mode user/system (default: ${test_mode})
|
||||
-e Disable -Werror
|
||||
-l Build with LLVM/clang
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -69,7 +71,10 @@ while true; do
|
||||
test_mode="$2"
|
||||
shift 2; continue ;;
|
||||
'-e')
|
||||
CFLAGS_EXTRA=""
|
||||
werror=0
|
||||
shift; continue ;;
|
||||
'-l')
|
||||
llvm=1
|
||||
shift; continue ;;
|
||||
'-h')
|
||||
print_usage
|
||||
@@ -140,7 +145,10 @@ test_arch() {
|
||||
ct_abi=$(crosstool_abi "$1")
|
||||
cross_compile=$(realpath "${download_location}gcc-${crosstool_version}-nolibc/${ct_arch}-${ct_abi}/bin/${ct_arch}-${ct_abi}-")
|
||||
build_dir="${build_location}/${arch}"
|
||||
MAKE=(make -j"${nproc}" XARCH="${arch}" CROSS_COMPILE="${cross_compile}" O="${build_dir}")
|
||||
if [ "$werror" -ne 0 ]; then
|
||||
CFLAGS_EXTRA="$CFLAGS_EXTRA -Werror"
|
||||
fi
|
||||
MAKE=(make -j"${nproc}" XARCH="${arch}" CROSS_COMPILE="${cross_compile}" LLVM="${llvm}" O="${build_dir}")
|
||||
|
||||
mkdir -p "$build_dir"
|
||||
if [ "$test_mode" = "system" ] && [ ! -f "${build_dir}/.config" ]; then
|
||||
|
||||
@@ -290,12 +290,12 @@ static int cat_run_test(const struct resctrl_test *test, const struct user_param
|
||||
|
||||
static bool arch_supports_noncont_cat(const struct resctrl_test *test)
|
||||
{
|
||||
unsigned int eax, ebx, ecx, edx;
|
||||
|
||||
/* AMD always supports non-contiguous CBM. */
|
||||
if (get_vendor() == ARCH_AMD)
|
||||
return true;
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__) /* arch */
|
||||
unsigned int eax, ebx, ecx, edx;
|
||||
/* Intel support for non-contiguous CBM needs to be discovered. */
|
||||
if (!strcmp(test->resource, "L3"))
|
||||
__cpuid_count(0x10, 1, eax, ebx, ecx, edx);
|
||||
@@ -305,6 +305,9 @@ static bool arch_supports_noncont_cat(const struct resctrl_test *test)
|
||||
return false;
|
||||
|
||||
return ((ecx >> 3) & 1);
|
||||
#endif /* end arch */
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int noncont_cat_run_test(const struct resctrl_test *test,
|
||||
|
||||
@@ -412,13 +412,6 @@ TEST_F_TIMEOUT(rtc, alarm_wkalm_set_minute, 65) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static void __attribute__((constructor))
|
||||
__constructor_order_last(void)
|
||||
{
|
||||
if (!__constructor_order)
|
||||
__constructor_order = _CONSTRUCTOR_ORDER_BACKWARD;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
switch (argc) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# CONFIG_GCC_PLUGINS is not set
|
||||
CONFIG_RUST=y
|
||||
CONFIG_SAMPLES=y
|
||||
CONFIG_SAMPLES_RUST=y
|
||||
CONFIG_SAMPLE_RUST_MINIMAL=m
|
||||
CONFIG_SAMPLE_RUST_PRINT=m
|
||||
CONFIG_SAMPLE_RUST_PRINT=m
|
||||
|
||||
@@ -30,9 +30,6 @@
|
||||
#include <time.h>
|
||||
#include "../kselftest.h"
|
||||
|
||||
#define NSEC_PER_SEC 1000000000LL
|
||||
|
||||
|
||||
int change_skew_test(int ppm)
|
||||
{
|
||||
struct timex tx;
|
||||
|
||||
@@ -36,8 +36,6 @@
|
||||
#include <sys/wait.h>
|
||||
#include "../kselftest.h"
|
||||
|
||||
#define NSEC_PER_SEC 1000000000LL
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct timex tx;
|
||||
|
||||
@@ -38,10 +38,10 @@ struct timespec global_list[LISTSIZE];
|
||||
int listcount = 0;
|
||||
|
||||
|
||||
void checklist(struct timespec *list, int size)
|
||||
void checklist(const struct timespec *list, int size)
|
||||
{
|
||||
int i, j;
|
||||
struct timespec *a, *b;
|
||||
const struct timespec *a, *b;
|
||||
|
||||
/* scan the list */
|
||||
for (i = 0; i < size-1; i++) {
|
||||
|
||||
@@ -7,4 +7,4 @@ ksft_skip=4
|
||||
[ -e /dev/tpm0 ] || exit $ksft_skip
|
||||
[ -e /dev/tpmrm0 ] || exit $ksft_skip
|
||||
|
||||
python3 -m unittest -v tpm2_tests.AsyncTest
|
||||
python3 -m unittest -v tpm2_tests.AsyncTest 2>&1
|
||||
|
||||
@@ -6,4 +6,4 @@ ksft_skip=4
|
||||
|
||||
[ -e /dev/tpm0 ] || exit $ksft_skip
|
||||
|
||||
python3 -m unittest -v tpm2_tests.SmokeTest
|
||||
python3 -m unittest -v tpm2_tests.SmokeTest 2>&1
|
||||
|
||||
@@ -6,4 +6,4 @@ ksft_skip=4
|
||||
|
||||
[ -e /dev/tpmrm0 ] || exit $ksft_skip
|
||||
|
||||
python3 -m unittest -v tpm2_tests.SpaceTest
|
||||
python3 -m unittest -v tpm2_tests.SpaceTest 2>&1
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
# Makefile for user memory selftests
|
||||
|
||||
# No binaries, but make sure arg-less "make" doesn't trigger "run_tests"
|
||||
all:
|
||||
|
||||
TEST_PROGS := test_user_copy.sh
|
||||
|
||||
include ../lib.mk
|
||||
@@ -1 +0,0 @@
|
||||
CONFIG_TEST_USER_COPY=m
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/bin/sh
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
# Runs copy_to/from_user infrastructure using test_user_copy kernel module
|
||||
|
||||
# Kselftest framework requirement - SKIP code is 4.
|
||||
ksft_skip=4
|
||||
|
||||
if ! /sbin/modprobe -q -n test_user_copy; then
|
||||
echo "user: module test_user_copy is not found [SKIP]"
|
||||
exit $ksft_skip
|
||||
fi
|
||||
if /sbin/modprobe -q test_user_copy; then
|
||||
/sbin/modprobe -q -r test_user_copy
|
||||
echo "user_copy: ok"
|
||||
else
|
||||
echo "user_copy: [FAIL]"
|
||||
exit 1
|
||||
fi
|
||||
Reference in New Issue
Block a user