forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check index before using it removing an element from Imperative prior…
…ity queue The queue uses an Array larger than the current size. It's possible that code check the index much later returning error but also setting the queue in an invalid state. So to avoid structure corruption check the index as soon as possible. Signed-off-by: Frediano Ziglio <[email protected]>
- Loading branch information
Showing
4 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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
40 changes: 40 additions & 0 deletions
40
ocaml/libs/xapi-stdext/lib/xapi-stdext-threads/ipq_test.ml
This file contains 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,40 @@ | ||
(* | ||
* Copyright (C) 2024 Cloud Software Group | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation; version 2.1 only. with the special | ||
* exception on linking described in file LICENSE. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
*) | ||
|
||
module Ipq = Xapi_stdext_threads_scheduler.Ipq | ||
|
||
(* test we get "out of bound" exception calling Ipq.remove *) | ||
let test_out_of_index () = | ||
let q = Ipq.create 10 in | ||
Ipq.add q {Ipq.ev= 123; Ipq.time= Mtime_clock.now ()} ; | ||
let is_oob = function | ||
| Invalid_argument s when String.ends_with ~suffix:" out of bounds" s -> | ||
true | ||
| _ -> | ||
false | ||
in | ||
let oob_check n = | ||
(Alcotest.match_raises "out of bound" is_oob @@ fun () -> Ipq.remove q n) ; | ||
Alcotest.(check bool) "same value" false (Ipq.is_empty q) | ||
in | ||
oob_check 10 ; | ||
oob_check (-1) ; | ||
oob_check 9 ; | ||
oob_check 1 ; | ||
(* this should succeed *) | ||
Ipq.remove q 0 | ||
|
||
let tests = [("test_out_of_index", `Quick, test_out_of_index)] | ||
|
||
let () = Alcotest.run "Ipq" [("generic", tests)] |
Empty file.