+function generate_filter_events_cpu0()
+{
+ # Generate many events (fill buffers) on CPU 0
+ taskset 0x00000001 /bin/echo -n "$1" > /proc/lttng-test-filter-event 2> /dev/null
+}
+
+function test_kernel_local_snapshot_discard ()
+{
+ diag "Test local kernel snapshots with small discard buffers"
+
+ local event_name="lttng_test_filter_event"
+
+ modprobe lttng-test
+ create_lttng_session_no_output $SESSION_NAME
+ enable_lttng_mmap_discard_small_kernel_channel $SESSION_NAME \
+ $CHANNEL_NAME
+ enable_kernel_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME
+ start_lttng_tracing_ok $SESSION_NAME
+ lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
+
+ generate_filter_events_cpu0 10000
+
+ # Take first snapshot, remember first line.
+ lttng_snapshot_record $SESSION_NAME
+ FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
+ diag "First line (1st snapshot): $FIRST_LINE"
+
+ rm -rf $TRACE_PATH
+
+ # Fill CPU 0's buffer and overwrite previous contents
+ generate_filter_events_cpu0 10000
+
+ # Take 2nd snapshot, compare first line. In discard mode, they
+ # should still be the same.
+ lttng_snapshot_record $SESSION_NAME
+ FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
+ diag "First line (2nd snapshot): $FIRST_LINE"
+ rm -rf $TRACE_PATH
+
+ if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
+ fail "First snapshot event do not match"
+ else
+ pass "First snapshot event match"
+ fi
+
+ stop_lttng_tracing_ok $SESSION_NAME
+ destroy_lttng_session_ok $SESSION_NAME
+ modprobe --remove lttng-test
+}
+
+function test_kernel_local_snapshot_overwrite_small_buffers ()
+{
+ diag "Test local kernel snapshot with small overwrite buffers"
+
+ local event_name="lttng_test_filter_event"
+
+ modprobe lttng-test
+ create_lttng_session_no_output $SESSION_NAME
+ enable_lttng_mmap_overwrite_small_kernel_channel $SESSION_NAME \
+ $CHANNEL_NAME
+ enable_kernel_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME
+ start_lttng_tracing_ok $SESSION_NAME
+ lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
+
+ generate_filter_events_cpu0 10000
+
+ # Take first snapshot, remember first line.
+ lttng_snapshot_record $SESSION_NAME
+ FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
+ diag "First line (1st snapshot): $FIRST_LINE"
+
+ rm -rf $TRACE_PATH
+
+ # Fill CPU 0's buffer and overwrite previous contents
+ generate_filter_events_cpu0 10000
+
+ # Take 2nd snapshot, compare first line. In overwrite mode, they
+ # WILL be different.
+ lttng_snapshot_record $SESSION_NAME
+ FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
+ diag "First line (2nd snapshot): $FIRST_LINE_2"
+ rm -rf $TRACE_PATH
+
+ if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
+ pass "First snapshot event do not match"
+ else
+ fail "First snapshot event match"
+ fi
+
+ stop_lttng_tracing_ok $SESSION_NAME
+ destroy_lttng_session_ok $SESSION_NAME
+ modprobe --remove lttng-test
+}
+