[VM/Timeline] Add a synchronization monitor to TimelineTrackMetadataRace test

The test is still timing out on many configurations. Hopefully changing
the spin lock to a monitor fixes this.

TEST=TSAN, CI

Issue: https://github.com/dart-lang/sdk/issues/51654
Change-Id: I03d1199c18a225bbd621613211ef6a4ceee93ac7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/289000
Commit-Queue: Derek Xu <derekx@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Derek Xu 2023-03-16 17:46:28 +00:00 committed by Commit Queue
parent 51d5eb6e93
commit ec39319bf7

View file

@ -382,10 +382,12 @@ TEST_CASE(TimelineRingRecorderJSONOrder) {
TEST_CASE(TimelineTrackMetadataRace) {
struct ReportMetadataArguments {
TimelineEventRingRecorder* recorder;
Monitor& synchronization_monitor;
TimelineEventRingRecorder& recorder;
ThreadJoinId join_id = OSThread::kInvalidThreadJoinId;
};
Monitor synchronization_monitor;
TimelineEventRingRecorder recorder;
// Try concurrently reading from / writing to the metadata map. I don't think
@ -394,17 +396,21 @@ TEST_CASE(TimelineTrackMetadataRace) {
// map code.
JSONStream js;
TimelineEventFilter filter;
ReportMetadataArguments report_metadata_1_arguments{&recorder};
ReportMetadataArguments report_metadata_2_arguments{&recorder};
ReportMetadataArguments report_metadata_1_arguments{synchronization_monitor,
recorder};
ReportMetadataArguments report_metadata_2_arguments{synchronization_monitor,
recorder};
OSThread::Start(
"ReportMetadata1",
[](uword arguments_ptr) {
ReportMetadataArguments& arguments =
*reinterpret_cast<ReportMetadataArguments*>(arguments_ptr);
arguments.recorder->AddTrackMetadataBasedOnThread(
arguments.recorder.AddTrackMetadataBasedOnThread(
FAKE_PROCESS_ID, FAKE_TRACE_ID, "Thread 1");
MonitorLocker ml(&arguments.synchronization_monitor);
arguments.join_id =
OSThread::GetCurrentThreadJoinId(OSThread::Current());
ml.Notify();
},
reinterpret_cast<uword>(&report_metadata_1_arguments));
OSThread::Start(
@ -412,17 +418,20 @@ TEST_CASE(TimelineTrackMetadataRace) {
[](uword arguments_ptr) {
ReportMetadataArguments& arguments =
*reinterpret_cast<ReportMetadataArguments*>(arguments_ptr);
arguments.recorder->AddTrackMetadataBasedOnThread(
arguments.recorder.AddTrackMetadataBasedOnThread(
FAKE_PROCESS_ID, FAKE_TRACE_ID, "Incorrect Name");
MonitorLocker ml(&arguments.synchronization_monitor);
arguments.join_id =
OSThread::GetCurrentThreadJoinId(OSThread::Current());
ml.Notify();
},
reinterpret_cast<uword>(&report_metadata_2_arguments));
recorder.PrintJSON(&js, &filter);
MonitorLocker ml(&synchronization_monitor);
while (
report_metadata_1_arguments.join_id == OSThread::kInvalidThreadJoinId ||
report_metadata_2_arguments.join_id == OSThread::kInvalidThreadJoinId) {
// Spin until the join IDs have been set.
ml.Wait();
}
OSThread::Join(report_metadata_1_arguments.join_id);
OSThread::Join(report_metadata_2_arguments.join_id);