Skip to contentSkip to conversation

Fix: test code assumes that child process is schedule to run before parent

PATCH In review Anders Wallin via lttng-dev 1 participant 10 messages Mar 31, 2021 – Apr 1, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix: test code assumes that child process is schedule to run before parent

the following tests fails on arm64
- test_event_vpid_tracker ust 0 "${EVENT_NAME}"
- test_event_vpid_track_untrack ust 0 "${EVENT_NAME}"
- test_event_pid_tracker ust 0 "${EVENT_NAME}"
- test_event_pid_track_untrack ust 0 "${EVENT_NAME}"

---
 tests/regression/tools/tracker/test_event_tracker | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tests/regression/tools/tracker/test_event_tracker +3 -1
index 711690af..649c7e61 100755
@@ -5,7 +5,7 @@
 #
 # SPDX-License-Identifier: GPL-2.0-only
 
-TEST_DESC="LTTng - Event traker test"
+TEST_DESC="LTTng - Event tracker test"
 
 CURDIR=$(dirname "$0")/
 TESTDIR="$CURDIR/../../.."
@@ -42,6 +42,8 @@ function prepare_ust_app
 
 	$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a "$AFTER_FIRST_PATH" -b "$BEFORE_LAST_PATH" &
 	CHILD_PID=$!
+	# voluntary context switch to start $TESTAPP_BIN
+	sleep 0.1
 }
 
 function trace_ust_app
Signature · 6 lines
2.31.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#1 lore raw
Quoted 9 lines

#
# SPDX-License-Identifier: GPL-2.0-only

tests/regression/tools/tracker/test_event_tracker +1 -1
-TEST_DESC="LTTng - Event traker test"
+TEST_DESC="LTTng - Event tracker test"

CURDIR=$(dirname "$0")/
TESTDIR="$CURDIR/../../.."

tests/regression/tools/tracker/test_event_tracker function prepare_ust_app · line 47

Quoted 6 lines
tests/regression/tools/tracker/test_event_tracker +2 -0
@@ -42,6 +42,8 @@ function prepare_ust_app
 
 	$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a "$AFTER_FIRST_PATH" -b
 	"$BEFORE_LAST_PATH" &
 	CHILD_PID=$!
+	# voluntary context switch to start $TESTAPP_BIN
+	sleep 0.1

A wait on the $AFTER_FIRST_PATH file would be probably more deterministic than a sleep here.

  while [ ! -f "${AFTER_FIRST_PATH}" ]; do
          sleep 0.1
  done

I would also expect something similar for the prepare_kernel_app function considering the same race is most probably present and simply not triggered by a chance of luck. Seems like gen-kernel-test-events does not expose the same sync capabilities here, please use gen-ust-events as an example of how it is done.

Let us know how your testing goes.

Thanks
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

#2 lore raw

Hi Julian,

Neither mine "sleep 0.1" or your version with "while [! -f ............" are race condition free.
I suggest that we add an option to gen-ust-events to wait before the first event is generated.
gen_kernel_test_events already have this functionality to wait before the first event.

Something like this
static struct option long_options[] =
{
/* These options set a flag. */
{"iter", required_argument, 0, 'i'},
{"wait", required_argument, 0, 'w'}, {"sync-after-first-event", required_argument, 0, 'a'}, {"sync-before-last-event", required_argument, 0, 'b'}, {"sync-before-last-event-touch", required_argument, 0, 'c'}, {"sync-before-exit", required_argument, 0, 'd'}, {"sync-before-exit-touch", required_argument, 0, 'e'}, *+ {"sync-before-first-event", required_argument, 0, 'f'},*

{0, 0, 0, 0}
};
....

I will create one or more patches for this tomorrow

Anders Wallin

Quoted 30 lines · Jonathan Rajotte-Julien
Quoted 9 lines

#
# SPDX-License-Identifier: GPL-2.0-only

tests/regression/tools/tracker/test_event_tracker +1 -1
-TEST_DESC="LTTng - Event traker test"
+TEST_DESC="LTTng - Event tracker test"

CURDIR=$(dirname "$0")/
TESTDIR="$CURDIR/../../.."

tests/regression/tools/tracker/test_event_tracker function prepare_ust_app · line 47

Quoted 6 lines
tests/regression/tools/tracker/test_event_tracker +2 -0
@@ -42,6 +42,8 @@ function prepare_ust_app
 
      $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a "$AFTER_FIRST_PATH" -b
      "$BEFORE_LAST_PATH" &
      CHILD_PID=$!
+     # voluntary context switch to start $TESTAPP_BIN
+     sleep 0.1

A wait on the $AFTER_FIRST_PATH file would be probably more deterministic than a sleep here.

  while [ ! -f "${AFTER_FIRST_PATH}" ]; do
          sleep 0.1
  done

I would also expect something similar for the prepare_kernel_app function considering the same race is most probably present and simply not triggered by a chance of luck.
Seems like gen-kernel-test-events does not expose the same sync capabilities here, please use gen-ust-events as an example of how it is done.

Quoted 4 lines

Let us know how your testing goes.

Thanks

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

#3 lore raw

Hi,

Quoted 1 line · Anders Wallin

Hi Julian,

You can use Jonathan. ;)

Quoted 3 lines

Neither mine "sleep 0.1" or your version with "while [! -f ............" are race condition free.

I might be missing something here but as far as I understand the race you are trying to mitigate is that the test script execute/continue before the backgrounded command (background test app) had time to execute, right?

If so at least waiting for the app to create a file is necessary. Now gen_kernel_test_events does not have this functionality. The PATH_WAIT_FILE is used to control when the testapp can continue. Hence the script still cannot know if the app have been scheduled.

Now based on the test case you might need more synchronization for the test cases.

Note that in the ust cases, the trace_ust_app uses touch "$BEFORE_LAST_PATH" that effectively unblock the app and allows it to perform the last tracepoint hit and the we wait on the background process.

Note: some tests case are a bit clever and uses "trace_"$domain"_app" instead of calling trace_ust_app directly.

For these tests case it seems that we are only expecting at least a single event matching the event name under test. Here the last tracepoint hit should satisfy this criteria.

Am I missing a race?

Cheers

Quoted 64 lines

I suggest that we add an option to gen-ust-events to wait before the first event is generated.
gen_kernel_test_events already have this functionality to wait before the first event.

Something like this
static struct option long_options[] =
{
/* These options set a flag. */
{"iter", required_argument, 0, 'i'},
{"wait", required_argument, 0, 'w'}, {"sync-after-first-event", required_argument, 0, 'a'}, {"sync-before-last-event", required_argument, 0, 'b'}, {"sync-before-last-event-touch", required_argument, 0, 'c'}, {"sync-before-exit", required_argument, 0, 'd'}, {"sync-before-exit-touch", required_argument, 0, 'e'}, *+ {"sync-before-first-event", required_argument, 0, 'f'},*

{0, 0, 0, 0}
};
....

I will create one or more patches for this tomorrow

Anders Wallin

Quoted 34 lines · Jonathan Rajotte-Julien
Quoted 9 lines

#
# SPDX-License-Identifier: GPL-2.0-only

tests/regression/tools/tracker/test_event_tracker +1 -1
-TEST_DESC="LTTng - Event traker test"
+TEST_DESC="LTTng - Event tracker test"

CURDIR=$(dirname "$0")/
TESTDIR="$CURDIR/../../.."

tests/regression/tools/tracker/test_event_tracker function prepare_ust_app · line 47

Quoted 6 lines
tests/regression/tools/tracker/test_event_tracker +2 -0
@@ -42,6 +42,8 @@ function prepare_ust_app
 
      $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a "$AFTER_FIRST_PATH" -b
      "$BEFORE_LAST_PATH" &
      CHILD_PID=$!
+     # voluntary context switch to start $TESTAPP_BIN
+     sleep 0.1

A wait on the $AFTER_FIRST_PATH file would be probably more deterministic than a sleep here.

  while [ ! -f "${AFTER_FIRST_PATH}" ]; do
          sleep 0.1
  done

I would also expect something similar for the prepare_kernel_app function considering the same race is most probably present and simply not triggered by a chance of luck.
Seems like gen-kernel-test-events does not expose the same sync capabilities here, please use gen-ust-events as an example of how it is done.

Let us know how your testing goes.

Thanks

Signature · 6 lines
Jonathan Rajotte-Julien
EfficiOS
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#4 lore raw

Hi Jonathan :)

It's very unlikely that the race could occur, BUT it can happen.

OK run
1. test_event_tracker starts gen-ust-events
2. test_event_tracker waits for gen-ust-events to create AFTER_FIRST_PATH
3. gen-ust-event create first event and create AFTER_FIRST_PATH
4. gen-ust-event continue and create 99 events
5. gen-ust-event wait for BEFORE_LAST_PATH
6. test_event_track start collecting events (lttng start .....)
7. test_event_tracker calls "lttng track ... -pid "Faulty PID"
8. test_event_tracker touches BEFORE_LAST_PATH
9. gen-ust-events creates the last event
10. test_event finishes and since it tracks the faulty pid the result will be 0 events == OK

Faulty run
1. test_event_tracker starts gen-ust-events
2. test_event_tracker waits for gen-ust-events to create AFTER_FIRST_PATH
3. gen-ust-event create first event and create AFTER_FIRST_PATH
4. gen-ust-event gets rescheduled before it has created 99 events, e.g after 9 events
5. test_event_track start collecting events (lttng start .....)
6. gen-ust-event is rescheduled and starts generating the remaining events. 90 events
7. lttng collects these 90 events since we have not setup "tracking" of PID yet
8. test_event_tracker calls "lttng track ... -pid "Faulty PID"
9. test_event_tracker touches BEFORE_LAST_PATH
10. gen-ust-events creates the last event
11. test_event finishes and since it tracks the faulty pid the result should be 0 events, but we got 90 == FAULTY

We can solve this by;
A: using NR_ITER=2
or
B: by adding a flag to gen-ust-events to wait before sending the first event
1. test_event_tracker starts gen-ust-events
2. test_event_tracker waits for gen-ust-events waits for BEFORE_FIRST_PATH
3. test_event_track start collecting events (lttng start .....)
4. test_event_tracker calls "lttng track ... -pid "Faulty PID"
5. test_event_track creates BEFORE_FIRST_PATH
6. gen_ust_event creates 100 events
7. test_event_tracker waits for gen_event_ust to end
8. test_event finishes and since it tracked the faulty pid the result will be 0 events == OK

This is in principle how gen-kernel-test-events works (but with different arguments)
I would suggest to use B since that will be bulletproof

Anders Wallin

Quoted 112 lines · Jonathan Rajotte-Julien

Hi,

Quoted 1 line · Anders Wallin

Hi Julian,

You can use Jonathan. ;)

Quoted 3 lines

Neither mine "sleep 0.1" or your version with "while [! -f ............" are race condition free.

I might be missing something here but as far as I understand the race you are
trying to mitigate is that the test script execute/continue before the backgrounded
command (background test app) had time to execute, right?

If so at least waiting for the app to create a file is necessary. Now gen_kernel_test_events does not have this functionality. The PATH_WAIT_FILE is
used to control when the testapp can continue. Hence the script still cannot
know if the app have been scheduled.

Now based on the test case you might need more synchronization for the test cases.

Note that in the ust cases, the trace_ust_app uses touch "$BEFORE_LAST_PATH"
that effectively unblock the app and allows it to perform the last tracepoint
hit and the we wait on the background process.

Note: some tests case are a bit clever and uses "trace_"$domain"_app" instead of
calling trace_ust_app directly.

For these tests case it seems that we are only expecting at least a single event
matching the event name under test. Here the last tracepoint hit should satisfy
this criteria.

Am I missing a race?

Cheers

Quoted 1 line

I suggest that we add an option to gen-ust-events to wait before the

first

Quoted 32 lines

event is generated.
gen_kernel_test_events already have this functionality to wait before the first event.

Something like this
static struct option long_options[] =
{
/* These options set a flag. */
{"iter", required_argument, 0, 'i'},
{"wait", required_argument, 0, 'w'}, {"sync-after-first-event", required_argument, 0, 'a'}, {"sync-before-last-event", required_argument, 0, 'b'}, {"sync-before-last-event-touch", required_argument, 0, 'c'}, {"sync-before-exit", required_argument, 0, 'd'}, {"sync-before-exit-touch", required_argument, 0, 'e'}, *+ {"sync-before-first-event", required_argument, 0, 'f'},*

{0, 0, 0, 0}
};
....

I will create one or more patches for this tomorrow

Anders Wallin

Quoted 3 lines · Jonathan Rajotte-Julien
Quoted 3 lines

#
# SPDX-License-Identifier: GPL-2.0-only

Quoted 8 lines
Quoted 8 lines

Review function prepare_ust_app · line 43

Quoted 8 lines
tests/regression/tools/tracker/test_event_tracker +1 -1
-TEST_DESC="LTTng - Event traker test"
+TEST_DESC="LTTng - Event tracker test"

CURDIR=$(dirname "$0")/
TESTDIR="$CURDIR/../../.."

(quoted diff) +0 -0
@@ -42,6 +42,8 @@ function prepare_ust_app
 
      $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a

"$AFTER_FIRST_PATH" -b

Quoted 6 lines
Quoted 6 lines

tests/regression/tools/tracker/test_event_tracker function prepare_ust_app · line 46

Quoted 4 lines
tests/regression/tools/tracker/test_event_tracker +2 -0
      "$BEFORE_LAST_PATH" &
      CHILD_PID=$!
+     # voluntary context switch to start $TESTAPP_BIN
+     sleep 0.1

A wait on the $AFTER_FIRST_PATH file would be probably more

deterministic

Quoted 8 lines
Quoted 8 lines

than a sleep here.

  while [ ! -f "${AFTER_FIRST_PATH}" ]; do
          sleep 0.1
  done

I would also expect something similar for the prepare_kernel_app function considering the same race is most probably present and simply

not

Quoted 5 lines
Quoted 5 lines

triggered by a chance of luck.
Seems like gen-kernel-test-events does not expose the same sync capabilities here, please use gen-ust-events as an example of how it is done.

Quoted 9 lines
Quoted 4 lines
Quoted 4 lines

Let us know how your testing goes.

Thanks

--
Jonathan Rajotte-Julien
EfficiOS

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

#5 lore raw
Quoted 12 lines · Anders Wallin

Hi Jonathan :)

It's very unlikely that the race could occur, BUT it can happen.

OK run
1. test_event_tracker starts gen-ust-events
2. test_event_tracker waits for gen-ust-events to create AFTER_FIRST_PATH
3. gen-ust-event create first event and create AFTER_FIRST_PATH
4. gen-ust-event continue and create 99 events
5. gen-ust-event wait for BEFORE_LAST_PATH
6. test_event_track start collecting events (lttng start .....)

Quoted 5 lines

7. test_event_tracker calls "lttng track ... -pid "Faulty PID"
8. test_event_tracker touches BEFORE_LAST_PATH
9. gen-ust-events creates the last event
10. test_event finishes and since it tracks the faulty pid the result will be 0 events == OK

The sequence of event for the test_event_tracker function is (as of master):

create
enable event
start
track

launch app
wait for app return
stop
destroy

The sequence you are describing here is:

lauch app
start
track
...

I'm pretty sure we are not talking about the same things. Please specify the test case and all functions involved and make sure to use the proper name for each of them.

I suspect you are talking about test_event_pid_tracker. Still let's make sure of it. If it is, I do agree that it seems to have a window where we can gather event for.

You might want to look if there is a real reason for this sequence instead of mimicking test_event_tracker

Current code:
enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard" "$channel" prepare_"$domain"_app
start_lttng_tracing_ok

if [ "$expect_event" -eq 1 ]; then

         lttng_track_"$domain"_ok "--vpid ${CHILD_PID}"
 else
         lttng_track_"$domain"_ok "--vpid $((CHILD_PID+1))"

fi
trace_"$domain"_app
stop_lttng_tracing_ok
destroy_lttng_session_ok $SESSION_NAME

We might simply want to move the track command before the start considering have all the information to do so.

enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard" "$channel"

prepare_"$domain"_app

if [ "$expect_event" -eq 1 ]; then

         lttng_track_"$domain"_ok "--vpid ${CHILD_PID}"
 else
         lttng_track_"$domain"_ok "--vpid $((CHILD_PID+1))"

fi

start_lttng_tracing_ok
trace_"$domain"_app

stop_lttng_tracing_ok
destroy_lttng_session_ok $SESSION_NAME

After testing this, seems like the validate_trace_empty does not handle the case were simply stream allocation did not take place since no application was 'valid' at the moment of the trace start.

Well we got a good one here. We will wait for your updated patch and go from there.

Cheers

Quoted 163 lines

Faulty run
1. test_event_tracker starts gen-ust-events
2. test_event_tracker waits for gen-ust-events to create AFTER_FIRST_PATH
3. gen-ust-event create first event and create AFTER_FIRST_PATH
4. gen-ust-event gets rescheduled before it has created 99 events, e.g after 9 events
5. test_event_track start collecting events (lttng start .....)
6. gen-ust-event is rescheduled and starts generating the remaining events. 90 events
7. lttng collects these 90 events since we have not setup "tracking" of PID yet
8. test_event_tracker calls "lttng track ... -pid "Faulty PID"
9. test_event_tracker touches BEFORE_LAST_PATH
10. gen-ust-events creates the last event
11. test_event finishes and since it tracks the faulty pid the result should be 0 events, but we got 90 == FAULTY

We can solve this by;
A: using NR_ITER=2
or
B: by adding a flag to gen-ust-events to wait before sending the first event
1. test_event_tracker starts gen-ust-events
2. test_event_tracker waits for gen-ust-events waits for BEFORE_FIRST_PATH
3. test_event_track start collecting events (lttng start .....)
4. test_event_tracker calls "lttng track ... -pid "Faulty PID"
5. test_event_track creates BEFORE_FIRST_PATH
6. gen_ust_event creates 100 events
7. test_event_tracker waits for gen_event_ust to end
8. test_event finishes and since it tracked the faulty pid the result will be 0 events == OK

This is in principle how gen-kernel-test-events works (but with different arguments)
I would suggest to use B since that will be bulletproof

Anders Wallin

Quoted 121 lines · Jonathan Rajotte-Julien

Hi,

Quoted 1 line · Anders Wallin

Hi Julian,

You can use Jonathan. ;)

Quoted 3 lines

Neither mine "sleep 0.1" or your version with "while [! -f ............" are race condition free.

I might be missing something here but as far as I understand the race you are
trying to mitigate is that the test script execute/continue before the backgrounded
command (background test app) had time to execute, right?

If so at least waiting for the app to create a file is necessary. Now gen_kernel_test_events does not have this functionality. The PATH_WAIT_FILE is
used to control when the testapp can continue. Hence the script still cannot
know if the app have been scheduled.

Now based on the test case you might need more synchronization for the test cases.

Note that in the ust cases, the trace_ust_app uses touch "$BEFORE_LAST_PATH"
that effectively unblock the app and allows it to perform the last tracepoint
hit and the we wait on the background process.

Note: some tests case are a bit clever and uses "trace_"$domain"_app" instead of
calling trace_ust_app directly.

For these tests case it seems that we are only expecting at least a single event
matching the event name under test. Here the last tracepoint hit should satisfy
this criteria.

Am I missing a race?

Cheers

Quoted 1 line

I suggest that we add an option to gen-ust-events to wait before the

first

Quoted 32 lines

event is generated.
gen_kernel_test_events already have this functionality to wait before the first event.

Something like this
static struct option long_options[] =
{
/* These options set a flag. */
{"iter", required_argument, 0, 'i'},
{"wait", required_argument, 0, 'w'}, {"sync-after-first-event", required_argument, 0, 'a'}, {"sync-before-last-event", required_argument, 0, 'b'}, {"sync-before-last-event-touch", required_argument, 0, 'c'}, {"sync-before-exit", required_argument, 0, 'd'}, {"sync-before-exit-touch", required_argument, 0, 'e'}, *+ {"sync-before-first-event", required_argument, 0, 'f'},*

{0, 0, 0, 0}
};
....

I will create one or more patches for this tomorrow

Anders Wallin

Quoted 3 lines · Jonathan Rajotte-Julien
Quoted 3 lines

#
# SPDX-License-Identifier: GPL-2.0-only

Quoted 8 lines
Quoted 8 lines

Review function prepare_ust_app · line 43

Quoted 8 lines
tests/regression/tools/tracker/test_event_tracker +1 -1
-TEST_DESC="LTTng - Event traker test"
+TEST_DESC="LTTng - Event tracker test"

CURDIR=$(dirname "$0")/
TESTDIR="$CURDIR/../../.."

(quoted diff) +0 -0
@@ -42,6 +42,8 @@ function prepare_ust_app
 
      $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a

"$AFTER_FIRST_PATH" -b

Quoted 6 lines
Quoted 6 lines

tests/regression/tools/tracker/test_event_tracker function prepare_ust_app · line 46

Quoted 4 lines
tests/regression/tools/tracker/test_event_tracker +2 -0
      "$BEFORE_LAST_PATH" &
      CHILD_PID=$!
+     # voluntary context switch to start $TESTAPP_BIN
+     sleep 0.1

A wait on the $AFTER_FIRST_PATH file would be probably more

deterministic

Quoted 8 lines
Quoted 8 lines

than a sleep here.

  while [ ! -f "${AFTER_FIRST_PATH}" ]; do
          sleep 0.1
  done

I would also expect something similar for the prepare_kernel_app function considering the same race is most probably present and simply

not

Quoted 9 lines
Quoted 9 lines

triggered by a chance of luck.
Seems like gen-kernel-test-events does not expose the same sync capabilities here, please use gen-ust-events as an example of how it is done.

Let us know how your testing goes.

Thanks

--
Jonathan Rajotte-Julien
EfficiOS

Signature · 6 lines
Jonathan Rajotte-Julien
EfficiOS
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#6 lore raw

Hi,

I think you understood what I meant. The issue I have is for this 4 test cases in ./regression/tools/tracker/test_event_tracker
- test_event_vpid_tracker ust 0 "${EVENT_NAME}"
- test_event_vpid_track_untrack ust 0 "${EVENT_NAME}"
- test_event_pid_tracker ust 0 "${EVENT_NAME}"
- test_event_pid_track_untrack ust 0 "${EVENT_NAME}"

I have 2 patches ready, but I want to run some more tests first before posting them

Anders Wallin

Quoted 273 lines · Jonathan Rajotte-Julien
Quoted 12 lines · Anders Wallin

Hi Jonathan :)

It's very unlikely that the race could occur, BUT it can happen.

OK run
1. test_event_tracker starts gen-ust-events
2. test_event_tracker waits for gen-ust-events to create AFTER_FIRST_PATH
3. gen-ust-event create first event and create AFTER_FIRST_PATH
4. gen-ust-event continue and create 99 events
5. gen-ust-event wait for BEFORE_LAST_PATH
6. test_event_track start collecting events (lttng start .....)

Quoted 4 lines

7. test_event_tracker calls "lttng track ... -pid "Faulty PID"
8. test_event_tracker touches BEFORE_LAST_PATH
9. gen-ust-events creates the last event
10. test_event finishes and since it tracks the faulty pid the result

will

Quoted 1 line

be 0 events == OK

The sequence of event for the test_event_tracker function is (as of master):

create
enable event
start
track

launch app
wait for app return
stop
destroy

The sequence you are describing here is:

lauch app
start
track
...

I'm pretty sure we are not talking about the same things. Please specify the
test case and all functions involved and make sure to use the proper name for
each of them.

I suspect you are talking about test_event_pid_tracker. Still let's make sure of
it. If it is, I do agree that it seems to have a window where we can gather event for.

You might want to look if there is a real reason for this sequence instead of
mimicking test_event_tracker

Current code:
enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard" "$channel" prepare_"$domain"_app
start_lttng_tracing_ok

if [ "$expect_event" -eq 1 ]; then

         lttng_track_"$domain"_ok "--vpid ${CHILD_PID}"
 else
         lttng_track_"$domain"_ok "--vpid $((CHILD_PID+1))"

fi
trace_"$domain"_app
stop_lttng_tracing_ok
destroy_lttng_session_ok $SESSION_NAME

We might simply want to move the track command before the start considering have
all the information to do so.

enable_"$domain"_lttng_event_ok $SESSION_NAME "$wildcard" "$channel"

prepare_"$domain"_app

if [ "$expect_event" -eq 1 ]; then

         lttng_track_"$domain"_ok "--vpid ${CHILD_PID}"
 else
         lttng_track_"$domain"_ok "--vpid $((CHILD_PID+1))"

fi

start_lttng_tracing_ok
trace_"$domain"_app

stop_lttng_tracing_ok
destroy_lttng_session_ok $SESSION_NAME

After testing this, seems like the validate_trace_empty does not handle the case were simply stream allocation did not take place since no application was
'valid' at the moment of the trace start.

Well we got a good one here. We will wait for your updated patch and go from
there.

Cheers

Quoted 9 lines

Faulty run
1. test_event_tracker starts gen-ust-events
2. test_event_tracker waits for gen-ust-events to create AFTER_FIRST_PATH
3. gen-ust-event create first event and create AFTER_FIRST_PATH
4. gen-ust-event gets rescheduled before it has created 99 events, e.g after 9 events
5. test_event_track start collecting events (lttng start .....)
6. gen-ust-event is rescheduled and starts generating the remaining

events.

Quoted 2 lines

90 events
7. lttng collects these 90 events since we have not setup "tracking" of

PID

Quoted 11 lines

yet
8. test_event_tracker calls "lttng track ... -pid "Faulty PID"
9. test_event_tracker touches BEFORE_LAST_PATH
10. gen-ust-events creates the last event
11. test_event finishes and since it tracks the faulty pid the result should be 0 events, but we got 90 == FAULTY

We can solve this by;
A: using NR_ITER=2
or
B: by adding a flag to gen-ust-events to wait before sending the first

event

Quoted 2 lines

1. test_event_tracker starts gen-ust-events
2. test_event_tracker waits for gen-ust-events waits for

BEFORE_FIRST_PATH

Quoted 6 lines

3. test_event_track start collecting events (lttng start .....)
4. test_event_tracker calls "lttng track ... -pid "Faulty PID"
5. test_event_track creates BEFORE_FIRST_PATH
6. gen_ust_event creates 100 events
7. test_event_tracker waits for gen_event_ust to end
8. test_event finishes and since it tracked the faulty pid the result

will

Quoted 6 lines

be 0 events == OK

This is in principle how gen-kernel-test-events works (but with different arguments)
I would suggest to use B since that will be bulletproof

Quoted 15 lines

Anders Wallin

Quoted 9 lines · Jonathan Rajotte-Julien

Hi,

Quoted 1 line · Anders Wallin

Hi Julian,

You can use Jonathan. ;)

Quoted 2 lines

Neither mine "sleep 0.1" or your version with "while [! -f

............"

Quoted 3 lines
Quoted 3 lines
Quoted 1 line

are race condition free.

I might be missing something here but as far as I understand the race

you

Quoted 5 lines
Quoted 5 lines

are
trying to mitigate is that the test script execute/continue before the backgrounded
command (background test app) had time to execute, right?

Quoted 8 lines
Quoted 8 lines

If so at least waiting for the app to create a file is necessary. Now gen_kernel_test_events does not have this functionality. The PATH_WAIT_FILE is
used to control when the testapp can continue. Hence the script still cannot
know if the app have been scheduled.

Now based on the test case you might need more synchronization for the

test

Quoted 8 lines
Quoted 8 lines

cases.

Note that in the ust cases, the trace_ust_app uses touch "$BEFORE_LAST_PATH"
that effectively unblock the app and allows it to perform the last tracepoint
hit and the we wait on the background process.

Quoted 5 lines
Quoted 5 lines

Note: some tests case are a bit clever and uses "trace_"$domain"_app" instead of
calling trace_ust_app directly.

For these tests case it seems that we are only expecting at least a

single

Quoted 7 lines
Quoted 7 lines

event
matching the event name under test. Here the last tracepoint hit should satisfy
this criteria.

Am I missing a race?

Quoted 7 lines
Quoted 7 lines

Cheers

Quoted 1 line

I suggest that we add an option to gen-ust-events to wait before the

first

Quoted 2 lines

event is generated.
gen_kernel_test_events already have this functionality to wait

before the

Quoted 46 lines
Quoted 46 lines
Quoted 30 lines

first event.

Something like this
static struct option long_options[] =
{
/* These options set a flag. */
{"iter", required_argument, 0, 'i'},
{"wait", required_argument, 0, 'w'}, {"sync-after-first-event", required_argument, 0, 'a'}, {"sync-before-last-event", required_argument, 0, 'b'}, {"sync-before-last-event-touch", required_argument, 0, 'c'}, {"sync-before-exit", required_argument, 0, 'd'}, {"sync-before-exit-touch", required_argument, 0, 'e'}, *+ {"sync-before-first-event", required_argument, 0, 'f'},*

{0, 0, 0, 0}
};
....

I will create one or more patches for this tomorrow

Anders Wallin

Quoted 3 lines · Jonathan Rajotte-Julien
Quoted 3 lines

#
# SPDX-License-Identifier: GPL-2.0-only

Quoted 8 lines
Quoted 8 lines

Review function prepare_ust_app · line 43

Quoted 8 lines
tests/regression/tools/tracker/test_event_tracker +1 -1
-TEST_DESC="LTTng - Event traker test"
+TEST_DESC="LTTng - Event tracker test"

CURDIR=$(dirname "$0")/
TESTDIR="$CURDIR/../../.."

(quoted diff) +0 -0
@@ -42,6 +42,8 @@ function prepare_ust_app
 
      $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a

"$AFTER_FIRST_PATH" -b

Quoted 6 lines
Quoted 6 lines

tests/regression/tools/tracker/test_event_tracker function prepare_ust_app · line 46

Quoted 4 lines
tests/regression/tools/tracker/test_event_tracker +2 -0
      "$BEFORE_LAST_PATH" &
      CHILD_PID=$!
+     # voluntary context switch to start $TESTAPP_BIN
+     sleep 0.1

A wait on the $AFTER_FIRST_PATH file would be probably more

deterministic

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

than a sleep here.

  while [ ! -f "${AFTER_FIRST_PATH}" ]; do
          sleep 0.1
  done

I would also expect something similar for the prepare_kernel_app function considering the same race is most probably present and

simply

Quoted 4 lines
Quoted 4 lines

not

Quoted 3 lines
Quoted 3 lines

triggered by a chance of luck.
Seems like gen-kernel-test-events does not expose the same sync capabilities here, please use gen-ust-events as an example of how

it is

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
Quoted 6 lines

done.

Let us know how your testing goes.

Thanks

Quoted 9 lines
Quoted 4 lines
Quoted 4 lines

--
Jonathan Rajotte-Julien
EfficiOS

--
Jonathan Rajotte-Julien
EfficiOS

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

#7 lore raw
In reply to Anders Wallin via lttng-dev
Quoted 26 lines · ----- On Mar 31, 2021, at 2:56 PM, lttng-dev [email protected] wrote:

the following tests fails on arm64
- test_event_vpid_tracker ust 0 "${EVENT_NAME}"
- test_event_vpid_track_untrack ust 0 "${EVENT_NAME}"
- test_event_pid_tracker ust 0 "${EVENT_NAME}"
- test_event_pid_track_untrack ust 0 "${EVENT_NAME}"

---
tests/regression/tools/tracker/test_event_tracker | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
tests/regression/tools/tracker/test_event_tracker +1 -1
index 711690af..649c7e61 100755
@@ -5,7 +5,7 @@
 #
 # SPDX-License-Identifier: GPL-2.0-only
 
-TEST_DESC="LTTng - Event traker test"
+TEST_DESC="LTTng - Event tracker test"
 

CURDIR=$(dirname "$0")/
TESTDIR="$CURDIR/../../.."

tests/regression/tools/tracker/test_event_tracker function prepare_ust_app · line 47

Quoted 6 lines
tests/regression/tools/tracker/test_event_tracker +2 -0
@@ -42,6 +42,8 @@ function prepare_ust_app
 
 	$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a "$AFTER_FIRST_PATH" -b
 	"$BEFORE_LAST_PATH" &
 	CHILD_PID=$!
+	# voluntary context switch to start $TESTAPP_BIN
+	sleep 0.1

No, we have been bitten again and again by test issues hidden by sleeps in the test code. Using sleeps for synchronization is flaky.

I don't know if we documented it, but we as maintainers are strongly against anything that looks like a delay-based approach to fixing a race in the tests. This typically just bury the race under the carpet and it shows up only in specific conditions on the CI workers.

We need to add proper rendez-vous based synchronization to the test if some is missing.

Adding Jérémie in CC.

Thanks,

Mathieu

Quoted 10 lines
tests/regression/tools/tracker/test_event_tracker +0 -0
 }
 

function trace_ust_app
--
2.31.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#8 lore raw
Quoted 43 lines · ----- On Apr 1, 2021, at 12:19 PM, lttng-dev [email protected] wrote:
Quoted 26 lines · ----- On Mar 31, 2021, at 2:56 PM, lttng-dev [email protected] wrote:

the following tests fails on arm64
- test_event_vpid_tracker ust 0 "${EVENT_NAME}"
- test_event_vpid_track_untrack ust 0 "${EVENT_NAME}"
- test_event_pid_tracker ust 0 "${EVENT_NAME}"
- test_event_pid_track_untrack ust 0 "${EVENT_NAME}"

---
tests/regression/tools/tracker/test_event_tracker | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
tests/regression/tools/tracker/test_event_tracker +1 -1
index 711690af..649c7e61 100755
@@ -5,7 +5,7 @@
 #
 # SPDX-License-Identifier: GPL-2.0-only
 
-TEST_DESC="LTTng - Event traker test"
+TEST_DESC="LTTng - Event tracker test"
 

CURDIR=$(dirname "$0")/
TESTDIR="$CURDIR/../../.."

tests/regression/tools/tracker/test_event_tracker function prepare_ust_app · line 47

Quoted 6 lines
tests/regression/tools/tracker/test_event_tracker +2 -0
@@ -42,6 +42,8 @@ function prepare_ust_app
 
 	$TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a "$AFTER_FIRST_PATH" -b
 	"$BEFORE_LAST_PATH" &
 	CHILD_PID=$!
+	# voluntary context switch to start $TESTAPP_BIN
+	sleep 0.1

No, we have been bitten again and again by test issues hidden by sleeps in the test code. Using sleeps for synchronization is flaky.

I don't know if we documented it, but we as maintainers are strongly against anything that looks like a delay-based approach to fixing a race in the tests. This typically just bury the race under the carpet and it shows up only in specific conditions on the CI workers.

Quoted 4 lines

We need to add proper rendez-vous based synchronization to the test if some is missing.

Adding Jérémie in CC.

And then I read on the rest of the email thread... so it's being taken care of, good! :)

Thanks,

Mathieu

Quoted 25 lines

Thanks,

Mathieu

Quoted 10 lines
tests/regression/tools/tracker/test_event_tracker +0 -0
 }
 

function trace_ust_app
--
2.31.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Signature · 7 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
#9 lore raw
In reply to Mathieu Desnoyers via lttng-dev

I agree, new version on the way w/o sleep!
Anders Wallin

Quoted 68 lines · Mathieu Desnoyers

----- On Mar 31, 2021, at 2:56 PM, lttng-dev [email protected]

Quoted 26 lines · wrote:

the following tests fails on arm64
- test_event_vpid_tracker ust 0 "${EVENT_NAME}"
- test_event_vpid_track_untrack ust 0 "${EVENT_NAME}"
- test_event_pid_tracker ust 0 "${EVENT_NAME}"
- test_event_pid_track_untrack ust 0 "${EVENT_NAME}"

---
tests/regression/tools/tracker/test_event_tracker | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)
tests/regression/tools/tracker/test_event_tracker +1 -1
index 711690af..649c7e61 100755
@@ -5,7 +5,7 @@
 #
 # SPDX-License-Identifier: GPL-2.0-only
 
-TEST_DESC="LTTng - Event traker test"
+TEST_DESC="LTTng - Event tracker test"
 

CURDIR=$(dirname "$0")/
TESTDIR="$CURDIR/../../.."

tests/regression/tools/tracker/test_event_tracker function prepare_ust_app · line 47

Quoted 6 lines
tests/regression/tools/tracker/test_event_tracker +2 -0
@@ -42,6 +42,8 @@ function prepare_ust_app
 
      $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT -a "$AFTER_FIRST_PATH" -b
      "$BEFORE_LAST_PATH" &
      CHILD_PID=$!
+     # voluntary context switch to start $TESTAPP_BIN
+     sleep 0.1

No, we have been bitten again and again by test issues hidden by sleeps in the
test code. Using sleeps for synchronization is flaky.

I don't know if we documented it, but we as maintainers are strongly against
anything that looks like a delay-based approach to fixing a race in the tests.
This typically just bury the race under the carpet and it shows up only in specific conditions on the CI workers.

We need to add proper rendez-vous based synchronization to the test if some is missing.

Adding Jérémie in CC.

Thanks,

Mathieu

Quoted 10 lines
tests/regression/tools/tracker/test_event_tracker +0 -0
 }
 

function trace_ust_app
--
2.31.1

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Quoted 5 lines

--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

_______________________________________________
lttng-dev mailing list
[email protected]
https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev