Skip to content

Commit 8ea97f1

Browse files
committed
improve test
1 parent d95aa6e commit 8ea97f1

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

quark-test.c

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@
3434
#include "manpages.h"
3535

3636
#define PATTERN "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
37-
// "Nobody calls me Lebowski. You got the wrong guy. I'm the Dude, man."
3837

39-
static int bflag; /* run bpf tests */
40-
static int kflag; /* run kprobe tests */
38+
struct udphdr {
39+
u16 source;
40+
u16 dest;
41+
u16 len;
42+
u16 check;
43+
};
4144

4245
#define msleep(_x) usleep((uint64_t)_x * 1000ULL)
4346

@@ -47,6 +50,9 @@ enum {
4750
GREEN
4851
};
4952

53+
static int bflag; /* run bpf tests */
54+
static int kflag; /* run kprobe tests */
55+
5056
static int
5157
fancy_tty(void)
5258
{
@@ -731,8 +737,12 @@ t_stats(const struct test *t, struct quark_queue_attr *qa)
731737
static int
732738
t_dns(const struct test *t, struct quark_queue_attr *qa)
733739
{
734-
struct quark_queue qq;
735-
pid_t child;
740+
struct quark_queue qq;
741+
const struct quark_event *qev;
742+
struct quark_packet *packet;
743+
pid_t child;
744+
struct iphdr ip;
745+
struct udphdr udp;
736746

737747
assert_localhost();
738748

@@ -742,7 +752,44 @@ t_dns(const struct test *t, struct quark_queue_attr *qa)
742752
err(1, "quark_queue_open");
743753

744754
child = fork_sock_write(53, SOCK_DGRAM);
745-
drain_for_pid(&qq, child);
755+
756+
/* first is the fork, no agg */
757+
qev = drain_for_pid(&qq, child);
758+
assert(qev->packet == NULL);
759+
760+
/* egress */
761+
qev = drain_for_pid(&qq, child);
762+
packet = qev->packet;
763+
assert(packet != NULL);
764+
assert(packet->cap_len == 90);
765+
assert(packet->orig_len == 90);
766+
/* ip */
767+
memcpy(&ip, packet->data, sizeof(ip));
768+
assert(ip.protocol == IPPROTO_UDP);
769+
assert(ip.saddr == htonl(INADDR_LOOPBACK));
770+
assert(ip.daddr == htonl(INADDR_LOOPBACK));
771+
/* udp */
772+
memcpy(&udp, packet->data + sizeof(ip), sizeof(udp));
773+
assert(udp.dest == htons(53));
774+
/* dns */
775+
assert(!memcmp(packet->data + 28, PATTERN, packet->cap_len - 28));
776+
777+
/* ingress */
778+
qev = drain_for_pid(&qq, child);
779+
packet = qev->packet;
780+
assert(packet != NULL);
781+
assert(packet->cap_len == 90);
782+
assert(packet->orig_len == 90);
783+
/* ip */
784+
memcpy(&ip, packet->data, sizeof(ip));
785+
assert(ip.protocol == IPPROTO_UDP);
786+
assert(ip.saddr == htonl(INADDR_LOOPBACK));
787+
assert(ip.daddr == htonl(INADDR_LOOPBACK));
788+
/* udp */
789+
memcpy(&udp, packet->data + sizeof(ip), sizeof(udp));
790+
assert(udp.dest == htons(53));
791+
/* dns */
792+
assert(!memcmp(packet->data + 28, PATTERN, packet->cap_len - 28));
746793

747794
quark_queue_close(&qq);
748795

0 commit comments

Comments
 (0)