From 90b4b230bfbe76a66ce1551c873532fe46c76d04 Mon Sep 17 00:00:00 2001 From: Romain Date: Tue, 20 May 2025 10:59:38 +0200 Subject: [PATCH] add --junit-mem-peak --- CHANGES.md | 5 ++++- lib_core/cli.ml | 14 ++++++++++++-- lib_core/cli.mli | 3 +++ lib_core/test.ml | 15 +++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 25abc4cb..70c7cce4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,12 +10,15 @@ - Added `--record-mem-peak`. It causes Tezt to regularly measure the memory usage of tests - and to record the peak in reports when using `--record`. + and to record the peak in reports when using `--record` or `--junit`. Only works with `-j N` with `N` being at least 2. - Added `--mem-poll-frequency`, which controls how often memory usage is measured when using `--record-mem-peak`. +- Added `--junit-mem-peak`. + It allows to specify the name of the JUnit property where to store peak memory usage. + ### Breaking Changes - Tezt is no longer available for OCaml versions earlier than 4.13. diff --git a/lib_core/cli.ml b/lib_core/cli.ml index ff1fc17d..0b0c39a0 100644 --- a/lib_core/cli.ml +++ b/lib_core/cli.ml @@ -413,8 +413,8 @@ module Reports = struct ~section ~set_long:"record-mem-peak" ~description: - "Include peak memory usage of tests in --record files. Only work with \ - -j and useless without --record." + "Include peak memory usage of tests in --record files and JUnit \ + reports. Only work with -j and useless without --record or --junit." false let from_records = @@ -446,6 +446,16 @@ module Reports = struct session. Test result (success or failure) is the result for the last \ run of the test." () + + let junit_mem_peak = + Clap.default_string + ~section + ~long:"junit-mem-peak" + ~placeholder:"PROPERTY_NAME" + ~description: + "If peak memory usage is recorded (with --record-mem-peak), it is also \ + stored in JUnit files as a with this name." + "memory.peak" end module Commands = struct diff --git a/lib_core/cli.mli b/lib_core/cli.mli index 7aa5733c..cc68bae6 100644 --- a/lib_core/cli.mli +++ b/lib_core/cli.mli @@ -179,6 +179,9 @@ module Reports : sig (** [--junit] *) val junit : string option + + (** [--junit-mem-peak] *) + val junit_mem_peak : string end module Commands : sig diff --git a/lib_core/test.ml b/lib_core/test.ml index 51633dfc..7cdf2596 100644 --- a/lib_core/test.ml +++ b/lib_core/test.ml @@ -1114,6 +1114,11 @@ let output_junit filename = Buffer.contents buffer in let title = replace_entities test.title in + let properties = + match test.session_peak_memory_usage with + | None -> [] + | Some peak -> [(Cli.Reports.junit_mem_peak, string_of_int peak)] + in echo {| |} title @@ -1121,6 +1126,16 @@ let output_junit filename = title (test_time test) test.session_retries ; + (match properties with + | [] -> () + | _ :: _ -> + echo {| |} ; + ( Fun.flip List.iter properties @@ fun (name, value) -> + echo + {| |} + (replace_entities name) + (replace_entities value) ) ; + echo {| |}) ; (match test.result with | None | Some Successful | Some Aborted -> () | Some (Failed message) -> -- GitLab