Skip to content

Commit 571522e

Browse files
authored
Merge pull request #15269 from lorentey/static-snow
[test] Merge hash determinism/randomisation tests
2 parents 821bfdb + 05168d7 commit 571522e

File tree

2 files changed

+25
-22
lines changed

2 files changed

+25
-22
lines changed

validation-test/stdlib/Hashing.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,4 @@ HashingTestSuite.test("_Hasher/DefaultKey") {
5757
expectEqual(customHasher.finalize(), defaultHash)
5858
}
5959

60-
HashingTestSuite.test("_Hasher/determinism") {
61-
// By defaults, tests are configured to run with deterministic hashing.
62-
expectTrue(_Hasher._isDeterministic)
63-
expectEqual((0, 0), _Hasher._seed)
64-
}
65-
6660
runAllTests()
Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
// RUN: %empty-directory(%t)
22
// 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
55

66
// 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.
119

1210
print("Deterministic: \(_Hasher._isDeterministic)")
1311
print("Seed: \(_Hasher._seed)")
1412
print("Hash values: <\(0.hashValue), \(1.hashValue)>")
1513

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]]
2026

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

Comments
 (0)