diff --git a/.github/workflows/user_function_tracer.yml b/.github/workflows/user_function_tracer.yml index f658b8461..f4a998425 100644 --- a/.github/workflows/user_function_tracer.yml +++ b/.github/workflows/user_function_tracer.yml @@ -36,6 +36,10 @@ jobs: gcc test/sleep.c -o test/sleep gcc test/mmap.c -o test/mmap gcc test/strcpy.c -o test/strcpy + gcc test/fib.c -o test/fib + gcc test/thread.c -o test/thread sudo build/utrace -c test/sleep sudo build/utrace -c test/mmap sudo build/utrace -c test/strcpy + sudo build/utrace -c test/fib + sudo build/utrace -c test/thread diff --git a/eBPF_Supermarket/User_Function_Tracer/test/args.c b/eBPF_Supermarket/User_Function_Tracer/test/args.c deleted file mode 100644 index b91582ef9..000000000 --- a/eBPF_Supermarket/User_Function_Tracer/test/args.c +++ /dev/null @@ -1,68 +0,0 @@ -#include -#include -#include - -void foobar() {} - -void foo() {} - -void bar() { - foobar(); - foobar(); -} - -void tf1() {} - -void tf2() {} - -void arg_int3(int x, int y, int z) { - /* - printf("&x: %p\n", &x); - printf("&y: %p\n", &y); - printf("&z: %p\n", &z); - */ -} -void arg_int2(int a, int b) { arg_int3(a, b, b + 1); } -void arg_int1(int i) { arg_int2(i, i + 1); } - -void arg_uint3(unsigned int x, unsigned int y, unsigned int z) {} -void arg_uint2(unsigned int a, unsigned int b) { arg_uint3(a, b, b + 1); } -void arg_uint1(unsigned int i) { arg_uint2(i, i + 1); } - -void arg_char3(char x, char y, char z) {} -void arg_char2(char a, char b) { arg_char3(a, b, b + 1); } -void arg_char1(char i) { arg_char2(i, i + 1); } - -void arg_short3(short x, short y, short z) {} -void arg_short2(short a, short b) { arg_short3(a, b, b + 1); } -void arg_short1(short i) { arg_short2(i, i + 1); } - -void arg_long3(long x, long y, long z) {} -void arg_long2(long a, long b) { arg_long3(a, b, b + 1); } -void arg_long1(long i) { arg_long2(i, i + 1); } -void arg_ulong3(unsigned long x, unsigned long y, unsigned long z) {} -void arg_ulong2(unsigned long a, unsigned long b) { arg_ulong3(a, b, b + 1); } -void arg_ulong1(long i) { arg_ulong2(i, i + 1); } - -void arg_longlong3(long long x, long long y, long long z) {} -void arg_longlong2(long long a, long long b) { arg_longlong3(a, b, b + 1); } -void arg_longlong1(long long i) { arg_longlong2(i, i + 1); } -void arg_ulonglong3(unsigned long long x, unsigned long long y, unsigned long long z) {} -void arg_ulonglong2(unsigned long long a, unsigned long long b) { arg_ulonglong3(a, b, b + 1); } -void arg_ulonglong1(unsigned long long i) { arg_ulonglong2(i, i + 1); } - -void arg_test(int x, char *z) {} - -int main(int argc, char *argv[]) { - sleep(2); - arg_int1(10); - arg_uint1(10); - arg_char1(20); - arg_short1(30); - arg_long1(40); - arg_ulong1(50); - arg_longlong1(60); - arg_ulonglong1(70); - arg_test(100, NULL); - return 0; -} diff --git a/eBPF_Supermarket/User_Function_Tracer/test/fib.c b/eBPF_Supermarket/User_Function_Tracer/test/fib.c index b610a5c01..a3d112d9b 100644 --- a/eBPF_Supermarket/User_Function_Tracer/test/fib.c +++ b/eBPF_Supermarket/User_Function_Tracer/test/fib.c @@ -1,6 +1,20 @@ -#include -#include -#include +// Copyright 2023 The LMP Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// author: jinyufeng2000@gmail.com +// +// 测试递归函数调用 int fib(int n) { if (n <= 2) return 1; @@ -8,8 +22,6 @@ int fib(int n) { } int main() { - sleep(2); - int n = 8; - - return !!fib(n); + fib(9); + return 0; } diff --git a/eBPF_Supermarket/User_Function_Tracer/test/mmap b/eBPF_Supermarket/User_Function_Tracer/test/mmap deleted file mode 100755 index e71531007..000000000 Binary files a/eBPF_Supermarket/User_Function_Tracer/test/mmap and /dev/null differ diff --git a/eBPF_Supermarket/User_Function_Tracer/test/mmap.c b/eBPF_Supermarket/User_Function_Tracer/test/mmap.c index f470049ac..4bc2cb73f 100644 --- a/eBPF_Supermarket/User_Function_Tracer/test/mmap.c +++ b/eBPF_Supermarket/User_Function_Tracer/test/mmap.c @@ -1,3 +1,21 @@ +// Copyright 2023 The LMP Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// author: jinyufeng2000@gmail.com +// +// 测试库函数调用 + #include #include #include diff --git a/eBPF_Supermarket/User_Function_Tracer/test/short.c b/eBPF_Supermarket/User_Function_Tracer/test/short.c deleted file mode 100644 index 7ec36c1aa..000000000 --- a/eBPF_Supermarket/User_Function_Tracer/test/short.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -void h() {} -void g() { h(); } -void f() { g(); } - -int main() { - f(); - return 0; -} diff --git a/eBPF_Supermarket/User_Function_Tracer/test/sleep.c b/eBPF_Supermarket/User_Function_Tracer/test/sleep.c index 761a3e1ad..53ed5583b 100644 --- a/eBPF_Supermarket/User_Function_Tracer/test/sleep.c +++ b/eBPF_Supermarket/User_Function_Tracer/test/sleep.c @@ -1,4 +1,21 @@ -#include +// Copyright 2023 The LMP Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// author: jinyufeng2000@gmail.com +// +// 测试函数时延统计 + #include void g() { sleep(2); } diff --git a/eBPF_Supermarket/User_Function_Tracer/test/strcpy.c b/eBPF_Supermarket/User_Function_Tracer/test/strcpy.c index eefccaded..0552347a2 100644 --- a/eBPF_Supermarket/User_Function_Tracer/test/strcpy.c +++ b/eBPF_Supermarket/User_Function_Tracer/test/strcpy.c @@ -1,3 +1,21 @@ +// Copyright 2023 The LMP Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// author: jinyufeng2000@gmail.com +// +// 测试库函数调用,涉及IFUNC符号 + #include #include int main() { diff --git a/eBPF_Supermarket/User_Function_Tracer/test/test.c b/eBPF_Supermarket/User_Function_Tracer/test/test.c deleted file mode 100644 index f07b4e027..000000000 --- a/eBPF_Supermarket/User_Function_Tracer/test/test.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() { - sleep(2); - return 0; -} diff --git a/eBPF_Supermarket/User_Function_Tracer/test/thread.c b/eBPF_Supermarket/User_Function_Tracer/test/thread.c new file mode 100644 index 000000000..1ee2c463d --- /dev/null +++ b/eBPF_Supermarket/User_Function_Tracer/test/thread.c @@ -0,0 +1,41 @@ +// Copyright 2023 The LMP Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://github.com/linuxkerneltravel/lmp/blob/develop/LICENSE +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// author: jinyufeng2000@gmail.com +// +// 测试多线程程序 + +#include +#include + +static void* c(void* n) { return n; } + +static void* b(void* n) { return c(n); } + +static void* a(void* n) { return b(n); } + +int main() { + int i; + void* v; + int n = 10; + pthread_t t[4]; + + for (i = 0; i < 4; i++) pthread_create(&t[i], NULL, a, &n); + for (i = 0; i < 4; i++) { + pthread_join(t[i], &v); + } + + assert(*(int*)v == n); + return 0; +}