-
Notifications
You must be signed in to change notification settings - Fork 3
Print final register and memory states #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
s-prism
wants to merge
13
commits into
main
Choose a base branch
from
x86-print-final-states
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e8612db
Print final states
s-prism 5a1b183
Refactoring
s-prism 3b21f1c
Display all relevant reg and mem locs, and combine observation count
s-prism 1e12b40
Fix formatting
s-prism bc67529
Deduplicate final states manually
s-prism 1a442e4
Change R+po+mfence test name back
s-prism fb54263
Refactoring
s-prism 44ec97d
Change lookupi_opt to lookupi
s-prism a813bee
Minor refactoring
s-prism 87cd22c
Separate logically different instances of checking if conds are satis…
s-prism 62596a3
Map 32-bit regs
s-prism acd769f
Map 16-bit regs
s-prism 534317e
Update sail-tiny-x86
s-prism File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,3 +10,4 @@ | |
| _build | ||
| _opam | ||
| .envrc | ||
| .vscode | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| (******************************************************************************) | ||
| (* ArchSem *) | ||
| (* *) | ||
| (* Copyright (c) 2021 *) | ||
| (* Thibaut Pérami, University of Cambridge *) | ||
| (* Yeji Han, Seoul National University *) | ||
| (* Zongyuan Liu, Aarhus University *) | ||
| (* Nils Lauermann, University of Cambridge *) | ||
| (* Jean Pichon-Pharabod, University of Cambridge, Aarhus University *) | ||
| (* Brian Campbell, University of Edinburgh *) | ||
| (* Alasdair Armstrong, University of Cambridge *) | ||
| (* Ben Simner, University of Cambridge *) | ||
| (* Peter Sewell, University of Cambridge *) | ||
| (* *) | ||
| (* Redistribution and use in source and binary forms, with or without *) | ||
| (* modification, are permitted provided that the following conditions *) | ||
| (* are met: *) | ||
| (* *) | ||
| (* 1. Redistributions of source code must retain the above copyright *) | ||
| (* notice, this list of conditions and the following disclaimer. *) | ||
| (* *) | ||
| (* 2. Redistributions in binary form must reproduce the above copyright *) | ||
| (* notice, this list of conditions and the following disclaimer in the *) | ||
| (* documentation and/or other materials provided with the distribution. *) | ||
| (* *) | ||
| (* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *) | ||
| (* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *) | ||
| (* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *) | ||
| (* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *) | ||
| (* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *) | ||
| (* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *) | ||
| (* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *) | ||
| (* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *) | ||
| (* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *) | ||
| (* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *) | ||
| (* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *) | ||
| (* *) | ||
| (******************************************************************************) | ||
|
|
||
| (** Functions for displaying mcompare-compatible output *) | ||
|
|
||
| (* Convert a list of register state to string format, | ||
| suitable for printing final register states for mcompare *) | ||
| let final_regs_to_string (rs : MinState.reg_state list) = | ||
| String.concat " " | ||
| (List.map | ||
| (fun (r : MinState.reg_state) -> | ||
| Printf.sprintf "%d:%s=%d;" r.tid r.regname r.value | ||
| ) | ||
| rs | ||
| ) | ||
|
|
||
| (* Convert a list of memory state to string format, | ||
| suitable for printing final memory states for mcompare *) | ||
| let final_mem_to_string (ms : MinState.mem_state list) = | ||
| String.concat " " | ||
| (List.map | ||
| (fun (m : MinState.mem_state) -> Printf.sprintf "[%s]=%d;" m.sym m.value) | ||
| ms | ||
| ) | ||
|
|
||
| (* Print how often an outcome occurs, part of the required Mcompare output *) | ||
| let outcome_freq_to_string yes_freq no_freq = | ||
| if yes_freq = 0 then "Never" else if no_freq = 0 then "Always" else "Sometimes" | ||
|
|
||
| (* Return string of format: Observation <test name> <string freq> <true count> <false count>. | ||
| which is required for Mcompare output*) | ||
| let test_observation_stats_to_string obs_count not_obs_count test_name = | ||
| Printf.sprintf "Observation %s %s %d %d" test_name | ||
| (outcome_freq_to_string obs_count not_obs_count) | ||
| obs_count not_obs_count | ||
|
|
||
| module Make (Arch : Archsem.Arch) = struct | ||
| open Arch | ||
| module MinimiseState = MinState.Make (Arch) | ||
| module RunnerUtils = Runner_utils.Make (Arch) | ||
|
|
||
| (* Get the number of states which satisfy at least one condition in conds *) | ||
| let get_obs_count | ||
| (conds : (Testrepr.thread_cond list * Testrepr.mem_cond list) list) | ||
| (state_list : ArchState.t list) | ||
| = | ||
| List.length state_list | ||
| - List.length | ||
| (List.fold_left | ||
| (fun unmatched_state_list (cond, mem_cond) -> | ||
| List.filter | ||
| (fun fs -> | ||
| not | ||
| (RunnerUtils.check_outcome fs cond | ||
| && RunnerUtils.check_mem_outcome fs mem_cond | ||
| ) | ||
| ) | ||
| unmatched_state_list | ||
| ) | ||
| state_list conds | ||
| ) | ||
|
|
||
| (* Print observation statistics for Mcompare. The format is: | ||
| Ok/No <Optional extra detail> | ||
| Observation <test_name> Always/Sometimes/Never <#observed> <#not_observed> *) | ||
| let observation_statistics_string | ||
| (conds : (Testrepr.thread_cond list * Testrepr.mem_cond list) list) | ||
| (checking_for_positive : bool) | ||
| (state_list : ArchState.t list) | ||
| (test_name : string) : string | ||
| = | ||
| let (matched_msg, not_matched_msg) = | ||
| if checking_for_positive then ("Ok", "No (\"allowed\" not found)") | ||
| else ("No (\"not allowed\" found)", "Ok") | ||
| in | ||
| let obs_count = get_obs_count conds state_list in | ||
| let msg = if obs_count > 0 then matched_msg else not_matched_msg in | ||
| msg ^ "\n" | ||
| ^ test_observation_stats_to_string obs_count | ||
| (List.length state_list - obs_count) | ||
| test_name | ||
|
|
||
| (* Top-level function to call for mcompare-compatible output *) | ||
| let print_final_states | ||
| (observable : (Testrepr.thread_cond list * Testrepr.mem_cond list) list) | ||
| (unobservable : (Testrepr.thread_cond list * Testrepr.mem_cond list) list) | ||
| (final_states : ArchState.t list) | ||
| (test_name : string) : string | ||
| = | ||
| let conds = observable @ unobservable in | ||
| let unique_cond = MinimiseState.get_unique_conds_ignoring_value conds in | ||
| let minimised_fs = MinimiseState.minimise_states unique_cond final_states in | ||
| let unique_minimised_fs = List.sort_uniq compare minimised_fs in | ||
|
|
||
| (* Print number of distinct observed states *) | ||
| let states_count_part = | ||
| Printf.sprintf "States %d\n" (List.length unique_minimised_fs) | ||
| in | ||
| (* Print each distinct observable state *) | ||
| let state_list_part = | ||
| if conds <> [] then | ||
| List.map | ||
| (fun (regs_state, mems_state) -> | ||
| Printf.sprintf "%s %s\n" | ||
| (final_regs_to_string regs_state) | ||
| (final_mem_to_string mems_state) | ||
| ) | ||
| unique_minimised_fs | ||
| |> String.concat "" | ||
| else "" | ||
| in | ||
| let observation_part = | ||
| if | ||
| (* Print statistics about the condition(s) that we did and didn't want to observe *) | ||
| observable <> [] | ||
| then observation_statistics_string observable true final_states test_name | ||
| else if unobservable <> [] then | ||
| observation_statistics_string unobservable false final_states test_name | ||
| else "ERROR: no conditions to observe" | ||
| in | ||
|
|
||
| states_count_part ^ state_list_part ^ observation_part | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| (******************************************************************************) | ||
| (* ArchSem *) | ||
| (* *) | ||
| (* Copyright (c) 2021 *) | ||
| (* Thibaut Pérami, University of Cambridge *) | ||
| (* Yeji Han, Seoul National University *) | ||
| (* Zongyuan Liu, Aarhus University *) | ||
| (* Nils Lauermann, University of Cambridge *) | ||
| (* Jean Pichon-Pharabod, University of Cambridge, Aarhus University *) | ||
| (* Brian Campbell, University of Edinburgh *) | ||
| (* Alasdair Armstrong, University of Cambridge *) | ||
| (* Ben Simner, University of Cambridge *) | ||
| (* Peter Sewell, University of Cambridge *) | ||
| (* *) | ||
| (* Redistribution and use in source and binary forms, with or without *) | ||
| (* modification, are permitted provided that the following conditions *) | ||
| (* are met: *) | ||
| (* *) | ||
| (* 1. Redistributions of source code must retain the above copyright *) | ||
| (* notice, this list of conditions and the following disclaimer. *) | ||
| (* *) | ||
| (* 2. Redistributions in binary form must reproduce the above copyright *) | ||
| (* notice, this list of conditions and the following disclaimer in the *) | ||
| (* documentation and/or other materials provided with the distribution. *) | ||
| (* *) | ||
| (* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *) | ||
| (* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *) | ||
| (* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS *) | ||
| (* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE *) | ||
| (* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *) | ||
| (* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, *) | ||
| (* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS *) | ||
| (* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *) | ||
| (* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *) | ||
| (* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE *) | ||
| (* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *) | ||
| (* *) | ||
| (******************************************************************************) | ||
|
|
||
| (** Convert an ArchState.t into a (reg_state list * mem_state list), and related functions | ||
| *) | ||
|
|
||
| type reg_state = | ||
|
s-prism marked this conversation as resolved.
|
||
| { tid : int; | ||
| regname : string; | ||
| value : int | ||
| } | ||
|
|
||
| type mem_state = | ||
| { sym : string; | ||
| addr : int; | ||
| size : int; | ||
| value : int | ||
| } | ||
|
|
||
| module Make (Arch : Archsem.Arch) = struct | ||
| open Arch | ||
|
|
||
| (* Convert a collection of register conditions (each having a thread id and a register name) | ||
| into a list of thread-regname pairs *) | ||
| let get_thread_regname_pairs (reg_cond : Testrepr.thread_cond list) : | ||
| (int * string) list | ||
| = | ||
| List.concat_map | ||
| (fun (thread, reg_pair) -> | ||
| List.map (fun (name, _) -> (thread, name)) reg_pair | ||
| ) | ||
| reg_cond | ||
|
|
||
| (* Compare the memory symbol of 2 memory conditions *) | ||
| let compare_mem_sym | ||
| (mem_cond_1 : Testrepr.mem_cond) | ||
| (mem_cond_2 : Testrepr.mem_cond) | ||
| = | ||
| String.compare mem_cond_1.sym mem_cond_2.sym | ||
|
|
||
| (* From the test conditions, get a list of all unique thread-register pairs, | ||
| and a list of all unique memory symbols *) | ||
| let get_unique_conds_ignoring_value | ||
| (conds : (Testrepr.thread_cond list * Testrepr.mem_cond list) list) : | ||
| (int * string) list * Testrepr.mem_cond list | ||
| = | ||
| let (reg_conds, mem_conds) = List.split conds in | ||
| let all_reg_conds = get_thread_regname_pairs (List.flatten reg_conds) in | ||
| ( List.sort_uniq compare all_reg_conds, | ||
| List.sort_uniq compare_mem_sym (List.flatten mem_conds) | ||
| ) | ||
|
|
||
| (* From a final state, extract the registers (and values) that the register conditions check *) | ||
| let minimise_reg_state (reg_conds : (int * string) list) (state : ArchState.t) : | ||
| reg_state list | ||
| = | ||
| List.map | ||
| (fun (tid, regname) -> | ||
| let regs = ArchState.reg tid state in | ||
| let value = RegMap.geti (Reg.of_string regname) regs in | ||
| {tid; regname; value} | ||
| ) | ||
| reg_conds | ||
|
|
||
| (* From a final state, extract the memory locations (and values) that the memory conditions check *) | ||
| let minimise_mem_state (mem_conds : Testrepr.mem_cond list) (state : ArchState.t) | ||
| : mem_state list | ||
| = | ||
| let mem = ArchState.mem state in | ||
| List.map | ||
| (fun (mc : Testrepr.mem_cond) -> | ||
| let value = MemMap.lookupi mc.addr mc.size mem in | ||
| {sym = mc.sym; addr = mc.addr; size = mc.size; value} | ||
| ) | ||
| mem_conds | ||
|
|
||
| (* For a list of final states, for each final state, | ||
| extract the registers and memory locations that the conditions check | ||
| (with the final values of these locations) *) | ||
| let minimise_states | ||
| ((reg_conds, mem_conds) : (int * string) list * Testrepr.mem_cond list) | ||
| (states : ArchState.t list) : (reg_state list * mem_state list) list | ||
| = | ||
| List.map | ||
| (fun state -> | ||
| (minimise_reg_state reg_conds state, minimise_mem_state mem_conds state) | ||
| ) | ||
| states | ||
|
|
||
| (* Find all the registers and memory locations that the conditions check, | ||
| extract only those locations from each final state, and deduplicate them *) | ||
| let get_unique_minimised_states | ||
| (conds : (Testrepr.thread_cond list * Testrepr.mem_cond list) list) | ||
| (final_states : ArchState.t list) : (reg_state list * mem_state list) list | ||
| = | ||
| let unique_cond = get_unique_conds_ignoring_value conds in | ||
| let minimised_fs = minimise_states unique_cond final_states in | ||
| List.sort_uniq compare minimised_fs | ||
| end | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.