Skip to content

Commit

Permalink
Fixup test errors in clang, c api
Browse files Browse the repository at this point in the history
Some errors seem to have cropped up due to updating kernels and clang
library versions.
1. test_c_api fails on kernels (seen on fedora 4.9) where startup_64
doesn't start at a particular address. Simplify the test to hopefully
work in more systems.
2. The lua and python test_clang did a dereference on a particular bio
field, which has been removed. Pick a different field that is more
uniquitous.
3. test_xlate1 was generating code where the verified pointer spilled.
Rewrite the example to store the result on the stack.

Signed-off-by: Brenden Blanco <[email protected]>
  • Loading branch information
Brenden Blanco committed Nov 24, 2016
1 parent 0d5d25e commit 35c7225
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
6 changes: 2 additions & 4 deletions tests/cc/test_c_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ TEST_CASE("binary resolution with `which`", "[c_api]") {
}

static void _test_ksym(const char *sym, uint64_t addr, void *_) {
if (!strcmp(sym, "startup_64")) {
REQUIRE(addr == 0xffffffff81000000ull);
} else if (!strcmp(sym, "system_reset_pSeries"))
REQUIRE(addr == 0xc000000000000100ull);
if (!strcmp(sym, "startup_64"))
REQUIRE(addr != 0x0ull);
}

TEST_CASE("list all kernel symbols", "[c_api]") {
Expand Down
4 changes: 2 additions & 2 deletions tests/lua/test_clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ function TestClang:test_unop_probe_read()
local text = [[
#include <linux/blkdev.h>
int trace_entry(struct pt_regs *ctx, struct request *req) {
if (!(req->bio->bi_rw & 1))
if (!(req->bio->bi_flags & 1))
return 1;
if (((req->bio->bi_rw)))
if (((req->bio->bi_flags)))
return 1;
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/python/test_clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ def test_unop_probe_read(self):
text = """
#include <linux/blkdev.h>
int trace_entry(struct pt_regs *ctx, struct request *req) {
if (!(req->bio->bi_rw & 1))
if (!(req->bio->bi_flags & 1))
return 1;
if (((req->bio->bi_rw)))
if (((req->bio->bi_flags)))
return 1;
return 0;
}
Expand Down
40 changes: 21 additions & 19 deletions tests/python/test_xlate1.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int on_packet(struct __sk_buff *skb) {

u32 orig_dip = 0;
u32 orig_sip = 0;
struct IPLeaf *xleaf;
struct IPLeaf xleaf = {};

ethernet: {
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
Expand All @@ -44,11 +44,12 @@ int on_packet(struct __sk_buff *skb) {
orig_dip = arp->tpa;
orig_sip = arp->spa;
struct IPKey key = {.dip=orig_dip, .sip=orig_sip};
xleaf = xlate.lookup(&key);
if (xleaf) {
arp->tpa = xleaf->xdip;
arp->spa = xleaf->xsip;
lock_xadd(&xleaf->arp_xlated_pkts, 1);
struct IPLeaf *xleafp = xlate.lookup(&key);
if (xleafp) {
xleaf = *xleafp;
arp->tpa = xleaf.xdip;
arp->spa = xleaf.xsip;
lock_xadd(&xleafp->arp_xlated_pkts, 1);
}
goto EOP;
}
Expand All @@ -58,13 +59,14 @@ int on_packet(struct __sk_buff *skb) {
orig_dip = ip->dst;
orig_sip = ip->src;
struct IPKey key = {.dip=orig_dip, .sip=orig_sip};
xleaf = xlate.lookup(&key);
if (xleaf) {
ip->dst = xleaf->xdip;
incr_cksum_l3(&ip->hchecksum, orig_dip, xleaf->xdip);
ip->src = xleaf->xsip;
incr_cksum_l3(&ip->hchecksum, orig_sip, xleaf->xsip);
lock_xadd(&xleaf->ip_xlated_pkts, 1);
struct IPLeaf *xleafp = xlate.lookup(&key);
if (xleafp) {
xleaf = *xleafp;
ip->dst = xleaf.xdip;
incr_cksum_l3(&ip->hchecksum, orig_dip, xleaf.xdip);
ip->src = xleaf.xsip;
incr_cksum_l3(&ip->hchecksum, orig_sip, xleaf.xsip);
lock_xadd(&xleafp->ip_xlated_pkts, 1);
}
switch (ip->nextp) {
case 6: goto tcp;
Expand All @@ -75,18 +77,18 @@ int on_packet(struct __sk_buff *skb) {

udp: {
struct udp_t *udp = cursor_advance(cursor, sizeof(*udp));
if (xleaf) {
incr_cksum_l4(&udp->crc, orig_dip, xleaf->xdip, 1);
incr_cksum_l4(&udp->crc, orig_sip, xleaf->xsip, 1);
if (xleaf.xdip) {
incr_cksum_l4(&udp->crc, orig_dip, xleaf.xdip, 1);
incr_cksum_l4(&udp->crc, orig_sip, xleaf.xsip, 1);
}
goto EOP;
}

tcp: {
struct tcp_t *tcp = cursor_advance(cursor, sizeof(*tcp));
if (xleaf) {
incr_cksum_l4(&tcp->cksum, orig_dip, xleaf->xdip, 1);
incr_cksum_l4(&tcp->cksum, orig_sip, xleaf->xsip, 1);
if (xleaf.xdip) {
incr_cksum_l4(&tcp->cksum, orig_dip, xleaf.xdip, 1);
incr_cksum_l4(&tcp->cksum, orig_sip, xleaf.xsip, 1);
}
goto EOP;
}
Expand Down

0 comments on commit 35c7225

Please sign in to comment.