|
1 | 1 | // RUN: %empty-directory(%t)
|
2 | 2 | // RUN: %target-build-swift -module-name main %s -o %t/hash
|
3 |
| -// RUN: (export -n %env-SWIFT_DETERMINISTIC_HASHING; %target-run %t/hash && %target-run %t/hash) | %FileCheck %s |
4 |
| -// REQUIRES: executable_test |
| 3 | +// RUN: (export -n %env-SWIFT_DETERMINISTIC_HASHING; %target-run %t/hash && %target-run %t/hash) | %FileCheck --check-prefixes=RANDOM %s |
| 4 | +// RUN: (export %env-SWIFT_DETERMINISTIC_HASHING=1; %target-run %t/hash && %target-run %t/hash) | %FileCheck --check-prefixes=STABLE %s |
5 | 5 |
|
6 | 6 | // This check verifies that the hash seed is randomly generated on every
|
7 |
| -// execution of a Swift program. There is a minuscule chance that the same seed |
8 |
| -// is generated on two separate executions; however, a test failure here is more |
9 |
| -// likely to indicate an issue with the random number generator or the testing |
10 |
| -// environment. |
| 7 | +// execution of a Swift program unless the SWIFT_DETERMINISTIC_HASHING |
| 8 | +// environment variable is set. |
11 | 9 |
|
12 | 10 | print("Deterministic: \(_Hasher._isDeterministic)")
|
13 | 11 | print("Seed: \(_Hasher._seed)")
|
14 | 12 | print("Hash values: <\(0.hashValue), \(1.hashValue)>")
|
15 | 13 |
|
16 |
| -// On the first run, remember the seed and hash value. |
17 |
| -// CHECK: Deterministic: false |
18 |
| -// CHECK-NEXT: Seed: [[SEED0:\([0-9]+, [0-9]+\)]] |
19 |
| -// CHECK-NEXT: Hash values: [[HASH0:<-?[0-9]+, -?[0-9]+>]] |
| 14 | +// With randomized hashing, we get a new seed and a new set of hash values on |
| 15 | +// each run. There is a minuscule chance that the same seed is generated on two |
| 16 | +// separate executions; however, a test failure here is more likely to indicate |
| 17 | +// an issue with the random number generator or the testing environment. |
| 18 | +// RANDOM: Deterministic: false |
| 19 | +// RANDOM-NEXT: Seed: [[SEED0:\([0-9]+, [0-9]+\)]] |
| 20 | +// RANDOM-NEXT: Hash values: [[HASH0:<-?[0-9]+, -?[0-9]+>]] |
| 21 | +// RANDOM-NEXT: Deterministic: false |
| 22 | +// RANDOM-NEXT: Seed: |
| 23 | +// RANDOM-NOT: [[SEED0]] |
| 24 | +// RANDOM-NEXT: Hash values: |
| 25 | +// RANDOM-NOT: [[HASH0]] |
20 | 26 |
|
21 |
| -// Check that the values are different on the second run. |
22 |
| -// CHECK-NEXT: Deterministic: false |
23 |
| -// CHECK-NEXT: Seed: |
24 |
| -// CHECK-NOT: [[SEED0]] |
25 |
| -// CHECK-NEXT: Hash values: |
26 |
| -// CHECK-NOT: [[HASH0]] |
| 27 | +// Stable runs have known seeds, and generate the same hash values. A test |
| 28 | +// failure here indicates that the seed override mechanism isn't working |
| 29 | +// correctly. |
| 30 | +// STABLE: Deterministic: true |
| 31 | +// STABLE-NEXT: Seed: (0, 0) |
| 32 | +// STABLE-NEXT: Hash values: [[HASH1:<-?[0-9]+, -?[0-9]+>]] |
| 33 | +// STABLE-NEXT: Deterministic: true |
| 34 | +// STABLE-NEXT: Seed: (0, 0) |
| 35 | +// STABLE-NEXT: Hash values: [[HASH1]] |
0 commit comments