mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-31 16:38:12 +00:00
41078907ee
Amazingly, some libc implementations don't call __NR_nanosleep syscall from
their nanosleep() APIs. Hammer it down with explicit syscall() call and never
get back to it again. Also simplify code for timespec initialization.
I verified that nanosleep is called w/ printk and in exactly same Linux image
that is used in Travis CI. So it should both sleep and call correct syscall.
v1->v2:
- math is too hard, fix usec -> nsec convertion (Martin);
- test_vmlinux has explicit nanosleep() call, convert that one as well.
Fixes: 4e1fd25d19
("selftests/bpf: Fix usleep() implementation")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20200314002743.3782677-1-andriin@fb.com
43 lines
997 B
C
43 lines
997 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
/* Copyright (c) 2020 Facebook */
|
|
|
|
#include <test_progs.h>
|
|
#include <time.h>
|
|
#include "test_vmlinux.skel.h"
|
|
|
|
#define MY_TV_NSEC 1337
|
|
|
|
static void nsleep()
|
|
{
|
|
struct timespec ts = { .tv_nsec = MY_TV_NSEC };
|
|
|
|
(void)syscall(__NR_nanosleep, &ts, NULL);
|
|
}
|
|
|
|
void test_vmlinux(void)
|
|
{
|
|
int duration = 0, err;
|
|
struct test_vmlinux* skel;
|
|
struct test_vmlinux__bss *bss;
|
|
|
|
skel = test_vmlinux__open_and_load();
|
|
if (CHECK(!skel, "skel_open", "failed to open skeleton\n"))
|
|
return;
|
|
bss = skel->bss;
|
|
|
|
err = test_vmlinux__attach(skel);
|
|
if (CHECK(err, "skel_attach", "skeleton attach failed: %d\n", err))
|
|
goto cleanup;
|
|
|
|
/* trigger everything */
|
|
nsleep();
|
|
|
|
CHECK(!bss->tp_called, "tp", "not called\n");
|
|
CHECK(!bss->raw_tp_called, "raw_tp", "not called\n");
|
|
CHECK(!bss->tp_btf_called, "tp_btf", "not called\n");
|
|
CHECK(!bss->kprobe_called, "kprobe", "not called\n");
|
|
CHECK(!bss->fentry_called, "fentry", "not called\n");
|
|
|
|
cleanup:
|
|
test_vmlinux__destroy(skel);
|
|
}
|