Skip to content

[gen] Rework on printing generated litmus tests#1582

Open
ShaleXIONG wants to merge 17 commits intoherd:masterfrom
ShaleXIONG:fix-init
Open

[gen] Rework on printing generated litmus tests#1582
ShaleXIONG wants to merge 17 commits intoherd:masterfrom
ShaleXIONG:fix-init

Conversation

@ShaleXIONG
Copy link
Copy Markdown
Collaborator

@ShaleXIONG ShaleXIONG commented Nov 18, 2025

This pull request replaces the diy manual test printing by lib/simpledumper.ml. It fixes two main problems for the initialisation list.

  • Incorrect array initialisation, for example, changing int y[2]; y=5 to int y[2] = {5,5}.
  • Using square bracket syntax for pte initialisation [PTE(x)].

A good example is diyone7 -arch AArch64 -variant kvm PodRW Pa Rfe PodRW PteV1 Rfe. The new result shows at the end of this message.

Separately, we made major rework to top_gen.ml and final.ml in the internal code of printing litmus test. It now use lib/SimpleDumper directly rather than manually print out all the information. This simplifies the code and ensure the formatting is consistent with other tools in this repo. The new formatting can be seen below. Notice that

  • the "PodRWPPa RfePaP PodRWPPteV1 RfePteV1P" is now at the end of prelude,
  • all the white space are the result of SimpleDumper,
  • the code label, e.g. L00, now is on the same line as the instruction, and
  • the fault in post-condition now is in lower case and logical negation is not rather than ~.

Last, we add automatic Variant= ... based on the diy* argument -variant .... This enables herd7 directly configure the expected variant.

AArch64 LB+popptev1+poppa
Com=Rf Rf
Generator=diyone7 (version 7.58+1)
Orig=PodRWPPa RfePaP PodRWPPteV1 RfePteV1P
Prefetch=0:x=F,0:y=W,1:y=F,1:x=W
Variant=vmsa
"PodRWPPa RfePaP PodRWPPteV1 RfePteV1P"
{
 [x]=1;
 [PTE(x)]=(oa:PA(x), valid:0);
 int y[2]={5,5};
 0:X0=x; 0:X2=y;
 1:X2=y; 1:X3=PTE(x); 1:X4=(oa:PA(x));
}
 P0               | P1          ;
 L00: LDR W1,[X0] | LDR W1,[X2] ;
 MOV W3,#7        | STR X4,[X3] ;
 SUB W4,W3,#1     |             ;
 STP W4,W3,[X2]   |             ;

exists (1:X1=6 /\ not (fault(P0:L00,x)))

It now has the same syntax as the mprog7 -mode text tool.

@ShaleXIONG ShaleXIONG force-pushed the fix-init branch 2 times, most recently from 9514464 to fa9bf99 Compare November 18, 2025 19:24
@ShaleXIONG ShaleXIONG marked this pull request as draft December 30, 2025 17:58
@ShaleXIONG ShaleXIONG changed the title [gen] Fix problems on the the initialisation list on array and vmsa [WIP][gen] Fix problems on the the initialisation list on array and vmsa Dec 30, 2025
@ShaleXIONG ShaleXIONG force-pushed the fix-init branch 4 times, most recently from a03a2a5 to 79f9939 Compare January 2, 2026 10:32
@ShaleXIONG ShaleXIONG changed the title [WIP][gen] Fix problems on the the initialisation list on array and vmsa [gen] Fix problems on the the initialisation list on array and vmsa Jan 2, 2026
@ShaleXIONG ShaleXIONG marked this pull request as ready for review January 2, 2026 14:13
@ShaleXIONG ShaleXIONG changed the title [gen] Fix problems on the the initialisation list on array and vmsa [gen] Rework on printing litmus tests Jan 2, 2026
@ShaleXIONG ShaleXIONG changed the title [gen] Rework on printing litmus tests [gen] Rework on printing generated litmus tests Jan 2, 2026
@ShaleXIONG ShaleXIONG force-pushed the fix-init branch 2 times, most recently from 3ab4c89 to cb5b268 Compare January 6, 2026 14:06
@ShaleXIONG ShaleXIONG requested a review from fsestini January 13, 2026 10:12
Copy link
Copy Markdown
Collaborator

@murzinv murzinv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How automatic insert of variant deal with

-info add metadata to generated test(s)

?
The reason I'm asking is that another way to inject variant into litmus test is using -info, for instance -info "variant=memtag". Now if combined with automatic variant insertion is would add two variants into the test and upset herd7

Warning: File "T.litmus": Duplicated meta-data on key Variant
 (User error)

@ShaleXIONG
Copy link
Copy Markdown
Collaborator Author

ShaleXIONG commented Jan 13, 2026

How automatic insert of variant deal with

-info add metadata to generated test(s)

? The reason I'm asking is that another way to inject variant into litmus test is using -info, for instance -info "variant=memtag". Now if combined with automatic variant insertion is would add two variants into the test and upset herd7

Warning: File "T.litmus": Duplicated meta-data on key Variant
 (User error)

[update] I managed to merge -info with the internal prelude by concat all the value in string if the key is the same in both -info and in the internal.

@ShaleXIONG ShaleXIONG force-pushed the fix-init branch 2 times, most recently from c803d25 to 66b54e0 Compare March 2, 2026 11:05
Shale Xiong added 6 commits March 4, 2026 16:33
This commit reworks `top_gen.ml` and `final.ml`, which now uses the
module `SimpleDumper` to format and print litmus tests.
- fix the `-metadata` in the new litmus print, so it correctly switch on
  and off on metadata.
- Fix multiple variants entry
- Rework on the code so it better to understand with some comments.
Replace the location type in archExtra_gen.ml by the `lib/location.ml`
@fsestini
Copy link
Copy Markdown
Collaborator

I will have a proper look at the code ASAP, but as a quick comment: I have a question about a change to the final conditions of generarted litmus tests introduced by this PR. For example, when running your example CLI command on current master:

$ dune exec diyone7 -- -arch AArch64 -variant kvm  PodRW Pa Rfe PodRW PteV1 Rfe -cond unicond
AArch64 LB+popptev1+poppa
"PodRWPPa RfePaP PodRWPPteV1 RfePteV1P"
Generator=diyone7 (version 7.58+1)
Prefetch=0:x=F,0:y=W,1:y=F,1:x=W
Com=Rf Rf
Orig=PodRWPPa RfePaP PodRWPPteV1 RfePteV1P
{
int y[2];
 int x=1; PTE(x)=(oa:PA(x), valid:0); y=5;
0:X0=x; 0:X2=y;
1:X2=y; 1:X3=PTE(x); 1:X4=(oa:PA(x));
}
 P0             | P1          ;
 L00:           | LDR W1,[X2] ;
 LDR W1,[X0]    | STR X4,[X3] ;
 MOV W3,#7      |             ;
 SUB W4,W3,#1   |             ;
 STP W4,W3,[X2] |             ;
forall (x=(oa:PA(x)) /\ (y=7 /\ (1:X1=7 \/ 1:X1=0))) /\ ~Fault(P0:L00,x)

But if I run the same command on top of this PR, I get:

$ dune exec diyone7 -- -arch AArch64 -variant kvm  PodRW Pa Rfe PodRW PteV1 Rfe -cond unicond
AArch64 LB+popptev1+poppa
Com=Rf Rf
Generator=diyone7 (version 7.58+1)
Orig=PodRWPPa RfePaP PodRWPPteV1 RfePteV1P
Prefetch=0:x=F,0:y=W,1:y=F,1:x=W
Variant=vmsa
"PodRWPPa RfePaP PodRWPPteV1 RfePteV1P"
{
 [x]=1;
 [PTE(x)]=(oa:PA(x), valid:0);
 int y[2]={5,5};
 0:X0=x; 0:X2=y;
 1:X2=y; 1:X3=PTE(x); 1:X4=(oa:PA(x));
}
 P0               | P1          ;
 L00: LDR W1,[X0] | LDR W1,[X2] ;
 MOV W3,#7        | STR X4,[X3] ;
 SUB W4,W3,#1     |             ;
 STP W4,W3,[X2]   |             ;

forall (not (fault(P0:L00,x)) \/ [x]=(oa:PA(x)) /\ ([y]=7 /\ (1:X1=7 \/ 1:X1=0)))

You can see that the final condition in the second run relates the fault proposition and the values propositions disjunctively, but the first run relates them conjunctively, which is a stronger assertion logically speaking. Is this intended, and if so, what is the rationale?

@ShaleXIONG
Copy link
Copy Markdown
Collaborator Author

ShaleXIONG commented Mar 13, 2026

diyone7 -- -arch AArch64 -variant kvm PodRW Pa Rfe PodRW PteV1 Rfe -cond unicond

This is a mistake. I just patched.

=To help you review, if you think it is helpful, we can have a chat in person or zoom and just go through code together, since there are many structure changes.

(add_args env c,f (F.FaultSet.empty,F.FaultSet.empty)),
F.run evts m flts
| Cycle -> F.check ~is_pos:true f flts
| Observe -> F.exist_true in
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, why is this set to F.exist_true in all cases?

Prior to this change, the command dune exec diyone7 -- -arch C PodWW Rfe PodRR Fre -cond observe would generate locations in the final condition, but now only generates exists (true).

Actually, other architectures as well now seem to always include this exists (true) line:

$ dune exec diyone7 -- -arch AArch64 PodWW Rfe PodRR Fre -cond observe
AArch64 MP
Com=Rf Fr
...
STR W2,[X3] |             ;

locations [x; y; 1:X0; 1:X2;]
exists (true)

Copy link
Copy Markdown
Collaborator Author

@ShaleXIONG ShaleXIONG Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the goal of this change is to line up with mprog7 -mode text. In the case where only exists locations [...], the tool mprog7 actually append a forall (true). I will match the behaviour there.

Regarding questions on when location[...] yields a different result in herd7, the example is diyone7 -variant vmsa -arch AArch64 PteV1 PodWW Rfe PodRR Fre -cond observe. The location contains fault(P1:L00,x). This requests herd7 to show the fault information in all stages.

gen/top_gen.ml Outdated
Comment on lines +1030 to +1037
let merge_info lhs rhs =
let mk_map info =
List.map ( fun (k,v) -> String.capitalize_ascii k,v ) info
|> List.to_seq |> StringMap.of_seq in
StringMap.union
( fun v1 v2 -> v1 ^ " " ^ v2 ) (mk_map lhs) (mk_map rhs)
|> StringMap.to_seq
|> List.of_seq
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the variants are sorted by key, which means the following comment by @relokin is still not implemented:

The variant should appear before the metadata, if not after all the metadata.

For example, if I run:

$ dune exec diyone7 -- -oneloc -variant mixed,MixedDisjoint -arch AArch64 h2 PosWW h0 Rfe Fre -hexa -info 'Z=foo'
AArch64 WW+R+posh2h0+w0
Com=Rf Fr
Generator=diyone7 (version 7.58+1)
Orig=PosWWh2h0 Rfeh0w0 Frew0h2
Variant=mixed
Z=foo
"PosWWh2h0 Rfeh0w0 Frew0h2"
{
 uint32_t 0:X0=0; 0:X1=x; uint32_t 0:X2=0;
...

The Variant key/value pair appears in between other metadata.

Code-wise, I don't see why we couldn't sort the keys via List.sort or similar, rather than StringMap.

Copy link
Copy Markdown
Collaborator Author

@ShaleXIONG ShaleXIONG Mar 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I update it in a way that the rhs will be merged into the lhs. Also I realised if the key collides, for example internal and user-defined, or between two user-defined. The value will be concatenate.

In the case of Variant it is in fact ok to have Variant = memtag memtag for herd7.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more request please. Can we make sure that the variant is always printed. That's even when I do -metadata false.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And similarly for TTHM, -metadata false shouldn't hide. Also TTHM should appear right after the Variant=....

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good point ! I will update now.

Shale Xiong added 4 commits March 18, 2026 12:57
- Change `check` and `run` to `exists_condition` and `forall_condition`
- Change `observe` to `location_list`
- Add an `observe_condition` to generate final condition, `forall(true)`
  when `-cond observe`.
@ShaleXIONG ShaleXIONG force-pushed the fix-init branch 2 times, most recently from bcee036 to 5f46e15 Compare March 20, 2026 09:29
Also fix a mistake when `prefetch` is emtpy, it now print no prefetch.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants