| 1 |
%{ |
| 2 |
#include <linux/tcp.h> |
| 3 |
static struct tcphdr foo = {0}; |
| 4 |
%} |
| 5 |
|
| 6 |
function get_ptr:long() %{ STAP_RETVALUE = (long)&foo; /* pure */ %} |
| 7 |
function get_ack:long() %{ STAP_RETVALUE = foo.ack; /* pure */ %} |
| 8 |
function get_urg:long() %{ STAP_RETVALUE = foo.urg; /* pure */ %} |
| 9 |
|
| 10 |
function check:long(ack:long, urg:long) { |
| 11 |
ptr = get_ptr() |
| 12 |
|
| 13 |
/* set the bits with cast */ |
| 14 |
@cast(ptr, "tcphdr", "kernel")->ack = ack |
| 15 |
@cast(ptr, "tcphdr", "kernel")->urg = urg |
| 16 |
|
| 17 |
/* check that reading with embedded-C is ok */ |
| 18 |
real_ack = get_ack() |
| 19 |
real_urg = get_urg() |
| 20 |
errors = (ack != real_ack) + (urg != real_urg) |
| 21 |
|
| 22 |
/* check that reading with a cast is ok */ |
| 23 |
cast_ack = @cast(ptr, "tcphdr", "kernel")->ack |
| 24 |
cast_urg = @cast(ptr, "tcphdr", "kernel")->urg |
| 25 |
errors += (ack != cast_ack) + (urg != cast_urg) |
| 26 |
|
| 27 |
if (errors) |
| 28 |
printf("bitfield had %d errors; expect(%d%d), real(%d%d), cast(%d%d)\n", |
| 29 |
errors, ack, urg, real_ack, real_urg, cast_ack, cast_urg) |
| 30 |
|
| 31 |
return errors |
| 32 |
} |
| 33 |
|
| 34 |
probe begin { |
| 35 |
println("systemtap starting probe") |
| 36 |
|
| 37 |
errors = check(0, 0) |
| 38 |
errors += check(0, 1) |
| 39 |
errors += check(1, 0) |
| 40 |
errors += check(1, 1) |
| 41 |
|
| 42 |
println("systemtap ending probe") |
| 43 |
if (errors == 0) |
| 44 |
println("systemtap test success") |
| 45 |
exit() |
| 46 |
} |