Skip to content

Commit e8bc323

Browse files
luisleo526claude
andcommitted
Tests: the quiet-bar battery takes one draw per statement, so every compiler builds the same random strategies (R5 lane XPLAT1)
test_adapter_quiet_bar matched 92 of its 272 pins on x86-64 Linux (GCC 13.4 on the owner's hosts, GCC 13.3 in Docker amd64), in Release and Debug alike, and 272 of 272 on arm64 (AppleClang, GCC 13 on spark). The cause is in the test's generator, not in the engine. Three call sites in random_scenario's script made two to four draws of the battery's Random inside one call's argument list: case 4 strategy_entry(... 1.0 + s.below(3), "", s.chance(30) ? "g" : "", s.chance(30) ? 1 + s.below(2) : 0) case 7 strategy_exit(kExits[s.below(2)], id, kNa, kNa, 4.0 + s.below(8), 1.0 + s.below(4)) default strategy_order(id, is_long, 1.0 + s.below(2), s.chance(50) ? ...) C++ leaves the order in which a call's arguments are evaluated unspecified. GCC on x86-64 evaluates them right to left; Clang, and GCC on aarch64, evaluate them left to right. A three-argument probe prints 321 with GCC 13.3 and 12.2 on x86-64 (-O0 and -O2), and 123 with AppleClang 17 and GCC 13.3 on aarch64 (-O2). The pins were harvested on the Mac (arm64, AppleClang), so on x86-64 45 of the 48 random strategies issued different commands: 180 runs differed, and the battery booked 66 margin-call rows instead of 62. Every fixture run matched. First divergence, Random01 with the magnifier off and recording off: the bars, the configuration and all 15,925 generator draws of the battery are bit-identical on both platforms. At bar 1 the script takes case 7. arm64 draws below(2)=1, below(8)=5, below(4)=1 and issues strategy_exit("Y", "L", trail_points 9 [0x4022000000000000], trail_offset 2 [0x4000000000000000]). x86-64 draws below(4)=3, below(8)=5, below(2)=1 and issues the same id and points, but trail_offset 4 [0x4010000000000000]. The source folds agree through callback 1 and first differ at callback 2 (bar 2). Each draw is now its own statement, taken left to right: the order the pins were harvested with. With the draws sequenced, x86-64 reproduces all 272 pins. So on this battery, margin-call regime included, the engine computes the same values on x86-64 as on arm64. expectation corrected: harvested with a platform-dependent generator, because the random strategies drew several values inside one call's arguments, whose evaluation order C++ leaves unspecified. No pinned row changes (old -> new: identical). Re-harvested as the provenance note says, with this TU at -std=c++17 -O2 -ffp-contract=off -DPINEFORGE_QUIET_BAR_HARVEST against a Release build of f71cd82. The harvest is byte-identical on Mac arm64 (AppleClang 17), x86-64 (GCC 13.3, Docker amd64) and aarch64 (GCC 13.3, spark), with sha256 08e90197...4c6d, equal to the committed test_adapter_quiet_bar_pinned.inc. The previous TU's harvest on x86-64 differs from it in exactly the 180 failing rows. No other test in tests/ has this pattern. A scan for full-expressions that make two or more draws, counting helpers that draw inside, flagged 33 distinct statements. Apart from these three, 29 are sequenced: ?:, &&, an if-condition before its body, one draw per declarator, or a helper passed the generator by reference. The last one is a false positive with no generator. The one implementation-defined distribution (test_native_point_checks) feeds an on-machine differential, not a pin. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 08f1f5f commit e8bc323

1 file changed

Lines changed: 28 additions & 12 deletions

File tree

‎tests/test_adapter_quiet_bar.cpp‎

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@
3838
//
3939
// Portability of the pinned values: they fold one fixed execution hash
4040
// instead of the consumer's continuation (which folds tzdata content, as
41-
// test_adapter_recording_hash_witness.cpp notes), and every price sits on
42-
// the 0.25 tick. The transcript folds the real continuation: both of its
41+
// test_adapter_recording_hash_witness.cpp notes), every price sits on the
42+
// 0.25 tick, and the random strategies take each draw in a statement of its
43+
// own. The order in which a call's arguments are evaluated is unspecified:
44+
// GCC on x86-64 evaluates them right to left, Clang and GCC on aarch64 left
45+
// to right, so two draws in one argument list would give each compiler a
46+
// different battery. The transcript folds the real continuation: both of its
4347
// runs are on the same machine.
4448
//
4549
// Provenance of the pinned data: this TU, compiled unchanged against the
4650
// f71cd820 library with -DPINEFORGE_QUIET_BAR_HARVEST. Rebuild them the same
47-
// way; never edit one by hand.
51+
// way; never edit one by hand. The harvest is byte-identical with AppleClang
52+
// on arm64 and with GCC 13 on aarch64 and x86-64.
4853
#include <pineforge/pineforge.h>
4954
#include <pineforge/source/pine_strategy_host.hpp>
5055
#if defined(PINEFORGE_QUIET_BAR_WITNESS_PROBE)
@@ -659,6 +664,8 @@ Scenario random_scenario(std::uint64_t seed) {
659664
static const char* const kIds[] = {"L", "S", "A", "B"};
660665
static const char* const kExits[] = {"X", "Y"};
661666
const int commands = s.chance(55) ? 1 + s.below(3) : 0;
667+
// One draw per statement, never two in one call's arguments (see the
668+
// portability note at the top of this file).
662669
for (int k = 0; k < commands; ++k) {
663670
const char* id = kIds[s.below(4)];
664671
const bool is_long = s.chance(55);
@@ -673,20 +680,26 @@ Scenario random_scenario(std::uint64_t seed) {
673680
case 3:
674681
h.strategy_entry(id, is_long, kNa, is_long ? bar.close + off : bar.close - off);
675682
break;
676-
case 4:
677-
h.strategy_entry(id, is_long, kNa, kNa, 1.0 + s.below(3), "", s.chance(30) ? "g" : "",
678-
s.chance(30) ? 1 + s.below(2) : 0);
683+
case 4: {
684+
const double qty = 1.0 + s.below(3);
685+
const char* const oca = s.chance(30) ? "g" : "";
686+
const int oca_type = s.chance(30) ? 1 + s.below(2) : 0;
687+
h.strategy_entry(id, is_long, kNa, kNa, qty, "", oca, oca_type);
679688
break;
689+
}
680690
case 5: case 6: {
681691
const double limit = s.chance(70) ? bar.close + off : kNa;
682692
const double stop = s.chance(70) ? bar.close - off : kNa;
683693
h.strategy_exit(kExits[s.below(2)], id, limit, stop);
684694
break;
685695
}
686-
case 7:
687-
h.strategy_exit(kExits[s.below(2)], id, kNa, kNa, 4.0 + s.below(8),
688-
1.0 + s.below(4));
696+
case 7: {
697+
const char* const exit_id = kExits[s.below(2)];
698+
const double trail_points = 4.0 + s.below(8);
699+
const double trail_offset = 1.0 + s.below(4);
700+
h.strategy_exit(exit_id, id, kNa, kNa, trail_points, trail_offset);
689701
break;
702+
}
690703
case 8:
691704
if (s.chance(50)) h.strategy_close(id);
692705
else h.strategy_close(id, "", kNa, 50.0);
@@ -699,11 +712,14 @@ Scenario random_scenario(std::uint64_t seed) {
699712
if (s.chance(50)) h.strategy_cancel_all();
700713
else h.strategy_exit(kExits[s.below(2)], "", bar.close + off, bar.close - off);
701714
break;
702-
default:
703-
h.strategy_order(id, is_long, 1.0 + s.below(2),
704-
s.chance(50) ? (is_long ? bar.close - off : bar.close + off) : kNa);
715+
default: {
716+
const double qty = 1.0 + s.below(2);
717+
const double limit =
718+
s.chance(50) ? (is_long ? bar.close - off : bar.close + off) : kNa;
719+
h.strategy_order(id, is_long, qty, limit);
705720
break;
706721
}
722+
}
707723
}
708724
};
709725
char name[32];

0 commit comments

Comments
 (0)