diff options
author | Matus Fabian <matfabia@cisco.com> | 2024-09-20 10:44:08 +0200 |
---|---|---|
committer | Matus Fabian <matfabia@cisco.com> | 2024-09-20 10:44:08 +0200 |
commit | 147585e7f6566fe08aa1cc774e7435660ab29e26 (patch) | |
tree | 47343a585e43700ab9c4cb461cddfc9715bd8c8f | |
parent | 2fb8d2f96d9df0657d21b411d9cc803c0e994530 (diff) |
hs-test: debugging utility methods
Type: test
Change-Id: I0c7e8424e53f1ad1896cd8439027e6081ccfeb28
Signed-off-by: Matus Fabian <matfabia@cisco.com>
-rw-r--r-- | extras/hs-test/README.rst | 52 | ||||
-rw-r--r-- | extras/hs-test/infra/vppinstance.go | 25 |
2 files changed, 63 insertions, 14 deletions
diff --git a/extras/hs-test/README.rst b/extras/hs-test/README.rst index 8a49ac6e7e2..6a4cea187c4 100644 --- a/extras/hs-test/README.rst +++ b/extras/hs-test/README.rst @@ -293,7 +293,23 @@ Alternatively copy the executable from host system to the Docker image, similarl However the tests currently run under test suites which set up topology and containers before actual test is run. For the reason of saving test run time it is not advisable to use aforementioned skip methods and instead, just don't register the test. -**Debugging a test** +**External dependencies** + +* Linux tools ``ip``, ``brctl`` +* Standalone programs ``wget``, ``iperf3`` - since these are downloaded when Docker image is made, + they are reasonably up-to-date automatically +* Programs in Docker images - ``envoyproxy/envoy-contrib`` and ``nginx`` +* ``http_server`` - homegrown application that listens on specified port and sends a test file in response +* Non-standard Go libraries - see ``extras/hs-test/go.mod`` + +Generally, these will be updated on a per-need basis, for example when a bug is discovered +or a new version incompatibility issue occurs. + +Debugging a test +---------------- + +GDB +^^^ It is possible to debug VPP by attaching ``gdb`` before test execution by adding ``DEBUG=true`` like follows: @@ -307,7 +323,27 @@ It is possible to debug VPP by attaching ``gdb`` before test execution by adding If a test consists of more VPP instances then this is done for each of them. -**Memory leak testing** +Utility methods +^^^^^^^^^^^^^^^ + +**Packet Capture** + +It is possible to use VPP pcap trace to capture received and sent packets. +You just need to add ``EnablePcapTrace`` to ``SetupTest`` method in test suite and ``CollectPcapTrace`` to ``TearDownTest``. +This way pcap trace is enabled on all interfaces and to capture maximum 10000 packets. +Your pcap file will be located in the test execution directory. + +**Event Logger** + +``clib_warning`` is a handy way to add debugging output, but in some cases it's not appropriate for per-packet use in data plane code. +In this case VPP event logger is better option, for example you can enable it for TCP or session layer in build time. +To collect traces when test ends you just need to add ``CollectEventLogs`` method to ``TearDownTest`` in the test suite. +Your event logger file will be located in the test execution directory. +To view events you can use :ref:`G2 graphical event viewer <eventviewer>` or ``convert_evt`` tool, located in ``src/scripts/host-stack/``, +which convert event logs to human readable text. + +Memory leak testing +^^^^^^^^^^^^^^^^^^^ It is possible to use VPP memory traces to diagnose if and where memory leaks happen by comparing of two traces at different point in time. You can do it by test like following: @@ -352,18 +388,6 @@ To get your memory leak report run following command: << Report Entries ------------------------------ -**External dependencies** - -* Linux tools ``ip``, ``brctl`` -* Standalone programs ``wget``, ``iperf3`` - since these are downloaded when Docker image is made, - they are reasonably up-to-date automatically -* Programs in Docker images - ``envoyproxy/envoy-contrib`` and ``nginx`` -* ``http_server`` - homegrown application that listens on specified port and sends a test file in response -* Non-standard Go libraries - see ``extras/hs-test/go.mod`` - -Generally, these will be updated on a per-need basis, for example when a bug is discovered -or a new version incompatibility issue occurs. - .. _ginkgo: https://onsi.github.io/ginkgo/ .. _volumes: https://docs.docker.com/storage/volumes/ diff --git a/extras/hs-test/infra/vppinstance.go b/extras/hs-test/infra/vppinstance.go index a93921ed5be..b3ae995870f 100644 --- a/extras/hs-test/infra/vppinstance.go +++ b/extras/hs-test/infra/vppinstance.go @@ -619,3 +619,28 @@ func (vpp *VppInstance) MemLeakCheck(first, second []VppMemTrace) { summary := fmt.Sprintf("\nSUMMARY: %d byte(s) leaked in %d allocation(s)\n", totalBytes, totalCounts) AddReportEntry(summary, report) } + +// CollectEventLogs saves event logs to the test execution directory +func (vpp *VppInstance) CollectEventLogs() { + vpp.getSuite().Log(vpp.Vppctl("event-logger save event_log")) + targetDir := vpp.Container.Suite.getLogDirPath() + err := vpp.Container.GetFile("/tmp/event_log", targetDir+"/"+vpp.Container.Name+"-event_log") + if err != nil { + vpp.getSuite().Log(fmt.Sprint(err)) + } +} + +// EnablePcapTrace enables packet capture on all interfaces and maximum 10000 packets +func (vpp *VppInstance) EnablePcapTrace() { + vpp.getSuite().Log(vpp.Vppctl("pcap trace rx tx max 10000 intfc any file vppTest.pcap")) +} + +// CollectPcapTrace saves pcap trace to the test execution directory +func (vpp *VppInstance) CollectPcapTrace() { + vpp.getSuite().Log(vpp.Vppctl("pcap trace off")) + targetDir := vpp.Container.Suite.getLogDirPath() + err := vpp.Container.GetFile("/tmp/vppTest.pcap", targetDir+"/"+vpp.Container.Name+".pcap") + if err != nil { + vpp.getSuite().Log(fmt.Sprint(err)) + } +} |