poke-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] testsuite: add test for BTF pickle


From: David Faust
Subject: Re: [PATCH] testsuite: add test for BTF pickle
Date: Tue, 4 Jan 2022 14:56:40 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0



On 1/4/22 14:49, Jose E. Marchesi wrote:

Hi David.

2022-01-04  David Faust  <david.faust@oracle.com>

        * testsuite/poke.pickles/btf-test.pk: New test.

OK for both master and maint/poke-1.
Thanks!

Pushed to both. Thanks.


---
  ChangeLog                          |   4 +
  testsuite/poke.pickles/btf-test.pk | 200 +++++++++++++++++++++++++++++
  2 files changed, 204 insertions(+)
  create mode 100644 testsuite/poke.pickles/btf-test.pk

diff --git a/ChangeLog b/ChangeLog
index b889ab5e..461c0ef1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2022-01-04  David Faust  <david.faust@oracle.com>
+
+       * testsuite/poke.pickles/btf-test.pk: New test.
+
  2022-01-04  David Faust  <david.faust@oracle.com>
* pickles/btf.pk (BTF_Header): Adjust constraint on magic number
diff --git a/testsuite/poke.pickles/btf-test.pk 
b/testsuite/poke.pickles/btf-test.pk
new file mode 100644
index 00000000..e2d0fe9d
--- /dev/null
+++ b/testsuite/poke.pickles/btf-test.pk
@@ -0,0 +1,200 @@
+/* btf-test.pk - Tests for the BTF pickle.  */
+
+/* Copyright (C) 2022 Oracle, Inc.  */
+
+/* This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+load pktest;
+load btf;
+
+var data = open ("*data*");
+
+uint<8>[622] @ data : 0#B = [
+  0x9fUB, 0xebUB, 0x01UB, 0x00UB, 0x18UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB,
+  0x00UB, 0x00UB, 0x00UB, 0x9cUB, 0x01UB, 0x00UB, 0x00UB, 0x9cUB, 0x01UB,
+  0x00UB, 0x00UB, 0xbaUB, 0x00UB, 0x00UB, 0x00UB, 0x01UB, 0x00UB, 0x00UB,
+  0x00UB, 0x04UB, 0x00UB, 0x00UB, 0x84UB, 0x08UB, 0x00UB, 0x00UB, 0x00UB,
+  0x0bUB, 0x00UB, 0x00UB, 0x00UB, 0x02UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB,
+  0x00UB, 0x00UB, 0x00UB, 0x1aUB, 0x00UB, 0x00UB, 0x00UB, 0x03UB, 0x00UB,
+  0x00UB, 0x00UB, 0x20UB, 0x00UB, 0x00UB, 0x07UB, 0x1fUB, 0x00UB, 0x00UB,
+  0x00UB, 0x03UB, 0x00UB, 0x00UB, 0x00UB, 0x27UB, 0x00UB, 0x00UB, 0x0dUB,
+  0x24UB, 0x00UB, 0x00UB, 0x00UB, 0x03UB, 0x00UB, 0x00UB, 0x00UB, 0x34UB,
+  0x00UB, 0x00UB, 0x02UB, 0x07UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB,
+  0x00UB, 0x01UB, 0x04UB, 0x00UB, 0x00UB, 0x00UB, 0x20UB, 0x00UB, 0x00UB,
+  0x01UB, 0x0dUB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x01UB,
+  0x04UB, 0x00UB, 0x00UB, 0x00UB, 0x20UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB,
+  0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x0aUB, 0x01UB, 0x00UB,
+  0x00UB, 0x00UB, 0x35UB, 0x00UB, 0x00UB, 0x00UB, 0x02UB, 0x00UB, 0x00UB,
+  0x04UB, 0x10UB, 0x00UB, 0x00UB, 0x00UB, 0x4bUB, 0x00UB, 0x00UB, 0x00UB,
+  0x06UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x5bUB,
+  0x00UB, 0x00UB, 0x00UB, 0x08UB, 0x00UB, 0x00UB, 0x00UB, 0x40UB, 0x00UB,
+  0x00UB, 0x00UB, 0x39UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB,
+  0x01UB, 0x08UB, 0x00UB, 0x00UB, 0x00UB, 0x40UB, 0x00UB, 0x00UB, 0x00UB,
+  0x4dUB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x01UB, 0x01UB,
+  0x00UB, 0x00UB, 0x00UB, 0x08UB, 0x00UB, 0x00UB, 0x02UB, 0x00UB, 0x00UB,
+  0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x03UB, 0x00UB, 0x00UB, 0x00UB,
+  0x00UB, 0x07UB, 0x00UB, 0x00UB, 0x00UB, 0x06UB, 0x00UB, 0x00UB, 0x00UB,
+  0x08UB, 0x00UB, 0x00UB, 0x00UB, 0x60UB, 0x00UB, 0x00UB, 0x00UB, 0x03UB,
+  0x00UB, 0x00UB, 0x04UB, 0x0cUB, 0x00UB, 0x00UB, 0x00UB, 0x6aUB, 0x00UB,
+  0x00UB, 0x00UB, 0x0aUB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB,
+  0x00UB, 0x6cUB, 0x00UB, 0x00UB, 0x00UB, 0x0aUB, 0x00UB, 0x00UB, 0x00UB,
+  0x20UB, 0x00UB, 0x00UB, 0x00UB, 0x6eUB, 0x00UB, 0x00UB, 0x00UB, 0x0aUB,
+  0x00UB, 0x00UB, 0x00UB, 0x40UB, 0x00UB, 0x00UB, 0x00UB, 0x64UB, 0x00UB,
+  0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x10UB, 0x04UB, 0x00UB, 0x00UB,
+  0x00UB, 0x70UB, 0x00UB, 0x00UB, 0x00UB, 0x02UB, 0x00UB, 0x00UB, 0x05UB,
+  0x10UB, 0x00UB, 0x00UB, 0x00UB, 0x72UB, 0x00UB, 0x00UB, 0x00UB, 0x05UB,
+  0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x74UB, 0x00UB,
+  0x00UB, 0x00UB, 0x09UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB,
+  0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x02UB, 0x00UB, 0x00UB, 0x0dUB,
+  0x02UB, 0x00UB, 0x00UB, 0x00UB, 0xa9UB, 0x00UB, 0x00UB, 0x00UB, 0x02UB,
+  0x00UB, 0x00UB, 0x00UB, 0xabUB, 0x00UB, 0x00UB, 0x00UB, 0x02UB, 0x00UB,
+  0x00UB, 0x00UB, 0x29UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB,
+  0x0eUB, 0x04UB, 0x00UB, 0x00UB, 0x00UB, 0x01UB, 0x00UB, 0x00UB, 0x00UB,
+  0x76UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x0eUB, 0x0bUB,
+  0x00UB, 0x00UB, 0x00UB, 0x01UB, 0x00UB, 0x00UB, 0x00UB, 0x7bUB, 0x00UB,
+  0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x0cUB, 0x0cUB, 0x00UB, 0x00UB,
+  0x00UB, 0xadUB, 0x00UB, 0x00UB, 0x00UB, 0x01UB, 0x00UB, 0x00UB, 0x0fUB,
+  0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x0eUB, 0x00UB, 0x00UB, 0x00UB, 0x00UB,
+  0x00UB, 0x00UB, 0x00UB, 0x10UB, 0x00UB, 0x00UB, 0x00UB, 0xb2UB, 0x00UB,
+  0x00UB, 0x00UB, 0x01UB, 0x00UB, 0x00UB, 0x0fUB, 0x00UB, 0x00UB, 0x00UB,
+  0x00UB, 0x0dUB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB,
+  0x08UB, 0x00UB, 0x00UB, 0x00UB, 0x00UB, 0x62UB, 0x69UB, 0x74UB, 0x74UB,
+  0x79UB, 0x00UB, 0x69UB, 0x6eUB, 0x74UB, 0x00UB, 0x61UB, 0x00UB, 0x75UB,
+  0x6eUB, 0x73UB, 0x69UB, 0x67UB, 0x6eUB, 0x65UB, 0x64UB, 0x20UB, 0x69UB,
+  0x6eUB, 0x74UB, 0x00UB, 0x62UB, 0x66UB, 0x5fUB, 0x61UB, 0x00UB, 0x62UB,
+  0x66UB, 0x5fUB, 0x62UB, 0x00UB, 0x62UB, 0x66UB, 0x5fUB, 0x63UB, 0x00UB,
+  0x63UB, 0x6fUB, 0x6eUB, 0x73UB, 0x74UB, 0x5fUB, 0x62UB, 0x69UB, 0x74UB,
+  0x74UB, 0x79UB, 0x00UB, 0x66UB, 0x6fUB, 0x6fUB, 0x00UB, 0x6cUB, 0x6fUB,
+  0x6eUB, 0x67UB, 0x20UB, 0x75UB, 0x6eUB, 0x73UB, 0x69UB, 0x67UB, 0x6eUB,
+  0x65UB, 0x64UB, 0x20UB, 0x69UB, 0x6eUB, 0x74UB, 0x00UB, 0x6cUB, 0x00UB,
+  0x75UB, 0x6eUB, 0x73UB, 0x69UB, 0x67UB, 0x6eUB, 0x65UB, 0x64UB, 0x20UB,
+  0x63UB, 0x68UB, 0x61UB, 0x72UB, 0x00UB, 0x64UB, 0x61UB, 0x74UB, 0x61UB,
+  0x00UB, 0x62UB, 0x61UB, 0x72UB, 0x00UB, 0x66UB, 0x6cUB, 0x6fUB, 0x61UB,
+  0x74UB, 0x00UB, 0x78UB, 0x00UB, 0x79UB, 0x00UB, 0x7aUB, 0x00UB, 0x75UB,
+  0x00UB, 0x66UB, 0x00UB, 0x62UB, 0x00UB, 0x6dUB, 0x79UB, 0x5fUB, 0x75UB,
+  0x00UB, 0x61UB, 0x63UB, 0x74UB, 0x00UB, 0x2fUB, 0x68UB, 0x6fUB, 0x6dUB,
+  0x65UB, 0x2fUB, 0x64UB, 0x66UB, 0x61UB, 0x75UB, 0x73UB, 0x74UB, 0x2fUB,
+  0x70UB, 0x6cUB, 0x61UB, 0x79UB, 0x70UB, 0x65UB, 0x6eUB, 0x2fUB, 0x62UB,
+  0x74UB, 0x66UB, 0x2fUB, 0x62UB, 0x74UB, 0x66UB, 0x2dUB, 0x74UB, 0x65UB,
+  0x73UB, 0x74UB, 0x2dUB, 0x70UB, 0x6fUB, 0x6bUB, 0x65UB, 0x2eUB, 0x63UB,
+  0x00UB, 0x00UB, 0x61UB, 0x00UB, 0x62UB, 0x00UB, 0x2eUB, 0x62UB, 0x73UB,
+  0x73UB, 0x00UB, 0x2eUB, 0x72UB, 0x6fUB, 0x64UB, 0x61UB, 0x74UB, 0x61UB,
+  0x00UB
+];
+
+var tests = [
+  PkTest {
+    name = "read header info",
+    func = lambda (string name) void:
+      {
+        var hdr = BTF_Header @ data : 0#B;
+
+        assert (hdr.magic == 0xeb9f);
+        assert (hdr.type_off == 0U#B);
+        assert (hdr.type_len == 412U#B);
+        assert (hdr.str_off  == hdr.type_len);
+        assert (hdr.str_len  == 186U#B);
+      },
+  },
+  PkTest {
+    name = "read types",
+    func = lambda (string name) void:
+      {
+        var btf = BTF_Section @ data : 0#B;
+
+        assert (btf.types'size == btf.header.type_len);
+        assert (btf.types'length == 17);
+
+        assert (btf.types[0].info.kind == BTF_KIND_STRUCT);
+        assert (btf.types[0].info.kind_flag == 1);
+        assert (btf.types[0].info.vlen == 4);
+        assert (btf.types[0].attrs.size == 8#B);
+        assert (btf.types[0].data.members'length == btf.types[0].info.vlen);
+        assert (btf.types[0].data.members[1].type_id == 3);
+        assert (btf.types[0].data.members[1].offset.bitfield.bitfield_size ==
+                    7#b);
+        assert (btf.types[0].data.members[1].offset.bitfield.bit_offset ==
+                    32#b);
+
+        assert (btf.types[1].info.kind == BTF_KIND_INT);
+        assert (btf.types[1].attrs.size == 4#B);
+
+        assert (btf.types[3].info.kind == BTF_KIND_CONST);
+        assert (btf.types[3].attrs.type_id == 1);
+
+        assert (btf.types[7].info.kind == BTF_KIND_ARRAY);
+        assert (btf.types[7].data.array.elem_type == 7);
+        assert (btf.types[7].data.array.index_type == 6);
+        assert (btf.types[7].data.array.nelems == 8);
+
+        assert (btf.types[8].info.kind == BTF_KIND_STRUCT);
+        assert (btf.types[8].info.kind_flag == 0);
+
+        assert (btf.types[9].info.kind == BTF_KIND_FLOAT);
+
+        assert (btf.types[10].info.kind == BTF_KIND_UNION);
+        assert (btf.types[10].info.vlen == 2);
+        assert (btf.types[10].attrs.size == 16#B);
+        assert (btf.types[10].data.members[0].type_id == 5);
+
+        assert (btf.types[11].info.kind == BTF_KIND_FUNC_PROTO);
+        assert (btf.types[11].info.vlen == 2);
+        assert (btf.types[11].attrs.type_id == 2);
+        assert (btf.types[11].data.func_proto.params[0].param_type == 2);
+
+        assert (btf.types[12].info.kind == BTF_KIND_VAR);
+        assert (btf.types[12].name == 41#B);
+        assert (btf.types[12].attrs.type_id == 4);
+        assert (btf.types[12].data.variable.linkage == 1);
+
+        assert (btf.types[14].info.kind == BTF_KIND_FUNC);
+        assert (btf.types[14].name == 123#B);
+        assert (btf.types[14].attrs.type_id == 12);
+
+        assert (btf.types[15].info.kind == BTF_KIND_DATASEC);
+        assert (btf.types[15].info.vlen == 1);
+        assert (btf.types[15].attrs.size == 0#B);
+        assert (btf.types[15].data.datasec[0].var_type == 14);
+        assert (btf.types[15].data.datasec[0].size == 16#B);
+      },
+  },
+  PkTest {
+    name = "read strings",
+    func = lambda (string name) void:
+      {
+        var btf = BTF_Section @ data : 0#B;
+
+        assert (btf.strings'size == btf.header.str_len);
+        assert (btf.strings'length == 30);
+
+        assert (btf.get_string (btf.types[0].name) == "bitty");
+        assert (btf.get_string (btf.types[0].data.members[1].name) == "bf_a");
+        assert (btf.get_string (btf.types[3].name) == "");
+        assert (btf.get_string (btf.types[5].name) == "long unsigned int");
+        assert (btf.get_string (btf.types[11].data.func_proto.params[0].name)
+                   == "a");
+        assert (btf.get_string (btf.types[14].name) == "act");
+        assert (btf.get_string (btf.types[15].name) == ".bss");
+
+        assert (btf.strings[0] == "");
+        assert (btf.strings[29] == ".rodata");
+      },
+  },
+];
+
+var ok = pktest_run (tests);
+
+close (data);
+exit (ok ? 0 : 1);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]