Skip to content

Commit

Permalink
[test] update test and add a test script
Browse files Browse the repository at this point in the history
  • Loading branch information
jyf111 committed Oct 5, 2023
1 parent f6465c6 commit 02fdc3b
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 23 deletions.
13 changes: 1 addition & 12 deletions .github/workflows/user_function_tracer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,4 @@ jobs:
bash tools/gen_vmlinux_h.sh > vmlinux/vmlinux.h
cmake -B build -S . -G Ninja
cmake --build build
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 -pthread
g++ test/bench.cpp -o test/bench
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
sudo build/utrace -c test/bench --output=/dev/null
bash test/run_test.sh
2 changes: 1 addition & 1 deletion eBPF_Supermarket/User_Function_Tracer/src/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ static void report_summary(struct report *report) {
: vector_sort(function_infos, total_time_greater);

int width = 60;
if (env.percent_total) {
if (env.percent_total || env.percent_self) {
LOG(report->printer->out, " PERCENT |");
width += 12;
}
Expand Down
18 changes: 18 additions & 0 deletions eBPF_Supermarket/User_Function_Tracer/test/bench.cpp
Original file line number Diff line number Diff line change
@@ -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: [email protected]
//
// Test performance

#include <cstdio>
#include <chrono>

Expand Down
2 changes: 1 addition & 1 deletion eBPF_Supermarket/User_Function_Tracer/test/fib.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// author: [email protected]
//
// 测试递归函数调用
// Test recursive function calls

int fib(int n) {
if (n <= 2) return 1;
Expand Down
2 changes: 1 addition & 1 deletion eBPF_Supermarket/User_Function_Tracer/test/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// author: [email protected]
//
// 测试库函数调用
// Test library calls

#include <fcntl.h>
#include <stdio.h>
Expand Down
42 changes: 42 additions & 0 deletions eBPF_Supermarket/User_Function_Tracer/test/run_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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: [email protected]
#
# Test script

#!/bin/bash

set -e

for file in test/*; do
if [[ $file == *.c ]]; then
gcc $file
echo "test $file using gcc"
sudo build/utrace -c a.out
echo "test $file using clang"
clang $file
sudo build/utrace -c a.out
elif [[ $file == *.cpp ]]; then
g++ $file
echo "test $file using g++"
sudo build/utrace -c a.out --output=/dev/null
echo "test $file using clang++"
clang++ $file
sudo build/utrace -c a.out --output=/dev/null
fi
break
done

rm a.out
2 changes: 1 addition & 1 deletion eBPF_Supermarket/User_Function_Tracer/test/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//
// author: [email protected]
//
// 测试函数时延统计
// Test function duration measurement

#include <unistd.h>

Expand Down
3 changes: 2 additions & 1 deletion eBPF_Supermarket/User_Function_Tracer/test/strcpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
//
// author: [email protected]
//
// 测试库函数调用,涉及IFUNC符号
// Test library calls, involving GNU ifunc calls

#include <stdlib.h>
#include <string.h>

int main() {
char *s = "Hello!";
char *t = malloc(15 * sizeof(char));
Expand Down
12 changes: 6 additions & 6 deletions eBPF_Supermarket/User_Function_Tracer/test/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
//
// author: [email protected]
//
// 测试多线程程序
// Test multi-threaded program

#include <assert.h>
#include <pthread.h>

static void* c(void* n) { return n; }
static void *c(void *n) { return n; }

static void* b(void* n) { return c(n); }
static void *b(void *n) { return c(n); }

static void* a(void* n) { return b(n); }
static void *a(void *n) { return b(n); }

int main() {
int i;
void* v;
void *v;
int n = 10;
pthread_t t[4];

Expand All @@ -36,6 +36,6 @@ int main() {
pthread_join(t[i], &v);
}

assert(*(int*)v == n);
assert(*(int *)v == n);
return 0;
}

0 comments on commit 02fdc3b

Please sign in to comment.