forked from xapi-project/xen-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_pusb.ml
68 lines (64 loc) · 2.31 KB
/
test_pusb.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
(*
* Copyright (C) Citrix Systems Inc.
*
* 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.
*)
let create_base_environment () =
let __context = Test_common.make_test_database () in
let pusb = Test_common.make_sr ~__context () in
(__context, pusb)
let start_thread ~__context info =
let usbs = Xapi_pusb_helpers.get_usbs info in
let f () = Xapi_pusb.scan_start ~__context usbs in
Xapi_pusb.start_thread f
let test_scan_with_usb_add_and_remove () =
let __context = Test_common.make_test_database () in
let test_pusb =
"[{\n\
\ \"product-desc\": \"\",\n\
\ \"product-id\": \"5591\",\n\
\ \"description\": \"SanDisk \
Corp._4C530001131223117342\",\n\
\ \"vendor-desc\": \"SanDisk Corp.\",\n\
\ \"version\": \"3.00\",\n\
\ \"vendor-id\": \"0781\",\n\
\ \"path\": \"2-2\",\n\
\ \"serial\": \"4C530001131223117342\",\n\
\ \"speed\": \"480\"\n\
\ }]"
in
(* add usb*)
start_thread ~__context test_pusb ;
let host = Helpers.get_localhost ~__context in
Xapi_pusb.scan ~__context ~host ;
Thread.delay 1.0 ;
(* delete PUSB from DB*)
List.iter
(fun (self, _) ->
let usb_group = Db.PUSB.get_USB_group ~__context ~self in
Db.PUSB.destroy ~__context ~self ;
Db.USB_group.destroy ~__context ~self:usb_group
)
(Db.PUSB.get_all_records ~__context) ;
Xapi_pusb.scan ~__context ~host ;
Thread.delay 1.0 ;
Alcotest.(check int)
"test_scan_with_usb_add_and_remove called assertion for number of PUSB \
records"
1
(List.length (Db.PUSB.get_all_records ~__context))
let test =
[
( "test_scan_with_usb_add_and_remove"
, `Quick
, test_scan_with_usb_add_and_remove
)
]