Refactor test name truncation

Refactors the logic used for determining if test names need to be
truncated in order to fit within the 256 character limit for ResultDB.

Previously, we checked if the test class + some fixed value + the
sanitized name was less than some arbitrary number of characters. This
was problematic since it did not cleanly take into account any prefixes
added to the test class or test names that were significantly longer
than the fixed value we used, leading to cases where tests were not
truncated when they should be.

Now, we keep track of the longest test name we've seen in the wild and
truncate if that + the sanitized parameters are over a threshold.

Bug: 413427416
Change-Id: I097f7a9f58ab5f2d74f61d0750e1fb60c3fa167f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/261440
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Auto-Submit: Brian Sheedy <bsheedy@google.com>
diff --git a/src/dawn/tests/DawnTest.cpp b/src/dawn/tests/DawnTest.cpp
index 380bc9c..f8e1b9e 100644
--- a/src/dawn/tests/DawnTest.cpp
+++ b/src/dawn/tests/DawnTest.cpp
@@ -166,16 +166,20 @@
         sanitizedName.resize(sanitizedName.length() - 1);
     }
 
-    // We don't know the test name at this point, but the format usually looks like
-    // this.
-    std::string prefix = mTest + ".TheTestNameUsuallyGoesHere/";
-    std::string testFormat = prefix + sanitizedName;
-    if (testFormat.length() > 210) {
+    // We don't know the test name, so assume that it is the longest one we
+    // have found in the wild for the purposes of calculating length.
+    std::string longestKnownTest =
+        (std::string("OpenGLES_EGLSync/SharedTextureMemoryTests.") +
+         std::string("GetPropertiesAHardwareBufferPropertiesRequiresAHBFeature/"));
+    std::string testFormat = longestKnownTest + sanitizedName;
+    if (testFormat.length() > 240) {
         // The bots don't support test names longer than 256. Shorten the name and append a unique
         // index if we're close. The failure log will still print the full param name.
+        // We use a number < 256 to leave a bit of buffer in case a new test gets added that is
+        // slightly longer than our longest known test.
         std::string suffix = std::string("__") + std::to_string(index);
         size_t targetLength = sanitizedName.length();
-        targetLength -= testFormat.length() - 210;
+        targetLength -= testFormat.length() - 240;
         targetLength -= suffix.length();
         sanitizedName.resize(targetLength);
         sanitizedName = sanitizedName + suffix;