[clang] e76a9f1 - [clang][deps] Fix fragile test

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 27 05:00:54 PDT 2021


Author: Jan Svoboda
Date: 2021-10-27T14:00:13+02:00
New Revision: e76a9f16363c4a37b2b68da816a7bc2de0e7965e

URL: https://github.com/llvm/llvm-project/commit/e76a9f16363c4a37b2b68da816a7bc2de0e7965e
DIFF: https://github.com/llvm/llvm-project/commit/e76a9f16363c4a37b2b68da816a7bc2de0e7965e.diff

LOG: [clang][deps] Fix fragile test

This test was failing on GreenDragon.

Added: 
    clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_a.json.template
    clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template

Modified: 
    clang/test/ClangScanDeps/modules-context-hash.c

Removed: 
    clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template


################################################################################
diff  --git a/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template b/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_a.json.template
similarity index 50%
rename from clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template
rename to clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_a.json.template
index 81f7084ca8854..60438df0fb339 100644
--- a/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb.json.template
+++ b/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_a.json.template
@@ -3,10 +3,5 @@
     "directory": "DIR",
     "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/a -o DIR/tu_a.o",
     "file": "DIR/tu.c"
-  },
-  {
-    "directory": "DIR",
-    "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/b -o DIR/tu_b.o",
-    "file": "DIR/tu.c"
   }
 ]

diff  --git a/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template b/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template
new file mode 100644
index 0000000000000..3a4ec35943370
--- /dev/null
+++ b/clang/test/ClangScanDeps/Inputs/modules-context-hash/cdb_b.json.template
@@ -0,0 +1,7 @@
+[
+  {
+    "directory": "DIR",
+    "command": "clang -c DIR/tu.c -fmodules -fmodules-cache-path=DIR/cache -IDIR/b -o DIR/tu_b.o",
+    "file": "DIR/tu.c"
+  }
+]

diff  --git a/clang/test/ClangScanDeps/modules-context-hash.c b/clang/test/ClangScanDeps/modules-context-hash.c
index 0b9a3e085ee6b..dfa3328335ef6 100644
--- a/clang/test/ClangScanDeps/modules-context-hash.c
+++ b/clang/test/ClangScanDeps/modules-context-hash.c
@@ -5,9 +5,17 @@
 // a single translation unit gets compiled with multiple command-lines that
 // produce 
diff erent **strict** context hashes.
 
-// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb.json.template > %t/cdb.json
+// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_a.json.template > %t/cdb_a.json
+// RUN: sed "s|DIR|%/t|g" %S/Inputs/modules-context-hash/cdb_b.json.template > %t/cdb_b.json
+
+// We run two separate scans. The context hash for "a" and "b" can 
diff er between
+// systems. If we'd scan both Clang invocations in a single run, the order of JSON
+// entities would be non-deterministic. To prevent this, run the scans separately
+// and verify that the context hashes 
diff er with a single FileCheck invocation.
+//
 // RUN: echo -%t > %t/result.json
-// RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full -j 1 >> %t/result.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_a.json -format experimental-full -j 1 >> %t/result.json
+// RUN: clang-scan-deps -compilation-database %t/cdb_b.json -format experimental-full -j 1 >> %t/result.json
 // RUN: cat %t/result.json | sed 's:\\\\\?:/:g' | FileCheck %s -check-prefix=CHECK
 
 // CHECK:      -[[PREFIX:.*]]
@@ -30,24 +38,6 @@
 // CHECK-NEXT:         "[[PREFIX]]/module.modulemap"
 // CHECK-NEXT:       ],
 // CHECK-NEXT:       "name": "mod"
-// CHECK-NEXT:     },
-// CHECK-NEXT:     {
-// CHECK-NEXT:       "clang-module-deps": [],
-// CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
-// CHECK-NEXT:       "command-line": [
-// CHECK-NEXT:         "-cc1"
-// CHECK:              "-emit-module"
-// CHECK:              "-I"
-// CHECK:              "[[PREFIX]]/b"
-// CHECK:              "-fmodule-name=mod"
-// CHECK:            ],
-// CHECK-NEXT:       "context-hash": "[[HASH_MOD_B:.*]]",
-// CHECK-NEXT:       "file-deps": [
-// CHECK-NEXT:         "[[PREFIX]]/b/dep.h",
-// CHECK-NEXT:         "[[PREFIX]]/mod.h",
-// CHECK-NEXT:         "[[PREFIX]]/module.modulemap"
-// CHECK-NEXT:       ],
-// CHECK-NEXT:       "name": "mod"
 // CHECK-NEXT:     }
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "translation-units": [
@@ -67,13 +57,37 @@
 // CHECK-NEXT:         "[[PREFIX]]/tu.c"
 // CHECK-NEXT:       ],
 // CHECK-NEXT:       "input-file": "[[PREFIX]]/tu.c"
-// CHECK-NEXT:     },
+// CHECK-NEXT:     }
+// CHECK-NEXT:   ]
+// CHECK-NEXT: }
+// CHECK-NEXT: {
+// CHECK-NEXT:   "modules": [
+// CHECK-NEXT:     {
+// CHECK-NEXT:       "clang-module-deps": [],
+// CHECK-NEXT:       "clang-modulemap-file": "[[PREFIX]]/module.modulemap",
+// CHECK-NEXT:       "command-line": [
+// CHECK-NEXT:         "-cc1"
+// CHECK:              "-emit-module"
+// CHECK:              "-I"
+// CHECK:              "[[PREFIX]]/b"
+// CHECK:              "-fmodule-name=mod"
+// CHECK:            ],
+// CHECK-NOT:        "context-hash": "[[HASH_MOD_A]]",
+// CHECK:            "file-deps": [
+// CHECK-NEXT:         "[[PREFIX]]/b/dep.h",
+// CHECK-NEXT:         "[[PREFIX]]/mod.h",
+// CHECK-NEXT:         "[[PREFIX]]/module.modulemap"
+// CHECK-NEXT:       ],
+// CHECK-NEXT:       "name": "mod"
+// CHECK-NEXT:     }
+// CHECK-NEXT:   ],
+// CHECK-NEXT:   "translation-units": [
 // CHECK-NEXT:     {
 // CHECK-NEXT:       "clang-context-hash": "{{.*}}",
 // CHECK-NEXT:       "clang-module-deps": [
 // CHECK-NEXT:         {
-// CHECK-NEXT:           "context-hash": "[[HASH_MOD_B]]",
-// CHECK-NEXT:           "module-name": "mod"
+// CHECK-NOT:            "context-hash": "[[HASH_MOD_A]]",
+// CHECK:                "module-name": "mod"
 // CHECK-NEXT:         }
 // CHECK-NEXT:       ],
 // CHECK-NEXT:       "command-line": [


        


More information about the cfe-commits mailing list