Add libbpfjit_jmp_ja_invalid test.

This commit is contained in:
alnsn 2015-02-11 23:17:16 +00:00
parent a8791f7770
commit 9dc6430c3c
1 changed files with 27 additions and 2 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_bpfjit.c,v 1.9 2015/02/11 23:00:41 alnsn Exp $ */
/* $NetBSD: t_bpfjit.c,v 1.10 2015/02/11 23:17:16 alnsn Exp $ */
/*-
* Copyright (c) 2011-2012, 2014 Alexander Nasonov.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__RCSID("$NetBSD: t_bpfjit.c,v 1.9 2015/02/11 23:00:41 alnsn Exp $");
__RCSID("$NetBSD: t_bpfjit.c,v 1.10 2015/02/11 23:17:16 alnsn Exp $");
#include <atf-c.h>
#include <stdint.h>
@ -67,6 +67,7 @@ ATF_TC_BODY(libbpfjit_empty, tc)
{
struct bpf_insn dummy;
ATF_CHECK(!bpf_validate(&dummy, 0));
ATF_CHECK(bpfjit_generate_code(NULL, &dummy, 0) == NULL);
}
@ -1917,6 +1918,29 @@ ATF_TC_BODY(libbpfjit_jmp_ja, tc)
bpfjit_free_code(code);
}
ATF_TC(libbpfjit_jmp_ja_invalid);
ATF_TC_HEAD(libbpfjit_jmp_ja_invalid, tc)
{
atf_tc_set_md_var(tc, "descr",
"Test BPF_JMP+BPF_JA to invalid destination");
}
ATF_TC_BODY(libbpfjit_jmp_ja_invalid, tc)
{
static struct bpf_insn insns[] = {
BPF_STMT(BPF_JMP+BPF_JA, 4),
BPF_STMT(BPF_RET+BPF_K, 0),
BPF_STMT(BPF_RET+BPF_K, 1),
BPF_STMT(BPF_RET+BPF_K, 2),
BPF_STMT(BPF_RET+BPF_K, 3),
};
size_t insn_count = sizeof(insns) / sizeof(insns[0]);
ATF_CHECK(!bpf_validate(insns, insn_count));
ATF_CHECK(bpfjit_generate_code(NULL, insns, insn_count) == NULL);
}
ATF_TC(libbpfjit_jmp_jgt_k);
ATF_TC_HEAD(libbpfjit_jmp_jgt_k, tc)
{
@ -4553,6 +4577,7 @@ ATF_TP_ADD_TCS(tp)
ATF_TP_ADD_TC(tp, libbpfjit_alu_modulo_x);
ATF_TP_ADD_TC(tp, libbpfjit_alu_neg);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_ja_invalid);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jgt_k);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jge_k);
ATF_TP_ADD_TC(tp, libbpfjit_jmp_jeq_k);