Add a python bindings sequence test
authorXiaona Han <xiaonahappy13@163.com>
Fri, 2 Aug 2013 21:42:32 +0000 (05:42 +0800)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 12 Nov 2013 16:25:13 +0000 (11:25 -0500)
This example is meant to test whether we can get a sequence's values in
the python binding well or not. It is used in conjunction with the
sequence test in the dir tests/ctf-traces/succeed/sequence.

Signed-off-by: Xiaona Han <xiaonahappy13@163.com>
Acked-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
bindings/python/examples/sequence_test.py [new file with mode: 0644]
tests/ctf-traces/succeed/sequence/channel0_0 [new file with mode: 0644]
tests/ctf-traces/succeed/sequence/channel0_1 [new file with mode: 0644]
tests/ctf-traces/succeed/sequence/channel0_2 [new file with mode: 0644]
tests/ctf-traces/succeed/sequence/channel0_3 [new file with mode: 0644]
tests/ctf-traces/succeed/sequence/metadata [new file with mode: 0644]

diff --git a/bindings/python/examples/sequence_test.py b/bindings/python/examples/sequence_test.py
new file mode 100644 (file)
index 0000000..403bdab
--- /dev/null
@@ -0,0 +1,66 @@
+#!/usr/bin/env python3
+# sequence_test.py
+#
+# Babeltrace example script based on the Babeltrace API test script
+#
+# Copyright 2013 Xiaona Han
+# Copyright 2012 EfficiOS Inc.
+#
+# Author: Danny Serres <danny.serres@efficios.com>
+# Author: Xiaona Han <xiaonahappy13@163.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# This example uses the babeltrace python module
+# to partially test the sequence API
+
+import sys
+from babeltrace import *
+
+# Check for path arg:
+if len(sys.argv) < 2:
+       raise TypeError("Usage: sequence_test.py path/to/file")
+
+# Create context and add trace:
+ctx = Context()
+trace_handle = ctx.add_trace(sys.argv[1], "ctf")
+if trace_handle is None:
+       raise IOError("Error adding trace")
+
+# Listing events
+lst = ctf.get_event_decl_list(trace_handle, ctx)
+print("--- Event list ---")
+for item in lst:
+       print("event : {}".format(item.get_name()))
+print("--- Done ---")
+
+# Iter trace
+bp = IterPos(SEEK_BEGIN)
+ctf_it = ctf.Iterator(ctx,bp)
+event = ctf_it.read_event()
+
+while(event is not None):
+       print("TS: {}, {} : {}".format(event.get_timestamp(),
+               event.get_cycles(), event.get_name()))
+       field = event.get_field("seq_int_field")
+       if field is not None:
+               print("int sequence values: {}". format(field[0].get_value()))
+       field = event.get_field("seq_long_field")
+       if field is not None:
+               print("long sequence values: {}". format(field[0].get_value()))
+
+       ret = ctf_it.next()
+       if ret < 0:
+               break
+       else:
+               event = ctf_it.read_event()
+
+del ctf_it
diff --git a/tests/ctf-traces/succeed/sequence/channel0_0 b/tests/ctf-traces/succeed/sequence/channel0_0
new file mode 100644 (file)
index 0000000..5038a22
Binary files /dev/null and b/tests/ctf-traces/succeed/sequence/channel0_0 differ
diff --git a/tests/ctf-traces/succeed/sequence/channel0_1 b/tests/ctf-traces/succeed/sequence/channel0_1
new file mode 100644 (file)
index 0000000..fd94738
Binary files /dev/null and b/tests/ctf-traces/succeed/sequence/channel0_1 differ
diff --git a/tests/ctf-traces/succeed/sequence/channel0_2 b/tests/ctf-traces/succeed/sequence/channel0_2
new file mode 100644 (file)
index 0000000..9d848fc
Binary files /dev/null and b/tests/ctf-traces/succeed/sequence/channel0_2 differ
diff --git a/tests/ctf-traces/succeed/sequence/channel0_3 b/tests/ctf-traces/succeed/sequence/channel0_3
new file mode 100644 (file)
index 0000000..ef385c3
Binary files /dev/null and b/tests/ctf-traces/succeed/sequence/channel0_3 differ
diff --git a/tests/ctf-traces/succeed/sequence/metadata b/tests/ctf-traces/succeed/sequence/metadata
new file mode 100644 (file)
index 0000000..2163abf
--- /dev/null
@@ -0,0 +1,106 @@
+/* CTF 1.8 */
+typealias integer { size = 8; align = 8; signed = false; } := uint8_t;
+typealias integer { size = 16; align = 8; signed = false; } := uint16_t;
+typealias integer { size = 32; align = 8; signed = false; } := uint32_t;
+typealias integer { size = 64; align = 8; signed = false; } := uint64_t;
+typealias integer { size = 64; align = 8; signed = false; } := unsigned long;
+typealias integer { size = 5; align = 1; signed = false; } := uint5_t;
+typealias integer { size = 27; align = 1; signed = false; } := uint27_t;
+
+trace {
+       major = 1;
+       minor = 8;
+       uuid = "59052333-e490-4ed9-af7a-b652437fba9a";
+       byte_order = le;
+       packet.header := struct {
+               uint32_t magic;
+               uint8_t  uuid[16];
+               uint32_t stream_id;
+       };
+};
+
+env {
+       hostname = "host";
+       domain = "ust";
+       tracer_name = "lttng-ust";
+       tracer_major = 2;
+       tracer_minor = 3;
+};
+
+clock {
+       name = monotonic;
+       uuid = "5f3ed925-9d73-4637-b8e4-02077abc8c8f";
+       description = "Monotonic Clock";
+       freq = 1000000000; /* Frequency, in Hz */
+       /* clock value offset from Epoch is: offset * (1/freq) */
+       offset = 1375437179542680815;
+};
+
+typealias integer {
+       size = 27; align = 1; signed = false;
+       map = clock.monotonic.value;
+} := uint27_clock_monotonic_t;
+
+typealias integer {
+       size = 32; align = 8; signed = false;
+       map = clock.monotonic.value;
+} := uint32_clock_monotonic_t;
+
+typealias integer {
+       size = 64; align = 8; signed = false;
+       map = clock.monotonic.value;
+} := uint64_clock_monotonic_t;
+
+struct packet_context {
+       uint64_clock_monotonic_t timestamp_begin;
+       uint64_clock_monotonic_t timestamp_end;
+       uint64_t content_size;
+       uint64_t packet_size;
+       unsigned long events_discarded;
+       uint32_t cpu_id;
+};
+
+struct event_header_compact {
+       enum : uint5_t { compact = 0 ... 30, extended = 31 } id;
+       variant <id> {
+               struct {
+                       uint27_clock_monotonic_t timestamp;
+               } compact;
+               struct {
+                       uint32_t id;
+                       uint64_clock_monotonic_t timestamp;
+               } extended;
+       } v;
+} align(8);
+
+struct event_header_large {
+       enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;
+       variant <id> {
+               struct {
+                       uint32_clock_monotonic_t timestamp;
+               } compact;
+               struct {
+                       uint32_t id;
+                       uint64_clock_monotonic_t timestamp;
+               } extended;
+       } v;
+} align(8);
+
+stream {
+       id = 0;
+       event.header := struct event_header_compact;
+       packet.context := struct packet_context;
+};
+
+event {
+       name = "sequence event";
+       id = 0;
+       stream_id = 0;
+       loglevel = 1;
+       fields := struct {
+               integer { size = 64; align = 8; signed = 0; encoding = none; base = 10; } __seq_int_field_length;
+               integer { size = 32; align = 8; signed = 1; encoding = none; base = 10; } _seq_int_field[ __seq_int_field_length ];
+               integer { size = 64; align = 8; signed = 0; encoding = none; base = 10; } __seq_long_field_length;
+               integer { size = 64; align = 8; signed = 1; encoding = none; base = 10; } _seq_long_field[ __seq_long_field_length ];
+       };
+};
This page took 0.038475 seconds and 4 git commands to generate.