From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alexei Starovoitov Subject: Re: [PATCH bpf-next v6 11/11] bpf: add selftest for tcpbpf Date: Fri, 19 Jan 2018 19:59:45 -0800 Message-ID: <20180120035944.xzpvvuikso46v7tt@ast-mbp> References: <20180120014548.2941040-1-brakmo@fb.com> <20180120014548.2941040-12-brakmo@fb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: netdev , Kernel Team , Blake Matheny , Alexei Starovoitov , Daniel Borkmann , Eric Dumazet , Neal Cardwell , Yuchung Cheng To: Lawrence Brakmo Return-path: Received: from mail-pf0-f175.google.com ([209.85.192.175]:44377 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751308AbeATD7t (ORCPT ); Fri, 19 Jan 2018 22:59:49 -0500 Received: by mail-pf0-f175.google.com with SMTP id m26so2840228pfj.11 for ; Fri, 19 Jan 2018 19:59:49 -0800 (PST) Content-Disposition: inline In-Reply-To: <20180120014548.2941040-12-brakmo@fb.com> Sender: netdev-owner@vger.kernel.org List-ID: On Fri, Jan 19, 2018 at 05:45:48PM -0800, Lawrence Brakmo wrote: > Added a selftest for tcpbpf (sock_ops) that checks that the appropriate > callbacks occured and that it can access tcp_sock fields and that their > values are correct. > > Run with command: ./test_tcpbpf_user > > Signed-off-by: Lawrence Brakmo ... > + __u32 key = 0; > + struct tcpbpf_globals g, *gp; > + > + gp = bpf_map_lookup_elem(&global_map, &key); > + if (gp == NULL) { > + struct tcpbpf_globals g = {0, 0, 0, 0, 0, 0, 0, 0}; > + > + g.event_map |= (1 << event); > + bpf_map_update_elem(&global_map, &key, &g, > + BPF_ANY); > + } else { > + g = *gp; > + g.event_map |= (1 << event); > + bpf_map_update_elem(&global_map, &key, &g, > + BPF_ANY); ... > + __u32 key = 0; > + struct tcpbpf_globals g, *gp; > + > + gp = bpf_map_lookup_elem(&global_map, &key); > + if (!gp) > + break; > + g = *gp; > + g.bad_cb_test_rv = bad_call_rv; > + g.good_cb_test_rv = good_call_rv; > + bpf_map_update_elem(&global_map, &key, &g, > + BPF_ANY); since 'g' is an array of one element and the tests designed for single flow anyway, there is no need to use map_update_elem. the program can directly assign into fields like: gp->bad_cb_test_rv = bad_call_rv; gp->good_cb_test_rv = good_call_rv; probably not worth respining just for that. Mainly fyi. Acked-by: Alexei Starovoitov