Commit 840712bc authored by williangaspar's avatar williangaspar

tests added

parent e8b99cd2
......@@ -59,7 +59,7 @@ class Builtin : public Expression {
public:
explicit Builtin(std::string ident) : ident(ident) {
if (ident == "stack") {
std::cout << "\033[33m warning: \033[0m";
std::cout << "\033[33mwarning: \033[0m";
std::cout << "stack is deprecated and will be removed in the future. Use kstack instead" << std::endl;
this->ident = "kstack";
}
......
#include "common.h"
namespace bpftrace {
namespace test {
namespace codegen {
TEST(codegen, builtin_stack)
{
test("kprobe:f { @x = kstack }",
R"EXPECTED(; Function Attrs: nounwind
declare i64 @llvm.bpf.pseudo(i64, i64) #0
; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
define i64 @"kprobe:f"(i8*) local_unnamed_addr section "s_kprobe:f_1" {
entry:
%"@x_val" = alloca i64, align 8
%"@x_key" = alloca i64, align 8
%pseudo = tail call i64 @llvm.bpf.pseudo(i64 1, i64 2)
%get_stackid = tail call i64 inttoptr (i64 27 to i64 (i8*, i8*, i64)*)(i8* %0, i64 %pseudo, i64 0)
%1 = bitcast i64* %"@x_key" to i8*
call void @llvm.lifetime.start.p0i8(i64 -1, i8* nonnull %1)
store i64 0, i64* %"@x_key", align 8
%2 = bitcast i64* %"@x_val" to i8*
call void @llvm.lifetime.start.p0i8(i64 -1, i8* nonnull %2)
store i64 %get_stackid, i64* %"@x_val", align 8
%pseudo1 = tail call i64 @llvm.bpf.pseudo(i64 1, i64 1)
%update_elem = call i64 inttoptr (i64 2 to i64 (i8*, i8*, i8*, i64)*)(i64 %pseudo1, i64* nonnull %"@x_key", i64* nonnull %"@x_val", i64 0)
call void @llvm.lifetime.end.p0i8(i64 -1, i8* nonnull %1)
call void @llvm.lifetime.end.p0i8(i64 -1, i8* nonnull %2)
ret i64 0
}
; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
attributes #0 = { nounwind }
attributes #1 = { argmemonly nounwind }
)EXPECTED");
}
} // namespace codegen
} // namespace test
} // namespace bpftrace
......@@ -35,7 +35,8 @@ TEST(Parser, builtin_variables)
test("kprobe:f { rand }", "Program\n kprobe:f\n builtin: rand\n");
test("kprobe:f { ctx }", "Program\n kprobe:f\n builtin: ctx\n");
test("kprobe:f { comm }", "Program\n kprobe:f\n builtin: comm\n");
test("kprobe:f { stack }", "Program\n kprobe:f\n builtin: stack\n");
test("kprobe:f { stack }", "Program\n kprobe:f\n builtin: kstack\n");
test("kprobe:f { kstack }", "Program\n kprobe:f\n builtin: kstack\n");
test("kprobe:f { ustack }", "Program\n kprobe:f\n builtin: ustack\n");
test("kprobe:f { arg0 }", "Program\n kprobe:f\n builtin: arg0\n");
test("kprobe:f { retval }", "Program\n kprobe:f\n builtin: retval\n");
......
......@@ -41,6 +41,12 @@ EXPECT SUCCESS stack
TIMEOUT 5
BEFORE sleep 1 && sleep 1 &
NAME kstack
RUN bpftrace -e 'k:do_nanosleep { printf("SUCCESS '$test' %s\n", kstack); exit(); }'
EXPECT SUCCESS kstack
TIMEOUT 5
BEFORE sleep 1 && sleep 1 &
NAME ustack
RUN bpftrace -e 'k:do_nanosleep { printf("SUCCESS '$test' %s\n", ustack); exit(); }'
EXPECT SUCCESS ustack
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment