~ubuntu-branches/ubuntu/quantal/xen-api/quantal

« back to all changes in this revision

Viewing changes to ocaml/xstest/xstest.ml

  • Committer: Package Import Robot
  • Author(s): Jon Ludlam
  • Date: 2011-07-07 21:50:18 UTC
  • Revision ID: package-import@ubuntu.com-20110707215018-3t9ekbh7qy5y2b1p
Tags: upstream-1.3
ImportĀ upstreamĀ versionĀ 1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(*
 
2
 * Copyright (C) 2006-2009 Citrix Systems Inc.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published
 
6
 * by the Free Software Foundation; version 2.1 only. with the special
 
7
 * exception on linking described in file LICENSE.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU Lesser General Public License for more details.
 
13
 *)
 
14
(***************************************************************************
 
15
 * Testing code
 
16
 **************************************************************************)
 
17
open Printf
 
18
open Stringext
 
19
open Common
 
20
open Xenbus
 
21
 
 
22
let tnb data =
 
23
        try int_of_string (List.hd (String.split '\000' data))
 
24
        with _ -> 0
 
25
 
 
26
let do_test xb =
 
27
        let i = ref 0 in
 
28
        let disp op pkt =
 
29
                let tid, rid, ty, data = pkt in
 
30
                printf "%3x %s %d(%d) %s \"%s\".\n%!" !i op tid rid (Xb.Op.to_string ty) (String.escaped data);
 
31
                in
 
32
        let y (tid, ty, data) =
 
33
                let spkt = (tid, !i, ty, data) in 
 
34
                disp "S: " spkt;
 
35
                send_packet xb tid !i ty data;
 
36
                let rpkt = recv_packet xb in
 
37
                disp "R: " rpkt;
 
38
                incr i;
 
39
                let (_, _, _, data) = rpkt in
 
40
                data
 
41
                in
 
42
        let x spkt = ignore (y spkt) in
 
43
        (* no arguments *)
 
44
        x (0, Xb.Op.Read, "\000");
 
45
        x (0, Xb.Op.Write, "\000");
 
46
        x (0, Xb.Op.Getdomainpath, "\000");
 
47
        x (0, Xb.Op.Directory, "\000");
 
48
        x (0, Xb.Op.Mkdir, "\000");
 
49
        x (0, Xb.Op.Getperms, "\000");
 
50
        x (0, Xb.Op.Setperms, "\000");
 
51
 
 
52
        (* too many arguments *)
 
53
        x (0, Xb.Op.Write, "/test\000xxx\000yyy\000\000zzz");
 
54
        x (0, Xb.Op.Read, "/test");
 
55
        x (0, Xb.Op.Read, "/test\000");
 
56
        x (0, Xb.Op.Read, "/test\000some\000otherargs");
 
57
        x (0, Xb.Op.Directory, "/test\000spurious\000abc");
 
58
        x (0, Xb.Op.Directory, "/test\000spurious");
 
59
        x (0, Xb.Op.Getperms, "/test\000someotherargs");
 
60
        x (0, Xb.Op.Getperms, "/test\000someotherargs\000others");
 
61
 
 
62
        (* others *)
 
63
        x (0, Xb.Op.Write, "/test\000");
 
64
        x (0, Xb.Op.Write, "/test\000abc");
 
65
        x (0, Xb.Op.Read, "/test");
 
66
        x (0, Xb.Op.Read, "/test\000");
 
67
        x (0, Xb.Op.Read, "/test\000\000");
 
68
        x (0, Xb.Op.Write, "/test");
 
69
        x (0, Xb.Op.Read, "/test");
 
70
        x (0, Xb.Op.Read, "/test\000");
 
71
        x (0, Xb.Op.Read, "/test\000\000");
 
72
 
 
73
        x (0, Xb.Op.Write, "\000/");
 
74
 
 
75
        x (0, Xb.Op.Directory, "/test");
 
76
        x (0, Xb.Op.Directory, "/test\000");
 
77
        x (0, Xb.Op.Directory, "/test\000\000");
 
78
 
 
79
        x (0, Xb.Op.Rm, "/test");
 
80
        x (0, Xb.Op.Directory, "/test");
 
81
        x (0, Xb.Op.Directory, "/test\000");
 
82
        x (0, Xb.Op.Directory, "/test\000\000");
 
83
 
 
84
        x (0, Xb.Op.Write, "/test/abc\000x1");
 
85
        x (0, Xb.Op.Write, "/test/def\000x2");
 
86
        x (0, Xb.Op.Write, "/test/xyz\000x3");
 
87
        x (0, Xb.Op.Write, "/test/xyz\000x4");
 
88
 
 
89
        x (0, Xb.Op.Directory, "/test");
 
90
        x (0, Xb.Op.Directory, "/test\000");
 
91
        x (0, Xb.Op.Directory, "/test\000spurious\000");
 
92
 
 
93
        x (0, Xb.Op.Getperms, "/test");
 
94
        x (0, Xb.Op.Getperms, "/test\000");
 
95
        x (0, Xb.Op.Getperms, "/test\000spurious\000");
 
96
 
 
97
        (* setperms getperms *)
 
98
        x (0, Xb.Op.Setperms, "/test");
 
99
        x (0, Xb.Op.Getperms, "/test\000");
 
100
        x (0, Xb.Op.Setperms, "/test\000");
 
101
        x (0, Xb.Op.Getperms, "/test\000");
 
102
        x (0, Xb.Op.Setperms, "/test\000\000");
 
103
        x (0, Xb.Op.Getperms, "/test\000");
 
104
        x (0, Xb.Op.Setperms, "/test\000n0\000");
 
105
        x (0, Xb.Op.Getperms, "/test\000");
 
106
        x (0, Xb.Op.Setperms, "/test\000n0");
 
107
        x (0, Xb.Op.Getperms, "/test\000");
 
108
        x (0, Xb.Op.Setperms, "/test\000n0\000r1");
 
109
        x (0, Xb.Op.Getperms, "/test\000");
 
110
        x (0, Xb.Op.Setperms, "/test\000n0\000r1\000");
 
111
        x (0, Xb.Op.Getperms, "/test\000");
 
112
        x (0, Xb.Op.Setperms, "/test\000n0r2\000spurious");
 
113
        x (0, Xb.Op.Getperms, "/test\000");
 
114
 
 
115
        (* get domain path *)
 
116
        x (0, Xb.Op.Getdomainpath, "3\000");
 
117
        x (0, Xb.Op.Getdomainpath, "10\000");
 
118
        x (0, Xb.Op.Getdomainpath, "13 \000");
 
119
        x (0, Xb.Op.Getdomainpath, " 17\000");
 
120
        x (0, Xb.Op.Getdomainpath, "45\000spurious");
 
121
        x (0, Xb.Op.Getdomainpath, "45\000really\000");
 
122
 
 
123
        let t1 = tnb (y (0, Xb.Op.Transaction_start, "\000")) in
 
124
        x (t1, Xb.Op.Transaction_end, "\000");
 
125
        let t2 = tnb (y (0, Xb.Op.Transaction_start, "\000")) in
 
126
        x (t2, Xb.Op.Transaction_end, string_of_int t2 ^ "\000");
 
127
        let t3 = tnb (y (0, Xb.Op.Transaction_start, "\000\000")) in
 
128
        x (t3, Xb.Op.Transaction_end, "0\000\000");
 
129
        ()
 
130
 
 
131
(***************************************************************************
 
132
 * Main
 
133
 **************************************************************************)
 
134
open Pervasiveext
 
135
 
 
136
let () =
 
137
        let xb = open_xb () in
 
138
        finally (fun () -> do_test xb) (fun () -> close_xb xb);